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,3 +8,6 @@ deploy-local.sh
8 8
 lib-jitsi-meet.*
9 9
 npm-*.log
10 10
 .sync-config.cson
11
+.jshintignore
12
+.jshintrc
13
+.DS_Store

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

@@ -148,14 +148,25 @@ export default class JitsiLocalTrack extends JitsiTrack {
148 148
         this._noDataFromSourceTimeout = null;
149 149
 
150 150
         this._onDeviceListWillChange = devices => {
151
+            const oldRealDeviceId = this._realDeviceId;
152
+
151 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 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 170
                 this._trackEnded = true;
160 171
             }
161 172
         };
@@ -182,6 +193,12 @@ export default class JitsiLocalTrack extends JitsiTrack {
182 193
      * @returns {boolean}
183 194
      */
184 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 202
         return this.getTrack().readyState === 'ended' || this._trackEnded;
186 203
     }
187 204
 
@@ -279,6 +296,8 @@ export default class JitsiLocalTrack extends JitsiTrack {
279 296
 
280 297
         if (device) {
281 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,6 +1460,10 @@ class RTCUtils extends Listenable {
1460 1460
      * @param mediaStream MediaStream object to stop.
1461 1461
      */
1462 1462
     stopMediaStream(mediaStream) {
1463
+        if (!mediaStream) {
1464
+            return;
1465
+        }
1466
+
1463 1467
         mediaStream.getTracks().forEach(track => {
1464 1468
             if (track.stop) {
1465 1469
                 track.stop();

Loading…
Cancel
Save