usb

  • Version 3.0.1
  • Published
  • 57.6 kB
  • 1 dependency
  • MIT license

Install

npm i usb
yarn add usb
pnpm add usb

Overview

Library to access USB devices

Index

Variables

variable usb

const usb: WebUSB;
  • Default USB object (allows all devices by default)

variable webusb

const webusb: any;
  • Default WebUSB object (mimics navigator.usb)

Classes

class WebUSB

class WebUSB extends EventTarget implements USB {}
  • WebUSB class

    ### Events

    | Name | Event | Description | | ---- | ----- | ----------- | | connect | USBConnectionEvent | Device connected | | disconnect | USBConnectionEvent | Device disconnected |

constructor

constructor(options?: USBOptions);

    property authorisedDevices

    protected authorisedDevices: Set<USBDeviceFilter>;

      property eventListeners

      protected eventListeners: Map<string, Set<EventListener>>;

        property knownDevices

        protected knownDevices: Map<string, UsbDevice>;

          property listenerCount

          protected listenerCount: number;

            property nativeEmitter

            protected nativeEmitter: Emitter;

              method addEventListener

              addEventListener: {
              (
              type: 'connect' | 'disconnect',
              listener: (this: this, ev: USBConnectionEvent) => void
              ): void;
              (type: 'connect' | 'disconnect', listener: EventListener): void;
              };

                method findDeviceByIds

                findDeviceByIds: (vid: number, pid: number) => Promise<UsbDevice | undefined>;
                • Convenience method to get the first device with the specified VID and PID, or undefined if no such device is present.

                  Parameter vid

                  Parameter pid

                method findDeviceBySerial

                findDeviceBySerial: (serialNumber: string) => Promise<UsbDevice | undefined>;
                • Convenience method to get the device with the specified serial number, or undefined if no such device is present.

                  Parameter serialNumber

                method getDevices

                getDevices: () => Promise<UsbDevice[]>;
                • Gets all allowed Web USB devices which are connected

                  Returns

                  Promise containing an array of devices

                method removeEventListener

                removeEventListener: {
                (
                type: 'connect' | 'disconnect',
                callback: (this: this, ev: USBConnectionEvent) => void
                ): void;
                (type: 'connect' | 'disconnect', callback: EventListener): void;
                };

                  method requestDevice

                  requestDevice: (options?: USBDeviceRequestOptions) => Promise<UsbDevice>;
                  • Requests a single Web USB device

                    Parameter options

                    The options to use when scanning

                    Returns

                    Promise containing the selected device

                  Interfaces

                  interface USBOptions

                  interface USBOptions {}
                  • USB Options

                  property allowAllDevices

                  allowAllDevices?: boolean;
                  • Optional flag to automatically allow all devices

                  property allowedDevices

                  allowedDevices?: USBDeviceFilter[];
                  • Optional array of preconfigured allowed devices

                  property devicesFound

                  devicesFound?: (devices: UsbDevice[]) => Promise<UsbDevice | void>;
                  • Optional device found callback function to allow the user to select a device

                  property deviceTimeout

                  deviceTimeout?: number;
                  • Optional timeout (in milliseconds) to use for the device control transfers

                  Package Files (1)

                  Dependencies (1)

                  Dev Dependencies (5)

                  Peer Dependencies (0)

                  No peer dependencies.

                  Badge

                  To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                  You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/usb.

                  • Markdown
                    [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/usb)
                  • HTML
                    <a href="https://www.jsdocs.io/package/usb"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>