add timeout to getAudioDevice

This commit is contained in:
Malte Jürgens 2022-08-01 22:26:44 +02:00
parent 95d391e869
commit f01c941c90
1 changed files with 5 additions and 0 deletions

View File

@ -3,10 +3,15 @@
navigator.mediaDevices.chromiumGetDisplayMedia = navigator.mediaDevices.chromiumGetDisplayMedia =
navigator.mediaDevices.getDisplayMedia; navigator.mediaDevices.getDisplayMedia;
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
const getAudioDevice = async (nameOfAudioDevice) => { const getAudioDevice = async (nameOfAudioDevice) => {
await navigator.mediaDevices.getUserMedia({ await navigator.mediaDevices.getUserMedia({
audio: true, audio: true,
}); });
await sleep(500);
let devices = await navigator.mediaDevices.enumerateDevices(); let devices = await navigator.mediaDevices.enumerateDevices();
let audioDevice = devices.find(({ label }) => label === nameOfAudioDevice); let audioDevice = devices.find(({ label }) => label === nameOfAudioDevice);
return audioDevice; return audioDevice;