poll for `enumerateDevices()` to get available
This commit is contained in:
parent
1a2d09fe3d
commit
8bd4d1896a
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue