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 -
userName, the name which should be displayed to other peers in the roomuserID, a unique identifier for the user. It can be your reference identifier or a UUID string.roomID, the unique room identifier which would have been generated & passed to your app from backendauthToken, 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
HMSSDKclass. 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 -
import HMSSDK class MyMeetingClass { let hmsSDK: HMSSDK // store instance of HMSSDK as a property in your class init() { hmsSDK = HMSSDK.build() // initialize the SDK using the `build()` class function } }
Note: If you are using Preview then you must already have an instance of HMSSDK before invoking Preview APIs.
- Next, create an object of
HMSConfigclass using the available joining configurations
let config = HMSConfig(userName: "My good name", userID: UUID().uuidString, roomID: "abc123", authToken: "eyJH5c")
- Now, we are primed to join the room. All you have to do is pass the
configobject tohmsSDK
hmsSDK.join(config: config, delegate: self)
That's it. You have joined a room successfully. 🥳
Now, let's take a look at the signature of the Join API
func join(config: HMSConfig, delegate: HMSUpdateListener)
As evident, join accepts 2 arguments -
config: an object of typeHMSConfigclass, the room configuration object which encapsulates user & token datadelegate: a class conforming toHMSUpdateListenerprotocol.
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 func on(join room: HMSRoom) method of HMSUpdateListener will be invoked with information about the room encapsulated in the HMSRoom object.
❌ If failure, the func on(error: HMSError) method will be invoked with exact failure reason.