Browse Source

fix(devices): when add/remove the selected device

dev1
Hristo Terezov 6 years ago
parent
commit
23503b0efd
3 changed files with 31 additions and 5 deletions
  1. 3
    0
      .gitignore
  2. 24
    5
      modules/RTC/JitsiLocalTrack.js
  3. 4
    0
      modules/RTC/RTCUtils.js

+ 3
- 0
.gitignore View File

8
 lib-jitsi-meet.*
8
 lib-jitsi-meet.*
9
 npm-*.log
9
 npm-*.log
10
 .sync-config.cson
10
 .sync-config.cson
11
+.jshintignore
12
+.jshintrc
13
+.DS_Store

+ 24
- 5
modules/RTC/JitsiLocalTrack.js View File

148
         this._noDataFromSourceTimeout = null;
148
         this._noDataFromSourceTimeout = null;
149
 
149
 
150
         this._onDeviceListWillChange = devices => {
150
         this._onDeviceListWillChange = devices => {
151
+            const oldRealDeviceId = this._realDeviceId;
152
+
151
             this._setRealDeviceIdFromDeviceList(devices);
153
             this._setRealDeviceIdFromDeviceList(devices);
152
 
154
 
153
-            // Mark track as ended for those browsers that do not support
154
-            // "readyState" property. We do not touch tracks created with
155
-            // default device ID "".
156
-            if (typeof this.getTrack().readyState === 'undefined'
155
+            if (
156
+                // Mark track as ended for those browsers that do not support
157
+                // "readyState" property. We do not touch tracks created with
158
+                // default device ID "".
159
+                (typeof this.getTrack().readyState === 'undefined'
157
                     && typeof this._realDeviceId !== 'undefined'
160
                     && typeof this._realDeviceId !== 'undefined'
158
-                    && !devices.find(d => d.deviceId === this._realDeviceId)) {
161
+                    && !devices.find(d => d.deviceId === this._realDeviceId))
162
+
163
+                // If there was an associated realDeviceID and after the device change the realDeviceId is undefined
164
+                // then the associated device has been disconnected and the _trackEnded flag needs to be set. In
165
+                // addition on some Chrome versions the readyState property is set after the device change event is
166
+                // triggered which causes issues in jitsi-meet with the selection of a new device because we don't
167
+                // detect that the old one was removed.
168
+                || (typeof oldRealDeviceId !== 'undefined' && typeof this._realDeviceId === 'undefined')
169
+            ) {
159
                 this._trackEnded = true;
170
                 this._trackEnded = true;
160
             }
171
             }
161
         };
172
         };
182
      * @returns {boolean}
193
      * @returns {boolean}
183
      */
194
      */
184
     isEnded() {
195
     isEnded() {
196
+        if (this.isVideoTrack() && this.isMuted()) {
197
+            // If a video track is muted the readyState will be ended, that's why we need to rely only on the
198
+            // _trackEnded flag.
199
+            return this._trackEnded;
200
+        }
201
+
185
         return this.getTrack().readyState === 'ended' || this._trackEnded;
202
         return this.getTrack().readyState === 'ended' || this._trackEnded;
186
     }
203
     }
187
 
204
 
279
 
296
 
280
         if (device) {
297
         if (device) {
281
             this._realDeviceId = device.deviceId;
298
             this._realDeviceId = device.deviceId;
299
+        } else {
300
+            this._realDeviceId = undefined;
282
         }
301
         }
283
     }
302
     }
284
 
303
 

+ 4
- 0
modules/RTC/RTCUtils.js View File

1460
      * @param mediaStream MediaStream object to stop.
1460
      * @param mediaStream MediaStream object to stop.
1461
      */
1461
      */
1462
     stopMediaStream(mediaStream) {
1462
     stopMediaStream(mediaStream) {
1463
+        if (!mediaStream) {
1464
+            return;
1465
+        }
1466
+
1463
         mediaStream.getTracks().forEach(track => {
1467
         mediaStream.getTracks().forEach(track => {
1464
             if (track.stop) {
1468
             if (track.stop) {
1465
                 track.stop();
1469
                 track.stop();

Loading…
Cancel
Save