Have you explored the newest version of the OpenTok platform? Check out OpenTok 2.0, built on top of WebRTC. Learn more

VolumeEvent class

The VoluemEvent object reports the microphone level for a stream the client has subscribed to. If you add an event listener for the microphoneLevelChanged event, each 500 milliseconds, the Session object dispatches the event for each stream you have subscribed to.

The VolumeEvent object defines the properties of the event object that is dispatched.

The following code shows how to detect microphone levels for the streams you subscribe to:

session.addEventListener("microphoneLevelChanged", microphoneLevelChangedHandler);

function microphoneLevelChangedHandler(event) {
    TB.log("The microphone level for stream " + event.streamId + " is: " + event.volume);
}

Instead of logging to the console using TB.log() (as in this example), your app may choose to change the user interface based on the microphone levels of subscribers.

Note that the publisher of the stream must set the reportMicLevels property of the properties parameter when calling TB.initPublisher(), as in the following:

var API_KEY = ""; // Replace with your OpenTok API key. See https://dashboard.tokbox.com/projects
var pubProps = {reportMicLevels: true};
publisher = TB.initPublisher(API_KEY, null, pubProps);
session.publish(publisher);

VolumeEvent properties

The VolumeEvent object has the following properties:

streamID (String) — The stream ID of the stream for which the volume level is reported.

target (Object) — The Session object that dispatched the event.

type (String) — The type of event ("microphoneLevelChanged").

volume (Number) — The microphone activity level, from 0 to 10.

See

Session events

IRC Live Chat

Have a quick question? Chat with TokBox Support on IRC. Join chat