浏览代码

Add shared video smart mike mutes unmutes

j8
yanas 9 年前
父节点
当前提交
3a9d743d47
共有 2 个文件被更改,包括 107 次插入34 次删除
  1. 15
    3
      conference.js
  2. 92
    31
      modules/UI/shared_video/SharedVideo.js

+ 15
- 3
conference.js 查看文件

@@ -1098,7 +1098,7 @@ export default {
1098 1098
         );
1099 1099
 
1100 1100
         APP.UI.addListener(UIEvents.UPDATE_SHARED_VIDEO,
1101
-            (url, state, time, volume) => {
1101
+            (url, state, time, isMuted, volume) => {
1102 1102
             // send start and stop commands once, and remove any updates
1103 1103
             // that had left
1104 1104
             if (state === 'stop' || state === 'start' || state === 'playing') {
@@ -1108,6 +1108,7 @@ export default {
1108 1108
                     attributes: {
1109 1109
                         state: state,
1110 1110
                         time: time,
1111
+                        muted: isMuted,
1111 1112
                         volume: volume
1112 1113
                     }
1113 1114
                 });
@@ -1121,6 +1122,7 @@ export default {
1121 1122
                     attributes: {
1122 1123
                         state: state,
1123 1124
                         time: time,
1125
+                        muted: isMuted,
1124 1126
                         volume: volume
1125 1127
                     }
1126 1128
                 });
@@ -1131,12 +1133,22 @@ export default {
1131 1133
 
1132 1134
                 if (attributes.state === 'stop') {
1133 1135
                     APP.UI.stopSharedVideo(id, attributes);
1134
-                } else if (attributes.state === 'start') {
1136
+                }
1137
+                else if (attributes.state === 'start') {
1135 1138
                     APP.UI.showSharedVideo(id, value, attributes);
1136
-                } else if (attributes.state === 'playing'
1139
+                }
1140
+                else if (attributes.state === 'playing'
1137 1141
                     || attributes.state === 'pause') {
1138 1142
                     APP.UI.updateSharedVideo(id, value, attributes);
1139 1143
                 }
1140 1144
             });
1145
+    },
1146
+    /**
1147
+     * Adss any room listener.
1148
+     * @param eventName one of the ConferenceEvents
1149
+     * @param callBack the function to be called when the event occurs
1150
+     */
1151
+     addConferenceListener(eventName, callBack) {
1152
+        room.on(eventName, callBack);
1141 1153
     }
1142 1154
 };

+ 92
- 31
modules/UI/shared_video/SharedVideo.js 查看文件

@@ -30,12 +30,18 @@ export default class SharedVideoManager {
30 30
     }
31 31
 
32 32
     /**
33
-     * Indicates if the player volume is currently on.
33
+     * Indicates if the player volume is currently on. This will return true if
34
+     * we have an available player, which is currently in a PLAYING state,
35
+     * which isn't muted and has it's volume greater than 0.
34 36
      *
35
-     * @returns {*|player|boolean}
37
+     * @returns {boolean} indicating if the volume of the shared video is
38
+     * currently on.
36 39
      */
37 40
     isSharedVideoVolumeOn() {
38
-        return (this.player && this.player.getVolume() > 0);
41
+        return (this.player
42
+                && this.player.getPlayerState() === YT.PlayerState.PLAYING
43
+                && !this.player.isMuted()
44
+                && this.player.getVolume() > 0);
39 45
     }
40 46
 
41 47
     /**
@@ -92,7 +98,7 @@ export default class SharedVideoManager {
92 98
         this.from = id;
93 99
 
94 100
         //listen for local audio mute events
95
-        this.localAudioMutedListener = this.localAudioMuted.bind(this);
101
+        this.localAudioMutedListener = this.onLocalAudioMuted.bind(this);
96 102
         this.emitter.on(UIEvents.AUDIO_MUTED, this.localAudioMutedListener);
97 103
 
98 104
         // This code loads the IFrame Player API code asynchronously.
@@ -156,13 +162,17 @@ export default class SharedVideoManager {
156 162
                 if(self.initialAttributes)
157 163
                 {
158 164
                     self.processAttributes(
159
-                        self.player, self.initialAttributes, self.playerPaused);
165
+                        self.player,
166
+                        self.initialAttributes,
167
+                        self.playerPaused);
168
+
160 169
                     self.initialAttributes = null;
161 170
                 }
162
-
171
+                self.smartMute();
163 172
                 self.updateCheck();
164 173
             } else if (event.data == YT.PlayerState.PAUSED) {
165 174
                 self.playerPaused = true;
175
+                self.smartUnmute();
166 176
                 self.updateCheck(true);
167 177
             }
168 178
         };
@@ -186,15 +196,11 @@ export default class SharedVideoManager {
186 196
             self.updateCheck();
187 197
 
188 198
             // let's check, if player is not muted lets mute locally
189
-            if(event.data.volume > 0 && !event.data.muted
190
-                && !APP.conference.isLocalAudioMuted()) {
191
-                self.emitter.emit(UIEvents.AUDIO_MUTED, true, false);
192
-                self.showMicMutedPopup(true);
199
+            if(event.data.volume > 0 && !event.data.muted) {
200
+                self.smartMute();
193 201
             }
194
-            else if (!self.mutedWithUserInteraction
195
-                        && (event.data.volume <=0 || event.data.muted)
196
-                        && APP.conference.isLocalAudioMuted()) {
197
-                self.emitter.emit(UIEvents.AUDIO_MUTED, false, false);
202
+            else if (event.data.volume <=0 || event.data.muted) {
203
+                self.smartUnmute();
198 204
             }
199 205
         };
200 206
 
@@ -253,18 +259,30 @@ export default class SharedVideoManager {
253 259
 
254 260
             this.processTime(player, attributes, playerPaused);
255 261
 
256
-            // lets check the volume
257
-            if (attributes.volume !== undefined
258
-                && player.getVolume() != attributes.volume
259
-                && (APP.conference.isLocalAudioMuted()
260
-                    || !this.mutedWithUserInteraction)) {
262
+            let isAttrMuted = (attributes.muted === "true");
263
+
264
+            // Process player unmute
265
+            if (player.isMuted() && !isAttrMuted) {
266
+                console.log("Process player unmute and smart mike mute.");
267
+                this.mutePlayer(false);
268
+            }
269
+            // Process player mute
270
+            else if (!player.isMuted() && isAttrMuted) {
271
+                console.log("Process player mute and smart mike unmute.");
272
+                this.mutePlayer(true);
273
+            }
274
+
275
+            // Process volume
276
+            if (!isAttrMuted
277
+                && attributes.volume !== undefined
278
+                && player.getVolume() != attributes.volume) {
261 279
 
262 280
                 player.setVolume(attributes.volume);
263 281
                 console.info("Player change of volume:" + attributes.volume);
264 282
                 this.showSharedVideoMutedPopup(false);
265 283
             }
266 284
 
267
-            if(playerPaused)
285
+            if (playerPaused)
268 286
                 player.playVideo();
269 287
 
270 288
         } else if (attributes.state == 'pause') {
@@ -328,7 +346,8 @@ export default class SharedVideoManager {
328 346
             this.emitter.emit(UIEvents.UPDATE_SHARED_VIDEO,
329 347
                 this.url, 'playing',
330 348
                 this.player.getCurrentTime(),
331
-                this.player.isMuted() ? 0 : this.player.getVolume());
349
+                this.player.isMuted(),
350
+                this.player.getVolume());
332 351
         }
333 352
     }
334 353
 
@@ -370,7 +389,7 @@ export default class SharedVideoManager {
370 389
         if(this.from !== id)
371 390
             return;
372 391
 
373
-        if(!this.player){
392
+        if(!this.player) {
374 393
             // if there is no error in the player till now,
375 394
             // store the initial attributes
376 395
             if (!this.errorInPlayer) {
@@ -388,8 +407,6 @@ export default class SharedVideoManager {
388 407
             this.localAudioMutedListener);
389 408
         this.localAudioMutedListener = null;
390 409
 
391
-        this.showSharedVideoMutedPopup(false);
392
-
393 410
         VideoLayout.removeParticipantContainer(this.url);
394 411
 
395 412
         VideoLayout.showLargeVideoContainer(SHARED_VIDEO_CONTAINER_TYPE, false)
@@ -405,6 +422,7 @@ export default class SharedVideoManager {
405 422
                     this.errorInPlayer.destroy();
406 423
                     this.errorInPlayer = null;
407 424
                 }
425
+                this.smartUnmute();
408 426
                 // revert to original behavior (prevents pausing
409 427
                 // for participants not sharing the video to pause it)
410 428
                 $("#sharedVideo").css("pointer-events","auto");
@@ -421,20 +439,63 @@ export default class SharedVideoManager {
421 439
      * @param {boolean} indicates if this mute was a result of user interaction,
422 440
      * i.e. pressing the mute button or it was programatically triggerred
423 441
      */
424
-    localAudioMuted (muted, userInteraction) {
442
+    onLocalAudioMuted (muted, userInteraction) {
425 443
         if(!this.player)
426 444
             return;
427 445
 
428 446
         if (muted) {
429 447
             this.mutedWithUserInteraction = userInteraction;
430
-            return;
431 448
         }
449
+        else if (!this.playerPaused) {
450
+            this.mutePlayer(true);
451
+        }
452
+    }
453
+
454
+    /**
455
+     * Mutes / unmutes the player.
456
+     * @param mute true to mute the shared video, false - otherwise.
457
+     */
458
+    mutePlayer(mute) {
459
+        if (!this.player.isMuted() && mute) {
460
+            this.player.mute();
461
+            this.smartUnmute();
462
+        }
463
+        else if (this.player.isMuted() && !mute) {
464
+            this.player.unMute();
465
+            this.smartMute();
466
+        }
467
+
468
+        // Check if we need to update other participants
469
+        this.updateCheck();
470
+
471
+        this.showSharedVideoMutedPopup(mute);
472
+    }
473
+
474
+    /**
475
+     * Smart mike unmute. If the mike is currently muted and it wasn't muted
476
+     * by the user via the mike button and the volume of the shared video is on
477
+     * we're unmuting the mike automatically.
478
+     */
479
+    smartUnmute() {
480
+        if (APP.conference.isLocalAudioMuted()
481
+            && !this.mutedWithUserInteraction
482
+            && !this.isSharedVideoVolumeOn()) {
483
+
484
+            this.emitter.emit(UIEvents.AUDIO_MUTED, false, false);
485
+            this.showMicMutedPopup(false);
486
+        }
487
+    }
488
+
489
+    /**
490
+     * Smart mike mute. If the mike isn't currently muted and the shared video
491
+     * volume is on we mute the mike.
492
+     */
493
+    smartMute() {
494
+        if (!APP.conference.isLocalAudioMuted()
495
+            && this.isSharedVideoVolumeOn()) {
432 496
 
433
-        // if we are un-muting and player is not muted, lets muted
434
-        // to not pollute the conference
435
-        if (this.player.getVolume() > 0 || !this.player.isMuted()) {
436
-            this.player.setVolume(0);
437
-            this.showSharedVideoMutedPopup(true);
497
+            this.emitter.emit(UIEvents.AUDIO_MUTED, true, false);
498
+            this.showMicMutedPopup(true);
438 499
         }
439 500
     }
440 501
 

正在加载...
取消
保存