WICG / webhid

Web API for accessing Human Interface Devices (HID)
Other
140 stars 35 forks source link

Fire connect and disconnect events on HIDDevice and bubble #91

Open reillyeon opened 2 years ago

reillyeon commented 2 years ago

The connect and disconnect events are currently only fired on navigator.hid. For disconnects in particular it is useful to be able to listen for a particular device being disconnected. For the Web Serial API we did this by making SerialPort itself an EventTarget and defining a custom parent algorithm so that the events bubble to navigator.serial after being fired on the SerialPort.

We should do the same for this API. I believe such a change would be backwards compatible. The only difference is that the target attribute of the HIDConnectionEvent would be set to the value of its device attribute instead of navigator.hid.

The current workaround developers have to employ is to register an event handler and compare it against the device they are interested in.