- From: Jan-Ivar Bruaroey via GitHub <sysbot+gh@w3.org>
- Date: Fri, 20 Mar 2020 14:14:00 +0000
- To: public-webrtc-logs@w3.org
> maybe the application wants to do the following when the user plugs in some new devices:
Apps will still be able to do that like today using:
```js
navigator.mediaDevices.ondevicechange = async () => {
const devices = await navigator.mediaDevices.enumerateDevices();
const [cams, mics, speakers] = ["videoinput", "audioinput, "audiooutput"]
.map(type => devices.filter(({kind}) => kind == type));
```
> * if the new audio input & output devices belong to the same headset, automatically switch to use them, because that's most likely what the user wants
```js
const [mic] = subtract(mics, oldMics);
const speaker = speakers.find(({groupId}) => mic.groupId == groupId);
if (mic && speaker) {
video.srcObject = new MediaStream([
...video.srcObject.getVideoTracks(),
await navigator.mediaDevices.getUserMedia({
audio: {deviceId: {exact: mic.deviceId}}
})
]);
await element.setSinkId({sinkId: speaker.deviceId});
}
```
> * if we didn't have a camera before but now the user plugs in one, automatically start using it, because that's most likely what the user wants
```js
const [cam] = cams;
if (cam && !oldCams.length) {
video.srcObject = new MediaStream([
...video.srcObject.getAudioTracks(),
await navigator.mediaDevices.getUserMedia({
video: {deviceId: {exact: cam.deviceId}}
})
]);
}
oldMics = mics;
oldCams = cams;
};
```
The only difference is we won't have `label` (all this presumes some initial permission btw).
> I think delegating the baseline device choosing task to the user agent sounds good.
Great! 🙂
--
GitHub Notification of comment by jan-ivar
Please view or discuss this issue at https://github.com/w3c/mediacapture-main/issues/652#issuecomment-601722000 using your GitHub account
Received on Friday, 20 March 2020 14:14:02 UTC