RTCMultiConnection Docs

RTCMultiConnection API Reference / "setDefaultEventsForMediaElement" method

"setDefaultEventsForMediaElement" method is added in RTCMultiConnection to provide built-in mute/unmute and volume synchronizations using normal <video> or <audio> elements.
// it looks like this
connection.setDefaultEventsForMediaElement = function(mediaElement, streamid) {
    // "mediaElement" can be video or audio
    // "streamid" is the current stream's unique identifier
    mediaElement.onpause = function() { };
    mediaElement.onplay  = function() { };
    mediaElement.onvolumechange = function() { };

How it works?

  1. When audio or video element is paused i.e. "onpause" event is fired; RTCMultiConnection auto invokes connection.streams['stream-id'].mute() method. Which auto mutes video among all users.
  2. When audio or video element is resumed or played-again i.e. "onplay" event is fired; RTCMultiConnection auto invokes connection.streams['stream-id'].unmute() method. Which auto unmutes video among all users.
  3. When audio or video element's volume is changed i.e. "onvolumechange" event is fired; RTCMultiConnection auto synchronizes volume among all users.

How to override default behaviour?

Simply set it to "false" or "null" or empty function.

// You can override setDefaultEventsForMediaElement to prevent 
// default mute/unmute handlers on media elements:

// false
connection.setDefaultEventsForMediaElement = false;

// null
connection.setDefaultEventsForMediaElement = null;

// empty function
connection.setDefaultEventsForMediaElement = function() {};


"I have implemented a simple audio-audio call. I am making an audio call from caller A to caller B. If I'm caller A, is there a way I can mute my microphone so I can't hear myself through my Chrome browser, but I am still sending my mic audio to caller B, and I can still hear caller B as well."

Simply override default behaviour:

// simply set it to false
connection.setDefaultEventsForMediaElement = false;

Now, feel free to pause/mute/resume your local video; it will not synchronize your action among all users. Other users will still get your video. You can watch them as well.

Want to ask a Question?

You can include your email for private conversation!

Latest Updates