浏览代码

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

j8
damencho 9 年前
父节点
当前提交
bede8feccc
共有 1 个文件被更改,包括 67 次插入10 次删除
  1. 67
    10
      modules/UI/shared_video/SharedVideo.js

+ 67
- 10
modules/UI/shared_video/SharedVideo.js 查看文件

@@ -73,6 +73,10 @@ export default class SharedVideoManager {
73 73
         // the owner of the video
74 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 80
         // This code loads the IFrame Player API code asynchronously.
77 81
         var tag = document.createElement('script');
78 82
 
@@ -110,7 +114,8 @@ export default class SharedVideoManager {
110 114
                         'onStateChange': onPlayerStateChange,
111 115
                         'onError': onPlayerError
112 116
                     }
113
-                });
117
+                }).addEventListener(// add listener for volume changes
118
+                    "onVolumeChange", "onVolumeChange");
114 119
             };
115 120
 
116 121
         window.onPlayerStateChange = function(event) {
@@ -119,10 +124,6 @@ export default class SharedVideoManager {
119 124
 
120 125
                 self.player = event.target;
121 126
 
122
-                // add listener for volume changes
123
-                self.player.addEventListener(
124
-                    "onVolumeChange", "onVolumeChange");
125
-
126 127
                 if(self.initialAttributes)
127 128
                 {
128 129
                     self.processAttributes(
@@ -142,10 +143,14 @@ export default class SharedVideoManager {
142 143
          * @param event
143 144
          */
144 145
         window.onVolumeChange = function (event) {
145
-            if(!self.player)
146
-                return;
147
-
148 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 156
         window.onPlayerReady = function(event) {
@@ -199,9 +204,11 @@ export default class SharedVideoManager {
199 204
 
200 205
             // lets check the volume
201 206
             if (attributes.volume !== undefined &&
202
-                player.getVolume() != attributes.volume) {
207
+                player.getVolume() != attributes.volume
208
+                && APP.conference.isLocalAudioMuted()) {
203 209
                 player.setVolume(attributes.volume);
204 210
                 console.info("Player change of volume:" + attributes.volume);
211
+                this.notifyUserComfortableVideoMute(false);
205 212
             }
206 213
 
207 214
             if(playerPaused)
@@ -323,6 +330,10 @@ export default class SharedVideoManager {
323 330
             this.intervalId = null;
324 331
         }
325 332
 
333
+        this.emitter.removeListener(UIEvents.AUDIO_MUTED,
334
+            this.localAudioMutedListener);
335
+        this.localAudioMutedListener = null;
336
+
326 337
         VideoLayout.removeParticipantContainer(this.url);
327 338
 
328 339
         VideoLayout.showLargeVideoContainer(SHARED_VIDEO_CONTAINER_TYPE, false)
@@ -333,7 +344,7 @@ export default class SharedVideoManager {
333 344
                 if(this.player) {
334 345
                     this.player.destroy();
335 346
                     this.player = null;
336
-                }//
347
+                } // if there is an error in player, remove that instance
337 348
                 else if (this.errorInPlayer) {
338 349
                     this.errorInPlayer.destroy();
339 350
                     this.errorInPlayer = null;
@@ -344,6 +355,52 @@ export default class SharedVideoManager {
344 355
         this.isSharedVideoShown = false;
345 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
 /**

正在加载...
取消
保存