When you connect to a session with a token that includes moderator privileges, you can force other clients to disconnect from a session or to stop publishing a stream:
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:
if (session.capabilities.forceDisconnect == 1) {
// The client can forceDisconnect. See the next section.
} else {
// The client cannot moderate.
}
if (session.capabilities.forceUnpublish == 1) {
// The client can forceUnpublish.
} else {
// The client cannot moderate.
}
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:
session.forceDisconnect(connection);
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.
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:
session.forceUnpublish(stream);
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 and
Detecting when new streams are created.
You can also get a Stream object from the stream
property of a Subscriber object.