UNPKG

2.23 kBTypeScriptView Raw
1import * as usb from '../usb';
2import { EventEmitter } from 'events';
3import { WebUSBDevice } from './webusb-device';
4/**
5 * USB Options
6 */
7export interface USBOptions {
8 /**
9 * Optional `device found` callback function to allow the user to select a device
10 */
11 devicesFound?: (devices: USBDevice[]) => Promise<USBDevice | void>;
12 /**
13 * Optional array of preconfigured allowed devices
14 */
15 allowedDevices?: USBDeviceFilter[];
16 /**
17 * Optional flag to automatically allow all devices
18 */
19 allowAllDevices?: boolean;
20 /**
21 * Optional timeout (in milliseconds) to use for the device control transfers
22 */
23 deviceTimeout?: number;
24}
25/**
26 * Convenience method to get the WebUSB interface available
27 */
28export declare const getWebUsb: () => USB;
29export declare class WebUSB implements USB {
30 private options;
31 protected emitter: EventEmitter<[never]>;
32 protected knownDevices: Map<usb.Device, WebUSBDevice>;
33 protected authorisedDevices: Set<USBDeviceFilter>;
34 constructor(options?: USBOptions);
35 private _onconnect;
36 set onconnect(fn: (ev: USBConnectionEvent) => void);
37 private _ondisconnect;
38 set ondisconnect(fn: (ev: USBConnectionEvent) => void);
39 addEventListener(type: 'connect' | 'disconnect', listener: (this: this, ev: USBConnectionEvent) => void): void;
40 addEventListener(type: 'connect' | 'disconnect', listener: EventListener): void;
41 removeEventListener(type: 'connect' | 'disconnect', callback: (this: this, ev: USBConnectionEvent) => void): void;
42 removeEventListener(type: 'connect' | 'disconnect', callback: EventListener): void;
43 dispatchEvent(_event: Event): boolean;
44 /**
45 * Requests a single Web USB device
46 * @param options The options to use when scanning
47 * @returns Promise containing the selected device
48 */
49 requestDevice(options?: USBDeviceRequestOptions): Promise<USBDevice>;
50 /**
51 * Gets all allowed Web USB devices which are connected
52 * @returns Promise containing an array of devices
53 */
54 getDevices(): Promise<USBDevice[]>;
55 private loadDevices;
56 private getWebDevice;
57 private quickFilter;
58 private filterDevice;
59 private isAuthorisedDevice;
60}