Join Room

Overview

To join and interact with others in audio or video call, the user needs to join a room.

When user indicates that they want to join the room, your app should have -

  1. User Name - the name which should be displayed to other peers in the room.
  2. Auth Token - the client side authentication token generated by the Token Service.

You can also optionally pass these fields -

  1. Track settings can used to set initial audio/video mute status.
  2. User metadata - this can be used to pass any additional metadata associated with the user.

Join a Room

We'll call the join method on the HMSSDK object with an optional config containing above fields to join the room.

  1. First, create an instance of HMSSDK class. Store this instance as a property. Ensure that the SDK object is alive in memory so that you can receive event callbacks from SDK. The simplest way to do this is:
private val hmsSDK = HMSSDK .Builder(application) // Optional .setTrackSettings(trackSettings) .build()

Note: If you are using Preview then you must already have an instance of HMSSDK before invoking Preview APIs.

  1. Next, create an object of HMSConfig class using the available joining configurations.

We will be passing in:

  • A user display name.
  • The auth token.
  • Metadata for the peer.
val hmsConfig = HMSConfig( userName = "user display name", authtoken = authToken, metadata = """{city: 'Winterfell', knowledge: 'nothing'}""")
  1. You'll want to handle the callbacks from joining the room by making your ViewModel, Presenter or whatever you're using to handle business logic implement the HMSUpdateListener interface.

  2. Now, we are primed to join the room. All you have to do is pass the config object to hmsSDK

fun joinRoom(config : HMSConfig, hmsUpdateListener : HMSUpdateListener){ hmsSdk.join(config, hmsUpdateListener) }

That's it. You have joined a room successfully 🥳. You should now be able to have an audio only call with this.

Now, let's take a look at the signature of the Join API

fun join(config: HMSConfig, hmsUpdateListener: HMSUpdateListener)

As evident, join accepts 2 arguments -

  • config: an object of type HMSConfig class, the room configuration object which encapsulates user & token data.
  • hmsUpdateListener: a class conforming to HMSUpdateListener interface.

The methods of HMSUpdateListener are invoked to notify updates happening in the room like a peer joins/leaves, a track got muted/unmutes, etc.

After calling join your app will be provided an update from the 100ms SDK.

If successful, the fun onJoin(room: HMSRoom) method of HMSUpdateListener will be invoked with information about the room encapsulated in the HMSRoom object.

If failure, the fun onError(error: HMSException) method will be invoked with exact failure reason.

Getting Current Room State

To navigate to another page once join has completed:

Use the onJoin callback in HMSUpdateListener.

fun joinRoom(config : HMSConfig){ hmsSDK.join(config, object : fun onJoin(room: HMSRoom) { override fun onJoin(room: HMSRoom) { // called when the user joins. } ... }) }

Have a suggestion? Recommend changes ->

Was this helpful?

1234