Skip to content

Commit

Permalink
Properly set mid when notifying about ended tracks in janus.js
Browse files Browse the repository at this point in the history
  • Loading branch information
lminiero committed Dec 6, 2023
1 parent ba92d97 commit dc0b9a3
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions html/janus.js
Original file line number Diff line number Diff line change
Expand Up @@ -1947,6 +1947,13 @@ function Janus(gatewayCallbacks) {
// Notify about the new track event
let mid = event.transceiver ? event.transceiver.mid : event.track.id;
try {
if(event.transceiver && event.transceiver.mid && event.track.id) {
// Keep track of the mapping between track ID and mid, since
// when a track is removed the transceiver may be gone already
if(!pluginHandle.mids)
pluginHandle.mids = {};
pluginHandle.mids[event.track.id] = event.transceiver.mid;
}
pluginHandle.onremotetrack(event.track, mid, true, { reason: 'created' });
} catch(e) {
Janus.error("Error calling onremotetrack", e);
Expand All @@ -1963,11 +1970,14 @@ function Janus(gatewayCallbacks) {
let transceiver = transceivers ? transceivers.find(
t => t.receiver.track === ev.target) : null;
let mid = transceiver ? transceiver.mid : ev.target.id;
if(mid === ev.target.id && pluginHandle.mids && pluginHandle.mids[event.track.id])
mid = pluginHandle.mids[event.track.id];
try {
pluginHandle.onremotetrack(ev.target, mid, false, { reason: 'ended' });
} catch(e) {
Janus.error("Error calling onremotetrack on removal", e);
}
delete pluginHandle.mids[event.track.id];
};
event.track.onmute = function(ev) {
Janus.log('Remote track muted:', ev);
Expand All @@ -1979,6 +1989,8 @@ function Janus(gatewayCallbacks) {
let transceiver = transceivers ? transceivers.find(
t => t.receiver.track === ev.target) : null;
let mid = transceiver ? transceiver.mid : ev.target.id;
if(mid === ev.target.id && pluginHandle.mids && pluginHandle.mids[event.track.id])
mid = pluginHandle.mids[event.track.id];
try {
pluginHandle.onremotetrack(ev.target, mid, false, { reason: 'mute' } );
} catch(e) {
Expand Down

0 comments on commit dc0b9a3

Please sign in to comment.