Parcourir la source

Mutes local video when shared video is playing and mutes shared video if user wants to talk.

j8
damencho il y a 9 ans
Parent
révision
bede8feccc
1 fichiers modifiés avec 67 ajouts et 10 suppressions
  1. 67
    10
      modules/UI/shared_video/SharedVideo.js

+ 67
- 10
modules/UI/shared_video/SharedVideo.js Voir le fichier

73
         // the owner of the video
73
         // the owner of the video
74
         this.from = id;
74
         this.from = id;
75
 
75
 
76
+        //listen for local audio mute events
77
+        this.localAudioMutedListener = this.localAudioMuted.bind(this);
78
+        this.emitter.on(UIEvents.AUDIO_MUTED, this.localAudioMutedListener);
79
+
76
         // This code loads the IFrame Player API code asynchronously.
80
         // This code loads the IFrame Player API code asynchronously.
77
         var tag = document.createElement('script');
81
         var tag = document.createElement('script');
78
 
82
 
110
                         'onStateChange': onPlayerStateChange,
114
                         'onStateChange': onPlayerStateChange,
111
                         'onError': onPlayerError
115
                         'onError': onPlayerError
112
                     }
116
                     }
113
-                });
117
+                }).addEventListener(// add listener for volume changes
118
+                    "onVolumeChange", "onVolumeChange");
114
             };
119
             };
115
 
120
 
116
         window.onPlayerStateChange = function(event) {
121
         window.onPlayerStateChange = function(event) {
119
 
124
 
120
                 self.player = event.target;
125
                 self.player = event.target;
121
 
126
 
122
-                // add listener for volume changes
123
-                self.player.addEventListener(
124
-                    "onVolumeChange", "onVolumeChange");
125
-
126
                 if(self.initialAttributes)
127
                 if(self.initialAttributes)
127
                 {
128
                 {
128
                     self.processAttributes(
129
                     self.processAttributes(
142
          * @param event
143
          * @param event
143
          */
144
          */
144
         window.onVolumeChange = function (event) {
145
         window.onVolumeChange = function (event) {
145
-            if(!self.player)
146
-                return;
147
-
148
             self.updateCheck();
146
             self.updateCheck();
147
+
148
+            // let's check, if player is not muted lets mute locally
149
+            if(event.data.volume > 0 && !event.data.muted
150
+                && !APP.conference.isLocalAudioMuted()){
151
+                self.emitter.emit(UIEvents.AUDIO_MUTED, true);
152
+                self.notifyUserComfortableMicMute(true);
153
+            }
149
         };
154
         };
150
 
155
 
151
         window.onPlayerReady = function(event) {
156
         window.onPlayerReady = function(event) {
199
 
204
 
200
             // lets check the volume
205
             // lets check the volume
201
             if (attributes.volume !== undefined &&
206
             if (attributes.volume !== undefined &&
202
-                player.getVolume() != attributes.volume) {
207
+                player.getVolume() != attributes.volume
208
+                && APP.conference.isLocalAudioMuted()) {
203
                 player.setVolume(attributes.volume);
209
                 player.setVolume(attributes.volume);
204
                 console.info("Player change of volume:" + attributes.volume);
210
                 console.info("Player change of volume:" + attributes.volume);
211
+                this.notifyUserComfortableVideoMute(false);
205
             }
212
             }
206
 
213
 
207
             if(playerPaused)
214
             if(playerPaused)
323
             this.intervalId = null;
330
             this.intervalId = null;
324
         }
331
         }
325
 
332
 
333
+        this.emitter.removeListener(UIEvents.AUDIO_MUTED,
334
+            this.localAudioMutedListener);
335
+        this.localAudioMutedListener = null;
336
+
326
         VideoLayout.removeParticipantContainer(this.url);
337
         VideoLayout.removeParticipantContainer(this.url);
327
 
338
 
328
         VideoLayout.showLargeVideoContainer(SHARED_VIDEO_CONTAINER_TYPE, false)
339
         VideoLayout.showLargeVideoContainer(SHARED_VIDEO_CONTAINER_TYPE, false)
333
                 if(this.player) {
344
                 if(this.player) {
334
                     this.player.destroy();
345
                     this.player.destroy();
335
                     this.player = null;
346
                     this.player = null;
336
-                }//
347
+                } // if there is an error in player, remove that instance
337
                 else if (this.errorInPlayer) {
348
                 else if (this.errorInPlayer) {
338
                     this.errorInPlayer.destroy();
349
                     this.errorInPlayer.destroy();
339
                     this.errorInPlayer = null;
350
                     this.errorInPlayer = null;
344
         this.isSharedVideoShown = false;
355
         this.isSharedVideoShown = false;
345
         this.initialAttributes = null;
356
         this.initialAttributes = null;
346
     }
357
     }
358
+
359
+    /**
360
+     * Receives events for local audio mute/unmute by local user.
361
+     * @param muted boolena whether it is muted or not.
362
+     */
363
+    localAudioMuted (muted) {
364
+        if(!this.player)
365
+            return;
366
+
367
+        if(muted)
368
+            return;
369
+
370
+        // if we are un-muting and player is not muted, lets muted
371
+        // to not pollute the conference
372
+        if(this.player.getVolume() > 0 || !this.player.isMuted()){
373
+            this.player.setVolume(0);
374
+            this.notifyUserComfortableVideoMute(true);
375
+        }
376
+    }
377
+
378
+    /**
379
+     * Notifies user for muting its audio due to video is unmuted.
380
+     * @param show boolean, show or hide the notification
381
+     */
382
+    notifyUserComfortableMicMute (show) {
383
+        if(show) {
384
+            this.notifyUserComfortableVideoMute(false);
385
+            console.log("Your audio was muted to enjoy the video");
386
+        }
387
+        else
388
+            console.log("Hide notification local audio muted");
389
+    }
390
+
391
+    /**
392
+     * Notifies user for muting the video due to audio is unmuted.
393
+     * @param show boolean, show or hide the notification
394
+     */
395
+    notifyUserComfortableVideoMute (show) {
396
+        if(show) {
397
+            this.notifyUserComfortableMicMute(false);
398
+            console.log(
399
+                "Your shared video was muted in order to speak freely!");
400
+        }
401
+        else
402
+            console.log("Hide notification share video muted");
403
+    }
347
 }
404
 }
348
 
405
 
349
 /**
406
 /**

Chargement…
Annuler
Enregistrer