Skip to main content
Version: 2.x.x

Participant Events - React Native

VideoSDK provides multiple types of events which can be listened to know about the participants in the room.

Here are the events specifically related to the participant:

onParticipantJoined()​

  • This event is triggered when someone joins the room, returning the Participant object as parameter.
  • It can be subscribed to using the useRoom hook.

onParticipantLeft()​

  • This event is triggered when a participant leaves the room, returning the Participant object and a reason. You can refer to the reason details here
  • It can be subscribed to using the useRoom hook.

onWebcamRequested()​

  • This event is triggered for participant B, when another participant, A requests to enable their webcam.
  • It passes the participantId of participant A, and accept() and reject(). accept() turns participant B's webcam on. reject() declines the request.
  • It can be subscribed to using the useRoom hook.

onMicRequested()​

  • This event is triggered for participant B, when another participant, A requests to enable their mic.
  • It passes the participantId of participant A, and accept() and reject(). accept() turns participant B's mic on. reject() declines the request.
  • It can be subscribed to using the useRoom hook.

Example​

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

function onMicRequested({ participantId, accept, reject }) {
// participantId is the participant who asked to enable your mic
accept(); // or reject()
}

function onWebcamRequested({ participantId, accept, reject }) {
// participantId is the participant who asked to enable your webcam
accept(); // or reject()
}

function onParticipantJoined(participant) {
console.log(" onParticipantJoined", participant);
}

function onParticipantLeft(participant,reason) {
console.log(`Participant "${participant.displayName}" left the room. Reason: ${reason.message} (Code: ${reason.code})`);
}

useRoom({
onParticipantJoined,
onParticipantLeft,
onMicRequested,
onWebcamRequested,
});

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