Просмотр исходного кода

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 8 лет назад
Родитель
Сommit
ab62690b97
2 измененных файлов: 29 добавлений и 7 удалений
  1. 26
    4
      conference.js
  2. 3
    3
      modules/API/API.js

+ 26
- 4
conference.js Просмотреть файл

63
 
63
 
64
 const eventEmitter = new EventEmitter();
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
  * Indicates whether extension external installation is in progress or not.
70
  * Indicates whether extension external installation is in progress or not.
581
                 analytics.init();
582
                 analytics.init();
582
                 return createInitialLocalTracksAndConnect(options.roomName);
583
                 return createInitialLocalTracksAndConnect(options.roomName);
583
             }).then(([tracks, con]) => {
584
             }).then(([tracks, con]) => {
585
+                tracks.forEach(track => {
586
+                    if((track.isAudioTrack() && initialAudioMutedState)
587
+                        || (track.isVideoTrack() && initialVideoMutedState)) {
588
+                        track.mute();
589
+                    }
590
+                });
584
                 logger.log('initialized with %s local tracks', tracks.length);
591
                 logger.log('initialized with %s local tracks', tracks.length);
585
                 con.addEventListener(
592
                 con.addEventListener(
586
                     ConnectionEvents.CONNECTION_FAILED,
593
                     ConnectionEvents.CONNECTION_FAILED,
645
         return this.audioMuted;
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
         this.muteAudio(!this.audioMuted);
666
         this.muteAudio(!this.audioMuted);
652
     },
667
     },
653
     /**
668
     /**
659
     },
674
     },
660
     /**
675
     /**
661
      * Simulates toolbar button click for video mute. Used by shortcuts and API.
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
         this.muteVideo(!this.videoMuted);
686
         this.muteVideo(!this.videoMuted);
665
     },
687
     },
666
     /**
688
     /**

+ 3
- 3
modules/API/API.js Просмотреть файл

47
     commands = {
47
     commands = {
48
         "display-name":
48
         "display-name":
49
             APP.conference.changeLocalDisplayName.bind(APP.conference),
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
         "toggle-chat": APP.UI.toggleChat,
53
         "toggle-chat": APP.UI.toggleChat,
54
         "toggle-contact-list": APP.UI.toggleContactList,
54
         "toggle-contact-list": APP.UI.toggleContactList,
55
         "toggle-share-screen":
55
         "toggle-share-screen":

Загрузка…
Отмена
Сохранить