Przeglądaj źródła

Add shared video smart mike mutes unmutes

j8
yanas 9 lat temu
rodzic
commit
3a9d743d47
2 zmienionych plików z 107 dodań i 34 usunięć
  1. 15
    3
      conference.js
  2. 92
    31
      modules/UI/shared_video/SharedVideo.js

+ 15
- 3
conference.js Wyświetl plik

1098
         );
1098
         );
1099
 
1099
 
1100
         APP.UI.addListener(UIEvents.UPDATE_SHARED_VIDEO,
1100
         APP.UI.addListener(UIEvents.UPDATE_SHARED_VIDEO,
1101
-            (url, state, time, volume) => {
1101
+            (url, state, time, isMuted, volume) => {
1102
             // send start and stop commands once, and remove any updates
1102
             // send start and stop commands once, and remove any updates
1103
             // that had left
1103
             // that had left
1104
             if (state === 'stop' || state === 'start' || state === 'playing') {
1104
             if (state === 'stop' || state === 'start' || state === 'playing') {
1108
                     attributes: {
1108
                     attributes: {
1109
                         state: state,
1109
                         state: state,
1110
                         time: time,
1110
                         time: time,
1111
+                        muted: isMuted,
1111
                         volume: volume
1112
                         volume: volume
1112
                     }
1113
                     }
1113
                 });
1114
                 });
1121
                     attributes: {
1122
                     attributes: {
1122
                         state: state,
1123
                         state: state,
1123
                         time: time,
1124
                         time: time,
1125
+                        muted: isMuted,
1124
                         volume: volume
1126
                         volume: volume
1125
                     }
1127
                     }
1126
                 });
1128
                 });
1131
 
1133
 
1132
                 if (attributes.state === 'stop') {
1134
                 if (attributes.state === 'stop') {
1133
                     APP.UI.stopSharedVideo(id, attributes);
1135
                     APP.UI.stopSharedVideo(id, attributes);
1134
-                } else if (attributes.state === 'start') {
1136
+                }
1137
+                else if (attributes.state === 'start') {
1135
                     APP.UI.showSharedVideo(id, value, attributes);
1138
                     APP.UI.showSharedVideo(id, value, attributes);
1136
-                } else if (attributes.state === 'playing'
1139
+                }
1140
+                else if (attributes.state === 'playing'
1137
                     || attributes.state === 'pause') {
1141
                     || attributes.state === 'pause') {
1138
                     APP.UI.updateSharedVideo(id, value, attributes);
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 Wyświetl plik

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.
156
                 if(self.initialAttributes)
162
                 if(self.initialAttributes)
157
                 {
163
                 {
158
                     self.processAttributes(
164
                     self.processAttributes(
159
-                        self.player, self.initialAttributes, self.playerPaused);
165
+                        self.player,
166
+                        self.initialAttributes,
167
+                        self.playerPaused);
168
+
160
                     self.initialAttributes = null;
169
                     self.initialAttributes = null;
161
                 }
170
                 }
162
-
171
+                self.smartMute();
163
                 self.updateCheck();
172
                 self.updateCheck();
164
             } else if (event.data == YT.PlayerState.PAUSED) {
173
             } else if (event.data == YT.PlayerState.PAUSED) {
165
                 self.playerPaused = true;
174
                 self.playerPaused = true;
175
+                self.smartUnmute();
166
                 self.updateCheck(true);
176
                 self.updateCheck(true);
167
             }
177
             }
168
         };
178
         };
186
             self.updateCheck();
196
             self.updateCheck();
187
 
197
 
188
             // let's check, if player is not muted lets mute locally
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
 
259
 
254
             this.processTime(player, attributes, playerPaused);
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
                 player.setVolume(attributes.volume);
280
                 player.setVolume(attributes.volume);
263
                 console.info("Player change of volume:" + attributes.volume);
281
                 console.info("Player change of volume:" + attributes.volume);
264
                 this.showSharedVideoMutedPopup(false);
282
                 this.showSharedVideoMutedPopup(false);
265
             }
283
             }
266
 
284
 
267
-            if(playerPaused)
285
+            if (playerPaused)
268
                 player.playVideo();
286
                 player.playVideo();
269
 
287
 
270
         } else if (attributes.state == 'pause') {
288
         } else if (attributes.state == 'pause') {
328
             this.emitter.emit(UIEvents.UPDATE_SHARED_VIDEO,
346
             this.emitter.emit(UIEvents.UPDATE_SHARED_VIDEO,
329
                 this.url, 'playing',
347
                 this.url, 'playing',
330
                 this.player.getCurrentTime(),
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
         if(this.from !== id)
389
         if(this.from !== id)
371
             return;
390
             return;
372
 
391
 
373
-        if(!this.player){
392
+        if(!this.player) {
374
             // if there is no error in the player till now,
393
             // if there is no error in the player till now,
375
             // store the initial attributes
394
             // store the initial attributes
376
             if (!this.errorInPlayer) {
395
             if (!this.errorInPlayer) {
388
             this.localAudioMutedListener);
407
             this.localAudioMutedListener);
389
         this.localAudioMutedListener = null;
408
         this.localAudioMutedListener = null;
390
 
409
 
391
-        this.showSharedVideoMutedPopup(false);
392
-
393
         VideoLayout.removeParticipantContainer(this.url);
410
         VideoLayout.removeParticipantContainer(this.url);
394
 
411
 
395
         VideoLayout.showLargeVideoContainer(SHARED_VIDEO_CONTAINER_TYPE, false)
412
         VideoLayout.showLargeVideoContainer(SHARED_VIDEO_CONTAINER_TYPE, false)
405
                     this.errorInPlayer.destroy();
422
                     this.errorInPlayer.destroy();
406
                     this.errorInPlayer = null;
423
                     this.errorInPlayer = null;
407
                 }
424
                 }
425
+                this.smartUnmute();
408
                 // revert to original behavior (prevents pausing
426
                 // revert to original behavior (prevents pausing
409
                 // for participants not sharing the video to pause it)
427
                 // for participants not sharing the video to pause it)
410
                 $("#sharedVideo").css("pointer-events","auto");
428
                 $("#sharedVideo").css("pointer-events","auto");
421
      * @param {boolean} indicates if this mute was a result of user interaction,
439
      * @param {boolean} indicates if this mute was a result of user interaction,
422
      * i.e. pressing the mute button or it was programatically triggerred
440
      * i.e. pressing the mute button or it was programatically triggerred
423
      */
441
      */
424
-    localAudioMuted (muted, userInteraction) {
442
+    onLocalAudioMuted (muted, userInteraction) {
425
         if(!this.player)
443
         if(!this.player)
426
             return;
444
             return;
427
 
445
 
428
         if (muted) {
446
         if (muted) {
429
             this.mutedWithUserInteraction = userInteraction;
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
 

Ładowanie…
Anuluj
Zapisz