poll for enumerateDevices()
to get available
This commit is contained in:
parent
1a2d09fe3d
commit
8bd4d1896a
1 changed files with 9 additions and 3 deletions
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue