Parcourir la source

fix(iframe_api): toggle audio/video race condition

If toggle audio or video is executed too early and the local
tracks don't exist we fail to execute the operation. Now we store
the mute state and we are executing it after the tracks are
created
j8
hristoterezov il y a 8 ans
Parent
révision
ab62690b97
2 fichiers modifiés avec 29 ajouts et 7 suppressions
  1. 26
    4
      conference.js
  2. 3
    3
      modules/API/API.js

+ 26
- 4
conference.js Voir le fichier

@@ -63,7 +63,8 @@ const ConnectionQualityEvents = JitsiMeetJS.events.connectionQuality;
63 63
 
64 64
 const eventEmitter = new EventEmitter();
65 65
 
66
-let room, connection, localAudio, localVideo;
66
+let room, connection, localAudio, localVideo,
67
+    initialAudioMutedState = false, initialVideoMutedState = false;
67 68
 
68 69
 /**
69 70
  * Indicates whether extension external installation is in progress or not.
@@ -581,6 +582,12 @@ export default {
581 582
                 analytics.init();
582 583
                 return createInitialLocalTracksAndConnect(options.roomName);
583 584
             }).then(([tracks, con]) => {
585
+                tracks.forEach(track => {
586
+                    if((track.isAudioTrack() && initialAudioMutedState)
587
+                        || (track.isVideoTrack() && initialVideoMutedState)) {
588
+                        track.mute();
589
+                    }
590
+                });
584 591
                 logger.log('initialized with %s local tracks', tracks.length);
585 592
                 con.addEventListener(
586 593
                     ConnectionEvents.CONNECTION_FAILED,
@@ -645,9 +652,17 @@ export default {
645 652
         return this.audioMuted;
646 653
     },
647 654
     /**
648
-     * Simulates toolbar button click for audio mute. Used by shortcuts and API.
655
+     * Simulates toolbar button click for audio mute. Used by shortcuts
656
+     * and API.
657
+     * @param {boolean} force - If the track is not created, the operation
658
+     * will be executed after the track is created. Otherwise the operation
659
+     * will be ignored.
649 660
      */
650
-    toggleAudioMuted () {
661
+    toggleAudioMuted (force = false) {
662
+        if(!localAudio && force) {
663
+            initialAudioMutedState = !initialAudioMutedState;
664
+            return;
665
+        }
651 666
         this.muteAudio(!this.audioMuted);
652 667
     },
653 668
     /**
@@ -659,8 +674,15 @@ export default {
659 674
     },
660 675
     /**
661 676
      * Simulates toolbar button click for video mute. Used by shortcuts and API.
677
+     * @param {boolean} force - If the track is not created, the operation
678
+     * will be executed after the track is created. Otherwise the operation
679
+     * will be ignored.
662 680
      */
663
-    toggleVideoMuted () {
681
+    toggleVideoMuted (force = false) {
682
+        if(!localVideo && force) {
683
+            initialVideoMutedState = !initialVideoMutedState;
684
+            return;
685
+        }
664 686
         this.muteVideo(!this.videoMuted);
665 687
     },
666 688
     /**

+ 3
- 3
modules/API/API.js Voir le fichier

@@ -47,9 +47,9 @@ function initCommands() {
47 47
     commands = {
48 48
         "display-name":
49 49
             APP.conference.changeLocalDisplayName.bind(APP.conference),
50
-        "toggle-audio": APP.conference.toggleAudioMuted.bind(APP.conference),
51
-        "toggle-video": APP.conference.toggleVideoMuted.bind(APP.conference),
52
-        "toggle-film-strip": APP.UI.toggleFilmstrip,
50
+        "toggle-audio": () => APP.conference.toggleAudioMuted(true),
51
+        "toggle-video": () => APP.conference.toggleVideoMuted(true),
52
+        "toggle-film-strip": APP.UI.toggleFilmStrip,
53 53
         "toggle-chat": APP.UI.toggleChat,
54 54
         "toggle-contact-list": APP.UI.toggleContactList,
55 55
         "toggle-share-screen":

Chargement…
Annuler
Enregistrer