- From: Jan-Ivar Bruaroey <jib@mozilla.com>
- Date: Wed, 27 Feb 2019 10:17:59 -0500
- To: Philipp Hancke <fippo@goodadvice.pages.de>, public-webrtc@w3.org
Received on Wednesday, 27 February 2019 15:18:26 UTC
On 2/27/19 8:48 AM, Jan-Ivar Bruaroey wrote:
> On 2/27/19 8:44 AM, Jan-Ivar Bruaroey wrote:
>> What I show above gives only one permission prompt in all browsers.
>
> Uh, I typed too fast. I meant:
Shame on me for putting shoddy code on the internet! Recursive is better
for proper error handling:
async function getSomeUserMedia({audio, video}) {
try {
return await navigator.mediaDevices.getUserMedia({audio, video});
} catch(e) {
if (e.name == "NotFoundError") {
if (video && audio) return gUM({audio});
if (audio) return gUM({video});
}
throw e;
}
}
// Example usage (works with constraints as well):
(async () => {
try {
video.srcObject = await getSomeUserMedia({video: {width: 1280}, audio: true});
} catch(e) {
console.log(e);
}
})();
https://jsfiddle.net/jib1/s83m4w2y/
.: Jan-Ivar :.
Received on Wednesday, 27 February 2019 15:18:26 UTC