Declaring a list of devices to watch
Closed this issue · 4 comments
Hi,
Is there a way to pre-declare a list of device to listen for connection/disconnection ?
When requesting device, if it is not plugged yet, it will fail, but i'd like to be able to watch for connection/disconnection on this device. But, as the device is not in "allowedDevices" list, I will ne be notified when it is plugged.
Is this possible ?
The webusb spec. doesn't allow for this (the user has to explicitly request a device is added).
You can fake it in the the node version by using a library like node-usb or usb-detection to fire on device connections and then create a webusb version of that device.
I can give you some pointers, but this would never work in the browser.
I can use usb
library in addition for these events, my runtime is on Electron. And I prefer a more modern standard like your implementation of webusb
.
So, you confirm that I will not be able to listen to a specific device connection with webusb
if haven't made a successful requestDevice
before ?
So, you confirm that I will not be able to listen to a specific device connection with webusb if haven't made a successful requestDevice before ?
Correct, I don't want to add things which wouldn't work in the browser.
In Electron you could potentially use node-usb to detect your device and then create a webusb object from it similar to:
Line 452 in 0a3f331
OK, I'll user another lib to handle connection/disconnection events.
Thank you for your answers !