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, aRoomState, as an event callback parameter which will indicate current state of the room.room.roomStateholds 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,
DISCONNECTEDfollows.
- CONNECTING: The room is in the process of establishing a connection. It fires when
-
Override it in a
RoomEventListenerand register the listener withroom.addEventListener(). -
When a join fails, this event reports
FAILEDandjoin()also throws aVideoSDKException. Handle the failure where you calljoin(). -
After a join fails, call
leave(): it releases the room and firesonRoomLeftwithLeaveReason.MANUAL_LEAVE_CALLED. To try again, create a new room withVideoSDK.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.
onRoomJoinedfires again, the room goes back toCONNECTED, and your mic and camera come back as they were. - If the network doesn't return within 2 minutes, the room goes
FAILED, thenDISCONNECTED, andonRoomLeftfires withLeaveReason.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
onParticipantLeftfor you, thenonParticipantJoinedwhen 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

