Suggestions

close search

Add Messaging, Voice, and Authentication to your apps with Vonage Communications APIs

Visit the Vonage API Developer Portal

Moderation — React Native

When you connect to a session with a token that includes moderator privileges, you can force other clients to disconnect from a session, stop publishing a stream or mute their audio:

Checking for moderation privileges

Once you have connected to a session, you can check if the client can moderate. Check the value of the capabilities.forceMute property of the OTSession object. If it is set to true, the client can moderate:

if (session.capabilities.forceMute) {
    // The client can mute participants.
} else {
    // The client cannot mute.
}

Muting the audio of streams in a session

Moderators can force all clients or a publisher of a specific stream to mute their published audio.

To force a publisher of a specific stream to mute its audio, call the forceMuteStream() method of the OTSession object, passing in the stream ID of the stream you want to mute:

session.forceMuteStream('stream-id')
  .then(function() {
    console.log("successfully called.");
  }).catch(function(error) {
    console.log("Error: ", error);
  });

The OTSession.forceMuteStream() method returns a Promise that is rejected if the call fails (for example, if the client does not have moderation privileges). In this context, success indicates that the options passed into the method are valid and the request to mute the stream was sent. It does not guarantee that the request was successfully acted upon.

Moderators can also force all streams (except for an optional array of streams) in a session to mute published audio. Call the forceMuteAll() method of the Session object, passing an array of streams that you want to exclude from muting:

session.forceMuteAll(excludedStreams);

A stream published by the moderator calling the forceMuteAll() method is muted along with other streams in the session, unless you add the moderator's stream (or streams) to the excluded streams array.

If you leave out the excludedStreams parameter, all streams in the session (including those of the moderator) will stop publishing audio:

session.forceMuteAll();

Also, any streams that are published after the call to the forceMuteAll() method are published with audio muted. You can remove the mute state of a session by calling the disableForceMute() method of the OTSession object:

session.disableForceMute();

After you call the OTSession.disableForceMute() method, new streams published to the session will no longer have audio muted.

You can get references to stream Ids when the Session object dispatches sessionConnected event and streamCreated events.

When the stream is muted as a result of one of these methods (or from aforce mute stream call in another client SDK),in each client publishing a muted stream, the OTPublisher object dispatches a muteForced event.

Similarly, in response to a call to the OTSession.forceMuteAll() method (or to a force mute all call in another client SDK), the OTSession object in each client connected to the session dispatches a muteForced event, and the active property of the event object is set to true.

And in response to a call to the OTSession.disableForceMute() method (or to a disable force mute call in another client SDK), the OTSession object in each client connected to the session dispatches a muteForced event, and the active property of the event object is set to false.