Skip to content

Commit

Permalink
fix(conference.js): prevent presenter track leak
Browse files Browse the repository at this point in the history
A duct tape fix for presenter track leak for a case when presenter GUM
is in progress when screensharing is being turned off.
  • Loading branch information
paweldomas committed Jan 13, 2020
1 parent c8939a1 commit f6c94ff
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions conference.js
Original file line number Diff line number Diff line change
Expand Up @@ -1425,10 +1425,23 @@ export default {

this._stopProxyConnection();

let promise = null;
// It can happen that presenter GUM is in progress while screensharing is being turned off. Here it needs to
// wait for that GUM to be resolved in order to prevent leaking the presenter track(this.localPresenterVideo
// will be null when SS is being turned off, but it will initialize once GUM resolves).
let promise = _prevMutePresenterVideo = _prevMutePresenterVideo.then(() => {
// mute the presenter track if it exists.
if (this.localPresenterVideo) {
APP.store.dispatch(setVideoMuted(true, MEDIA_TYPE.PRESENTER));

return this.localPresenterVideo.dispose().then(() => {
APP.store.dispatch(trackRemoved(this.localPresenterVideo));
this.localPresenterVideo = null;
});
}
});

if (didHaveVideo) {
promise = createLocalTracksF({ devices: [ 'video' ] })
promise = promise.then(() => createLocalTracksF({ devices: [ 'video' ] }))
.then(([ stream ]) => this.useVideoStream(stream))
.then(() => {
sendAnalytics(createScreenSharingEvent('stopped'));
Expand All @@ -1444,17 +1457,7 @@ export default {
);
});
} else {
promise = this.useVideoStream(null);
}

// mute the presenter track if it exists.
if (this.localPresenterVideo) {
APP.store.dispatch(
setVideoMuted(true, MEDIA_TYPE.PRESENTER));
this.localPresenterVideo.dispose();
APP.store.dispatch(
trackRemoved(this.localPresenterVideo));
this.localPresenterVideo = null;
promise = promise.then(() => this.useVideoStream(null));
}

return promise.then(
Expand Down Expand Up @@ -2179,6 +2182,7 @@ export default {

// dispose the existing presenter track and create a new
// camera track.
// FIXME JitsiLocalTrack.dispose is async and should be waited for
this.localPresenterVideo && this.localPresenterVideo.dispose();
this.localPresenterVideo = null;

Expand All @@ -2199,6 +2203,8 @@ export default {
const { height } = this.localVideo.track.getSettings();

this._updateVideoDeviceId();

// FIXME JitsiLocalTrack.dispose is async and should be waited for
this.localPresenterVideo && this.localPresenterVideo.dispose();
this.localPresenterVideo = null;
this._createPresenterStreamEffect(height, cameraDeviceId);
Expand Down

0 comments on commit f6c94ff

Please sign in to comment.