Browse Source

Adds smart un-mute to the shared video logic

j8
yanas 9 years ago
parent
commit
d08e37b42b

+ 4
- 1
conference.js View File

73
 /**
73
 /**
74
  * Mute or unmute local audio stream if it exists.
74
  * Mute or unmute local audio stream if it exists.
75
  * @param {boolean} muted if audio stream should be muted or unmuted.
75
  * @param {boolean} muted if audio stream should be muted or unmuted.
76
+ * @param {boolean} indicates if this local audio mute was a result of user
77
+ * interaction
78
+ *
76
  */
79
  */
77
-function muteLocalAudio (muted) {
80
+function muteLocalAudio (muted, userInteraction) {
78
     if (!localAudio) {
81
     if (!localAudio) {
79
         return;
82
         return;
80
     }
83
     }

+ 3
- 0
index.html View File

124
                         <ul id="micMutedPopup" class="loginmenu">
124
                         <ul id="micMutedPopup" class="loginmenu">
125
                             <li data-i18n="[html]toolbar.micMutedPopup"></li>
125
                             <li data-i18n="[html]toolbar.micMutedPopup"></li>
126
                         </ul>
126
                         </ul>
127
+                        <ul id="unableToUnmutePopup" class="loginmenu">
128
+                            <li data-i18n="[html]toolbar.unableToUnmutePopup"></li>
129
+                        </ul>
127
                     </a>
130
                     </a>
128
                     <a class="button icon-camera" id="toolbar_button_camera" data-container="body" data-toggle="popover" data-placement="bottom" shortcut="toggleVideoPopover" data-i18n="[content]toolbar.videomute" content="Start / stop camera"></a>
131
                     <a class="button icon-camera" id="toolbar_button_camera" data-container="body" data-toggle="popover" data-placement="bottom" shortcut="toggleVideoPopover" data-i18n="[content]toolbar.videomute" content="Start / stop camera"></a>
129
                     <a class="button" id="toolbar_button_record" data-container="body" data-toggle="popover" data-placement="bottom" style="display: none"></a>
132
                     <a class="button" id="toolbar_button_record" data-container="body" data-toggle="popover" data-placement="bottom" style="display: none"></a>

+ 2
- 1
lang/main.json View File

65
         "logout": "Logout",
65
         "logout": "Logout",
66
         "dialpad": "Show dialpad",
66
         "dialpad": "Show dialpad",
67
         "sharedVideoMutedPopup": "Your shared video has been muted so<br/>that you can talk to the other participants.",
67
         "sharedVideoMutedPopup": "Your shared video has been muted so<br/>that you can talk to the other participants.",
68
-        "micMutedPopup": "Your microphone has been muted so that you<br/>would fully enjoy your shared video."
68
+        "micMutedPopup": "Your microphone has been muted so that you<br/>would fully enjoy your shared video.",
69
+        "unableToUnmutePopup": "You're not able to un-mute while the shared video is on."
69
     },
70
     },
70
     "bottomtoolbar": {
71
     "bottomtoolbar": {
71
         "chat": "Open / close chat",
72
         "chat": "Open / close chat",

+ 8
- 0
modules/UI/UI.js View File

331
     $(window).resize(onResize);
331
     $(window).resize(onResize);
332
 }
332
 }
333
 
333
 
334
+/**
335
+ * Returns the shared document manager object.
336
+ * @return {EtherpadManager} the shared document manager object
337
+ */
338
+UI.getSharedVideoManager = function () {
339
+    return sharedVideoManager;
340
+};
341
+
334
 /**
342
 /**
335
  * Starts the UI module and initializes all related components.
343
  * Starts the UI module and initializes all related components.
336
  *
344
  *

+ 41
- 52
modules/UI/shared_video/SharedVideo.js View File

26
         this.emitter = emitter;
26
         this.emitter = emitter;
27
         this.isSharedVideoShown = false;
27
         this.isSharedVideoShown = false;
28
         this.isPlayerAPILoaded = false;
28
         this.isPlayerAPILoaded = false;
29
+        this.mutedWithUserInteraction = false;
30
+    }
31
+
32
+    /**
33
+     * Indicates if the player volume is currently on.
34
+     *
35
+     * @returns {*|player|boolean}
36
+     */
37
+    isSharedVideoVolumeOn() {
38
+        return (this.player && this.player.getVolume() > 0);
39
+    }
40
+
41
+    /**
42
+     * Indicates if the local user is the owner of the shared video.
43
+     * @returns {*|boolean}
44
+     */
45
+    isSharedVideoOwner() {
46
+        return this.from && APP.conference.isLocalId(this.from);
29
     }
47
     }
30
 
48
 
31
     /**
49
     /**
169
 
187
 
170
             // let's check, if player is not muted lets mute locally
188
             // let's check, if player is not muted lets mute locally
171
             if(event.data.volume > 0 && !event.data.muted
189
             if(event.data.volume > 0 && !event.data.muted
172
-                && !APP.conference.isLocalAudioMuted()){
173
-                self.emitter.emit(UIEvents.AUDIO_MUTED, true);
190
+                && !APP.conference.isLocalAudioMuted()) {
191
+                self.emitter.emit(UIEvents.AUDIO_MUTED, true, false);
174
                 self.showMicMutedPopup(true);
192
                 self.showMicMutedPopup(true);
175
             }
193
             }
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);
198
+            }
176
         };
199
         };
177
 
200
 
178
         window.onPlayerReady = function(event) {
201
         window.onPlayerReady = function(event) {
231
             this.processTime(player, attributes, playerPaused);
254
             this.processTime(player, attributes, playerPaused);
232
 
255
 
233
             // lets check the volume
256
             // lets check the volume
234
-            if (attributes.volume !== undefined &&
235
-                player.getVolume() != attributes.volume
236
-                && APP.conference.isLocalAudioMuted()) {
257
+            if (attributes.volume !== undefined
258
+                && player.getVolume() != attributes.volume
259
+                && (APP.conference.isLocalAudioMuted()
260
+                    || !this.mutedWithUserInteraction)) {
261
+
237
                 player.setVolume(attributes.volume);
262
                 player.setVolume(attributes.volume);
238
                 console.info("Player change of volume:" + attributes.volume);
263
                 console.info("Player change of volume:" + attributes.volume);
239
                 this.showSharedVideoMutedPopup(false);
264
                 this.showSharedVideoMutedPopup(false);
393
     /**
418
     /**
394
      * Receives events for local audio mute/unmute by local user.
419
      * Receives events for local audio mute/unmute by local user.
395
      * @param muted boolena whether it is muted or not.
420
      * @param muted boolena whether it is muted or not.
421
+     * @param {boolean} indicates if this mute was a result of user interaction,
422
+     * i.e. pressing the mute button or it was programatically triggerred
396
      */
423
      */
397
-    localAudioMuted (muted) {
424
+    localAudioMuted (muted, userInteraction) {
398
         if(!this.player)
425
         if(!this.player)
399
             return;
426
             return;
400
 
427
 
401
-        if(muted)
428
+        if (muted) {
429
+            this.mutedWithUserInteraction = userInteraction;
402
             return;
430
             return;
431
+        }
403
 
432
 
404
         // if we are un-muting and player is not muted, lets muted
433
         // if we are un-muting and player is not muted, lets muted
405
         // to not pollute the conference
434
         // to not pollute the conference
406
-        if(this.player.getVolume() > 0 || !this.player.isMuted()){
435
+        if (this.player.getVolume() > 0 || !this.player.isMuted()) {
407
             this.player.setVolume(0);
436
             this.player.setVolume(0);
408
             this.showSharedVideoMutedPopup(true);
437
             this.showSharedVideoMutedPopup(true);
409
         }
438
         }
415
      * @param show boolean, show or hide the notification
444
      * @param show boolean, show or hide the notification
416
      */
445
      */
417
     showMicMutedPopup (show) {
446
     showMicMutedPopup (show) {
418
-        var micMutedPopupSelector = $("#micMutedPopup");
419
-        if(show) {
447
+        if(show)
420
             this.showSharedVideoMutedPopup(false);
448
             this.showSharedVideoMutedPopup(false);
421
 
449
 
422
-            if (!micMutedPopupSelector.is(":visible"))
423
-                micMutedPopupSelector.css("display", "inline-block");
424
-
425
-            // FIXME: we need an utility method for that.
426
-            micMutedPopupSelector.fadeIn(300,
427
-                () => {micMutedPopupSelector.css({opacity: 1});}
428
-            );
429
-
430
-            setTimeout(
431
-                function () {
432
-                    micMutedPopupSelector.fadeOut(300,
433
-                        () => {micMutedPopupSelector.css({opacity: 0});}
434
-                    );
435
-                }, 5000);
436
-        }
437
-        else {
438
-            micMutedPopupSelector.fadeOut(300,
439
-                () => {micMutedPopupSelector.css({opacity: 0});}
440
-            );
441
-        }
450
+        UIUtil.animateShowElement($("#micMutedPopup"), show, 5000);
442
     }
451
     }
443
 
452
 
444
     /**
453
     /**
448
      * @param show boolean, show or hide the notification
457
      * @param show boolean, show or hide the notification
449
      */
458
      */
450
     showSharedVideoMutedPopup (show) {
459
     showSharedVideoMutedPopup (show) {
451
-        var sharedVideoMutedPopupSelector = $("#sharedVideoMutedPopup");
452
-        if(show) {
460
+        if(show)
453
             this.showMicMutedPopup(false);
461
             this.showMicMutedPopup(false);
454
 
462
 
455
-            if (!sharedVideoMutedPopupSelector.is(":visible"))
456
-                sharedVideoMutedPopupSelector.css("display", "inline-block");
457
-
458
-            // FIXME: we need an utility method for that.
459
-            sharedVideoMutedPopupSelector.fadeIn(300,
460
-                () => {sharedVideoMutedPopupSelector.css({opacity: 1});}
461
-            );
462
-
463
-            setTimeout(
464
-                function () {
465
-                    sharedVideoMutedPopupSelector.fadeOut(300,
466
-                        () => {sharedVideoMutedPopupSelector.css({opacity: 0});}
467
-                    );
468
-                }, 5000);
469
-        }
470
-        else {
471
-            sharedVideoMutedPopupSelector.fadeOut(300,
472
-                () => {sharedVideoMutedPopupSelector.css({opacity: 0});}
473
-            );
474
-        }
463
+        UIUtil.animateShowElement($("#sharedVideoMutedPopup"), show, 5000);
475
     }
464
     }
476
 }
465
 }
477
 
466
 

+ 16
- 3
modules/UI/toolbars/Toolbar.js View File

44
 
44
 
45
 const buttonHandlers = {
45
 const buttonHandlers = {
46
     "toolbar_button_mute": function () {
46
     "toolbar_button_mute": function () {
47
+        let sharedVideoManager = APP.UI.getSharedVideoManager();
48
+
47
         if (APP.conference.audioMuted) {
49
         if (APP.conference.audioMuted) {
48
-            AnalyticsAdapter.sendEvent('toolbar.audio.unmuted');
49
-            emitter.emit(UIEvents.AUDIO_MUTED, false);
50
+            // If there's a shared video with the volume "on" and we aren't
51
+            // the video owner, we warn the user
52
+            // that currently it's not possible to unmute.
53
+            if (sharedVideoManager
54
+                && sharedVideoManager.isSharedVideoVolumeOn()
55
+                && !sharedVideoManager.isSharedVideoOwner()) {
56
+                UIUtil.animateShowElement(
57
+                    $("#unableToUnmutePopup"), true, 5000);
58
+            }
59
+            else {
60
+                AnalyticsAdapter.sendEvent('toolbar.audio.unmuted');
61
+                emitter.emit(UIEvents.AUDIO_MUTED, false, true);
62
+            }
50
         } else {
63
         } else {
51
             AnalyticsAdapter.sendEvent('toolbar.audio.muted');
64
             AnalyticsAdapter.sendEvent('toolbar.audio.muted');
52
-            emitter.emit(UIEvents.AUDIO_MUTED, true);
65
+            emitter.emit(UIEvents.AUDIO_MUTED, true, true);
53
         }
66
         }
54
     },
67
     },
55
     "toolbar_button_camera": function () {
68
     "toolbar_button_camera": function () {

+ 33
- 0
modules/UI/util/UIUtil.js View File

166
      */
166
      */
167
     isVisible(el) {
167
     isVisible(el) {
168
         return (el.offsetParent !== null);
168
         return (el.offsetParent !== null);
169
+    },
170
+
171
+    /**
172
+     * Shows / hides the element given by {selector} and sets a timeout if the
173
+     * {hideDelay} is set to a value > 0.
174
+     * @param selector the jquery selector of the element to show/hide.
175
+     * @param show a {boolean} that indicates if the element should be shown or
176
+     * hidden
177
+     * @param hideDelay the value in milliseconds to wait before hiding the
178
+     * element
179
+     */
180
+    animateShowElement(selector, show, hideDelay) {
181
+        if(show) {
182
+            if (!selector.is(":visible"))
183
+                selector.css("display", "inline-block");
184
+
185
+            selector.fadeIn(300,
186
+                () => {selector.css({opacity: 1});}
187
+            );
188
+
189
+            if (hideDelay && hideDelay > 0)
190
+                setTimeout(
191
+                    function () {
192
+                        selector.fadeOut(300,
193
+                        () => {selector.css({opacity: 0});}
194
+                    );
195
+                }, hideDelay);
196
+        }
197
+        else {
198
+            selector.fadeOut(300,
199
+                () => {selector.css({opacity: 0});}
200
+            );
201
+        }
169
     }
202
     }
170
 };
203
 };
171
 
204
 

Loading…
Cancel
Save