0

I am encountering a rather strange problem on the javascript side. I'm trying to put information about the media device in an array, but they appear in the array but with length 0 and I can't even access them

const enumerateDevicesKey = () => {
        const enumerateDevices = [];
        if (! isEnumerateDevicesSupported) return;
        let test = '';

        navigator.mediaDevices.enumerateDevices()
        .then((devices) => {
            setTimeout(() => {
                devices.forEach((device) => {
                    enumerateDevices.push(`${device.kind}:${device.label}id=${device.groupId}`)
                });
            }, 200)
        })
        .catch((err) => {
            console.error(`${err.name}: ${err.message}`);
        });

        return enumerateDevices;
    }
const enumerateAudioSupport = enumerateDevicesKey();
        console.log("enumerateaudioSupport", enumerateAudioSupport);
enumerateaudioSupport 
[]
0
: 
"audioinput:id=eb6591fd602ceec2096231b64673e7d98019182aabc63227f6bab6631af6356f"
1
: 
"videoinput:id=deabb3ff8ee9f2c30471c0c55db96870fcaaae418a5a2fcc122ff2adc057b486"
2
: 
"audiooutput:id=5f6c43c9d678b329b136e33fd1900b2ed17377fe95bbf1305a548c2e6d76e600"
length
: 
3
[[Prototype]]
: 
Array(0)

How could I solve the problem? I also tried with snooze or async functions, but in vain

Key Lol
  • 75
  • 6

0 Answers0