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.
This commit is contained in:
parent
ea54713f9a
commit
e7812c7d84
|
@ -75,7 +75,7 @@ export function configureInitialDevices() {
|
||||||
|
|
||||||
Object.keys(deviceLabels).forEach(key => {
|
Object.keys(deviceLabels).forEach(key => {
|
||||||
const label = deviceLabels[key];
|
const label = deviceLabels[key];
|
||||||
const deviceId = getDeviceIdByLabel(state, label);
|
const deviceId = getDeviceIdByLabel(state, label, key);
|
||||||
|
|
||||||
if (deviceId) {
|
if (deviceId) {
|
||||||
newSettings[devicesKeysToSettingsKeys[key]] = deviceId;
|
newSettings[devicesKeysToSettingsKeys[key]] = deviceId;
|
||||||
|
|
|
@ -44,19 +44,26 @@ export function getAudioOutputDeviceId() {
|
||||||
*
|
*
|
||||||
* @param {Object} state - The redux state.
|
* @param {Object} state - The redux state.
|
||||||
* @param {string} label - The label.
|
* @param {string} label - The label.
|
||||||
|
* @param {string} kind - The type of the device. One of "audioInput",
|
||||||
|
* "audioOutput", and "videoInput". Also supported is all lowercase versions
|
||||||
|
* of the preceding types.
|
||||||
* @returns {string|undefined}
|
* @returns {string|undefined}
|
||||||
*/
|
*/
|
||||||
export function getDeviceIdByLabel(state: Object, label: string) {
|
export function getDeviceIdByLabel(state: Object, label: string, kind: string) {
|
||||||
const types = [ 'audioInput', 'audioOutput', 'videoInput' ];
|
const webrtcKindToJitsiKindTranslator = {
|
||||||
|
audioinput: 'audioInput',
|
||||||
|
audiooutput: 'audioOutput',
|
||||||
|
videoinput: 'videoInput'
|
||||||
|
};
|
||||||
|
|
||||||
for (const type of types) {
|
const kindToSearch = webrtcKindToJitsiKindTranslator[kind] || kind;
|
||||||
const device
|
|
||||||
= (state['features/base/devices'].availableDevices[type] || [])
|
|
||||||
.find(d => d.label === label);
|
|
||||||
|
|
||||||
if (device) {
|
const device
|
||||||
return device.deviceId;
|
= (state['features/base/devices'].availableDevices[kindToSearch] || [])
|
||||||
}
|
.find(d => d.label === label);
|
||||||
|
|
||||||
|
if (device) {
|
||||||
|
return device.deviceId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -155,7 +155,9 @@ export function processExternalDeviceRequest( // eslint-disable-line max-params
|
||||||
}
|
}
|
||||||
|
|
||||||
const { label, id } = device;
|
const { label, id } = device;
|
||||||
const deviceId = label ? getDeviceIdByLabel(state, device.label) : id;
|
const deviceId = label
|
||||||
|
? getDeviceIdByLabel(state, device.label, device.kind)
|
||||||
|
: id;
|
||||||
|
|
||||||
if (deviceId) {
|
if (deviceId) {
|
||||||
switch (device.kind) {
|
switch (device.kind) {
|
||||||
|
|
Loading…
Reference in New Issue