Просмотр исходного кода

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.
j8
paweldomas 9 лет назад
Родитель
Сommit
66bbc4d9fd
1 измененных файлов: 17 добавлений и 6 удалений
  1. 17
    6
      modules/UI/videolayout/RemoteVideo.js

+ 17
- 6
modules/UI/videolayout/RemoteVideo.js Просмотреть файл

@@ -29,6 +29,14 @@ function RemoteVideo(user, VideoLayout, emitter) {
29 29
     this.setDisplayName();
30 30
     this.flipX = false;
31 31
     this.isLocal = false;
32
+    /**
33
+     * The flag is set to <tt>true</tt> after the 'onplay' event has been
34
+     * triggered on the current video element. It goes back to <tt>false</tt>
35
+     * when the stream is removed. It is used to determine whether the video
36
+     * playback has ever started.
37
+     * @type {boolean}
38
+     */
39
+    this.wasVideoPlayed = false;
32 40
 }
33 41
 
34 42
 RemoteVideo.prototype = Object.create(SmallVideo.prototype);
@@ -218,6 +226,10 @@ RemoteVideo.prototype.removeRemoteStreamElement = function (stream) {
218 226
     var select = $('#' + elementID);
219 227
     select.remove();
220 228
 
229
+    if (isVideo) {
230
+        this.wasVideoPlayed = false;
231
+    }
232
+
221 233
     console.info((isVideo ? "Video" : "Audio") +
222 234
                  " removed " + this.id, select);
223 235
 
@@ -316,6 +328,7 @@ RemoteVideo.prototype.waitForPlayback = function (streamElement, stream) {
316 328
     // Register 'onplaying' listener to trigger 'videoactive' on VideoLayout
317 329
     // when video playback starts
318 330
     var onPlayingHandler = function () {
331
+        self.wasVideoPlayed = true;
319 332
         self.VideoLayout.videoactive(streamElement, self.id);
320 333
         streamElement.onplaying = null;
321 334
         // Refresh to show the video
@@ -325,15 +338,13 @@ RemoteVideo.prototype.waitForPlayback = function (streamElement, stream) {
325 338
 };
326 339
 
327 340
 /**
328
- * Checks whether or not video stream exists and has started for this
329
- * RemoteVideo instance. This is checked by trying to select video element in
330
- * this container and checking if 'currentTime' field's value is greater than 0.
341
+ * Checks whether the video stream has started for this RemoteVideo instance.
331 342
  *
332
- * @returns {*|boolean} true if this RemoteVideo has active video stream running
343
+ * @returns {boolean} true if this RemoteVideo has a video stream for which
344
+ * the playback has been started.
333 345
  */
334 346
 RemoteVideo.prototype.hasVideoStarted = function () {
335
-    var videoSelector = this.selectVideoElement();
336
-    return videoSelector.length && videoSelector[0].currentTime > 0;
347
+    return this.wasVideoPlayed;
337 348
 };
338 349
 
339 350
 RemoteVideo.prototype.addRemoteStreamElement = function (stream) {

Загрузка…
Отмена
Сохранить