瀏覽代碼

Merge pull request #622 from jitsi/add-smart-mutes-unmutes-shared-video

Add shared video smart mike mutes unmutes
j8
damencho 9 年之前
父節點
當前提交
65c49b6b4c
共有 2 個文件被更改,包括 109 次插入37 次删除
  1. 15
    3
      conference.js
  2. 94
    34
      modules/UI/shared_video/SharedVideo.js

+ 15
- 3
conference.js 查看文件

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

+ 94
- 34
modules/UI/shared_video/SharedVideo.js 查看文件

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

Loading…
取消
儲存