poll for enumerateDevices() to get available

This commit is contained in:
Malte Jürgens 2022-08-02 11:56:08 +02:00
parent 1a2d09fe3d
commit 8bd4d1896a

View file

@ -11,9 +11,15 @@ const getAudioDevice = async (nameOfAudioDevice) => {
await navigator.mediaDevices.getUserMedia({ await navigator.mediaDevices.getUserMedia({
audio: true, audio: true,
}); });
await sleep(500); let audioDevice;
let devices = await navigator.mediaDevices.enumerateDevices(); while (audioDevice === undefined) {
let audioDevice = devices.find(({ label }) => label === nameOfAudioDevice); let devices = await navigator.mediaDevices.enumerateDevices();
audioDevice = devices.find(({ label }) => label === nameOfAudioDevice);
if (!audioDevice)
console.log(`Did not find '${nameOfAudioDevice}', trying again in 100ms`);
await sleep(100);
}
console.log(`Found '${nameOfAudioDevice}'`);
return audioDevice; return audioDevice;
}; };