I write this code in JavaScript in Chrome:
navigator.mediaDevices.enumerateDevices()
.then((list) => {
console.log(list);
});
This outputs a list of media devices like microphones and cameras. Each device is represented as an object with its own deviceId
. But some devices, like one of the microphones in particular, are listed twice. And one time their respective deviceId
is set to 'default'
. What is so special about a one default microphone? And how do I tell which actual deviceId
it has?
enumerateDevices() The MediaDevices method enumerateDevices() requests a list of the available media input and output devices, such as microphones, cameras, headsets, and so forth. The returned Promise is resolved with a MediaDeviceInfo array describing the devices.
The Navigator. mediaDevices read-only property returns a MediaDevices object, which provides access to connected media input devices like cameras and microphones, as well as screen sharing.
A deviceId
lets web sites manage which device their user is using. E.g. store it in a cookie to remember the user's preference from last time.
Some browsers (Chrome, Opera) list the same microphone twice, with different ids. In my case:
The former is "the OS default", whatever the end-user has configured in System Preferences/Sound (OSX) or Control Panel/Sound (Windows). The idea is: when recalled from a cookie and used, its id gets you whatever is configured in the OS at the time of use, which may differ from last time.
The latter is always the specific mic. Their groupId
s match; they're the same physical device atm.
The deviceId = "default"
is an oddity of Chrome (and Opera). AFAICT it's a valid id like any other. If you want the other one, compare their groupId
s to find it.
Safari does not do this. Firefox recently stopped doing it (as of version 63).
Cameras are never duplicated in this way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With