onRoomStateChanged

open fun onRoomStateChanged(roomState: RoomState)

Called on every connection-state transition. Fired on the main thread. Room.roomState holds the latest one.

RoomState.CONNECTING arrives as Room.join starts. RoomState.CONNECTED arrives with onRoomJoined, and on its own when a media outage healed in place without a rejoin. RoomState.RECONNECTING means actions are refused with 3065 until it clears. RoomState.FAILED arrives once when a join fails or a reconnect gives up, and is unrecoverable. RoomState.DISCONNECTED is delivered exactly once per session, always immediately before onRoomLeft.

Code Example:

room.addEventListener(object : RoomEventListener() {
override fun onRoomStateChanged(roomState: RoomState) {
when (roomState) {
RoomState.CONNECTING -> showSpinner("Joining…")
RoomState.RECONNECTING -> showSpinner("Reconnecting…")
RoomState.CONNECTED -> hideSpinner()
RoomState.FAILED -> showError("Could not connect")
RoomState.DISCONNECTED -> Unit
}
}
})