2022-11-22 21:50:32 +00:00
|
|
|
function getDeviceDetails(device) {
|
|
|
|
return grantedDevice.productName || `Unknown device ${grantedDevice.deviceId}`
|
|
|
|
}
|
|
|
|
|
|
|
|
async function testIt() {
|
|
|
|
const noDevicesFoundMsg = 'No devices found'
|
|
|
|
const grantedDevices = await navigator.usb.getDevices()
|
|
|
|
let grantedDeviceList = ''
|
2023-02-01 11:59:16 +00:00
|
|
|
if (grantedDevices.length > 0) {
|
2022-11-22 21:50:32 +00:00
|
|
|
grantedDevices.forEach(device => {
|
|
|
|
grantedDeviceList += `<hr>${getDeviceDetails(device)}</hr>`
|
2023-02-01 11:59:16 +00:00
|
|
|
})
|
2022-11-22 21:50:32 +00:00
|
|
|
} else {
|
|
|
|
grantedDeviceList = noDevicesFoundMsg
|
|
|
|
}
|
|
|
|
document.getElementById('granted-devices').innerHTML = grantedDeviceList
|
|
|
|
|
|
|
|
grantedDeviceList = ''
|
|
|
|
try {
|
|
|
|
const grantedDevice = await navigator.usb.requestDevice({
|
|
|
|
filters: []
|
|
|
|
})
|
|
|
|
grantedDeviceList += `<hr>${getDeviceDetails(device)}</hr>`
|
2023-02-01 11:59:16 +00:00
|
|
|
|
2022-11-22 21:50:32 +00:00
|
|
|
} catch (ex) {
|
|
|
|
if (ex.name === 'NotFoundError') {
|
|
|
|
grantedDeviceList = noDevicesFoundMsg
|
|
|
|
}
|
|
|
|
}
|
|
|
|
document.getElementById('granted-devices2').innerHTML = grantedDeviceList
|
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById('clickme').addEventListener('click',testIt)
|