Browse Source

fix: unmute video on audio only switch off

Will unmute local video (and ask for permissions if needed) in case user
started in audio only mode and is turing it off.
j8
paweldomas 8 years ago
parent
commit
a5f61714bd
2 changed files with 45 additions and 39 deletions
  1. 42
    38
      conference.js
  2. 3
    1
      modules/API/API.js

+ 42
- 38
conference.js View File

@@ -72,7 +72,7 @@ const eventEmitter = new EventEmitter();
72 72
 let room;
73 73
 let connection;
74 74
 let localAudio, localVideo;
75
-let initialAudioMutedState = false, initialVideoMutedState = false;
75
+let initialAudioMutedState = false;
76 76
 
77 77
 import {VIDEO_CONTAINER_TYPE} from "./modules/UI/videolayout/VideoContainer";
78 78
 
@@ -495,6 +495,11 @@ export default {
495 495
 
496 496
                         return [];
497 497
                     });
498
+
499
+            // Enable audio only mode
500
+            if (config.startAudioOnly) {
501
+                APP.store.dispatch(toggleAudioOnly());
502
+            }
498 503
         } else if (options.startScreenSharing) {
499 504
             tryCreateLocalTracks = this._createDesktopTrack()
500 505
                 .then(desktopStream => {
@@ -608,8 +613,9 @@ export default {
608 613
                     });
609 614
             }).then(([tracks, con]) => {
610 615
                 tracks.forEach(track => {
611
-                    if((track.isAudioTrack() && initialAudioMutedState)
612
-                        || (track.isVideoTrack() && initialVideoMutedState)) {
616
+                    if (track.isAudioTrack() && initialAudioMutedState) {
617
+                        track.mute();
618
+                    } else if (track.isVideoTrack() && this.videoMuted) {
613 619
                         track.mute();
614 620
                     }
615 621
                 });
@@ -662,15 +668,6 @@ export default {
662 668
                     this.updateVideoIconEnabled();
663 669
                 }
664 670
 
665
-                // Enable audio only mode
666
-                if (config.startAudioOnly) {
667
-                    // It is important to have that toggled after video muted
668
-                    // state is adjusted by the code about lack of video tracks
669
-                    // above. That's because audio only will store muted state
670
-                    // on toggle action.
671
-                    APP.store.dispatch(toggleAudioOnly());
672
-                }
673
-
674 671
                 this._initDeviceList();
675 672
 
676 673
                 if (config.iAmRecorder)
@@ -722,22 +719,41 @@ export default {
722 719
     /**
723 720
      * Simulates toolbar button click for video mute. Used by shortcuts and API.
724 721
      * @param mute true for mute and false for unmute.
725
-     */
726
-    muteVideo(mute) {
727
-        muteLocalVideo(mute);
722
+     * @param {boolean} [showUI] when set to false will not display any error
723
+     * dialogs in case of media permissions error.
724
+     */
725
+    muteVideo(mute, showUI = true) {
726
+        if (!localVideo && this.videoMuted && !mute) {
727
+            // Try to create local video if there wasn't any.
728
+            // This handles the case when user joined with no video
729
+            // (dismissed screen sharing screen or in audio only mode), but
730
+            // decided to add it later on by clicking on muted video icon or
731
+            // turning off the audio only mode.
732
+            //
733
+            // FIXME when local track creation is moved to react/redux
734
+            // it should take care of the use case described above
735
+            createLocalTracks({ devices: ['video'] }, false)
736
+                .then(([videoTrack]) => videoTrack)
737
+                .catch(error => {
738
+                    // FIXME should send some feedback to the API on error ?
739
+                    if (showUI) {
740
+                        APP.UI.showDeviceErrorDialog(null, error);
741
+                    }
742
+                    // Rollback the video muted status by using null track
743
+                    return null;
744
+                })
745
+                .then(videoTrack => this.useVideoStream(videoTrack));
746
+        } else {
747
+            muteLocalVideo(mute);
748
+        }
728 749
     },
729 750
     /**
730 751
      * Simulates toolbar button click for video mute. Used by shortcuts and API.
731
-     * @param {boolean} force - If the track is not created, the operation
732
-     * will be executed after the track is created. Otherwise the operation
733
-     * will be ignored.
752
+     * @param {boolean} [showUI] when set to false will not display any error
753
+     * dialogs in case of media permissions error.
734 754
      */
735
-    toggleVideoMuted(force = false) {
736
-        if(!localVideo && force) {
737
-            initialVideoMutedState = !initialVideoMutedState;
738
-            return;
739
-        }
740
-        this.muteVideo(!this.videoMuted);
755
+    toggleVideoMuted(showUI = true) {
756
+        this.muteVideo(!this.videoMuted, showUI);
741 757
     },
742 758
     /**
743 759
      * Retrieve list of conference participants (without local user).
@@ -1731,20 +1747,8 @@ export default {
1731 1747
         APP.UI.addListener(UIEvents.VIDEO_MUTED, muted => {
1732 1748
             if (this.isAudioOnly() && !muted) {
1733 1749
                 this._displayAudioOnlyTooltip('videoMute');
1734
-            } else if (!localVideo && this.videoMuted && !muted) {
1735
-                // Maybe try to create local video if there wasn't any ?
1736
-                // This handles the case when user joined with no video
1737
-                // (dismissed screen sharing screen), but decided to add it
1738
-                // later on by clicking on muted video icon.
1739
-                createLocalTracks({ devices: ['video'] }, false)
1740
-                    .then(([videoTrack]) => {
1741
-                        APP.conference.useVideoStream(videoTrack);
1742
-                    })
1743
-                    .catch(error => {
1744
-                        APP.UI.showDeviceErrorDialog(null, error);
1745
-                    });
1746 1750
             } else {
1747
-                muteLocalVideo(muted);
1751
+                this.muteVideo(muted);
1748 1752
             }
1749 1753
         });
1750 1754
 
@@ -1946,7 +1950,7 @@ export default {
1946 1950
         );
1947 1951
 
1948 1952
         APP.UI.addListener(UIEvents.TOGGLE_AUDIO_ONLY, audioOnly => {
1949
-            muteLocalVideo(audioOnly);
1953
+            this.muteVideo(audioOnly);
1950 1954
 
1951 1955
             // Immediately update the UI by having remote videos and the large
1952 1956
             // video update themselves instead of waiting for some other event

+ 3
- 1
modules/API/API.js View File

@@ -36,7 +36,9 @@ function initCommands() {
36 36
         'display-name':
37 37
             APP.conference.changeLocalDisplayName.bind(APP.conference),
38 38
         'toggle-audio': () => APP.conference.toggleAudioMuted(true),
39
-        'toggle-video': () => APP.conference.toggleVideoMuted(true),
39
+        'toggle-video': () => {
40
+            APP.conference.toggleVideoMuted(false /* no UI */);
41
+        },
40 42
         'toggle-film-strip': APP.UI.toggleFilmstrip,
41 43
         'toggle-chat': APP.UI.toggleChat,
42 44
         'toggle-contact-list': APP.UI.toggleContactList,

Loading…
Cancel
Save