From 703f4f493b6d648ad9c187d8f8bbea6b71752967 Mon Sep 17 00:00:00 2001 From: paweldomas Date: Wed, 16 Nov 2016 13:05:14 -0600 Subject: [PATCH] fix(LocalVideo): prevent from leaking video elements It appears that the TrackEvents.LOCAL_TRACK_STOPPED is not triggered when switching between camera and screen. This is a temporary workaround to prevent excessive amount of warnings (added in the previous commit) about multiple video elements. --- modules/UI/videolayout/LocalVideo.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/modules/UI/videolayout/LocalVideo.js b/modules/UI/videolayout/LocalVideo.js index 4fac84b18..68f59efca 100644 --- a/modules/UI/videolayout/LocalVideo.js +++ b/modules/UI/videolayout/LocalVideo.js @@ -154,6 +154,19 @@ LocalVideo.prototype.createConnectionIndicator = function() { }; LocalVideo.prototype.changeVideo = function (stream) { + // FIXME temporary workaround for the fact that 'endedHandler' is not called + // This is to avoid potential side effect of the fact that multiple video + // elements are leaked into the 'localVideoWrapper' after screen sharing + if (this.videoStream) { + var localVideoElement = document.getElementById(this.localVideoId); + if (localVideoElement) { + this.videoStream.detach(localVideoElement); + var container = localVideoElement.parentNode; + if (container) { + container.removeChild(localVideoElement); + } + } + } this.videoStream = stream; let localVideoClick = (event) => { @@ -192,6 +205,9 @@ LocalVideo.prototype.changeVideo = function (stream) { // Attach WebRTC stream localVideo = stream.attach(localVideo); + // FIXME this is never called for some reason + // It was expected for this callback to be called whenever local video + // stream is switched between camera and screen videos. let endedHandler = () => { localVideoContainer.removeChild(localVideo); // when removing only the video element and we are on stage