浏览代码

Merge pull request #633 from jitsi/fix-and-refactor-shared-video

Fix and refactor shared video
master
hristoterezov 9 年前
父节点
当前提交
cdefca9fbd
共有 3 个文件被更改,包括 61 次插入57 次删除
  1. 4
    4
      conference.js
  2. 6
    6
      modules/UI/UI.js
  3. 51
    47
      modules/UI/shared_video/SharedVideo.js

+ 4
- 4
conference.js 查看文件

@@ -762,7 +762,7 @@ export default {
762 762
             console.log('USER %s LEFT', id, user);
763 763
             APP.API.notifyUserLeft(id);
764 764
             APP.UI.removeUser(id, user.getDisplayName());
765
-            APP.UI.stopSharedVideo(id);
765
+            APP.UI.onSharedVideoStop(id);
766 766
         });
767 767
 
768 768
 
@@ -1130,14 +1130,14 @@ export default {
1130 1130
             this.commands.defaults.SHARED_VIDEO, ({value, attributes}, id) => {
1131 1131
 
1132 1132
                 if (attributes.state === 'stop') {
1133
-                    APP.UI.stopSharedVideo(id, attributes);
1133
+                    APP.UI.onSharedVideoStop(id, attributes);
1134 1134
                 }
1135 1135
                 else if (attributes.state === 'start') {
1136
-                    APP.UI.showSharedVideo(id, value, attributes);
1136
+                    APP.UI.onSharedVideoStart(id, value, attributes);
1137 1137
                 }
1138 1138
                 else if (attributes.state === 'playing'
1139 1139
                     || attributes.state === 'pause') {
1140
-                    APP.UI.updateSharedVideo(id, value, attributes);
1140
+                    APP.UI.onSharedVideoUpdate(id, value, attributes);
1141 1141
                 }
1142 1142
             });
1143 1143
     },

+ 6
- 6
modules/UI/UI.js 查看文件

@@ -1116,9 +1116,9 @@ UI.updateDevicesAvailability = function (id, devices) {
1116 1116
  * @param {string} url video url
1117 1117
  * @param {string} attributes
1118 1118
 */
1119
-UI.showSharedVideo = function (id, url, attributes) {
1119
+UI.onSharedVideoStart = function (id, url, attributes) {
1120 1120
     if (sharedVideoManager)
1121
-        sharedVideoManager.showSharedVideo(id, url, attributes);
1121
+        sharedVideoManager.onSharedVideoStart(id, url, attributes);
1122 1122
 };
1123 1123
 
1124 1124
 /**
@@ -1127,9 +1127,9 @@ UI.showSharedVideo = function (id, url, attributes) {
1127 1127
  * @param {string} url video url
1128 1128
  * @param {string} attributes
1129 1129
  */
1130
-UI.updateSharedVideo = function (id, url, attributes) {
1130
+UI.onSharedVideoUpdate = function (id, url, attributes) {
1131 1131
     if (sharedVideoManager)
1132
-        sharedVideoManager.updateSharedVideo(id, url, attributes);
1132
+        sharedVideoManager.onSharedVideoUpdate(id, url, attributes);
1133 1133
 };
1134 1134
 
1135 1135
 /**
@@ -1137,9 +1137,9 @@ UI.updateSharedVideo = function (id, url, attributes) {
1137 1137
  * @param {string} id the id of the sender of the command
1138 1138
  * @param {string} attributes
1139 1139
  */
1140
-UI.stopSharedVideo = function (id, attributes) {
1140
+UI.onSharedVideoStop = function (id, attributes) {
1141 1141
     if (sharedVideoManager)
1142
-        sharedVideoManager.stopSharedVideo(id, attributes);
1142
+        sharedVideoManager.onSharedVideoStop(id, attributes);
1143 1143
 };
1144 1144
 
1145 1145
 module.exports = UI;

+ 51
- 47
modules/UI/shared_video/SharedVideo.js 查看文件

@@ -79,13 +79,14 @@ export default class SharedVideoManager {
79 79
     }
80 80
 
81 81
     /**
82
-     * Shows the player component and starts the checking function
83
-     * that will be sending updates, if we are the one shared the video
82
+     * Shows the player component and starts the process that will be sending
83
+     * updates, if we are the one shared the video.
84
+     *
84 85
      * @param id the id of the sender of the command
85 86
      * @param url the video url
86 87
      * @param attributes
87 88
      */
88
-    showSharedVideo (id, url, attributes) {
89
+    onSharedVideoStart (id, url, attributes) {
89 90
         if (this.isSharedVideoShown)
90 91
             return;
91 92
 
@@ -97,6 +98,8 @@ export default class SharedVideoManager {
97 98
         // the owner of the video
98 99
         this.from = id;
99 100
 
101
+        this.mutedWithUserInteraction = APP.conference.isLocalAudioMuted();
102
+
100 103
         //listen for local audio mute events
101 104
         this.localAudioMutedListener = this.onLocalAudioMuted.bind(this);
102 105
         this.emitter.on(UIEvents.AUDIO_MUTED, this.localAudioMutedListener);
@@ -153,6 +156,10 @@ export default class SharedVideoManager {
153 156
                 }
154 157
             };
155 158
 
159
+        /**
160
+         * Indicates that a change in state has occurred for the shared video.
161
+         * @param event the event notifying us of the change
162
+         */
156 163
         window.onPlayerStateChange = function(event) {
157 164
             if (event.data == YT.PlayerState.PLAYING) {
158 165
 
@@ -160,19 +167,19 @@ export default class SharedVideoManager {
160 167
 
161 168
                 if(self.initialAttributes)
162 169
                 {
163
-                    self.processAttributes(
170
+                    // If a network update has occurred already now is the
171
+                    // time to process it.
172
+                    self.processVideoUpdate(
164 173
                         self.player,
165
-                        self.initialAttributes,
166
-                        false);
174
+                        self.initialAttributes);
167 175
 
168 176
                     self.initialAttributes = null;
169 177
                 }
170
-                self.smartMute();
171
-                self.updateCheck();
178
+                self.smartAudioMute();
172 179
             } else if (event.data == YT.PlayerState.PAUSED) {
173
-                self.smartUnmute();
174
-                self.updateCheck(true);
180
+                self.smartAudioUnmute();
175 181
             }
182
+            self.fireSharedVideoEvent(event.data == YT.PlayerState.PAUSED);
176 183
         };
177 184
 
178 185
         /**
@@ -182,7 +189,7 @@ export default class SharedVideoManager {
182 189
         window.onVideoProgress = function (event) {
183 190
             let state = event.target.getPlayerState();
184 191
             if (state == YT.PlayerState.PAUSED) {
185
-                self.updateCheck(true);
192
+                self.fireSharedVideoEvent(true);
186 193
             }
187 194
         };
188 195
 
@@ -191,14 +198,14 @@ export default class SharedVideoManager {
191 198
          * @param event
192 199
          */
193 200
         window.onVolumeChange = function (event) {
194
-            self.updateCheck();
201
+            self.fireSharedVideoEvent();
195 202
 
196 203
             // let's check, if player is not muted lets mute locally
197 204
             if(event.data.volume > 0 && !event.data.muted) {
198
-                self.smartMute();
205
+                self.smartAudioMute();
199 206
             }
200 207
             else if (event.data.volume <=0 || event.data.muted) {
201
-                self.smartUnmute();
208
+                self.smartAudioUnmute();
202 209
             }
203 210
         };
204 211
 
@@ -230,7 +237,7 @@ export default class SharedVideoManager {
230 237
             // we need to continuously send the player current time position
231 238
             if(APP.conference.isLocalId(self.from)) {
232 239
                 self.intervalId = setInterval(
233
-                    self.updateCheck.bind(self),
240
+                    self.fireSharedVideoEvent.bind(self),
234 241
                     updateInterval);
235 242
             }
236 243
         };
@@ -246,28 +253,24 @@ export default class SharedVideoManager {
246 253
      * Process attributes, whether player needs to be paused or seek.
247 254
      * @param player the player to operate over
248 255
      * @param attributes the attributes with the player state we want
249
-     * @param playerPaused current saved state for the player
250 256
      */
251
-    processAttributes (player, attributes, playerPaused)
257
+    processVideoUpdate (player, attributes)
252 258
     {
253 259
         if(!attributes)
254 260
             return;
255 261
 
256 262
         if (attributes.state == 'playing') {
257 263
 
258
-            this.processTime(player, attributes, playerPaused);
264
+            let isPlayerPaused
265
+                = (this.player.getPlayerState() === YT.PlayerState.PAUSED);
259 266
 
260
-            let isAttrMuted = (attributes.muted === "true");
267
+            // If our player is currently paused force the seek.
268
+            this.processTime(player, attributes, isPlayerPaused);
261 269
 
262
-            // Process player unmute
263
-            if (player.isMuted() && !isAttrMuted) {
264
-                console.log("Process player unmute and smart mike mute.");
265
-                this.mutePlayer(false);
266
-            }
267
-            // Process player mute
268
-            else if (!player.isMuted() && isAttrMuted) {
269
-                console.log("Process player mute and smart mike unmute.");
270
-                this.mutePlayer(true);
270
+            // Process mute.
271
+            let isAttrMuted = (attributes.muted === "true");
272
+            if (player.isMuted() !== isAttrMuted) {
273
+                this.smartPlayerMute(isAttrMuted, true);
271 274
             }
272 275
 
273 276
             // Process volume
@@ -280,7 +283,7 @@ export default class SharedVideoManager {
280 283
                 this.showSharedVideoMutedPopup(false);
281 284
             }
282 285
 
283
-            if (playerPaused)
286
+            if (isPlayerPaused)
284 287
                 player.playVideo();
285 288
 
286 289
         } else if (attributes.state == 'pause') {
@@ -288,8 +291,6 @@ export default class SharedVideoManager {
288 291
             player.pauseVideo();
289 292
 
290 293
             this.processTime(player, attributes, true);
291
-        } else if (attributes.state == 'stop') {
292
-            this.stopSharedVideo(this.from);
293 294
         }
294 295
     }
295 296
 
@@ -323,7 +324,7 @@ export default class SharedVideoManager {
323 324
     /**
324 325
      * Checks current state of the player and fire an event with the values.
325 326
      */
326
-    updateCheck(sendPauseEvent)
327
+    fireSharedVideoEvent(sendPauseEvent)
327 328
     {
328 329
         // ignore update checks if we are not the owner of the video
329 330
         // or there is still no player defined or we are stopped
@@ -356,22 +357,21 @@ export default class SharedVideoManager {
356 357
      * @param url the video url
357 358
      * @param attributes
358 359
      */
359
-    updateSharedVideo (id, url, attributes) {
360
+    onSharedVideoUpdate (id, url, attributes) {
360 361
         // if we are sending the event ignore
361 362
         if(APP.conference.isLocalId(this.from)) {
362 363
             return;
363 364
         }
364 365
 
365 366
         if(!this.isSharedVideoShown) {
366
-            this.showSharedVideo(id, url, attributes);
367
+            this.onSharedVideoStart(id, url, attributes);
367 368
             return;
368 369
         }
369 370
 
370 371
         if(!this.player)
371 372
             this.initialAttributes = attributes;
372 373
         else {
373
-            this.processAttributes(this.player, attributes,
374
-                (this.player.getPlayerState() === YT.PlayerState.PAUSED));
374
+            this.processVideoUpdate(this.player, attributes);
375 375
         }
376 376
     }
377 377
 
@@ -381,7 +381,7 @@ export default class SharedVideoManager {
381 381
      * left and we want to remove video if the user sharing it left).
382 382
      * @param id the id of the sender of the command
383 383
      */
384
-    stopSharedVideo (id, attributes) {
384
+    onSharedVideoStop (id, attributes) {
385 385
         if (!this.isSharedVideoShown)
386 386
             return;
387 387
 
@@ -421,7 +421,7 @@ export default class SharedVideoManager {
421 421
                     this.errorInPlayer.destroy();
422 422
                     this.errorInPlayer = null;
423 423
                 }
424
-                this.smartUnmute();
424
+                this.smartAudioUnmute();
425 425
                 // revert to original behavior (prevents pausing
426 426
                 // for participants not sharing the video to pause it)
427 427
                 $("#sharedVideo").css("pointer-events","auto");
@@ -446,27 +446,31 @@ export default class SharedVideoManager {
446 446
             this.mutedWithUserInteraction = userInteraction;
447 447
         }
448 448
         else if (this.player.getPlayerState() !== YT.PlayerState.PAUSED) {
449
-            this.mutePlayer(true);
449
+            this.smartPlayerMute(true, false);
450
+            // Check if we need to update other participants
451
+            this.fireSharedVideoEvent();
450 452
         }
451 453
     }
452 454
 
453 455
     /**
454 456
      * Mutes / unmutes the player.
455 457
      * @param mute true to mute the shared video, false - otherwise.
458
+     * @param {boolean} Indicates if this mute is a consequence of a network
459
+     * video update or is called locally.
456 460
      */
457
-    mutePlayer(mute) {
461
+    smartPlayerMute(mute, isVideoUpdate) {
458 462
         if (!this.player.isMuted() && mute) {
459 463
             this.player.mute();
460
-            this.smartUnmute();
464
+
465
+            if (isVideoUpdate)
466
+                this.smartAudioUnmute();
461 467
         }
462 468
         else if (this.player.isMuted() && !mute) {
463 469
             this.player.unMute();
464
-            this.smartMute();
470
+            if (isVideoUpdate)
471
+                this.smartAudioMute();
465 472
         }
466 473
 
467
-        // Check if we need to update other participants
468
-        this.updateCheck();
469
-
470 474
         this.showSharedVideoMutedPopup(mute);
471 475
     }
472 476
 
@@ -475,7 +479,7 @@ export default class SharedVideoManager {
475 479
      * by the user via the mike button and the volume of the shared video is on
476 480
      * we're unmuting the mike automatically.
477 481
      */
478
-    smartUnmute() {
482
+    smartAudioUnmute() {
479 483
         if (APP.conference.isLocalAudioMuted()
480 484
             && !this.mutedWithUserInteraction
481 485
             && !this.isSharedVideoVolumeOn()) {
@@ -489,7 +493,7 @@ export default class SharedVideoManager {
489 493
      * Smart mike mute. If the mike isn't currently muted and the shared video
490 494
      * volume is on we mute the mike.
491 495
      */
492
-    smartMute() {
496
+    smartAudioMute() {
493 497
         if (!APP.conference.isLocalAudioMuted()
494 498
             && this.isSharedVideoVolumeOn()) {
495 499
 

正在加载...
取消
保存