1 | import * as usb from '../usb';
|
2 | import { EventEmitter } from 'events';
|
3 | import { WebUSBDevice } from './webusb-device';
|
4 |
|
5 |
|
6 |
|
7 | export interface USBOptions {
|
8 | |
9 |
|
10 |
|
11 | devicesFound?: (devices: USBDevice[]) => Promise<USBDevice | void>;
|
12 | |
13 |
|
14 |
|
15 | allowedDevices?: USBDeviceFilter[];
|
16 | |
17 |
|
18 |
|
19 | allowAllDevices?: boolean;
|
20 | |
21 |
|
22 |
|
23 | deviceTimeout?: number;
|
24 | }
|
25 |
|
26 |
|
27 |
|
28 | export declare const getWebUsb: () => USB;
|
29 | export 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 | }
|