Search code examples
video-streamingopentoktokbox

tokbox moderating toggle off/on subscriber's video/audio


I want to be able to turn on / off the volume of the users in the session. For example, in a group interview of 3 people, I should be able to reduce the voice of one person while talking. or when someone's sizzle comes in, I should be able to shorten it and reopen it if necessary. I have reviewed the documentation of the Tokbox and saw only 2 methods of moderating there.

(https://tokbox.com/developer/guides/moderation/js/)

first is forcing the user to disconnect,

and the second is to interrupt the user's broadcast (in this case I can not link the user back to the broadcast).


Solution

  • TokBox Developer Evangelist here.

    The moderator token doesn't allow you to mute other streams because you can stop publishing audio by calling publishAudio(false) or stop subscribing to the audio by calling subscribeToAudio(false).

    You can design your application to send a signal and make it so that everyone listening to the specific signal in the connect session will stop publishing their audio. You can add custom logic to only have some participants stop publishing their audio.

    Let's assume that you're connected to a session and have a reference to the Session object stored as session. You can send a signal by calling the signal method on the session object like so:

    session.signal(
      {
        data:'mutePublisher',
      },
      function(error) {
        if (error) {
          console.log("signal error ("
                       + error.name
                       + "): " + error.message);
        } else {
          console.log("signal sent.");
        }
      }
    );
    

    Let's assume that there are other participants connected to the same session and who are also publishing audio. You can set an event listener for the signal event for them like so:

    session.on({
      signal: function (event) {
        if (event.data === 'mutePublisher') {
          // mute publisher
          publisher.publishAudio(false);
        }
      }
    

    As you can see in the code above, anyone listening for the signal event with data set to mutePublisher would stop publishing their audio. You can use the same approach to send another signal for these participants to start publishing audio or video using publisher.publishAudio(true) and publisher.publishVideo(true), respectively.

    Please keep in mind the sample above would send a signal to everyone in the session. To send a signal to a specific client in a session, call the signal() method of the Session object and set the to property of the signal parameter.