thegecko / webusb

Node.js implementation of the WebUSB Specification
https://thegecko.github.io/webusb/
MIT License
183 stars 27 forks source link

Only attach node-usb attach/detach listeners when there is a connect/disconnected listener #42

Closed sandeepmistry closed 5 years ago

sandeepmistry commented 5 years ago

Depends on https://github.com/DefinitelyTyped/DefinitelyTyped/pull/32106

These changes only add the usb "attach"/"detach" handlers if a listener is "connected"/"disconnected".

It allows apps that don't listen to these events to exit automatically, as well as exit automatically if listeners for both events are not attached.

node-usb uses a similar pattern here: https://github.com/tessel/node-usb/blob/master/usb.js#L511-L524

thegecko commented 5 years ago

Thanks, LGTM.

I'll leave this open until https://github.com/DefinitelyTyped/DefinitelyTyped/pull/32106 is released so the version of the type can be updated.

thegecko commented 5 years ago

@types/usb 1.1.8 has been published with your addition. Would you ind updating this PR to use it?

sandeepmistry commented 5 years ago

@thegecko sure thing, just pushed a change the package.json to use "@types/usb": "^1.1.8".

thegecko commented 5 years ago

Awesome!

thegecko commented 5 years ago

Thanks @sandeepmistry I've released a new version on npm.