Skip to main content
Version: 3.x.x

Room Connection Events - Android

The onRoomStateChanged event tells you the current connection state of the room.

onRoomStateChanged​

  • This event will be triggered when state of room changes.

  • It will pass roomState, a RoomState, as an event callback parameter which will indicate current state of the room. room.roomState holds the latest state.

  • All available states are :

    • CONNECTING: The room is in the process of establishing a connection. It fires when join() starts.
    • CONNECTED: The room has successfully connected. It fires right after onRoomJoined, and again when the connection recovers without rejoining.
    • RECONNECTING: The room is trying to reconnect after the connection was lost. Until it recovers, most actions are refused with 3065 (ERROR_ROOM_RECONNECTING).
    • DISCONNECTED: The room has been disconnected. It fires once per session, just before onRoomLeft.
    • FAILED: The join failed, or reconnecting gave up. The SDK does not retry it. When reconnecting gives up, DISCONNECTED follows.
  • Override it in a RoomEventListener and register the listener with room.addEventListener().

  • When a join fails, this event reports FAILED and join() also throws a VideoSDKException. Handle the failure where you call join().

  • After a join fails, call leave(): it releases the room and fires onRoomLeft with LeaveReason.MANUAL_LEAVE_CALLED. To try again, create a new room with VideoSDK.createRoom() and join that.

When the network drops​

  • The room goes RECONNECTING, and the SDK keeps trying to get back in. While the phone has no network at all, it waits for the network to return instead of using up its attempts, for up to 2 minutes.
  • A short outage reconnects by itself. onRoomJoined fires again, the room goes back to CONNECTED, and your mic and camera come back as they were.
  • If the network doesn't return within 2 minutes, the room goes FAILED, then DISCONNECTED, and onRoomLeft fires with LeaveReason.WEBSOCKET_CONNECTION_ATTEMPTS_EXHAUSTED. To continue, create a new room and join it.
  • Other participants see the drop only if it lasts more than about 64 seconds: they get onParticipantLeft for you, then onParticipantJoined when you're back.

Example​

Here is the usage of the event mentioned in this page.

private val roomEventListener: RoomEventListener = object : RoomEventListener() {
override fun onRoomStateChanged(roomState: RoomState) {
when (roomState) {
RoomState.CONNECTING -> {
Log.d("onRoomStateChanged", "Room is Connecting")
}
RoomState.CONNECTED -> {
Log.d("onRoomStateChanged", "Room is Connected")
}
RoomState.RECONNECTING -> {
Log.d("onRoomStateChanged", "Room is RECONNECTING")
}
RoomState.DISCONNECTED -> {
Log.d("onRoomStateChanged", "Room is Disconnected")
}
RoomState.FAILED -> {
Log.d("onRoomStateChanged", "Room connection Failed")
}
}
}

}

override fun onCreate(savedInstanceState: Bundle?) {
//...

// add listener to room
room!!.addEventListener(roomEventListener)
}

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