thegecko / webusb

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

support for allowing all devices #82

Closed pelikhan closed 3 years ago

pelikhan commented 3 years ago

In order to enable headless scenario, it would be nice to allow any device matching the filters.

thegecko commented 3 years ago

I believe passing options with an empty filter array matches all devices, the same as in the browser.

For a headless scenario, you need a function to select the device, this can be achieved by implementing your own devicesFound function, see this example.

pelikhan commented 3 years ago

I was specifically thinking about the getDrvices function (https://github.com/thegecko/webusb/blob/d800c8103ca18d04264551b86eb0e05fb47a970a/src/usb.ts#L214). Unlike in the browser, I would like to override the behavior and allow any device matching a filter (if that makes sense)


From: Rob Moran @.> Sent: Sunday, May 9, 2021 10:38:37 AM To: thegecko/webusb @.> Cc: Peli de Halleux @.>; Author @.> Subject: Re: [thegecko/webusb] support for allowing all devices (#82)

I believe passing options with an empty filter array matches all devices, the same as in the browser.

For a headless scenario, you need a function to select the device, this can be achieved by implementing your own devicesFound function, see this examplehttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fthegecko%2Fwebusb%2Fblob%2Fmaster%2Fexamples%2Fselector.js&data=04%7C01%7Cjhalleux%40microsoft.com%7Cacc5523539c449b7178808d913114719%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637561787245771963%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=mJhOjmiryHIHXXqGJPtaag1KanIaDVpqjT8ln5h895I%3D&reserved=0.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fthegecko%2Fwebusb%2Fissues%2F82%23issuecomment-835850439&data=04%7C01%7Cjhalleux%40microsoft.com%7Cacc5523539c449b7178808d913114719%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637561787245771963%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=znbeuYPxUyytkQHI6ziT55CKo57krnH4MUUiSQOQBtE%3D&reserved=0, or unsubscribehttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAA73QKNPLNYS2RVZ6CLD6PTTM3CB3ANCNFSM44PJ6C2Q&data=04%7C01%7Cjhalleux%40microsoft.com%7Cacc5523539c449b7178808d913114719%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637561787245781957%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=tzoMOBxT0hJHhTD4zAuwDnLJaY%2B2AQfS2L3aY7FNXbQ%3D&reserved=0.

thegecko commented 3 years ago

I'm keen to align to the spec where possible, this function is designed to return all previously allowed devices.

Could you outline your use case? I guess an optional allowAll flag could be used, but then you would lose compatibility with the specification and your code wouldn't work as expected in the browser.

You could always use the underlying usb library if you just want to list usb devices:

https://github.com/tessel/node-usb#usbgetdevicelist

pelikhan commented 3 years ago

Since the allowed list is not serialized, the behavior is different from the browser, which remembers. My scenario was to use webusb to build a jacdac node-red node; thus in a headless environment.

I have solded it by calling requestDevices from getDevices.

Sent from Outlookhttp://aka.ms/weboutlook


From: Rob Moran @.> Sent: Monday, May 10, 2021 1:10 AM To: thegecko/webusb @.> Cc: Peli de Halleux @.>; Author @.> Subject: Re: [thegecko/webusb] support for allowing all devices (#82)

I'm keen to align to the spec where possible, this function is designed to return all previously allowed devices.

Could you outline your use case? I guess an optional allowAll flag could be used, but then you would lose compatibility with the specification.

You could always use the underlying usb library if you just want to list usb devices:

https://github.com/tessel/node-usb#usbgetdevicelisthttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Ftessel%2Fnode-usb%23usbgetdevicelist&data=04%7C01%7Cjhalleux%40microsoft.com%7C2546661d1b9a4502574108d9138b0e64%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637562310233490687%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=IYdnSXnTftAy2qK43iHRA35ltUUala5WnfQOn%2BUVJEs%3D&reserved=0

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fthegecko%2Fwebusb%2Fissues%2F82%23issuecomment-836340705&data=04%7C01%7Cjhalleux%40microsoft.com%7C2546661d1b9a4502574108d9138b0e64%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637562310233490687%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=Qb92thlGga5IS0tpKw2BavUveUP0%2BoZHHnorJI6uczo%3D&reserved=0, or unsubscribehttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAA73QKO7LVGLPBVGLZIIITLTM6IGZANCNFSM44PJ6C2Q&data=04%7C01%7Cjhalleux%40microsoft.com%7C2546661d1b9a4502574108d9138b0e64%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637562310233500688%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=mmnHwOOe7pdpcvq%2B3mO7dVN6GJXWMgf2j3rvzif1jy0%3D&reserved=0.