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.
This commit is contained in:
Leonard Kim 2019-05-16 14:00:55 -07:00 committed by Дамян Минков
parent 7f1df5629e
commit 149485905c
1 changed files with 28 additions and 6 deletions

View File

@ -21,6 +21,28 @@ import {
const logger = require('jitsi-meet-logger').getLogger(__filename); 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. * Adds a pending device request.
* *
@ -70,19 +92,19 @@ export function configureInitialDevices() {
return; return;
} }
const newSettings = {}; const newSettings = {};
const devicesKeysToSettingsKeys = {
audioInput: 'micDeviceId',
audioOutput: 'audioOutputDeviceId',
videoInput: 'cameraDeviceId'
};
Object.keys(deviceLabels).forEach(key => { Object.keys(deviceLabels).forEach(key => {
const label = deviceLabels[key]; const label = deviceLabels[key];
const deviceId = getDeviceIdByLabel(state, label, key); const deviceId = getDeviceIdByLabel(state, label, key);
if (deviceId) { 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;
} }
}); });