From 66bbc4d9fdf01ece8a14862ac83ca04f70ab50ba Mon Sep 17 00:00:00 2001 From: paweldomas Date: Thu, 22 Sep 2016 15:57:43 -0500 Subject: [PATCH] fix(RemoteVideo): change hasVideoStarted logic We used to rely on 'currentTime' of the video element, but we execute 'updateView' from the 'onplay' callback and on fast machines it may happen that the value is 0 even though the video has just started. --- modules/UI/videolayout/RemoteVideo.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/modules/UI/videolayout/RemoteVideo.js b/modules/UI/videolayout/RemoteVideo.js index ae5952443..05750f045 100644 --- a/modules/UI/videolayout/RemoteVideo.js +++ b/modules/UI/videolayout/RemoteVideo.js @@ -29,6 +29,14 @@ function RemoteVideo(user, VideoLayout, emitter) { this.setDisplayName(); this.flipX = false; this.isLocal = false; + /** + * The flag is set to true after the 'onplay' event has been + * triggered on the current video element. It goes back to false + * when the stream is removed. It is used to determine whether the video + * playback has ever started. + * @type {boolean} + */ + this.wasVideoPlayed = false; } RemoteVideo.prototype = Object.create(SmallVideo.prototype); @@ -218,6 +226,10 @@ RemoteVideo.prototype.removeRemoteStreamElement = function (stream) { var select = $('#' + elementID); select.remove(); + if (isVideo) { + this.wasVideoPlayed = false; + } + console.info((isVideo ? "Video" : "Audio") + " removed " + this.id, select); @@ -316,6 +328,7 @@ RemoteVideo.prototype.waitForPlayback = function (streamElement, stream) { // Register 'onplaying' listener to trigger 'videoactive' on VideoLayout // when video playback starts var onPlayingHandler = function () { + self.wasVideoPlayed = true; self.VideoLayout.videoactive(streamElement, self.id); streamElement.onplaying = null; // Refresh to show the video @@ -325,15 +338,13 @@ RemoteVideo.prototype.waitForPlayback = function (streamElement, stream) { }; /** - * Checks whether or not video stream exists and has started for this - * RemoteVideo instance. This is checked by trying to select video element in - * this container and checking if 'currentTime' field's value is greater than 0. + * Checks whether the video stream has started for this RemoteVideo instance. * - * @returns {*|boolean} true if this RemoteVideo has active video stream running + * @returns {boolean} true if this RemoteVideo has a video stream for which + * the playback has been started. */ RemoteVideo.prototype.hasVideoStarted = function () { - var videoSelector = this.selectVideoElement(); - return videoSelector.length && videoSelector[0].currentTime > 0; + return this.wasVideoPlayed; }; RemoteVideo.prototype.addRemoteStreamElement = function (stream) {