Join Room
To join and interact with others in audio or video call, the user needs to join a room
.
Prerequisites
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.
- Auth Token - the client side authentication token generated by the Token Service.
Join a Room
We'll call the join
method on HMSSDK
object with a config containing above fields to join the room.
Create HMSSDK Instance
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 -
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 } }
Optional: Join with Muted Audio / Video
You can optionally set the initial audio/video state at the time of joining like below (they are unmute by default):
class MyMeetingClass { let hmsSDK: HMSSDK // store instance of HMSSDK as a property in your class init() { // initialize the SDK using the `build()` class function hmsSDK = HMSSDK.build() { sdk in sdk.trackSettings = HMSTrackSettings.build { videoSettingsBuilder, audioSettingsBuilder in videoSettingsBuilder.initialMuteState = .mute audioSettingsBuilder.initialMuteState = .mute } } } }
Create HMSConfig Instance
Next, create an object of HMSConfig
class using the available joining configurations
let config = HMSConfig(userName: "John Doe", authToken: "eyJH5c")
Optional: Set metadata for the user
Optionally, you can use metadata param that can be used to attach any additional data associated with this user. You can access this data on this peer later using peer's 'metadata' property.
let config = HMSConfig(userName: "John Doe", authToken: "eyJH5c", metadata: "{"avatar": "location/on/amazon/storage"}")
Call join
Now, we are primed to join the room. All you have to do is pass the config
object to hmsSDK
hmsSDK.join(config: config, delegate: self)
Once on(join room: HMSRoom) callback is fired you have joined the room successfully. 🥳
class MyMeetingClass: HMSUpdateListener { func on(join room: HMSRoom) { ... } }
Note: Make sure to wait for onJoin callback before calling any other SDK API (except leave) as they require an active connection and will fail with a “not connected” error.
Join API Signature
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 typeHMSConfig
class, the room configuration object which encapsulates user & token datadelegate
: a class conforming toHMSUpdateListener
protocol.
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.