Join Room
Joining a room is one of the most basic functionalities so we at 100ms have built an easy, developer friendly API to get you started.
A user can interact with participants of a room only after joining the room.
When user indicates that they want to join the room, your app should have -
- User Name, the name which should be displayed to other peers in the room
- User ID, a unique identifier for the user. Usually a UUID string.
- Room ID, the unique room identifier which would have been generated & passed to your app from the backend.
- Authentication Token, the client side authentication token generated by your Token Service.
Now that you have aforementioned data, you can proceed to join a room.
- 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. Simplest way to do this is as follows -
private val hmsSDK = HMSSDK .Builder(application) .build()
Note: If you are using Preview then you must already have an instance of HMSSDK before invoking Preview APIs.
- Next, create an object of
HMSConfig
class using the available joining configurations
val hmsConfig = HMSConfig("user display name", authToken)
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 and overriding the methods.
Now, we are primed to join the room. All you have to do is pass the
config
object tohmsSDK
fun joinRoom(config : HMSConfig, hmsUpdateListener : HMSUpdateListener){ hmsSDK.join(config, hmsUpdateListener) }
That's it. You have joined a room successfully. 🥳
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 typeHMSConfig
class, the room configuration object which encapsulates user & token data.hmsUpdateListener
: a class conforming toHMSUpdateListener
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.