From 149485905c37b029310187360fd439c9d88180fd Mon Sep 17 00:00:00 2001 From: Leonard Kim Date: Thu, 16 May 2019 14:00:55 -0700 Subject: [PATCH] fix(api): store passed in devices as user selected Currently devices set through the api are stored as ids, and not user selected. This can cause other existing user selected devices to take precedence over the devices passed into the api. --- react/features/base/devices/actions.js | 34 +++++++++++++++++++++----- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/react/features/base/devices/actions.js b/react/features/base/devices/actions.js index 48903bcf2..20b8dec0d 100644 --- a/react/features/base/devices/actions.js +++ b/react/features/base/devices/actions.js @@ -21,6 +21,28 @@ import { const logger = require('jitsi-meet-logger').getLogger(__filename); +/** + * Maps the WebRTC string for device type to the keys used to store configure, + * within redux, which devices should be used by default. + */ +const DEVICE_TYPE_TO_SETTINGS_KEYS = { + audioInput: { + currentDeviceId: 'micDeviceId', + userSelectedDeviceId: 'userSelectedMicDeviceId', + userSelectedDeviceLabel: 'userSelectedMicDeviceLabel' + }, + audioOutput: { + currentDeviceId: 'audioOutputDeviceId', + userSelectedDeviceId: 'userSelectedAudioOutputDeviceId', + userSelectedDeviceLabel: 'userSelectedAudioOutputDeviceLabel' + }, + videoInput: { + currentDeviceId: 'audioOutputDeviceId', + userSelectedDeviceId: 'userSelectedCameraDeviceId', + userSelectedDeviceLabel: 'userSelectedCameraDeviceLabel' + } +}; + /** * Adds a pending device request. * @@ -70,19 +92,19 @@ export function configureInitialDevices() { return; } + const newSettings = {}; - const devicesKeysToSettingsKeys = { - audioInput: 'micDeviceId', - audioOutput: 'audioOutputDeviceId', - videoInput: 'cameraDeviceId' - }; Object.keys(deviceLabels).forEach(key => { const label = deviceLabels[key]; const deviceId = getDeviceIdByLabel(state, label, key); if (deviceId) { - newSettings[devicesKeysToSettingsKeys[key]] = deviceId; + const settingsTranslationMap = DEVICE_TYPE_TO_SETTINGS_KEYS[key]; + + newSettings[settingsTranslationMap.currentDeviceId] = deviceId; + newSettings[settingsTranslationMap.userSelectedDeviceId] = deviceId; + newSettings[settingsTranslationMap.userSelectedDeviceLabel] = label; } });