我有一个数组示例:
// let's assume we don't have any headphones connected
let headphonesConnected = false;
const updateDevices = () => {
navigator.mediaDevices.enumerateDevices()
.then(function(devices) {
// check to see if we have any device with "head" in its name connected
// like "headset" or "headphones"
headphonesConnected = devices
.filter(device => /audio\w+/.test(device.kind))
.find(device => device.label.toLowerCase().includes('head'))
;
})
;
};
updateDevices();
// add an ondevicechange event listener so we can tell when
// an input device is connected and disconnected
navigator.mediaDevices.ondevicechange = updateDevices;
当我引用我的页面时,我想要这样的结果。
第一次推荐
ondevicechange
第二次刷新
Array
(
[0] => 5c832a3fec3a6
[1] => 5c832a3fdbe90
[2] => 5c832a3fc6335
[3] => 5c832a3fb080d
[4] => 5c832a3f89d5b
)
这意味着每次出现新的随机数组。