Browse Source

fix(JitsiLocalTrack): realDeviceId.

dev1
Hristo Terezov 6 years ago
parent
commit
7dece05e34
3 changed files with 20 additions and 7 deletions
  1. 12
    7
      modules/RTC/JitsiLocalTrack.js
  2. 3
    0
      modules/RTC/RTCUtils.js
  3. 5
    0
      service/RTC/RTCEvents.js

+ 12
- 7
modules/RTC/JitsiLocalTrack.js View File

@@ -136,6 +136,8 @@ export default class JitsiLocalTrack extends JitsiTrack {
136 136
         // created (until getConstraints() support), however we can associate
137 137
         // tracks with real devices obtained from enumerateDevices() call as
138 138
         // soon as it's called.
139
+        // NOTE: this.deviceId corresponds to the device id specified in GUM constraints and this._realDeviceId seems to
140
+        // correspond to the id of a matching device from the available device list.
139 141
         this._realDeviceId = this.deviceId === '' ? undefined : this.deviceId;
140 142
 
141 143
         /**
@@ -169,9 +171,7 @@ export default class JitsiLocalTrack extends JitsiTrack {
169 171
                 this._onAudioOutputDeviceChanged);
170 172
         }
171 173
 
172
-        RTCUtils.addListener(
173
-            RTCEvents.DEVICE_LIST_CHANGED,
174
-            this._onDeviceListChanged);
174
+        RTCUtils.addListener(RTCEvents.DEVICE_LIST_WILL_CHANGE, this._onDeviceListChanged);
175 175
 
176 176
         this._initNoDataFromSourceHandlers();
177 177
     }
@@ -265,8 +265,14 @@ export default class JitsiLocalTrack extends JitsiTrack {
265 265
      */
266 266
     _setRealDeviceIdFromDeviceList(devices) {
267 267
         const track = this.getTrack();
268
-        const device = devices.find(
269
-            d => d.kind === `${track.kind}input` && d.label === track.label);
268
+        const kind = `${track.kind}input`;
269
+        let device = devices.find(d => d.kind === kind && d.label === track.label);
270
+
271
+        if (!device && this._realDeviceId === 'default') { // the default device has been changed.
272
+            const label = (track.label || '').replace('Default - ', '');
273
+
274
+            device = devices.find(d => d.kind === kind && d.label === label);
275
+        }
270 276
 
271 277
         if (device) {
272 278
             this._realDeviceId = device.deviceId;
@@ -519,8 +525,7 @@ export default class JitsiLocalTrack extends JitsiTrack {
519 525
             this.detach();
520 526
         }
521 527
 
522
-        RTCUtils.removeListener(RTCEvents.DEVICE_LIST_CHANGED,
523
-            this._onDeviceListChanged);
528
+        RTCUtils.removeListener(RTCEvents.DEVICE_LIST_WILL_CHANGE, this._onDeviceListChanged);
524 529
 
525 530
         if (this._onAudioOutputDeviceChanged) {
526 531
             RTCUtils.removeListener(RTCEvents.AUDIO_OUTPUT_DEVICE_CHANGED,

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

@@ -592,6 +592,9 @@ function onMediaDevicesListChanged(devicesReceived) {
592 592
 
593 593
     sendDeviceListToAnalytics(availableDevices);
594 594
 
595
+    // Used by tracks to update the real device id before the consumer of lib-jitsi-meet receives the new device list.
596
+    eventEmitter.emit(RTCEvents.DEVICE_LIST_WILL_CHANGE, devicesReceived);
597
+
595 598
     eventEmitter.emit(RTCEvents.DEVICE_LIST_CHANGED, devicesReceived);
596 599
 }
597 600
 

+ 5
- 0
service/RTC/RTCEvents.js View File

@@ -70,6 +70,11 @@ const RTCEvents = {
70 70
     SET_REMOTE_DESCRIPTION_FAILED: 'rtc.set_remote_description_failed',
71 71
     AUDIO_OUTPUT_DEVICE_CHANGED: 'rtc.audio_output_device_changed',
72 72
     DEVICE_LIST_CHANGED: 'rtc.device_list_changed',
73
+
74
+    /**
75
+     * Indicates that the list with available devices will change.
76
+     */
77
+    DEVICE_LIST_WILL_CHANGE: 'rtc.device_list_will_change',
73 78
     DEVICE_LIST_AVAILABLE: 'rtc.device_list_available',
74 79
 
75 80
     /**

Loading…
Cancel
Save