ParticipantsModule Overview
ParticipantsModule Overview
ParticipantsModule Overview

ParticipantsModule

Exposes the ability to retrieve the participants in a video call effect. Each user on the call is considered a participant, including the host.

When a new user joins the call a new Participant object is added to the array returned by getAllOtherParticipants() and otherParticipantCount is increased.

Participants are not removed from the array if they leave while the call is still active. This allows individual participants to retain the same unique ID that can be referenced for the duration of the video call, even after a dropout.

Similarly, otherParticipantCount is not decreased when a participant leaves. However, if the the video call ends then the participant array and count are both reset.

Importing this module automatically enables the Participants capability within the project's Properties.

Example

//============================================================================
// Retrieves the participants in the video call and logs the participant
// count in the console.
//
// Required project capabilities:
// - Participant (auto added on module import)
//
//============================================================================


// Load in the required modules
const Participants = require('Participants');
const Diagnostics = require('Diagnostics');


(async function() { // Enable async/await in JS [part 1]

  //==========================================================================
  // Retrieve the current user
  //==========================================================================

  // Create a reference to the current participant and log their unique ID
  // to the console
  const self = await Participants.self;
  Diagnostics.log(self.id);


  //==========================================================================
  // Retrieve other participants on the call
  //==========================================================================

  const participants = await Participants.getAllOtherParticipants();

  // Log the array of participants on the call
  //Diagnostics.log(participants);


  // Log the ID of the first participant in the array
  const firstParticipant = participants[0];


  // Monitor when the first participant joins or leaves the call
  firstParticipant.isActiveInCall.monitor({fireOnInitialValue: true}).subscribe((event) => {
    Diagnostics.log(`First participant is active in call: ${event.newValue}`);
  });


  //==========================================================================
  // Retrieve the number of other participants on the call
  //==========================================================================

  // Log the number of other participants on the call to the console
  // This value does not include the current user, 'self'
  const participantCount = Participants.otherParticipantCount;

  participantCount.monitor({fireOnInitialValue: true}).subscribe((event) => {
    Diagnostics.log(`Other participant count: ${event.newValue}`);
  });


})(); // Enable async/await in JS [part 2]

Properties

PropertyDescription
otherParticipantCount
(get) otherParticipantCount: ScalarSignal
(set) (Not Available)


The total number of participants in the video call, not including the current participant (self), as a ScalarSignal.
self
(get) self: Promise<Participant>
(set) (Not Available)


The current user, as a Participant object.

Methods

MethodDescription
getAllOtherParticipants
getAllOtherParticipants(): Promise<Array<Participant>>


Returns an array of Participant objects containing all of the other participants in the current video call, not including the current user (self).
getParticipantById
getParticipantById(id: string): Promise<Participant>


Returns the Participant object attached to the unique ID specified.
A Participant object's unique ID is accessible via its id property. For example:

const otherParticipants = await Participants.getAllOtherParticipants();
const participant = otherParticipants[0];
const participantId = participant.id;

// Retrieves the above participant via its unique ID
const sameParticipant = Participants.getParticipantById(participantId)
onOtherParticipantAdded
onOtherParticipantAdded(): EventSource<Participant>


Returns an EventSource object that emits a new Participant object each time a new participant joins the video call. For example:
Participants.onOtherParticipantAdded().subscribe((participant) =>{
// const newParticipantId = participant.id;
});

Classes

ClassDescription
ParticipantExposes details of an individual participant in a video call effect.

Was this article helpful?