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

abstract out remoteVideos management

j8
isymchych пре 9 година
родитељ
комит
b375b14696

+ 4
- 3
modules/UI/UI.js Прегледај датотеку

@@ -88,7 +88,7 @@ function setupChat() {
88 88
 function setupToolbars() {
89 89
     Toolbar.init(eventEmitter);
90 90
     Toolbar.setupButtonsFromConfig();
91
-    BottomToolbar.init(eventEmitter);
91
+    BottomToolbar.setupListeners(eventEmitter);
92 92
 }
93 93
 
94 94
 /**
@@ -246,6 +246,8 @@ UI.start = function () {
246 246
 
247 247
     registerListeners();
248 248
 
249
+    BottomToolbar.init();
250
+
249 251
     VideoLayout.init(eventEmitter);
250 252
     if (!interfaceConfig.filmStripOnly) {
251 253
         VideoLayout.initLargeVideo(PanelToggler.isVisible());
@@ -277,8 +279,7 @@ UI.start = function () {
277 279
         $("#header").css("display", "none");
278 280
         $("#bottomToolbar").css("display", "none");
279 281
         $("#downloadlog").css("display", "none");
280
-        $("#remoteVideos").css("padding", "0px 0px 18px 0px");
281
-        $("#remoteVideos").css("right", "0px");
282
+        BottomToolbar.setupFilmStripOnly();
282 283
         messageHandler.disableNotifications();
283 284
         $('body').popover("disable");
284 285
         JitsiPopover.enabled = false;

+ 12
- 31
modules/UI/audio_levels/AudioLevels.js Прегледај датотеку

@@ -2,6 +2,7 @@
2 2
 /* jshint -W101 */
3 3
 
4 4
 import CanvasUtil from './CanvasUtils';
5
+import BottomToolbar from '../toolbars/BottomToolbar';
5 6
 
6 7
 const LOCAL_LEVEL = 'local';
7 8
 
@@ -126,7 +127,7 @@ const AudioLevels = {
126 127
      * Updates the audio level canvas for the given id. If the canvas
127 128
      * didn't exist we create it.
128 129
      */
129
-    updateAudioLevelCanvas (id, VideoLayout) {
130
+    updateAudioLevelCanvas (id, thumbWidth, thumbHeight) {
130 131
         let videoSpanId = 'localVideoContainer';
131 132
         if (id) {
132 133
             videoSpanId = `participant_${id}`;
@@ -145,24 +146,19 @@ const AudioLevels = {
145 146
 
146 147
         let audioLevelCanvas = $(`#${videoSpanId}>canvas`);
147 148
 
148
-        let videoSpaceWidth = $('#remoteVideos').width();
149
-        let thumbnailSize = VideoLayout.calculateThumbnailSize(videoSpaceWidth);
150
-        let thumbnailWidth = thumbnailSize[0];
151
-        let thumbnailHeight = thumbnailSize[1];
152
-
153 149
         if (!audioLevelCanvas || audioLevelCanvas.length === 0) {
154 150
 
155 151
             audioLevelCanvas = document.createElement('canvas');
156 152
             audioLevelCanvas.className = "audiolevel";
157 153
             audioLevelCanvas.style.bottom = `-${interfaceConfig.CANVAS_EXTRA/2}px`;
158 154
             audioLevelCanvas.style.left = `-${interfaceConfig.CANVAS_EXTRA/2}px`;
159
-            resizeAudioLevelCanvas(audioLevelCanvas, thumbnailWidth, thumbnailHeight);
155
+            resizeAudioLevelCanvas(audioLevelCanvas, thumbWidth, thumbHeight);
160 156
 
161 157
             videoSpan.appendChild(audioLevelCanvas);
162 158
         } else {
163 159
             audioLevelCanvas = audioLevelCanvas.get(0);
164 160
 
165
-            resizeAudioLevelCanvas(audioLevelCanvas, thumbnailWidth, thumbnailHeight);
161
+            resizeAudioLevelCanvas(audioLevelCanvas, thumbWidth, thumbHeight);
166 162
         }
167 163
     },
168 164
 
@@ -223,31 +219,16 @@ const AudioLevels = {
223 219
         ASDrawContext.fill();
224 220
     },
225 221
 
226
-    /**
227
-     * Indicates that the remote video has been resized.
228
-     */
229
-    onRemoteVideoResized (width, height) {
230
-        let resized = false;
231
-
232
-        $('#remoteVideos>span>canvas').each(function() {
233
-            let canvas = $(this).get(0);
234
-            if (canvas.width !== width + interfaceConfig.CANVAS_EXTRA) {
235
-                canvas.width = width + interfaceConfig.CANVAS_EXTRA;
236
-                resized = true;
237
-            }
222
+    updateCanvasSize (thumbWidth, thumbHeight) {
223
+        let canvasWidth = thumbWidth + interfaceConfig.CANVAS_EXTRA;
224
+        let canvasHeight = thumbHeight + interfaceConfig.CANVAS_EXTRA;
238 225
 
239
-            if (canvas.height !== height + interfaceConfig.CANVAS_EXTRA) {
240
-                canvas.height = height + interfaceConfig.CANVAS_EXTRA;
241
-                resized = true;
242
-            }
243
-        });
226
+        BottomToolbar.getThumbs().children('canvas').width(canvasWidth).height(canvasHeight);
244 227
 
245
-        if (resized) {
246
-            Object.keys(audioLevelCanvasCache).forEach(function (id) {
247
-                audioLevelCanvasCache[id].width = width + interfaceConfig.CANVAS_EXTRA;
248
-                audioLevelCanvasCache[id].height = height + interfaceConfig.CANVAS_EXTRA;
249
-            });
250
-        }
228
+        Object.keys(audioLevelCanvasCache).forEach(function (id) {
229
+            audioLevelCanvasCache[id].width = canvasWidth;
230
+            audioLevelCanvasCache[id].height = canvasHeight;
231
+        });
251 232
     }
252 233
 };
253 234
 

+ 2
- 3
modules/UI/etherpad/Etherpad.js Прегледај датотеку

@@ -4,6 +4,7 @@ import VideoLayout from "../videolayout/VideoLayout";
4 4
 import LargeContainer from '../videolayout/LargeContainer';
5 5
 import UIUtil from "../util/UIUtil";
6 6
 import SidePanelToggler from "../side_pannels/SidePanelToggler";
7
+import BottomToolbar from '../toolbars/BottomToolbar';
7 8
 
8 9
 const options = $.param({
9 10
     showControns: true,
@@ -88,9 +89,7 @@ class Etherpad extends LargeContainer {
88 89
     }
89 90
 
90 91
     resize (containerWidth, containerHeight, animate) {
91
-        let remoteVideos = $('#remoteVideos');
92
-
93
-        let height = containerHeight - remoteVideos.outerHeight();
92
+        let height = containerHeight - BottomToolbar.getFilmStripHeight();
94 93
         let width = containerWidth;
95 94
 
96 95
         $(this.iframe).width(width).height(height);

+ 2
- 2
modules/UI/prezi/Prezi.js Прегледај датотеку

@@ -9,6 +9,7 @@ import UIEvents from '../../../service/UI/UIEvents';
9 9
 import messageHandler from '../util/MessageHandler';
10 10
 import ToolbarToggler from "../toolbars/ToolbarToggler";
11 11
 import SidePanelToggler from "../side_pannels/SidePanelToggler";
12
+import BottomToolbar from '../toolbars/BottomToolbar';
12 13
 
13 14
 const defaultPreziLink = "http://prezi.com/wz7vhjycl7e6/my-prezi";
14 15
 const alphanumRegex = /^[a-z0-9-_\/&\?=;]+$/i;
@@ -244,8 +245,7 @@ class PreziContainer extends LargeContainer {
244 245
     }
245 246
 
246 247
     resize (containerWidth, containerHeight) {
247
-        let remoteVideos = $('#remoteVideos');
248
-        let height = containerHeight - remoteVideos.outerHeight();
248
+        let height = containerHeight - BottomToolbar.getFilmStripHeight();
249 249
 
250 250
         let width = containerWidth;
251 251
 

+ 66
- 6
modules/UI/toolbars/BottomToolbar.js Прегледај датотеку

@@ -10,7 +10,12 @@ const defaultBottomToolbarButtons = {
10 10
 };
11 11
 
12 12
 const BottomToolbar = {
13
-    init (emitter) {
13
+    init () {
14
+        this.filmStrip = $('#remoteVideos');
15
+        this.toolbar = $('#bottomToolbar');
16
+    },
17
+
18
+    setupListeners (emitter) {
14 19
         UIUtil.hideDisabledButtons(defaultBottomToolbarButtons);
15 20
 
16 21
         const buttonHandlers = {
@@ -34,14 +39,69 @@ const BottomToolbar = {
34 39
     },
35 40
 
36 41
     toggleFilmStrip () {
37
-        $("#remoteVideos").toggleClass("hidden");
42
+        this.filmStrip.toggleClass("hidden");
43
+    },
44
+
45
+    isFilmStripVisible () {
46
+        return !this.filmStrip.hasClass('hidden');
47
+    },
48
+
49
+    setupFilmStripOnly () {
50
+        this.filmStrip.css({
51
+            padding: "0px 0px 18px 0px",
52
+            right: 0
53
+        });
54
+    },
55
+
56
+    getFilmStripHeight () {
57
+        if (this.isFilmStripVisible()) {
58
+            return this.filmStrip.outerHeight();
59
+        } else {
60
+            return 0;
61
+        }
62
+    },
63
+
64
+    getFilmStripWidth () {
65
+        return this.filmStrip.width();
66
+    },
67
+
68
+    resizeThumbnails (thumbWidth, thumbHeight, animate = false) {
69
+        return new Promise(resolve => {
70
+            this.filmStrip.animate({
71
+                // adds 2 px because of small video 1px border
72
+                height: thumbHeight + 2
73
+            }, {
74
+                queue: false,
75
+                duration: animate ? 500 : 0
76
+            });
77
+
78
+            this.getThumbs().animate({
79
+                height: thumbHeight,
80
+                width: thumbWidth
81
+            }, {
82
+                queue: false,
83
+                duration: animate ? 500 : 0,
84
+                complete:  resolve
85
+            });
86
+
87
+            if (!animate) {
88
+                resolve();
89
+            }
90
+        });
91
+    },
92
+
93
+    resizeToolbar (thumbWidth, thumbHeight) {
94
+        let bottom = (thumbHeight - this.toolbar.outerHeight())/2 + 18;
95
+        this.toolbar.css({bottom});
38 96
     },
39 97
 
40
-    onRemoteVideoResized (width, height) {
41
-        let toolbar = $('#bottomToolbar');
42
-        let bottom = (height - toolbar.outerHeight())/2 + 18;
98
+    getThumbs (visible = false) {
99
+        let selector = 'span';
100
+        if (visible) {
101
+            selector += ':visible';
102
+        }
43 103
 
44
-        toolbar.css({bottom});
104
+        return this.filmStrip.children(selector);
45 105
     }
46 106
 };
47 107
 

+ 2
- 1
modules/UI/toolbars/ToolbarToggler.js Прегледај датотеку

@@ -1,6 +1,7 @@
1 1
 /* global APP, config, $, interfaceConfig */
2 2
 
3 3
 import UIUtil from '../util/UIUtil';
4
+import BottomToolbar from './BottomToolbar';
4 5
 
5 6
 let toolbarTimeoutObject;
6 7
 let toolbarTimeout = interfaceConfig.INITIAL_TOOLBAR_TIMEOUT;
@@ -47,7 +48,7 @@ function hideToolbar() {
47 48
     } else {
48 49
         header.hide("slide", { direction: "up", duration: 300});
49 50
         $('#subject').animate({top: "-=40"}, 300);
50
-        if ($("#remoteVideos").hasClass("hidden")) {
51
+        if (!BottomToolbar.isFilmStripVisible()) {
51 52
             bottomToolbar.hide(
52 53
                 "slide", {direction: "right", duration: 300}
53 54
             );

+ 2
- 4
modules/UI/videolayout/LargeVideo.js Прегледај датотеку

@@ -4,6 +4,7 @@
4 4
 import UIUtil from "../util/UIUtil";
5 5
 import UIEvents from "../../../service/UI/UIEvents";
6 6
 import LargeContainer from './LargeContainer';
7
+import BottomToolbar from '../toolbars/BottomToolbar';
7 8
 
8 9
 const RTCBrowserType = require("../../RTC/RTCBrowserType");
9 10
 
@@ -34,10 +35,7 @@ function getDesktopVideoSize(videoWidth,
34 35
     let availableWidth = Math.max(videoWidth, videoSpaceWidth);
35 36
     let availableHeight = Math.max(videoHeight, videoSpaceHeight);
36 37
 
37
-    let filmstrip = $("#remoteVideos");
38
-
39
-    if (!filmstrip.hasClass("hidden"))
40
-        videoSpaceHeight -= filmstrip.outerHeight();
38
+    videoSpaceHeight -= BottomToolbar.getFilmStripHeight();
41 39
 
42 40
     if (availableWidth / aspectRatio >= videoSpaceHeight) {
43 41
         availableHeight = videoSpaceHeight;

+ 2
- 1
modules/UI/videolayout/RemoteVideo.js Прегледај датотеку

@@ -34,7 +34,8 @@ RemoteVideo.prototype.addRemoteVideoContainer = function() {
34 34
     if (APP.conference.isModerator) {
35 35
         this.addRemoteVideoMenu();
36 36
     }
37
-    AudioLevels.updateAudioLevelCanvas(this.id, this.VideoLayout);
37
+    let {thumbWidth, thumbHeight} = this.VideoLayout.calculateThumbnailSize();
38
+    AudioLevels.updateAudioLevelCanvas(this.id, thumbWidth, thumbHeight);
38 39
 
39 40
     return this.container;
40 41
 };

+ 40
- 49
modules/UI/videolayout/VideoLayout.js Прегледај датотеку

@@ -34,6 +34,8 @@ var eventEmitter = null;
34 34
  */
35 35
 var focusedVideoResourceJid = null;
36 36
 
37
+const thumbAspectRatio = 16.0 / 9.0;
38
+
37 39
 /**
38 40
  * On contact list item clicked.
39 41
  */
@@ -153,7 +155,8 @@ var VideoLayout = {
153 155
         let localId = APP.conference.localId;
154 156
         this.onVideoTypeChanged(localId, stream.getType());
155 157
 
156
-        AudioLevels.updateAudioLevelCanvas(null, VideoLayout);
158
+        let {thumbWidth, thumbHeight} = this.calculateThumbnailSize();
159
+        AudioLevels.updateAudioLevelCanvas(null, thumbWidth, thumbHeight);
157 160
 
158 161
         localVideoThumbnail.changeVideo(stream);
159 162
 
@@ -215,9 +218,11 @@ var VideoLayout = {
215 218
     electLastVisibleVideo () {
216 219
         // pick the last visible video in the row
217 220
         // if nobody else is left, this picks the local video
218
-        let pick = $('#remoteVideos>span[id!="mixedstream"]:visible:last');
219
-        if (pick.length) {
220
-            let id = getPeerContainerResourceId(pick[0]);
221
+        let thumbs = BottomToolbar.getThumbs(true).filter('id!="mixedstream"');
222
+
223
+        let lastVisible = thumbs.filter(':visible:last');
224
+        if (lastVisible.length) {
225
+            let id = getPeerContainerResourceId(lastVisible[0]);
221 226
             if (remoteVideos[id]) {
222 227
                 console.info("electLastVisibleVideo: " + id);
223 228
                 return id;
@@ -227,9 +232,9 @@ var VideoLayout = {
227 232
         }
228 233
 
229 234
         console.info("Last visible video no longer exists");
230
-        pick = $('#remoteVideos>span[id!="mixedstream"]');
231
-        if (pick.length) {
232
-            let id = getPeerContainerResourceId(pick[0]);
235
+        thumbs = BottomToolbar.getThumbs();
236
+        if (thumbs.length) {
237
+            let id = getPeerContainerResourceId(thumbs[0]);
233 238
             if (remoteVideos[id]) {
234 239
                 console.info("electLastVisibleVideo: " + id);
235 240
                 return id;
@@ -332,7 +337,7 @@ var VideoLayout = {
332 337
 
333 338
         // In case this is not currently in the last n we don't show it.
334 339
         if (localLastNCount && localLastNCount > 0 &&
335
-            $('#remoteVideos>span').length >= localLastNCount + 2) {
340
+            BottomToolbar.getThumbs().length >= localLastNCount + 2) {
336 341
             remoteVideo.showPeerContainer('hide');
337 342
         } else {
338 343
             VideoLayout.resizeThumbnails();
@@ -419,67 +424,53 @@ var VideoLayout = {
419 424
      * Resizes thumbnails.
420 425
      */
421 426
     resizeThumbnails (animate = false) {
422
-        let videoSpaceWidth = $('#remoteVideos').width();
427
+        let {thumbWidth, thumbHeight} = this.calculateThumbnailSize();
423 428
 
424
-        let [width, height] = this.calculateThumbnailSize(videoSpaceWidth);
429
+        $('.userAvatar').css('left', (thumbWidth - thumbHeight) / 2);
425 430
 
426
-        $('.userAvatar').css('left', (width - height) / 2);
427
-
428
-        $('#remoteVideos').animate({
429
-            // adds 2 px because of small video 1px border
430
-            height: height + 2
431
-        }, {
432
-            queue: false,
433
-            duration: animate ? 500 : 0
434
-        });
435
-
436
-        $('#remoteVideos>span').animate({
437
-            height, width
438
-        }, {
439
-            queue: false,
440
-            duration: animate ? 500 : 0,
441
-            complete: function () {
442
-                BottomToolbar.onRemoteVideoResized(width, height);
443
-                AudioLevels.onRemoteVideoResized(width, height);
444
-            }
431
+        BottomToolbar.resizeThumbnails(thumbWidth, thumbHeight, animate).then(function () {
432
+            BottomToolbar.resizeToolbar(thumbWidth, thumbHeight);
433
+            AudioLevels.updateCanvasSize(thumbWidth, thumbHeight);
445 434
         });
446 435
     },
447 436
 
448 437
     /**
449 438
      * Calculates the thumbnail size.
450 439
      *
451
-     * @param videoSpaceWidth the width of the video space
452 440
      */
453
-    calculateThumbnailSize (videoSpaceWidth) {
441
+    calculateThumbnailSize () {
442
+        let videoSpaceWidth = BottomToolbar.getFilmStripWidth();
454 443
         // Calculate the available height, which is the inner window height
455 444
         // minus 39px for the header minus 2px for the delimiter lines on the
456 445
         // top and bottom of the large video, minus the 36px space inside the
457 446
         // remoteVideos container used for highlighting shadow.
458
-       var availableHeight = 100;
447
+        let availableHeight = 100;
459 448
 
460
-        var numvids = $('#remoteVideos>span:visible').length;
449
+        let numvids = BottomToolbar.getThumbs().length;
461 450
         if (localLastNCount && localLastNCount > 0) {
462 451
             numvids = Math.min(localLastNCount + 1, numvids);
463 452
         }
464 453
 
465
-       // Remove the 3px borders arround videos and border around the remote
466
-       // videos area and the 4 pixels between the local video and the others
467
-       //TODO: Find out where the 4 pixels come from and remove them
468
-       var availableWinWidth = videoSpaceWidth - 2 * 3 * numvids - 70 - 4;
454
+        // Remove the 3px borders arround videos and border around the remote
455
+        // videos area and the 4 pixels between the local video and the others
456
+        //TODO: Find out where the 4 pixels come from and remove them
457
+        let availableWinWidth = videoSpaceWidth - 2 * 3 * numvids - 70 - 4;
469 458
 
470
-       var availableWidth = availableWinWidth / numvids;
471
-       var aspectRatio = 16.0 / 9.0;
472
-       var maxHeight = Math.min(160, availableHeight);
473
-       availableHeight
474
-           = Math.min(  maxHeight,
475
-                        availableWidth / aspectRatio,
476
-                        window.innerHeight - 18);
459
+        let availableWidth = availableWinWidth / numvids;
460
+        let maxHeight = Math.min(160, availableHeight);
461
+        availableHeight
462
+            = Math.min(  maxHeight,
463
+                         availableWidth / thumbAspectRatio,
464
+                         window.innerHeight - 18);
477 465
 
478
-       if (availableHeight < availableWidth / aspectRatio) {
479
-           availableWidth = Math.floor(availableHeight * aspectRatio);
480
-       }
466
+        if (availableHeight < availableWidth / thumbAspectRatio) {
467
+            availableWidth = Math.floor(availableHeight * thumbAspectRatio);
468
+        }
481 469
 
482
-       return [availableWidth, availableHeight];
470
+        return {
471
+            thumbWidth: availableWidth,
472
+            thumbHeight: availableHeight
473
+        };
483 474
    },
484 475
 
485 476
     /**
@@ -623,7 +614,7 @@ var VideoLayout = {
623 614
         var updateLargeVideo = false;
624 615
 
625 616
         // Handle LastN/local LastN changes.
626
-        $('#remoteVideos>span').each(function( index, element ) {
617
+        BottomToolbar.getThumbs().each(function( index, element ) {
627 618
             var resourceJid = getPeerContainerResourceId(element);
628 619
 
629 620
             // We do not want to process any logic for our own(local) video

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