Skip to content

Commit

Permalink
Merge pull request #12152 from nextcloud/backport/12151/stable29
Browse files Browse the repository at this point in the history
[stable29] fix(media): Fix initial selection of devices
  • Loading branch information
danxuliu authored Apr 18, 2024
2 parents 2ddbace + 30856b2 commit 2053eed
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/utils/webrtc/MediaDevicesManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,22 @@ MediaDevicesManager.prototype = {
this._addDevice(addedDevice)
})

this._populatePreferences(devices)

// Selecting preferred device in case it was removed/unplugged, or it is a first initialization after reload,
// or we add/plug preferred device and overwriting automatic selection
// If the preference list is empty the default device falls back to
// the first device of that kind found. This can happen, for
// example, when no permissions were given yet. In that case,
// according to the spec, a single device of each kind (if at least
// one device of that kind is available) with an empty deviceId is
// returned, which will not be registered in the preference list.
if (this.attributes.audioInputId === undefined || this.attributes.audioInputId === previousFirstAvailableAudioInputId) {
this.attributes.audioInputId = getFirstAvailableMediaDevice(devices, this._preferenceAudioInputList)
this.attributes.audioInputId = getFirstAvailableMediaDevice(devices, this._preferenceAudioInputList) || devices.find(device => device.kind === 'audioinput')?.deviceId
console.debug(listMediaDevices(this.attributes, this._preferenceAudioInputList, this._preferenceVideoInputList))
}
if (this.attributes.videoInputId === undefined || this.attributes.videoInputId === previousFirstAvailableVideoInputId) {
this.attributes.videoInputId = getFirstAvailableMediaDevice(devices, this._preferenceVideoInputList)
this.attributes.videoInputId = getFirstAvailableMediaDevice(devices, this._preferenceVideoInputList) || devices.find(device => device.kind === 'videoinput')?.deviceId
console.debug(listMediaDevices(this.attributes, this._preferenceAudioInputList, this._preferenceVideoInputList))
}

Expand All @@ -226,8 +234,6 @@ MediaDevicesManager.prototype = {
}

this._pendingEnumerateDevicesPromise = null

this._populatePreferences(devices)
}).catch(function(error) {
console.error('Could not update known media devices: ' + error.name + ': ' + error.message)

Expand Down

0 comments on commit 2053eed

Please sign in to comment.