w3c / mediacapture-output

API to manage the rendering of audio on any audio output device
https://w3c.github.io/mediacapture-output/
Other
26 stars 25 forks source link

Adding "subkind" in MediaDeviceInfo (for detection headphones) #125

Open hoch opened 3 years ago

hoch commented 3 years ago

Summary

Adds .subkind field MediaDeviceInfo to indicate the nature of the output device, specifically for personal listening devices. (e.g. headphones, headset, or earbuds)

Potential use cases:

Proposal

[Exposed=Window, SecureContext]
partial interface MediaDeviceInfo {
  readonly attribute MediaDeviceSubkind subkind;
};

enum MediaDeviceSubkind {
  "unknown",
  "headphones",
  "speakers"
};

Example

let oldDeviceList_ = [];
const onDeviceChange = async (event) => {

  const newDeviceList = await navigator.MediaDevices.enumerateDevices();
  const newDeviceInfo = detectNewDevice(oldDeviceList_, newDeviceList);
  if (newDeviceInfo && newDeviceInfo.kind === 'audiooutput' &&
      newDeviceInfo.subkind === 'headphones') {
    useBinauralAudio(newDeviceInfo);
  }
  oldDeviceList_ = newDeviceList;
}

const detectNewDevice = (oldDeviceList, newDeviceList) => {
  // Compare two device lists and return a MediaDeviceInfo object if there is
  // a newly detected device in |newDeviceList|.
};

Privacy Concerns

This information is already guarded by an explicit user permission via getUserMedia(). Note that when the permission is granted the device information exposed by MediaDevices.enumerateDevices() call is already abundant. (e.g. device name, unique ID, device kind) The device information obtained from MediaDevices.enumerateDevices() without a permission does NOT expose this field.

hoch commented 3 years ago

The issue was originally raised in Audio WG: https://github.com/WebAudio/web-audio-api-v2/issues/89

aboba commented 2 years ago

Is this actually an output device issue?