thegecko / webusb

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

Feature request: Ability to specify device timeouts #86

Closed freshollie closed 2 years ago

freshollie commented 2 years ago

I was getting Control Transfer In timeouts. Couldn't see anything in the documentation here, but found the docs for node-usb and realised I had to set the default timeout on the Device class in node-usb.

Seems a bit hacky, but all worked when I did that.

import { USB } from "webusb";
import { Device as NativeUSBDevice } from "usb";
NativeUSBDevice.prototype.timeout = 60000;

const usb = new USB({
  devicesFound: async (devices) => {
    ...
  },
});

Would be good if a default timeout could be passed in as the options to the USB constructor. Otherwise, I hope others find this hack useful :)

thegecko commented 2 years ago

This would be a great addition to the USBOptions object and would need to be passed down to the adapter.

We are currently merging this library with node-usb, so happy to consider an addition there.

If it's needed here, feel free to create a PR and I'll merge it.

freshollie commented 2 years ago

Cool. Nice to see this is now merged with node-usb. I still think an option on WebUSB so set the default timeout for all devices, but I'll create a PR for that if I have time.