Join Room - Android
Overview
createRoom() returns a new Room instance. If you have not created a room yet, you can follow the guide here. The room does not join automatically. To join it, call join().
join()
- To join the room, call the
join()method of theRoomclass. - Call it after the room is created with
VideoSDK.createRoom(). join()is asuspendfunction, so call it from a coroutine, for examplelifecycleScope.launch(fromandroidx.lifecycle:lifecycle-runtime-ktx). See Coroutines and Error Handling.- You are in the room once
onRoomJoinedfires, not whenjoin()returns. The event can arrive beforejoin()returns. - Add your
RoomEventListenerbefore you calljoin(), or you can miss the first events. - Get the
CAMERAandRECORD_AUDIOpermissions before you calljoin(). The SDK does not ask for them, and a missing permission leaves that device off. See Precall Setup. - If the room can't be joined,
join()throwsVideoSDKException:3055(ERROR_OPERATION_IN_PROGRESS) if a join is already running.3054(ERROR_ALREADY_IN_REQUESTED_STATE) if the room is already joined.3056(ERROR_OPERATION_ABORTED) ifleave()cancelled the join.- The server's error code, such as
4002(INVALID_TOKEN) for a token the server rejects, or3047(ERROR_UNABLE_TO_JOIN_ROOM).
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// create the room
...
// join the room
lifecycleScope.launch {
try {
room!!.join()
} catch (e: VideoSDKException) {
Log.e("VideoSDK", "Join failed: ${e.code} ${e.name}")
}
}
}
}
Events associated with Join
The following callbacks are received when a participant joins successfully.
- Local Participant will receive an
onRoomJoinedevent, when successfully joined. It can arrive beforejoin()returns. - Remote Participant will receive an
onParticipantJoinedevent with the newly joinedParticipantobject from the event callback.
note
onRoomJoined also fires again on the same Room after a reconnect that needed a fresh join, and after switchTo(), where switchRoomId is the new room's id. Don't use it for one-time setup. After a reconnect or a room switch, the SDK turns your mic and camera back on as they were before.
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// create the room
...
// Add event listener for listening upcoming events of the room
room!!.addEventListener(roomEventListener)
// join the room
lifecycleScope.launch {
try {
room!!.join()
} catch (e: VideoSDKException) {
Log.e("VideoSDK", "Join failed: ${e.code} ${e.name}")
}
}
}
private val roomEventListener: RoomEventListener = object : RoomEventListener() {
// Event to know the room is joined
override fun onRoomJoined(switchRoomId: String?) {
Log.d("VideoSDK", "onRoomJoined")
}
// Event to know some other participant joined
override fun onParticipantJoined(participant: Participant) {
Log.d("#VideoSDK", participant.displayName + " joined")
}
}
}
API Reference
The API references for all the methods and events utilised in this guide are provided below.
Got a Question? Ask us on discord

