Skip to main content
Version: 2.x.x

Room Events - React Native

VideoSDK provides several types of events that can be listened to in order to determine the current state of the room.

Here are the events specifically related to the room:

onRoomJoined()​

  • This event is triggered when the room is successfully joined.
  • It receives an object { messages, switchRoomId }. switchRoomId is the id of the room that switchTo() landed in, or null for an ordinary join. messages is always empty on React Native.
  • It can be subscribed to using the useRoom hook.

onRoomLeft()​

  • This event is triggered when the room is left. It receives a reason object with a code and a message. Compare code with Constants.leaveReason. You can refer to the reason details here
  • It can be subscribed to using the useRoom hook.

onSpeakerChanged()​

  • This event is triggered when there is a change in the active speaker during the room. It receives the speaker's participant id, or null when nobody is speaking.
  • To read the current speaker at any time, call getActiveSpeakerId() from useRoom().
  • It can be subscribed to using the useRoom hook.

onPresenterChanged()​

  • This event is triggered when there is a change in the presenter during the room. It receives the presenter's participant id, or null when the share stops.
  • To read the current presenter at any time, call getActivePresenterId() from useRoom().
  • It can be subscribed to using the useRoom hook.

Example​

Here is the usage of all the events mentioned in this page.

function onRoomJoined({ switchRoomId }) {
// switchRoomId is null unless switchTo() moved you to another room
console.log("onRoomJoined", switchRoomId);
}

function onRoomLeft(reason) {
console.log("onRoomLeft", reason.code, reason.message);
}

function onSpeakerChanged(activeSpeakerId) {
console.log("onSpeakerChanged", activeSpeakerId);
}

function onPresenterChanged(presenterId) {
console.log("onPresenterChanged", presenterId);
}

const { roomId } = useRoom({
onRoomJoined,
onRoomLeft,
onSpeakerChanged,
onPresenterChanged,
});

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