Re: [mediacapture-output] The first "audiooutput" `MediaDeviceInfo` returned from `enumerateDevices()` is not the default device when the default device is not exposed (#133)

> That's correct, and this finds a `deviceId` that can be passed to `setSinkId()` or compared with a `sinkId`. To distinguish between a virtual and physical device and so whether the physical default device is exposed, the `deviceId` would be compared with "".
> 

If "default" is the ID for the system default device as exposed in enumerateDevices() then you just need to compare with "default" instead of "". 

> > > Chromium's solution is to use "default" as device ID.
> > 
> > 
> > Unfortunately, this poses a competing model for finding the default device:
> > ```js
> > const defSpkr = await mediaDevices.enumerateDevices().
> >                                   .find(d => d.kind == “audio-output” && d.deviceId == "default");
> > ```
> > 
What is exactly the problem with this? And the model is competing with what?
There is nothing in the spec as currently written that specifies what the deviceId field should be for a system-default device.


> >   
> > > There is little difference between using "default", "" or any other constant string.
> > 
> > 
> > `setSinkId("")` is special and unsets the sinkId.
> 
> `setSinkId("")` and `sinkId` are the main reason for re-using "", to which the spec already gives meaning as the user-agent default device. This is also consistent with the empty `deviceId` on the single "audioinput" (or "videoinput") `MediaDeviceInfo` provided to indicate that at least one microphone exists before "audioinput" devices are exposed.
> 

The spec uses the empty string for several different things. And the `deviceId` field for the system-default device in the output of `enumerateDevices` is not one of those things.


> Chrome is using `deviceId: ""` and `deviceId: "default"` in different situations. When no "audiooutput" devices are exposed, Chrome provides
> 
> ```js
> {label: "", deviceId: "", groupId: ""}
> ```
> 
In this case "" is not the ID of the default device. It is an entry with that signals that the system has output devices, but the information about them cannot be exposed (because gUM hasn´t been  called or because there are no permissions).   


> The spec (and the proposal here, which is Gecko's behavior now) would expect no "audiooutput" devices.
> 
> When the default "audiooutput" device is exposed via `getUserMedia()`, Chrome provides (on Linux)
> 
> ```js
> {label: "Default", deviceId: "default", groupId: "default"}
> {label: "Built-in Audio Analog Stereo", deviceId: "38cf59402979c7c92a7dfe139b46a07932288d562b1dce9bca711b1e7d2097bc", groupId: "fc5673e12055618bb6840857ef5ffaf81ae28949a50d518734c167530922a3bf"}
> ```
> 
> https://jan-ivar.github.io/dummy/enumerate.html is useful for testing browser behavior.
> 
> In Chrome currently `find(d => d.kind == “audio-output”)` returns the `MediaDeviceInfo` with `deviceId: "default"`, so `find(d => d.kind == “audio-output” && d.deviceId == "default")` would return the same.
> 


> AFAIK there is currently no way to create a situation where Chrome would expose a non-default "audiooutput" device without exposing the user-agent default "audiooutput" device. 

This is correct.

> If there were, then Chrome's virtual `deviceId: "default"` device would be a solution to the problem of sites that assume that the first "audiooutput" device is the default device, because in Chrome `setSinkId("default")` switches output to the user-agent default if the default is exposed.
> 

I haven´t thought about the details of what Chrome would do if it had a per-device permission model, but if the system default device is exposed by enumerateDevices, its ID (whatever it is) should be accepted by setSinkId and should send the output to the system default device.


> Chrome's `deviceId: "default"` on its virtual device is not a solution to the issue of providing a client app with a means to determine which exposed physical device, if any, is the user-agent default device.

Why would using the empty string  (which has different meanings in different contexts)  as ID for the default device in enumerateDevices solve this problem?

The way Chrome solves that problem right now is by setting the groupId to the same groupId of the physical device currently considered the default.


-- 
GitHub Notification of comment by guidou
Please view or discuss this issue at https://github.com/w3c/mediacapture-output/issues/133#issuecomment-2309857512 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Monday, 26 August 2024 10:15:37 UTC