Use fallback device once all devices were processed

Otherwise the first device found would be used even if a "default"
device was found later.

In practice this may not be needed, as Chromium seems to always list the
"default" device first if it is available, but just in case.

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2021-08-27 10:51:15 +02:00 коммит произвёл Daniel Calviño Sánchez
Родитель 44ad976b56
Коммит 84834e6384
1 изменённых файлов: 8 добавлений и 6 удалений

Просмотреть файл

@ -226,6 +226,14 @@ MediaDevicesManager.prototype = {
this._addDevice(addedDevice)
})
// Fallback in case we didn't find the previously picked device
if (this.attributes.audioInputId === undefined) {
this.attributes.audioInputId = this._fallbackAudioInputId
}
if (this.attributes.videoInputId === undefined) {
this.attributes.videoInputId = this._fallbackVideoInputId
}
// Trigger change events after all the devices are processed to
// prevent change events for intermediate states.
if (previousAudioInputId !== this.attributes.audioInputId) {
@ -325,9 +333,6 @@ MediaDevicesManager.prototype = {
if (!this._fallbackAudioInputId || addedDevice.deviceId === 'default') {
this._fallbackAudioInputId = addedDevice.deviceId
}
if (this.attributes.audioInputId === undefined) {
this.attributes.audioInputId = this._fallbackAudioInputId
}
} else if (addedDevice.kind === 'videoinput') {
if (BrowserStorage.getItem('videoInputId') === addedDevice.deviceId) {
this.attributes.videoInputId = addedDevice.deviceId
@ -335,9 +340,6 @@ MediaDevicesManager.prototype = {
if (!this._fallbackVideoInputId || addedDevice.deviceId === 'default') {
this._fallbackVideoInputId = addedDevice.deviceId
}
if (this.attributes.videoInputId === undefined) {
this.attributes.videoInputId = this._fallbackVideoInputId
}
}
this.attributes.devices.push(addedDevice)