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
1 changed files with 9 additions and 3 deletions

View File

@ -11,9 +11,15 @@ const getAudioDevice = async (nameOfAudioDevice) => {
await navigator.mediaDevices.getUserMedia({
audio: true,
});
await sleep(500);
let devices = await navigator.mediaDevices.enumerateDevices();
let audioDevice = devices.find(({ label }) => label === nameOfAudioDevice);
let audioDevice;
while (audioDevice === undefined) {
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;
};