Bladeren bron

fix(API): early audio muted status

Apply the same early audio muted logic as for the video.
j8
paweldomas 8 jaren geleden
bovenliggende
commit
e818fa1e9e
2 gewijzigde bestanden met toevoegingen van 57 en 33 verwijderingen
  1. 54
    32
      conference.js
  2. 3
    1
      modules/API/API.js

+ 54
- 32
conference.js Bestand weergeven

78
 let room;
78
 let room;
79
 let connection;
79
 let connection;
80
 let localAudio, localVideo;
80
 let localAudio, localVideo;
81
-let initialAudioMutedState = false;
82
 
81
 
83
 import {VIDEO_CONTAINER_TYPE} from "./modules/UI/videolayout/VideoContainer";
82
 import {VIDEO_CONTAINER_TYPE} from "./modules/UI/videolayout/VideoContainer";
84
 
83
 
177
 /**
176
 /**
178
  * Mute or unmute local audio stream if it exists.
177
  * Mute or unmute local audio stream if it exists.
179
  * @param {boolean} muted - if audio stream should be muted or unmuted.
178
  * @param {boolean} muted - if audio stream should be muted or unmuted.
180
- * @param {boolean} userInteraction - indicates if this local audio mute was a
181
- * result of user interaction
179
+ *
180
+ * @returns {Promise} resolved in case mute/unmute operations succeeds or
181
+ * rejected with an error if something goes wrong. It is expected that often
182
+ * the error will be of the {@link JitsiTrackError} type, but it's not
183
+ * guaranteed.
182
  */
184
  */
183
 function muteLocalAudio(muted) {
185
 function muteLocalAudio(muted) {
184
-    muteLocalMedia(localAudio, muted);
186
+    return muteLocalMedia(localAudio, muted);
185
 }
187
 }
186
 
188
 
187
 /**
189
 /**
680
                     });
682
                     });
681
             }).then(([tracks, con]) => {
683
             }).then(([tracks, con]) => {
682
                 tracks.forEach(track => {
684
                 tracks.forEach(track => {
683
-                    if (track.isAudioTrack() && initialAudioMutedState) {
685
+                    if (track.isAudioTrack() && this.audioMuted) {
684
                         track.mute();
686
                         track.mute();
685
                     } else if (track.isVideoTrack() && this.videoMuted) {
687
                     } else if (track.isVideoTrack() && this.videoMuted) {
686
                         track.mute();
688
                         track.mute();
751
     },
753
     },
752
     /**
754
     /**
753
      * Simulates toolbar button click for audio mute. Used by shortcuts and API.
755
      * Simulates toolbar button click for audio mute. Used by shortcuts and API.
754
-     * @param mute true for mute and false for unmute.
756
+     * @param {boolean} mute true for mute and false for unmute.
757
+     * @param {boolean} [showUI] when set to false will not display any error
758
+     * dialogs in case of media permissions error.
755
      */
759
      */
756
-    muteAudio(mute) {
757
-        muteLocalAudio(mute);
760
+    muteAudio(mute, showUI = true) {
761
+        // Not ready to modify track's state yet
762
+        if (!this._localTracksInitialized) {
763
+            this.audioMuted = mute;
764
+            return;
765
+        } else if (localAudio && localAudio.isMuted() === mute) {
766
+            // NO-OP
767
+            return;
768
+        }
769
+
770
+        const maybeShowErrorDialog = (error) => {
771
+            if (showUI) {
772
+                APP.UI.showDeviceErrorDialog(error, null);
773
+            }
774
+        };
775
+
776
+        if (!localAudio && this.audioMuted && !mute) {
777
+            createLocalTracks({ devices: ['audio'] }, false)
778
+                .then(([audioTrack]) => audioTrack)
779
+                .catch(error => {
780
+                    maybeShowErrorDialog(error);
781
+
782
+                    // Rollback the audio muted status by using null track
783
+                    return null;
784
+                })
785
+                .then(audioTrack => this.useAudioStream(audioTrack));
786
+        } else {
787
+            const oldMutedStatus = this.audioMuted;
788
+
789
+            muteLocalAudio(mute)
790
+                .catch(error => {
791
+                    maybeShowErrorDialog(error);
792
+                    this.audioMuted = oldMutedStatus;
793
+                    APP.UI.setAudioMuted(this.getMyUserId(), this.audioMuted);
794
+                });
795
+        }
758
     },
796
     },
759
     /**
797
     /**
760
      * Returns whether local audio is muted or not.
798
      * Returns whether local audio is muted or not.
766
     /**
804
     /**
767
      * Simulates toolbar button click for audio mute. Used by shortcuts
805
      * Simulates toolbar button click for audio mute. Used by shortcuts
768
      * and API.
806
      * and API.
769
-     * @param {boolean} force - If the track is not created, the operation
770
-     * will be executed after the track is created. Otherwise the operation
771
-     * will be ignored.
772
-     */
773
-    toggleAudioMuted(force = false) {
774
-        if(!localAudio && force) {
775
-            // NOTE this logic will be adjusted to the same one as for the video
776
-            // once 'startWithAudioMuted' option is added.
777
-            initialAudioMutedState = !initialAudioMutedState;
778
-            return;
779
-        }
780
-        this.muteAudio(!this.audioMuted);
807
+     * @param {boolean} [showUI] when set to false will not display any error
808
+     * dialogs in case of media permissions error.
809
+     */
810
+    toggleAudioMuted(showUI = true) {
811
+        this.muteAudio(!this.audioMuted, showUI);
781
     },
812
     },
782
     /**
813
     /**
783
      * Simulates toolbar button click for video mute. Used by shortcuts and API.
814
      * Simulates toolbar button click for video mute. Used by shortcuts and API.
1213
                     this.audioMuted = newStream.isMuted();
1244
                     this.audioMuted = newStream.isMuted();
1214
                     APP.UI.addLocalStream(newStream);
1245
                     APP.UI.addLocalStream(newStream);
1215
                 } else {
1246
                 } else {
1216
-                    this.audioMuted = false;
1247
+                    // No audio is treated the same way as being audio muted
1248
+                    this.audioMuted = true;
1217
                 }
1249
                 }
1218
                 APP.UI.setAudioMuted(this.getMyUserId(), this.audioMuted);
1250
                 APP.UI.setAudioMuted(this.getMyUserId(), this.audioMuted);
1219
             });
1251
             });
1836
         });
1868
         });
1837
 
1869
 
1838
         APP.UI.addListener(UIEvents.AUDIO_MUTED, muted => {
1870
         APP.UI.addListener(UIEvents.AUDIO_MUTED, muted => {
1839
-            if (!localAudio && this.audioMuted && !muted) {
1840
-                createLocalTracks({ devices: ['audio'] }, false)
1841
-                    .then(([audioTrack]) => {
1842
-                        this.useAudioStream(audioTrack);
1843
-                    })
1844
-                    .catch(error => {
1845
-                        APP.UI.showDeviceErrorDialog(error, null);
1846
-                    });
1847
-            } else {
1848
-                muteLocalAudio(muted);
1849
-            }
1871
+            this.muteAudio(muted);
1850
         });
1872
         });
1851
         APP.UI.addListener(UIEvents.VIDEO_MUTED, muted => {
1873
         APP.UI.addListener(UIEvents.VIDEO_MUTED, muted => {
1852
             if (this.isAudioOnly() && !muted) {
1874
             if (this.isAudioOnly() && !muted) {

+ 3
- 1
modules/API/API.js Bestand weergeven

35
     commands = {
35
     commands = {
36
         'display-name':
36
         'display-name':
37
             APP.conference.changeLocalDisplayName.bind(APP.conference),
37
             APP.conference.changeLocalDisplayName.bind(APP.conference),
38
-        'toggle-audio': () => APP.conference.toggleAudioMuted(true),
38
+        'toggle-audio': () => {
39
+            APP.conference.toggleAudioMuted(false /* no UI */);
40
+        },
39
         'toggle-video': () => {
41
         'toggle-video': () => {
40
             APP.conference.toggleVideoMuted(false /* no UI */);
42
             APP.conference.toggleVideoMuted(false /* no UI */);
41
         },
43
         },

Laden…
Annuleren
Opslaan