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 }.switchRoomIdis the id of the room thatswitchTo()landed in, ornullfor an ordinary join.messagesis always empty on React Native. - It can be subscribed to using the
useRoomhook.
onRoomLeft()
- This event is triggered when the room is left. It receives a reason object with a
codeand amessage. ComparecodewithConstants.leaveReason. You can refer to the reason details here - It can be subscribed to using the
useRoomhook.
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
nullwhen nobody is speaking. - To read the current speaker at any time, call
getActiveSpeakerId()fromuseRoom(). - It can be subscribed to using the
useRoomhook.
onPresenterChanged()
- This event is triggered when there is a change in the presenter during the room. It receives the presenter's participant id, or
nullwhen the share stops. - To read the current presenter at any time, call
getActivePresenterId()fromuseRoom(). - It can be subscribed to using the
useRoomhook.
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

