Skip to main content
Version: 3.x.x

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 the Room class.
  • Call it after the room is created with VideoSDK.createRoom().
  • join() is a suspend function, so call it from a coroutine, for example lifecycleScope.launch (from androidx.lifecycle:lifecycle-runtime-ktx). See Coroutines and Error Handling.
  • You are in the room once onRoomJoined fires, not when join() returns. The event can arrive before join() returns.
  • Add your RoomEventListener before you call join(), or you can miss the first events.
  • Get the CAMERA and RECORD_AUDIO permissions before you call join(). 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() throws VideoSDKException:
    • 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) if leave() cancelled the join.
    • The server's error code, such as 4002 (INVALID_TOKEN) for a token the server rejects, or 3047 (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.

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