Re: [mediacapture-main] Only fire devicechange event when devices physically added/removed (#688)

> As of detecting whether there is a new device or not, this is easy to determine.
In the new device detection algorithm, if the previous list of devices is empty or devices have empty device ids, there is no new device.

That seems incorrect for detecting insertion both _before_ & _during_ (shortly after) getUserMedia:
 1. **Before:** event fires ([works]( in Edge; Chrome, Safari & [Firefox]( are non-compliant)
 2. **During:** How can you know the device wasn't just inserted? (may have gone from 0 to 1 device)

The _"new devices detection"_ algorithm for most years of this spec has been a simple subtract:
let old = await navigator.mediaDevices.enumerateDevices();
navigator.mediaDevices.ondevicechange = async () => {
  const devices = await navigator.mediaDevices.enumerateDevices();
  const newDevices = devices.filter(d => !old.find(o => o.deviceId == d.deviceId));
  old = devices;
Expecting web devs to do more than that seems ambitious. As I recall, the use-cases are:
 1. **Pre-gUM:** User inserts a device for which they had none before, qualifying them for feature.
 2. **Post-gUM:** User inserts a device (e.g. headset) preferred over the one they have now.

We should not break those IMHO. How do you propose we support those?

> Some web applications may buffer enumerateDevices result and only update it based on the device change event.

That would be a silly thing to do when _enumerateDevices_ already buffers (see [storedDeviceList]( 

But it does point to a spec problem: The list is [not allowed to be updated]( without an event.

So we broke something when we went:
 1. from a simpler world where the list only changed when devices were inserted/pulled, and the event signified both
 2. to a world where the event can no longer mean both. 

It's now unclear what the event means. It's lost it's meaning.

GitHub Notification of comment by jan-ivar
Please view or discuss this issue at using your GitHub account

Received on Monday, 27 April 2020 21:23:52 UTC