浏览代码

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

master
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,26 +59,38 @@ export default class LargeVideoManager {
59 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 88
      * @returns {void}
79 89
      */
80 90
     destroy() {
81 91
         window.clearInterval(this._updateVideoResolutionInterval);
92
+        this.videoContainer.removeResizeListener(
93
+            this._updateVideoResolutionStatus);
82 94
     }
83 95
 
84 96
     onHoverIn (e) {

+ 44
- 0
modules/UI/videolayout/VideoContainer.js 查看文件

@@ -216,6 +216,28 @@ export class VideoContainer extends LargeContainer {
216 216
         // copied between new <object> elements
217 217
         //this.$video.on('play', onPlay);
218 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,6 +366,18 @@ export class VideoContainer extends LargeContainer {
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 382
      * Update video stream.
349 383
      * @param {JitsiTrack?} stream new stream
@@ -502,4 +536,14 @@ export class VideoContainer extends LargeContainer {
502 536
             (this.videoType === VIDEO_CONTAINER_TYPE && !isAvatar)
503 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
 }

正在加载...
取消
保存