Преглед изворни кода

fix(video-label): Listen to resize events on video elements when possible

j8
Leonard Kim пре 8 година
родитељ
комит
896dcde2b2
2 измењених фајлова са 68 додато и 12 уклоњено
  1. 24
    12
      modules/UI/videolayout/LargeVideoManager.js
  2. 44
    0
      modules/UI/videolayout/VideoContainer.js

+ 24
- 12
modules/UI/videolayout/LargeVideoManager.js Прегледај датотеку

59
             e => this.onHoverOut(e)
59
             e => this.onHoverOut(e)
60
         );
60
         );
61
 
61
 
62
-        // TODO Use the onresize event when temasys video objects support it.
63
-        /**
64
-         * The interval for checking if the displayed video resolution is or is
65
-         * not high-definition.
66
-         *
67
-         * @private
68
-         * @type {timeoutId}
69
-         */
70
-        this._updateVideoResolutionInterval = window.setInterval(
71
-            () => this._updateVideoResolutionStatus(),
72
-            VIDEO_RESOLUTION_POLL_INTERVAL);
62
+        // Bind event handler so it is only bound once for every instance.
63
+        this._updateVideoResolutionStatus
64
+            = this._updateVideoResolutionStatus.bind(this);
65
+
66
+        this.videoContainer.addResizeListener(
67
+            this._updateVideoResolutionStatus);
68
+
69
+        if (!JitsiMeetJS.util.RTCUIHelper.isResizeEventSupported()) {
70
+            /**
71
+             * An interval for polling if the displayed video resolution is or
72
+             * is not high-definition. For browsers that do not support video
73
+             * resize events, polling is the fallback.
74
+             *
75
+             * @private
76
+             * @type {timeoutId}
77
+             */
78
+            this._updateVideoResolutionInterval = window.setInterval(
79
+                this._updateVideoResolutionStatus,
80
+                VIDEO_RESOLUTION_POLL_INTERVAL);
81
+        }
73
     }
82
     }
74
 
83
 
75
     /**
84
     /**
76
-     * Stops any polling intervals on the instance.
85
+     * Stops any polling intervals on the instance and and removes any
86
+     * listeners registered on child components.
77
      *
87
      *
78
      * @returns {void}
88
      * @returns {void}
79
      */
89
      */
80
     destroy() {
90
     destroy() {
81
         window.clearInterval(this._updateVideoResolutionInterval);
91
         window.clearInterval(this._updateVideoResolutionInterval);
92
+        this.videoContainer.removeResizeListener(
93
+            this._updateVideoResolutionStatus);
82
     }
94
     }
83
 
95
 
84
     onHoverIn (e) {
96
     onHoverIn (e) {

+ 44
- 0
modules/UI/videolayout/VideoContainer.js Прегледај датотеку

216
         // copied between new <object> elements
216
         // copied between new <object> elements
217
         //this.$video.on('play', onPlay);
217
         //this.$video.on('play', onPlay);
218
         this.$video[0].onplay = onPlayCallback;
218
         this.$video[0].onplay = onPlayCallback;
219
+
220
+        /**
221
+         * A Set of functions to invoke when the video element resizes.
222
+         *
223
+         * @private
224
+         */
225
+        this._resizeListeners = new Set();
226
+
227
+        // As of May 16, 2017, temasys does not support resize events.
228
+        this.$video[0].onresize = this._onResize.bind(this);
229
+    }
230
+
231
+    /**
232
+     * Adds a function to the known subscribers of video element resize
233
+     * events.
234
+     *
235
+     * @param {Function} callback - The subscriber to notify when the video
236
+     * element resizes.
237
+     * @returns {void}
238
+     */
239
+    addResizeListener(callback) {
240
+        this._resizeListeners.add(callback);
219
     }
241
     }
220
 
242
 
221
     /**
243
     /**
344
         });
366
         });
345
     }
367
     }
346
 
368
 
369
+    /**
370
+     * Removes a function from the known subscribers of video element resize
371
+     * events.
372
+     *
373
+     * @param {Function} callback - The callback to remove from known
374
+     * subscribers of video resize events.
375
+     * @returns {void}
376
+     */
377
+    removeResizeListener(callback) {
378
+        this._resizeListeners.delete(callback);
379
+    }
380
+
347
     /**
381
     /**
348
      * Update video stream.
382
      * Update video stream.
349
      * @param {JitsiTrack?} stream new stream
383
      * @param {JitsiTrack?} stream new stream
502
             (this.videoType === VIDEO_CONTAINER_TYPE && !isAvatar)
536
             (this.videoType === VIDEO_CONTAINER_TYPE && !isAvatar)
503
                 ? "#000" : interfaceConfig.DEFAULT_BACKGROUND);
537
                 ? "#000" : interfaceConfig.DEFAULT_BACKGROUND);
504
     }
538
     }
539
+
540
+    /**
541
+     * Callback invoked when the video element changes dimensions.
542
+     *
543
+     * @private
544
+     * @returns {void}
545
+     */
546
+    _onResize() {
547
+        this._resizeListeners.forEach(callback => callback());
548
+    }
505
 }
549
 }

Loading…
Откажи
Сачувај