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.
This commit is contained in:
virtuacoplenny 2019-04-03 08:06:41 -07:00 committed by GitHub
parent f73d3a4063
commit b731459ea4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 19 deletions

View File

@ -82,31 +82,36 @@ export function processExternalDeviceRequest( // eslint-disable-line max-params
case 'getCurrentDevices': case 'getCurrentDevices':
dispatch(getAvailableDevices()).then(devices => { dispatch(getAvailableDevices()).then(devices => {
if (areDeviceLabelsInitialized(state)) { if (areDeviceLabelsInitialized(state)) {
let audioInput, audioOutput, videoInput; const deviceDescriptions = {
const audioOutputDeviceId = getAudioOutputDeviceId(); audioInput: undefined,
const { cameraDeviceId, micDeviceId } = settings; audioOutput: undefined,
videoInput: undefined
};
const currentlyUsedDeviceIds = new Set([
getAudioOutputDeviceId(),
settings.micDeviceId,
settings.cameraDeviceId
]);
devices.forEach(device => { devices.forEach(device => {
const { deviceId } = device; const { deviceId, kind } = device;
switch (deviceId) { if (currentlyUsedDeviceIds.has(deviceId)) {
case micDeviceId: switch (kind) {
audioInput = device; case 'audioinput':
break; deviceDescriptions.audioInput = device;
case audioOutputDeviceId: break;
audioOutput = device; case 'audiooutput':
break; deviceDescriptions.audioOutput = device;
case cameraDeviceId: break;
videoInput = device; case 'videoinput':
break; deviceDescriptions.videoInput = device;
break;
}
} }
}); });
responseCallback({ responseCallback(deviceDescriptions);
audioInput,
audioOutput,
videoInput
});
} else { } else {
// The labels are not available if the A/V permissions are // The labels are not available if the A/V permissions are
// not yet granted. // not yet granted.