From b731459ea464c424b635e199fc61b19cf07f5afc Mon Sep 17 00:00:00 2001 From: virtuacoplenny Date: Wed, 3 Apr 2019 08:06:41 -0700 Subject: [PATCH] fix(device-selection): use device kind when getting current devices (#4059) Devices of different kinds can have the same id, such as speaker and mic both being default. Using id only can then lead to incorrectly setting device descriptions in the current devices object. --- react/features/device-selection/functions.js | 43 +++++++++++--------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/react/features/device-selection/functions.js b/react/features/device-selection/functions.js index 21b537e03..02571a968 100644 --- a/react/features/device-selection/functions.js +++ b/react/features/device-selection/functions.js @@ -82,31 +82,36 @@ export function processExternalDeviceRequest( // eslint-disable-line max-params case 'getCurrentDevices': dispatch(getAvailableDevices()).then(devices => { if (areDeviceLabelsInitialized(state)) { - let audioInput, audioOutput, videoInput; - const audioOutputDeviceId = getAudioOutputDeviceId(); - const { cameraDeviceId, micDeviceId } = settings; + const deviceDescriptions = { + audioInput: undefined, + audioOutput: undefined, + videoInput: undefined + }; + const currentlyUsedDeviceIds = new Set([ + getAudioOutputDeviceId(), + settings.micDeviceId, + settings.cameraDeviceId + ]); devices.forEach(device => { - const { deviceId } = device; + const { deviceId, kind } = device; - switch (deviceId) { - case micDeviceId: - audioInput = device; - break; - case audioOutputDeviceId: - audioOutput = device; - break; - case cameraDeviceId: - videoInput = device; - break; + if (currentlyUsedDeviceIds.has(deviceId)) { + switch (kind) { + case 'audioinput': + deviceDescriptions.audioInput = device; + break; + case 'audiooutput': + deviceDescriptions.audioOutput = device; + break; + case 'videoinput': + deviceDescriptions.videoInput = device; + break; + } } }); - responseCallback({ - audioInput, - audioOutput, - videoInput - }); + responseCallback(deviceDescriptions); } else { // The labels are not available if the A/V permissions are // not yet granted.