Skip to main content
Version: 2.x.x

Room Connection Events - React Native

VideoSDK offers the onRoomStateChanged() event, providing information about the current connection state of the room.

onRoomStateChanged()​

  • This event is triggered when the state of a room changes.
  • The event callback will include the current state of the room, which can be one of the following: CONNECTING, CONNECTED, RECONNECTING, DISCONNECTED, FAILED. These states are also available as Constants.RoomState.
    • CONNECTING: The room is connecting.
    • CONNECTED: The room is connected.
    • RECONNECTING: The connection dropped and the SDK is reconnecting.
    • DISCONNECTED: The room connection is closed.
    • FAILED: The room connection failed.
  • The callback receives { roomState }.
  • It can be subscribed to using the useRoom hook.

Example​

Here is an example demonstrating the usage of the event mentioned on this page.

function onRoomStateChanged(data) {
const { roomState } = data;

switch(roomState){
case 'CONNECTING':
console.log("Room is Connecting" );
break;
case 'CONNECTED':
console.log("Room is Connected" );
break;
case 'RECONNECTING':
console.log("Room is Reconnecting" );
break;
case 'FAILED':
console.log("Room connection failed" );
break;
case 'DISCONNECTED':
console.log("Room connection closed" );
break;
}
}

const { roomId } = useRoom({
onRoomStateChanged,
});

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