Skip to content

Commit

Permalink
Only process mute events if a timer fired to avoid video flashing. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
alexamirante authored May 12, 2020
1 parent 415e025 commit bb86acf
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions html/janus.js
Original file line number Diff line number Diff line change
Expand Up @@ -1772,23 +1772,42 @@ function Janus(gatewayCallbacks) {
pluginHandle.onremotestream(config.remoteStream);
if(event.track.onended)
return;
var trackMutedTimeoutId = null;
Janus.log("Adding onended callback to track:", event.track);
event.track.onended = function(ev) {
Janus.log("Remote track muted/removed:", ev);
Janus.log("Remote track removed:", ev);
if(config.remoteStream) {
clearTimeout(trackMutedTimeoutId);
config.remoteStream.removeTrack(ev.target);
pluginHandle.onremotestream(config.remoteStream);
}
};
event.track.onmute = event.track.onended;
event.track.onmute = function(ev) {
Janus.log("Remote track muted:", ev);
if(config.remoteStream && trackMutedTimeoutId == null) {
trackMutedTimeoutId = setTimeout(function() {
Janus.log("Removing remote track");
config.remoteStream.removeTrack(ev.target);
pluginHandle.onremotestream(config.remoteStream);
trackMutedTimeoutId = null;
// Chrome seems to raise mute events only at multiples of 834ms;
// we set the timeout to three times this value (rounded to 840ms)
}, 3 * 840);
}
};
event.track.onunmute = function(ev) {
Janus.log("Remote track flowing again:", ev);
try {
config.remoteStream.addTrack(ev.target);
pluginHandle.onremotestream(config.remoteStream);
} catch(e) {
Janus.error(e);
};
if(trackMutedTimeoutId != null) {
clearTimeout(trackMutedTimeoutId);
trackMutedTimeoutId = null;
} else {
try {
config.remoteStream.addTrack(ev.target);
pluginHandle.onremotestream(config.remoteStream);
} catch(e) {
Janus.error(e);
};
}
};
};
}
Expand Down

0 comments on commit bb86acf

Please sign in to comment.