Moderation
When you connect to a session with a token that includes moderator privileges, you can force other clients to 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.forceDisconnect or capabilities.forceUnpublish property of the Session object. If it is set to 1, 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:
Check the value of the canForceMute property of the object returned by Session.getCapabilities(). If it is set to true, the client can moderate:
Check the value of the capabilities.canForceMute property of the OTSession object. If it is set to YES, the client can moderate (and force other clients to mute):
Check if the client can moderate by checking the value of the CanForceMute property of the Session.Capabilities object.
Check the value of force_mute in the otc_session_capabilities instance:
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 Session object, passing in the Stream object representing the stream you want to mute:
The Session.forceMuteStream() method returns a Promise that is rejected if the call fails. For example, if the client does not have moderation privileges, the Promise is rejected with the name property of the Error object set to "OT_PERMISSION_DENIED". 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:
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:
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 Session object:
After you call the Session.disableForceMute() method, new streams published to the session will no longer have audio muted.
You can get references to Stream objects when the Session object dispatches a sessionConnected event and a streamCreated event. See Getting available streams when connecting to a session.
You can also get a Stream object from the stream property of a Subscriber object.
When the stream is muted as a result of one of these methods (or from a force mute stream call in another client SDK, in each client publishing a muted stream, the Publisher object dispatches a muteForced event.
Similarly, in response to a call to the Session.forceMuteAll() method (or to a force mute all call in another client SDK, the Session 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 Session.disableForceMute() method (or to a disable force mute call in another client SDK, the Session object in each client connected to the session dispatches a muteForced event, and the active property of the event object is set to false.
To force a publisher of a specific stream to mute its audio, call the forceMuteStream() method of the Session object, passing in the Stream object representing the stream you want to mute:
The Session.forceMuteStream() method returns a Promise that is rejected if the call fails. For example, if the client does not have moderation privileges, the Promise is rejected with the name property of the Error object set to "OT_PERMISSION_DENIED". 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:
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:
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 Session object:
After you call the Session.disableForceMute() method, new streams published to the session will no longer have audio muted.
You can get references to Stream objects when the Session object dispatches a sessionConnected event and a streamCreated event. See Getting available streams when connecting to a session.
You can also get a Stream object from the stream property of a Subscriber object.
When the stream is muted as a result of one of these methods (or from a force mute stream call in another client SDK, in each client publishing a muted stream, the Publisher object dispatches a muteForced event.
Similarly, in response to a call to the Session.forceMuteAll() method (or to a force mute all call in another client SDK, the Session 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 Session.disableForceMute() method (or to a disable force mute call in another client SDK, the Session object in each client connected to the session dispatches a muteForced event, and the active property of the event object is set to false.
To force a publisher of a specific stream to mute its audio, call the forceMuteStream() method of the Session object, passing in the Stream object corresponding to the stream to be muted:
When the call to the Session.forceMuteStream() method fails, the Session.SessionListener.onError() method is called. For example, if the client does not have moderation privileges, the code parameter of the OpentokError object passed into this method is set to SessionUnableToForceMute. 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 list of streams) in a session to mute published audio. Create an array of excluded streams:
Then call the forceMuteAll() method of the Session object, passing in the excluded stream array:
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 list.
If you leave out the excludedStreams parameter, all streams in the session (including those of the moderator) will stop publishing audio:
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 Session object:
After you call the Session.disableForceMute() method, new streams published to the session will no longer have audio muted.
You can get references to Stream objects when the onStreamReceived(Session session, Stream stream) of the Session.SessionListener object is called. See Detecting streams in a session. You can also get a Stream object from the getStream() method of a Publisher or Subscriber object.
When the stream is muted as a result of one of these methods (or from a force mute stream call in another client SDK), in each client publishing a muted stream, the onMuteForced(PublisherKit publisher, MuteForcedInfo info) method of the PublisherKit.MuteListener object is called.
Similarly, in response to a call to the Session.forceMuteAll() method (or to a force mute all call in another client SDK), onMuteForced(Session session, MuteForcedInfo info) method of the Session.MuteListener object is called in each client connected to the session, and the active property of the MuteForcedInfo object passed in is set to true.
And in response to a call to the Session.disableForceMute() method (or to a disable force mute call in another client SDK), the onMuteForced(Session session, MuteForcedInfo info) method of the Session.MuteListener object in each client connected to the session, and the active property of the MuteForcedInfo object passed in is set to false.
To force a publisher of a specific stream to mute its audio, call the [OTSession forceMuteStream:options:error:] method, passing in the OTStream object corresponding to the stream to be muted:
When the call fails, the error parameter is set to an OTError object. For example, if the client does not have moderation privileges, the error parameter is set to an OTError object with the code property set to OTSessionUnableToForceMute. 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 [OTSession forceMuteAll:excludedStreams:error:] method, passing in an array of OTStream objects corresponding to the streams you want to exclude from muting:
A stream published by the moderator calling the [OTSession forceMuteAll:excludedStreams:error:] 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 set the excludedStreams parameter to nil, all streams in the session (including those of the moderator) will stop publishing audio:
Any streams that are published after the call to the [OTSession forceMuteAll:excludedStreams:error:] method are published with audio muted. You can remove the mute state of a session by calling the [OTSession disableForceMute:error:] method:
After you call the [OTSession disableForceMute:error:] method, new streams published to the session will no longer have audio muted.
You can get references to OTStream objects when the [OTSessionDelegate:session:streamCreated:] message is sent. See Detecting streams in a session. You can also get an OTStream object from the stream property of an OTPublisher or OTSubscriber object.
When the stream is muted as a result of one of these methods (or from a force mute stream call in another client SDK), the [OTPublisherKitDelegate publisher:muteForced:] message is sent in each client publishing a muted stream.
Similarly, in response to a call to the [OTSession forceMuteAll:excludedStreams:error:] method (or to a force mute all call in another client SDK), [OTSessionDelegate session:muteForced:info] message is sent in each client connected to the session, and the active property of the OTMuteForcedInfo object passed in as the info parameter is set to YES.
And in response to a call to the [OTSession disableForceMute:error:] method (or to a disable force mute call in another client SDK), the [OTSessionDelegate session:muteForced:info] message is sent in each client connected to the session, and the active property of the OTMuteForcedInfo object passed in as the info parameter is set to NO.
To force a publisher of a specific stream to mute its audio, call the forceMuteStream() method of the Session object, passing in the Stream object corresponding to the stream to be muted:
When the call to the Session.ForceMuteStream() method fails, the Session object sends the Error event. For example, if the client does not have moderation privileges, the ErrorCode parameter passed in with the ErrorEventArgs object is set to SessionUnableToForceMute. 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 in an enumeration of excluded streams that you want to exclude from muting:
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:
Also, any streams that are published after the call to the Session.ForceMuteAll() method are published with audio muted. You can remove the mute state of a session by calling the Session.DisableForceMute():
After you call the Session.DisableForceMute() method, new streams published to the session will no longer have audio muted.
You can get references to Stream objects when Session object sends the StreamReceived event, which includes a Stream argument. See Detecting streams in a session. You can also get a Stream object from the Stream property of a Publisher or Subscriber object.
When the stream is muted as a result of one of these methods (or from a force mute stream call in another client SDK), in each client publishing a muted stream, Publisher objects send MuteForced events.
Similarly, in response to a call to the Session.ForceMuteAll() method (or to a force mute all call in another client SDK), the Session object sends a MuteForced event in each client connected to the session, and the IsActive property of the MuteForcedEventArgs object is set to true.
To force a publisher of a specific stream to mute its audio, call the otc_session_force_mute_stream() function, passing a pointer to the otc_session instance and a the stream ID string for the stream to be muted. This function takes the following parameters:
session— A pointer to the otc_session instance.stream_id_to_mute— A pointer to the stream ID string for the stream to be muted.
The function returns an otc_status instance indicating either error or success.
Moderators can also force all streams (except for an optional array of streams) in a session to mute published audio. Call the otc_session_force_mute_all() function. This function takes the following parameters:
session— A pointer to the otc_session instance.excluded_streams_ids— A pointer to an array of stream IDs for streams you want to exclude from muting. If this parameter is set to nullptr, all the streams will be muted (including those published by the local client).excluded_streams_len— The length of the excluded stream array.
The function returns an otc_status instance indicating either error or success:
A stream published by the moderator calling the otc_session_force_mute_all() function is muted along with other streams in the session, unless you add the moderator's stream (or streams) to the excluded streams array.
If the excluded_streams_len parameter is set to 0, all streams in the session (including those of the moderator) will stop publishing audio.
Also, any streams that are published after the call to the otc_session_force_mute_all() function are published with audio muted. You can remove the mute state of a session by calling the otc_session_disable_force_mute(otc_session *session)() function
After you call the otc_session_disable_force_mute() function, new streams published to the session will no longer have audio muted.
You can get references to otc_stream instances when the on_stream_received() callback function of the otc_session_callbacks instance is called. The callback includes a pointer to the otc_stream struct representing a stream. Call the otc_stream_get_id() function (passing in the pointer to an otc_stream instance) to get the stream ID. See Detecting streams in a session. You can also get an otc_stream instance representing a publisher's stream by calling the otc_publisher_get_stream() function, passing in the otc_publisher instance. You can also get an otc_stream instance representing a subscriber's stream by calling the otc_subscriber_get_stream() function, passing in the otc_subscriber instance.
When the stream is muted as a result of one of these functions (or from a force mute stream call in another client SDK), the on_mute_forced() callback function of the otc_publisher_callbacks struct is called in each client publishing a muted stream.
Similarly, in response to a call to the otc_session_force_mute_all() function (or to a force mute all call in another client SDK), the on_mute_forced() callback function of the otc_session_callbacks struct in each client connected to the session. and the active property of the otc_on_mute_forced_info struct passed into the function is set to true.
And in response to a call to the otc_session_disable_force_mute() function (or to a disable force mute call in another client SDK), the on_mute_forced() callback function of the otc_publisher_callbacks struct is called in each client connected to the session, and the active property of the otc_on_mute_forced_info struct passed in set to false.
Forcing a Client to Disconnect
Moderators can force any client to disconnect from the session.
To force a client to disconnect, call the forceDisconnect() method of the Session object, passing in the Connection object for the client you want to disconnect:
You can get references to Connection objects when the Session object dispatches a connectionCreated event. See Detecting when other clients have connected and disconnected. You can also get the Connection object for any stream from the connection property of the Stream object.
Forcing a Client to Stop Publishing a Stream
Moderators can force any publisher of a stream to stop streaming to the session.
To force a stream to stop, call the forceUnpublish() method of the Session object, passing in the Stream object that you want to stop:
You can get references to Stream objects when the Session object dispatches a sessionConnected event and a streamCreated event. See Getting available streams when connecting to a session.
You can also get a Stream object from the stream property of a Subscriber object.