@nico-martin/webusb-controller
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

WebUSBController Class

A JavaScript class that abstracts the WebUSB API and concentrates it on a handful of methods:

Install

npm i @nico-martin/webusb-controller

About

import WebUSBController from '@nico-martin/webusb-controller';

const Controller = new WebUSBController();

// Connect to a device, accepts USBDeviceRequestOptions as a parameter
Controller.connect({ filters: [{ vendorId: 0x2e8a }] });

// Send a DataView to the connected device
Controller.send(new Uint8Array([0, 255]));

// listener that accepts a callback function that runs whenever new data (DataView) is sent
Controller.onReceive((data) => console.log('received', data));

// listener that accepts a callback function that runs whenever a device is connected or disconnected
Controller.onDeviceConnect((device) =>
  console.log(device ? 'connect' : 'disconnect')
);

Package Sidebar

Install

npm i @nico-martin/webusb-controller

Weekly Downloads

2

Version

1.0.0

License

none

Unpacked Size

17.5 kB

Total Files

7

Last publish

Collaborators

  • nico_martin