浏览代码

fix(device-selection): search for device by label and kind (#4064)

Searching for a device (id) by label alone can result in
false results when devices share labels, such as a mic
and speaker having the same label. To prevent such,
specify the device kind to be found instead of iterating
over all device kinds.
master
virtuacoplenny 6 年前
父节点
当前提交
e7812c7d84
没有帐户链接到提交者的电子邮件

+ 1
- 1
react/features/base/devices/actions.js 查看文件

75
 
75
 
76
                 Object.keys(deviceLabels).forEach(key => {
76
                 Object.keys(deviceLabels).forEach(key => {
77
                     const label = deviceLabels[key];
77
                     const label = deviceLabels[key];
78
-                    const deviceId = getDeviceIdByLabel(state, label);
78
+                    const deviceId = getDeviceIdByLabel(state, label, key);
79
 
79
 
80
                     if (deviceId) {
80
                     if (deviceId) {
81
                         newSettings[devicesKeysToSettingsKeys[key]] = deviceId;
81
                         newSettings[devicesKeysToSettingsKeys[key]] = deviceId;

+ 16
- 9
react/features/base/devices/functions.js 查看文件

44
  *
44
  *
45
  * @param {Object} state - The redux state.
45
  * @param {Object} state - The redux state.
46
  * @param {string} label - The label.
46
  * @param {string} label - The label.
47
+ * @param {string} kind - The type of the device. One of "audioInput",
48
+ * "audioOutput", and "videoInput". Also supported is all lowercase versions
49
+ * of the preceding types.
47
  * @returns {string|undefined}
50
  * @returns {string|undefined}
48
  */
51
  */
49
-export function getDeviceIdByLabel(state: Object, label: string) {
50
-    const types = [ 'audioInput', 'audioOutput', 'videoInput' ];
52
+export function getDeviceIdByLabel(state: Object, label: string, kind: string) {
53
+    const webrtcKindToJitsiKindTranslator = {
54
+        audioinput: 'audioInput',
55
+        audiooutput: 'audioOutput',
56
+        videoinput: 'videoInput'
57
+    };
51
 
58
 
52
-    for (const type of types) {
53
-        const device
54
-            = (state['features/base/devices'].availableDevices[type] || [])
55
-                .find(d => d.label === label);
59
+    const kindToSearch = webrtcKindToJitsiKindTranslator[kind] || kind;
56
 
60
 
57
-        if (device) {
58
-            return device.deviceId;
59
-        }
61
+    const device
62
+        = (state['features/base/devices'].availableDevices[kindToSearch] || [])
63
+            .find(d => d.label === label);
64
+
65
+    if (device) {
66
+        return device.deviceId;
60
     }
67
     }
61
 }
68
 }
62
 
69
 

+ 3
- 1
react/features/device-selection/functions.js 查看文件

155
         }
155
         }
156
 
156
 
157
         const { label, id } = device;
157
         const { label, id } = device;
158
-        const deviceId = label ? getDeviceIdByLabel(state, device.label) : id;
158
+        const deviceId = label
159
+            ? getDeviceIdByLabel(state, device.label, device.kind)
160
+            : id;
159
 
161
 
160
         if (deviceId) {
162
         if (deviceId) {
161
             switch (device.kind) {
163
             switch (device.kind) {

正在加载...
取消
保存