summaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2020-08-05 03:55:12 +0200
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2020-08-05 05:41:16 +0200
commitec7fa54fafb326c111ce7a8c61a6d8e3b46c4093 (patch)
treea6f4a7982cc3008660b9625d40476d4f4d5bc11e /src/utils
parentab10ed58b40c14d3ba6e27b982bb81e1204b246d (diff)
Handle empty "deviceId" when media permissions are not granted
In latest MediaDevices spec if permanent media permissions have not been granted and there is no active stream "enumerateDevices" returns at most one device of each kind, and all of them with empty attributes (including the deviceId) except for the kind. This is already partially implemented by Chromium, so devices with an empty "deviceId" need to be taken into account. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/webrtc/MediaDevicesManager.js18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/utils/webrtc/MediaDevicesManager.js b/src/utils/webrtc/MediaDevicesManager.js
index 53cd4b236..a8a8e0bf3 100644
--- a/src/utils/webrtc/MediaDevicesManager.js
+++ b/src/utils/webrtc/MediaDevicesManager.js
@@ -41,9 +41,13 @@
* limitations (for example, currently Firefox does not list "audiooutput"
* devices).
*
- * The label may not be available if persistent media permissions have not been
- * granted and a MediaStream has not been active. In those cases the fallback
- * label can be used instead.
+ * In some browsers if persistent media permissions have not been granted and a
+ * MediaStream is not active the list may contain at most one device of each
+ * kind, and all of them with empty attributes except for the kind.
+ *
+ * In other browsers just the label may not be available if persistent media
+ * permissions have not been granted and a MediaStream has not been active. In
+ * those cases the fallback label can be used instead.
*
* "attributes.audioInputId" and "attributes.videoInputId" define the devices
* that will be used when calling "getUserMedia(constraints)".
@@ -191,14 +195,14 @@ MediaDevicesManager.prototype = {
} else {
// Generate a fallback label to be used when the actual label is
// not available.
- if (addedDevice.deviceId === 'default') {
+ if (addedDevice.deviceId === 'default' || addedDevice.deviceId === '') {
addedDevice.fallbackLabel = t('spreed', 'Default')
} else if (addedDevice.kind === 'audioinput') {
- addedDevice.fallbackLabel = t('spreed', 'Microphone {number}', { number: Object.values(this._knownDevices).filter(device => device.kind === 'audioinput').length + 1 })
+ addedDevice.fallbackLabel = t('spreed', 'Microphone {number}', { number: Object.values(this._knownDevices).filter(device => device.kind === 'audioinput' && device.deviceId !== '').length + 1 })
} else if (addedDevice.kind === 'videoinput') {
- addedDevice.fallbackLabel = t('spreed', 'Camera {number}', { number: Object.values(this._knownDevices).filter(device => device.kind === 'videoinput').length + 1 })
+ addedDevice.fallbackLabel = t('spreed', 'Camera {number}', { number: Object.values(this._knownDevices).filter(device => device.kind === 'videoinput' && device.deviceId !== '').length + 1 })
} else if (addedDevice.kind === 'audiooutput') {
- addedDevice.fallbackLabel = t('spreed', 'Speaker {number}', { number: Object.values(this._knownDevices).filter(device => device.kind === 'audioutput').length + 1 })
+ addedDevice.fallbackLabel = t('spreed', 'Speaker {number}', { number: Object.values(this._knownDevices).filter(device => device.kind === 'audioutput' && device.deviceId !== '').length + 1 })
}
}