usb 3.0.0-alpha.2 → 3.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +140 -28
- package/dist/index.d.ts +37 -29
- package/dist/index.js +123 -138
- package/index.d.ts +59 -20
- package/index.js +55 -55
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -8,6 +8,9 @@ Node.JS library for communicating with USB devices.
|
|
|
8
8
|
|
|
9
9
|
This is a complete rewrite in rust using [@kevinmehall](https://github.com/kevinmehall)'s excellent [nusb library](https://docs.rs/nusb/latest/nusb) and [napi-rs](https://napi.rs/).
|
|
10
10
|
|
|
11
|
+
# License
|
|
12
|
+
[MIT](LICENSE.md)
|
|
13
|
+
|
|
11
14
|
# Prerequisites
|
|
12
15
|
|
|
13
16
|
[Node.js >= v12.22.0](https://nodejs.org), which includes `npm`.
|
|
@@ -26,7 +29,22 @@ You may need to modify your udev and permission rules in order to access your de
|
|
|
26
29
|
SUBSYSTEM=="usb", ATTR{idVendor}=="USB-VENDOR-ID", ATTR{idProduct}=="USB-PRODUCT-ID", MODE="0660", GROUP="GROUP-YOUR-USER-IS-IN"
|
|
27
30
|
```
|
|
28
31
|
|
|
29
|
-
#
|
|
32
|
+
# Getting Started
|
|
33
|
+
|
|
34
|
+
## Supported Architectures and Operating Systems
|
|
35
|
+
|
|
36
|
+
- i686-pc-windows-msvc
|
|
37
|
+
- x86_64-apple-darwin
|
|
38
|
+
- x86_64-pc-windows-msvc
|
|
39
|
+
- x86_64-unknown-linux-gnu
|
|
40
|
+
- x86_64-unknown-linux-musl
|
|
41
|
+
- aarch64-apple-darwin
|
|
42
|
+
- aarch64-pc-windows-msvc
|
|
43
|
+
- aarch64-unknown-linux-gnu
|
|
44
|
+
- aarch64-unknown-linux-musl
|
|
45
|
+
- armv7-unknown-linux-gnueabihf
|
|
46
|
+
|
|
47
|
+
## Installation
|
|
30
48
|
|
|
31
49
|
Native modules are bundled as separate optional packages, so installation should be as simple as installing the package.
|
|
32
50
|
|
|
@@ -42,27 +60,85 @@ With `yarn`:
|
|
|
42
60
|
yarn add usb
|
|
43
61
|
```
|
|
44
62
|
|
|
45
|
-
|
|
46
|
-
|
|
63
|
+
## Examples
|
|
64
|
+
Use the following examples to kickstart your development. Once you have a desired device, use the APIs below to interact with it.
|
|
47
65
|
|
|
48
|
-
|
|
49
|
-
|
|
66
|
+
### List all devices
|
|
67
|
+
```typescript
|
|
68
|
+
import { usb } from 'usb';
|
|
50
69
|
|
|
51
|
-
|
|
70
|
+
const devices = await usb.getDevices();
|
|
52
71
|
|
|
53
|
-
|
|
54
|
-
|
|
72
|
+
for (const device of devices) {
|
|
73
|
+
console.log(device); // WebUSB device
|
|
74
|
+
}
|
|
75
|
+
```
|
|
55
76
|
|
|
56
|
-
|
|
57
|
-
|
|
77
|
+
### Find device by vid/pid
|
|
78
|
+
```typescript
|
|
79
|
+
import { usb } from 'usb';
|
|
58
80
|
|
|
59
|
-
|
|
81
|
+
const device = await usb.findDeviceByIds(0x59e3, 0x0a23);
|
|
60
82
|
|
|
61
|
-
|
|
83
|
+
if (device) {
|
|
84
|
+
console.log(device); // WebUSB device
|
|
85
|
+
}
|
|
86
|
+
```
|
|
62
87
|
|
|
63
|
-
|
|
88
|
+
### Find device by SerialNumber
|
|
89
|
+
```typescript
|
|
90
|
+
import { usb } from 'usb';
|
|
91
|
+
|
|
92
|
+
const device = await usb.findDeviceBySerial('TEST_DEVICE');
|
|
93
|
+
|
|
94
|
+
if (device) {
|
|
95
|
+
console.log(device); // WebUSB device
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Watch for connect/disconnect events
|
|
100
|
+
```typescript
|
|
101
|
+
import { usb } from 'usb';
|
|
102
|
+
|
|
103
|
+
usb.addEventListener('connect', (event) => {
|
|
104
|
+
console.log('Device connected:', event.device.serialNumber);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
usb.addEventListener('disconnect', (event) => {
|
|
108
|
+
console.log('Device disconnected:', event.device.serialNumber);
|
|
109
|
+
});
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Use WebUSB approach to find a device
|
|
113
|
+
```typescript
|
|
114
|
+
import { webusb } from 'usb';
|
|
115
|
+
|
|
116
|
+
// Returns first matching device
|
|
117
|
+
const device = await webusb.requestDevice({
|
|
118
|
+
filters: [{}]
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
console.log(device); // WebUSB device
|
|
122
|
+
```
|
|
64
123
|
|
|
65
|
-
|
|
124
|
+
### Use WebUSB approach to find a device with custom selection method
|
|
125
|
+
```typescript
|
|
126
|
+
import { WebUSB } from 'usb';
|
|
127
|
+
|
|
128
|
+
const customWebUSB = new WebUSB({
|
|
129
|
+
// This function can return a promise which allows a UI to be displayed if required
|
|
130
|
+
devicesFound: devices => devices.find(device => device.serialNumber === 'TEST_DEVICE')
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// Returns device based on injected 'devicesFound' function
|
|
134
|
+
const device = await customWebUSB.requestDevice({
|
|
135
|
+
filters: [{}]
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
console.log(device); // WebUSB device
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Electron
|
|
66
142
|
Please refer to the maintained example for using `node-usb` in electron:
|
|
67
143
|
|
|
68
144
|
https://github.com/node-usb/node-usb-example-electron
|
|
@@ -73,31 +149,39 @@ If using a packaging system for electron, ensure the `node-usb` library does not
|
|
|
73
149
|
- nodeGypRebuild: false
|
|
74
150
|
- npmRebuild: false
|
|
75
151
|
|
|
76
|
-
|
|
152
|
+
# APIs
|
|
153
|
+
Since `v3.0.0`, the `node-usb` API follows the WebUSB specification which can be found here:
|
|
77
154
|
|
|
78
|
-
|
|
79
|
-
Return a list of `USB` objects for the USB devices attached to the system.
|
|
155
|
+
https://wicg.github.io/webusb/
|
|
80
156
|
|
|
81
|
-
|
|
82
|
-
Convenience method to get the first device with the specified VID and PID, or `undefined` if no such device is present.
|
|
157
|
+
Two versions of the WebUSB API exist by default:
|
|
83
158
|
|
|
84
|
-
|
|
85
|
-
|
|
159
|
+
- `usb` - which exposes all functionality in an unrestricted manner (e.g. without needing to `requestDevice()` first)
|
|
160
|
+
- `webusb` - which follows the WebUSB specification exactly and requires the user to authorise devices via `requestDevice()` first.
|
|
86
161
|
|
|
87
|
-
|
|
162
|
+
You may also construct your own WebUSB (e.g. to specify a `requestDevice()` callback) using the exported `WebUSB` class.
|
|
88
163
|
|
|
89
|
-
|
|
164
|
+
Full auto-generated API documentation can be seen here:
|
|
90
165
|
|
|
91
|
-
https://
|
|
166
|
+
https://node-usb.github.io/node-usb-rs/
|
|
167
|
+
|
|
168
|
+
## Implementation Status
|
|
92
169
|
|
|
93
|
-
###
|
|
170
|
+
### USB
|
|
94
171
|
|
|
95
|
-
####
|
|
172
|
+
#### WebUSB Features
|
|
96
173
|
|
|
97
174
|
- [x] getDevices()
|
|
98
175
|
- [x] requestDevice()
|
|
99
176
|
|
|
100
|
-
####
|
|
177
|
+
#### Extended Features
|
|
178
|
+
|
|
179
|
+
- [x] findDeviceByIds()
|
|
180
|
+
- [x] findDeviceBySerial()
|
|
181
|
+
|
|
182
|
+
### USBDevice
|
|
183
|
+
|
|
184
|
+
#### WebUSB Features
|
|
101
185
|
|
|
102
186
|
- [x] usbVersionMajor
|
|
103
187
|
- [x] usbVersionMinor
|
|
@@ -132,14 +216,42 @@ https://wicg.github.io/webusb/
|
|
|
132
216
|
- [ ] isochronousTransferIn()
|
|
133
217
|
- [ ] isochronousTransferOut()
|
|
134
218
|
|
|
135
|
-
####
|
|
219
|
+
#### Extended Features
|
|
220
|
+
|
|
221
|
+
- [x] bus
|
|
222
|
+
- [x] address
|
|
223
|
+
- [x] ports
|
|
224
|
+
- [x] speed
|
|
225
|
+
- [x] detachKernelDriver() (Linux only)
|
|
226
|
+
- [x] attachKernelDriver() (Linux only)
|
|
227
|
+
|
|
228
|
+
### Events
|
|
136
229
|
|
|
137
230
|
- [x] connect
|
|
138
231
|
- [x] disconnect
|
|
139
232
|
|
|
233
|
+
## Extended Functions
|
|
234
|
+
|
|
235
|
+
This library extends the WebUSB specification to add further functionality and convenience
|
|
236
|
+
|
|
237
|
+
### findDeviceByIds(vid, pid)
|
|
238
|
+
Convenience method to get the first device with the specified VID and PID, or `undefined` if no such device is present.
|
|
239
|
+
|
|
240
|
+
### findDeviceBySerial(serialNumber)
|
|
241
|
+
Convenience method to get the device with the specified serial number, or `undefined` if no such device is present.
|
|
242
|
+
|
|
243
|
+
### detachKernelDriver(interfaceNumber) (Linux only)
|
|
244
|
+
Detaches the kernel driver from the interface.
|
|
245
|
+
You may need to execute this with elevated privileges.
|
|
246
|
+
|
|
247
|
+
### attachKernelDriver(interfaceNumber) (Linux only)
|
|
248
|
+
Re-attaches the kernel driver for the interface.
|
|
249
|
+
|
|
140
250
|
# Development
|
|
141
251
|
The library is based on native rust bindings wrapping the [nusb](https://docs.rs/nusb/latest/nusb) crate.
|
|
142
252
|
|
|
253
|
+
Ensure you have a working rust environment, instructions for setting this up are avalable at https://rust-lang.org/tools/install/
|
|
254
|
+
|
|
143
255
|
## Setup
|
|
144
256
|
|
|
145
257
|
```bash
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Emitter } from '../index.js';
|
|
2
|
-
import { EventEmitter } from 'events';
|
|
1
|
+
import { UsbDevice, Emitter } from '../index.js';
|
|
3
2
|
/**
|
|
4
3
|
* USB Options
|
|
5
4
|
*/
|
|
@@ -7,7 +6,7 @@ interface USBOptions {
|
|
|
7
6
|
/**
|
|
8
7
|
* Optional `device found` callback function to allow the user to select a device
|
|
9
8
|
*/
|
|
10
|
-
devicesFound?: (devices:
|
|
9
|
+
devicesFound?: (devices: UsbDevice[]) => Promise<UsbDevice | void>;
|
|
11
10
|
/**
|
|
12
11
|
* Optional array of preconfigured allowed devices
|
|
13
12
|
*/
|
|
@@ -20,57 +19,66 @@ interface USBOptions {
|
|
|
20
19
|
* Optional timeout (in milliseconds) to use for the device control transfers
|
|
21
20
|
*/
|
|
22
21
|
deviceTimeout?: number;
|
|
23
|
-
/**
|
|
24
|
-
* Optional flag to enable/disable automatic kernal driver detaching (defaults to true)
|
|
25
|
-
*/
|
|
26
|
-
autoDetachKernelDriver?: boolean;
|
|
27
22
|
}
|
|
28
|
-
|
|
23
|
+
interface WebUSB {
|
|
24
|
+
addEventListener(type: "connect" | "disconnect", listener: (this: this, ev: USBConnectionEvent) => any, useCapture?: boolean): void;
|
|
25
|
+
addEventListener(type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions): void;
|
|
26
|
+
removeEventListener(type: "connect" | "disconnect", callback: (this: this, ev: USBConnectionEvent) => any, useCapture?: boolean): void;
|
|
27
|
+
removeEventListener(type: string, callback: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean): void;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* WebUSB class
|
|
31
|
+
*
|
|
32
|
+
* ### Events
|
|
33
|
+
*
|
|
34
|
+
* | Name | Event | Description |
|
|
35
|
+
* | ---- | ----- | ----------- |
|
|
36
|
+
* | `connect` | {@link USBConnectionEvent} | Device connected |
|
|
37
|
+
* | `disconnect` | {@link USBConnectionEvent} | Device disconnected |
|
|
38
|
+
*/
|
|
39
|
+
declare class WebUSB extends EventTarget implements USB {
|
|
29
40
|
private options;
|
|
30
41
|
protected nativeEmitter: Emitter;
|
|
31
|
-
protected emitter: EventEmitter<any>;
|
|
32
42
|
protected authorisedDevices: Set<USBDeviceFilter>;
|
|
33
|
-
protected knownDevices: Map<string,
|
|
43
|
+
protected knownDevices: Map<string, UsbDevice>;
|
|
34
44
|
constructor(options?: USBOptions);
|
|
35
45
|
private _onconnect;
|
|
36
46
|
set onconnect(fn: (ev: USBConnectionEvent) => void);
|
|
37
47
|
private _ondisconnect;
|
|
38
48
|
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
49
|
/**
|
|
45
50
|
* Requests a single Web USB device
|
|
46
51
|
* @param options The options to use when scanning
|
|
47
52
|
* @returns Promise containing the selected device
|
|
48
53
|
*/
|
|
49
|
-
requestDevice(options?: USBDeviceRequestOptions): Promise<
|
|
54
|
+
requestDevice(options?: USBDeviceRequestOptions): Promise<UsbDevice>;
|
|
50
55
|
/**
|
|
51
56
|
* Gets all allowed Web USB devices which are connected
|
|
52
57
|
* @returns Promise containing an array of devices
|
|
53
58
|
*/
|
|
54
|
-
getDevices(): Promise<
|
|
59
|
+
getDevices(): Promise<UsbDevice[]>;
|
|
60
|
+
/**
|
|
61
|
+
* Convenience method to get the first device with the specified VID and PID, or `undefined` if no such device is present.
|
|
62
|
+
* @param vid
|
|
63
|
+
* @param pid
|
|
64
|
+
*/
|
|
65
|
+
findDeviceByIds(vid: number, pid: number): Promise<UsbDevice | undefined>;
|
|
66
|
+
/**
|
|
67
|
+
* Convenience method to get the device with the specified serial number, or `undefined` if no such device is present.
|
|
68
|
+
* @param serialNumber
|
|
69
|
+
*/
|
|
70
|
+
findDeviceBySerial(serialNumber: string): Promise<UsbDevice | undefined>;
|
|
55
71
|
private loadDevices;
|
|
56
72
|
private quickFilter;
|
|
57
73
|
private filterDevice;
|
|
58
74
|
private isAuthorisedDevice;
|
|
59
75
|
}
|
|
60
76
|
/**
|
|
61
|
-
*
|
|
62
|
-
*/
|
|
63
|
-
declare const getDeviceList: () => Promise<USBDevice[]>;
|
|
64
|
-
/**
|
|
65
|
-
* Convenience method to get the first device with the specified VID and PID, or `undefined` if no such device is present.
|
|
66
|
-
* @param vid
|
|
67
|
-
* @param pid
|
|
77
|
+
* Default USB object (allows all devices by default)
|
|
68
78
|
*/
|
|
69
|
-
declare const
|
|
79
|
+
declare const usb: WebUSB;
|
|
70
80
|
/**
|
|
71
|
-
*
|
|
72
|
-
* @param serialNumber
|
|
81
|
+
* Default WebUSB object (mimics navigator.usb)
|
|
73
82
|
*/
|
|
74
|
-
declare const findBySerialNumber: (serialNumber: string) => Promise<USBDevice | undefined>;
|
|
75
83
|
declare const webusb: WebUSB | USB;
|
|
76
|
-
export { webusb, WebUSB, USBOptions,
|
|
84
|
+
export { usb, webusb, WebUSB, USBOptions, };
|
package/dist/index.js
CHANGED
|
@@ -1,133 +1,128 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.WebUSB = exports.webusb = exports.usb = void 0;
|
|
4
4
|
const index_js_1 = require("../index.js");
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Hidden
|
|
7
|
+
*/
|
|
8
|
+
const DEFAULT_TIMEOUT = 1000;
|
|
9
|
+
/**
|
|
10
|
+
* Hidden
|
|
11
|
+
*/
|
|
12
|
+
const toUint8Array = (data) => {
|
|
13
|
+
if (data instanceof ArrayBuffer) {
|
|
14
|
+
return new Uint8Array(data);
|
|
15
|
+
}
|
|
16
|
+
// ArrayBufferView
|
|
17
|
+
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Hidden
|
|
21
|
+
*/
|
|
22
|
+
index_js_1.UsbDevice.prototype.controlTransferIn = async function (setup, length, timeout = DEFAULT_TIMEOUT) {
|
|
23
|
+
const res = await this.nativeControlTransferIn(setup, timeout, length);
|
|
24
|
+
return {
|
|
25
|
+
data: res ? new DataView(res.buffer) : undefined,
|
|
26
|
+
status: res ? 'ok' : 'stall',
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Hidden
|
|
31
|
+
*/
|
|
32
|
+
index_js_1.UsbDevice.prototype.controlTransferOut = async function (setup, data, timeout = DEFAULT_TIMEOUT) {
|
|
33
|
+
const res = await this.nativeControlTransferOut(setup, timeout, toUint8Array(data));
|
|
34
|
+
return {
|
|
35
|
+
bytesWritten: res,
|
|
36
|
+
status: res >= 0 ? 'ok' : 'stall',
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Hidden
|
|
41
|
+
*/
|
|
42
|
+
index_js_1.UsbDevice.prototype.transferIn = async function (endpointNumber, length, timeout = DEFAULT_TIMEOUT) {
|
|
43
|
+
const res = await this.nativeTransferIn(endpointNumber, timeout, length);
|
|
44
|
+
return {
|
|
45
|
+
data: res ? new DataView(res.buffer) : undefined,
|
|
46
|
+
status: res ? 'ok' : 'stall',
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Hidden
|
|
51
|
+
*/
|
|
52
|
+
index_js_1.UsbDevice.prototype.transferOut = async function (endpointNumber, data, timeout = DEFAULT_TIMEOUT) {
|
|
53
|
+
const res = await this.nativeTransferOut(endpointNumber, timeout, toUint8Array(data));
|
|
54
|
+
return {
|
|
55
|
+
bytesWritten: res,
|
|
56
|
+
status: res >= 0 ? 'ok' : 'stall',
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Hidden
|
|
61
|
+
*/
|
|
62
|
+
index_js_1.UsbDevice.prototype.isochronousTransferIn = async function (endpointNumber, packetLengths, timeout = DEFAULT_TIMEOUT) {
|
|
63
|
+
const res = await this.nativeIsochronousTransferIn(endpointNumber, packetLengths, timeout);
|
|
64
|
+
return res;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Hidden
|
|
68
|
+
*/
|
|
69
|
+
index_js_1.UsbDevice.prototype.isochronousTransferOut = async function (endpointNumber, data, packetLengths, timeout = DEFAULT_TIMEOUT) {
|
|
70
|
+
const res = await this.nativeIsochronousTransferOut(endpointNumber, toUint8Array(data), packetLengths, timeout);
|
|
71
|
+
return res;
|
|
72
|
+
};
|
|
6
73
|
class NamedError extends Error {
|
|
7
74
|
constructor(message, name) {
|
|
8
75
|
super(message);
|
|
9
76
|
this.name = name;
|
|
10
77
|
}
|
|
11
78
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
enumerable: false,
|
|
33
|
-
configurable: false,
|
|
34
|
-
value: async function (setup, data) {
|
|
35
|
-
const res = await this.nativeControlTransferOut(setup, toUint8Array(data));
|
|
36
|
-
return {
|
|
37
|
-
bytesWritten: res,
|
|
38
|
-
status: res >= 0 ? 'ok' : 'stall',
|
|
39
|
-
};
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
Object.defineProperty(device, 'transferIn', {
|
|
43
|
-
enumerable: false,
|
|
44
|
-
configurable: false,
|
|
45
|
-
value: async function (endpointNumber, length) {
|
|
46
|
-
const res = await this.nativeTransferIn(endpointNumber, length);
|
|
47
|
-
return {
|
|
48
|
-
data: res ? new DataView(res.buffer) : undefined,
|
|
49
|
-
status: res ? 'ok' : 'stall',
|
|
50
|
-
};
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
Object.defineProperty(device, 'transferOut', {
|
|
54
|
-
enumerable: false,
|
|
55
|
-
configurable: false,
|
|
56
|
-
value: async function (endpointNumber, data) {
|
|
57
|
-
const res = await this.nativeTransferOut(endpointNumber, toUint8Array(data));
|
|
58
|
-
return {
|
|
59
|
-
bytesWritten: res,
|
|
60
|
-
status: res >= 0 ? 'ok' : 'stall',
|
|
61
|
-
};
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
return device;
|
|
65
|
-
};
|
|
66
|
-
class WebUSB {
|
|
79
|
+
class ConnectionEvent extends Event {
|
|
80
|
+
constructor(type, eventInitDict) {
|
|
81
|
+
super(type, eventInitDict);
|
|
82
|
+
this.eventInitDict = eventInitDict;
|
|
83
|
+
}
|
|
84
|
+
get device() {
|
|
85
|
+
return this.eventInitDict.device;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* WebUSB class
|
|
90
|
+
*
|
|
91
|
+
* ### Events
|
|
92
|
+
*
|
|
93
|
+
* | Name | Event | Description |
|
|
94
|
+
* | ---- | ----- | ----------- |
|
|
95
|
+
* | `connect` | {@link USBConnectionEvent} | Device connected |
|
|
96
|
+
* | `disconnect` | {@link USBConnectionEvent} | Device disconnected |
|
|
97
|
+
*/
|
|
98
|
+
class WebUSB extends EventTarget {
|
|
67
99
|
constructor(options = {}) {
|
|
100
|
+
super();
|
|
68
101
|
this.options = options;
|
|
69
102
|
this.nativeEmitter = new index_js_1.Emitter();
|
|
70
|
-
this.emitter = new events_1.EventEmitter();
|
|
71
103
|
this.authorisedDevices = new Set();
|
|
72
104
|
this.knownDevices = new Map();
|
|
73
105
|
const deviceConnectCallback = async (device) => {
|
|
74
|
-
|
|
75
|
-
this.knownDevices.set(device.handle, webDevice);
|
|
106
|
+
this.knownDevices.set(device.handle, device);
|
|
76
107
|
// When connected, emit an event if it is an allowed device
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
type: 'connect',
|
|
80
|
-
device: webDevice
|
|
81
|
-
};
|
|
82
|
-
this.emitter.emit('connect', event);
|
|
108
|
+
if (device && this.isAuthorisedDevice(device)) {
|
|
109
|
+
this.dispatchEvent(new ConnectionEvent('connect', { device }));
|
|
83
110
|
}
|
|
84
111
|
};
|
|
85
112
|
const deviceDisconnectCallback = async (handle) => {
|
|
86
113
|
// When disconnected, emit an event if the device was a known allowed device
|
|
87
114
|
if (this.knownDevices.has(handle)) {
|
|
88
|
-
const
|
|
89
|
-
if (
|
|
90
|
-
|
|
91
|
-
type: 'disconnect',
|
|
92
|
-
device: webDevice
|
|
93
|
-
};
|
|
94
|
-
this.emitter.emit('disconnect', event);
|
|
115
|
+
const device = this.knownDevices.get(handle);
|
|
116
|
+
if (device && this.isAuthorisedDevice(device)) {
|
|
117
|
+
this.dispatchEvent(new ConnectionEvent('disconnect', { device }));
|
|
95
118
|
}
|
|
96
119
|
this.knownDevices.delete(handle);
|
|
97
120
|
}
|
|
98
121
|
};
|
|
99
|
-
this.emitter.on('newListener', async (event) => {
|
|
100
|
-
const listenerCount = this.emitter.listenerCount(event);
|
|
101
|
-
if (listenerCount !== 0) {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
if (event === 'connect') {
|
|
105
|
-
this.nativeEmitter.addAttach(deviceConnectCallback);
|
|
106
|
-
}
|
|
107
|
-
else if (event === 'disconnect') {
|
|
108
|
-
// Ensure we know the current devices
|
|
109
|
-
this.knownDevices.clear();
|
|
110
|
-
const devices = await (0, index_js_1.nativeGetDeviceList)();
|
|
111
|
-
devices.forEach(device => {
|
|
112
|
-
this.knownDevices.set(device.handle, augmentDevice(device));
|
|
113
|
-
});
|
|
114
|
-
this.nativeEmitter.addDetach(deviceDisconnectCallback);
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
this.emitter.on('removeListener', event => {
|
|
118
|
-
const listenerCount = this.emitter.listenerCount(event);
|
|
119
|
-
if (listenerCount !== 0) {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
if (event === 'connect') {
|
|
123
|
-
this.nativeEmitter.removeAttach(deviceConnectCallback);
|
|
124
|
-
}
|
|
125
|
-
else if (event === 'disconnect') {
|
|
126
|
-
this.knownDevices.clear();
|
|
127
|
-
this.nativeEmitter.removeDetach(deviceDisconnectCallback);
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
122
|
this.nativeEmitter.start();
|
|
123
|
+
this.nativeEmitter.addAttach(deviceConnectCallback);
|
|
124
|
+
this.nativeEmitter.addDetach(deviceDisconnectCallback);
|
|
125
|
+
(0, index_js_1.nativeGetDevices)().then(devices => devices.forEach(device => this.knownDevices.set(device.handle, device)));
|
|
131
126
|
}
|
|
132
127
|
set onconnect(fn) {
|
|
133
128
|
if (this._onconnect) {
|
|
@@ -149,16 +144,6 @@ class WebUSB {
|
|
|
149
144
|
this.addEventListener('disconnect', this._ondisconnect);
|
|
150
145
|
}
|
|
151
146
|
}
|
|
152
|
-
addEventListener(type, listener) {
|
|
153
|
-
this.emitter.addListener(type, listener);
|
|
154
|
-
}
|
|
155
|
-
removeEventListener(type, callback) {
|
|
156
|
-
this.emitter.removeListener(type, callback);
|
|
157
|
-
}
|
|
158
|
-
dispatchEvent(_event) {
|
|
159
|
-
// Don't dispatch from here
|
|
160
|
-
return false;
|
|
161
|
-
}
|
|
162
147
|
/**
|
|
163
148
|
* Requests a single Web USB device
|
|
164
149
|
* @param options The options to use when scanning
|
|
@@ -227,8 +212,25 @@ class WebUSB {
|
|
|
227
212
|
const devices = await this.loadDevices(preFilters);
|
|
228
213
|
return devices.filter(device => this.isAuthorisedDevice(device));
|
|
229
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* Convenience method to get the first device with the specified VID and PID, or `undefined` if no such device is present.
|
|
217
|
+
* @param vid
|
|
218
|
+
* @param pid
|
|
219
|
+
*/
|
|
220
|
+
async findDeviceByIds(vid, pid) {
|
|
221
|
+
const device = await (0, index_js_1.nativeFindDeviceByIds)(vid, pid);
|
|
222
|
+
return device || undefined;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Convenience method to get the device with the specified serial number, or `undefined` if no such device is present.
|
|
226
|
+
* @param serialNumber
|
|
227
|
+
*/
|
|
228
|
+
async findDeviceBySerial(serialNumber) {
|
|
229
|
+
const device = await (0, index_js_1.nativeFindDeviceBySerial)(serialNumber);
|
|
230
|
+
return device || undefined;
|
|
231
|
+
}
|
|
230
232
|
async loadDevices(preFilters) {
|
|
231
|
-
let devices = await
|
|
233
|
+
let devices = await (0, index_js_1.nativeGetDevices)();
|
|
232
234
|
// Pre-filter devices
|
|
233
235
|
devices = this.quickFilter(devices, preFilters);
|
|
234
236
|
return devices;
|
|
@@ -321,32 +323,15 @@ class WebUSB {
|
|
|
321
323
|
}
|
|
322
324
|
exports.WebUSB = WebUSB;
|
|
323
325
|
/**
|
|
324
|
-
*
|
|
326
|
+
* Default USB object (allows all devices by default)
|
|
325
327
|
*/
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
exports.getDeviceList = getDeviceList;
|
|
328
|
+
const usb = new WebUSB({
|
|
329
|
+
allowAllDevices: true
|
|
330
|
+
});
|
|
331
|
+
exports.usb = usb;
|
|
331
332
|
/**
|
|
332
|
-
*
|
|
333
|
-
* @param vid
|
|
334
|
-
* @param pid
|
|
333
|
+
* Default WebUSB object (mimics navigator.usb)
|
|
335
334
|
*/
|
|
336
|
-
const findByIds = async (vid, pid) => {
|
|
337
|
-
const device = await (0, index_js_1.nativeFindByIds)(vid, pid);
|
|
338
|
-
return device ? augmentDevice(device) : undefined;
|
|
339
|
-
};
|
|
340
|
-
exports.findByIds = findByIds;
|
|
341
|
-
/**
|
|
342
|
-
* Convenience method to get the device with the specified serial number, or `undefined` if no such device is present.
|
|
343
|
-
* @param serialNumber
|
|
344
|
-
*/
|
|
345
|
-
const findBySerialNumber = async (serialNumber) => {
|
|
346
|
-
const device = await (0, index_js_1.nativeFindBySerialNumber)(serialNumber);
|
|
347
|
-
return device ? augmentDevice(device) : undefined;
|
|
348
|
-
};
|
|
349
|
-
exports.findBySerialNumber = findBySerialNumber;
|
|
350
335
|
const webusb = typeof navigator !== 'undefined' && navigator.usb ? navigator.usb : new WebUSB();
|
|
351
336
|
exports.webusb = webusb;
|
|
352
337
|
//# sourceMappingURL=index.js.map
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export type USBSpeed = 'low' | 'full' | 'high' | 'super' | 'superPlus';
|
|
2
|
+
|
|
3
|
+
export declare interface UsbDevice extends USBDevice {
|
|
4
|
+
/**
|
|
5
|
+
* The USB bus the device is connected to (e.g. `1-1`, `2-3.4`, etc.)
|
|
6
|
+
*/
|
|
7
|
+
bus: string;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The USB address the device is connected to
|
|
11
|
+
*/
|
|
12
|
+
address: number;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The USB port numbers the device is connected through (e.g. `[1]`, `[3, 4]`, etc.)
|
|
16
|
+
*/
|
|
17
|
+
ports: Array<number>
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The USB speed of the device (e.g. `Low`, `Full`, `High`, `Super`, `SuperPlus` or `undefined` if unknown)
|
|
21
|
+
*/
|
|
22
|
+
speed?: USBSpeed;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Detaches the kernel driver from the specified interface number (Linux only)
|
|
26
|
+
* @param interfaceNumber
|
|
27
|
+
*/
|
|
28
|
+
detachKernelDriver(interfaceNumber: number): Promise<void>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Attaches the kernel driver for the specified interface number (Linux only)
|
|
32
|
+
* @param interfaceNumber
|
|
33
|
+
*/
|
|
34
|
+
attachKernelDriver(interfaceNumber: number): Promise<void>;
|
|
35
|
+
}
|
|
3
36
|
export declare class Emitter {
|
|
4
37
|
constructor()
|
|
5
38
|
start(): Promise<void>
|
|
@@ -21,12 +54,16 @@ export declare class UsbDevice {
|
|
|
21
54
|
deviceClass: number
|
|
22
55
|
deviceSubclass: number
|
|
23
56
|
deviceProtocol: number
|
|
57
|
+
bus: string
|
|
58
|
+
address: number
|
|
59
|
+
ports: Array<number>
|
|
60
|
+
speed?: USBSpeed
|
|
24
61
|
get handle(): string
|
|
25
62
|
get manufacturerName(): string | null
|
|
26
63
|
get productName(): string | null
|
|
27
64
|
get serialNumber(): string | null
|
|
28
65
|
get opened(): boolean
|
|
29
|
-
get configuration(): USBConfiguration
|
|
66
|
+
get configuration(): USBConfiguration
|
|
30
67
|
get configurations(): Array<USBConfiguration>
|
|
31
68
|
open(): Promise<void>
|
|
32
69
|
close(): Promise<void>
|
|
@@ -36,34 +73,36 @@ export declare class UsbDevice {
|
|
|
36
73
|
claimInterface(interfaceNumber: number): Promise<void>
|
|
37
74
|
releaseInterface(interfaceNumber: number): Promise<void>
|
|
38
75
|
selectAlternateInterface(interfaceNumber: number, alternateSetting: number): Promise<void>
|
|
39
|
-
nativeControlTransferIn(setup: USBControlTransferParameters, length: number): Promise<Uint8Array | null>
|
|
40
|
-
nativeControlTransferOut(setup: USBControlTransferParameters, data?: Uint8Array | undefined | null): Promise<number>
|
|
41
|
-
nativeTransferIn(endpointNumber: number, length: number): Promise<Uint8Array | null>
|
|
42
|
-
nativeTransferOut(endpointNumber: number, data: Uint8Array): Promise<number>
|
|
43
|
-
|
|
44
|
-
|
|
76
|
+
nativeControlTransferIn(setup: USBControlTransferParameters, timeout: number, length: number): Promise<Uint8Array | null>
|
|
77
|
+
nativeControlTransferOut(setup: USBControlTransferParameters, timeout: number, data?: Uint8Array | undefined | null): Promise<number>
|
|
78
|
+
nativeTransferIn(endpointNumber: number, timeout: number, length: number): Promise<Uint8Array | null>
|
|
79
|
+
nativeTransferOut(endpointNumber: number, timeout: number, data: Uint8Array): Promise<number>
|
|
80
|
+
nativeIsochronousTransferIn(endpointNumber: number, packetLengths: Array<number>, timeout: number): Promise<USBIsochronousInTransferResult>
|
|
81
|
+
nativeIsochronousTransferOut(endpointNumber: number, data: Uint8Array, packetLengths: Array<number>, timeout: number): Promise<USBIsochronousOutTransferResult>
|
|
45
82
|
clearHalt(direction: USBDirection, endpointNumber: number): Promise<void>
|
|
83
|
+
detachKernelDriver(interfaceNumber: number): Promise<void>
|
|
84
|
+
attachKernelDriver(interfaceNumber: number): Promise<void>
|
|
46
85
|
}
|
|
47
86
|
|
|
48
|
-
export declare function
|
|
87
|
+
export declare function nativeFindDeviceByIds(vendorId: number, productId: number): Promise<UsbDevice | null>
|
|
49
88
|
|
|
50
|
-
export declare function
|
|
89
|
+
export declare function nativeFindDeviceBySerial(serialNumber: string): Promise<UsbDevice | null>
|
|
51
90
|
|
|
52
|
-
export declare function
|
|
91
|
+
export declare function nativeGetDevices(): Promise<Array<UsbDevice>>
|
|
53
92
|
|
|
54
|
-
export interface
|
|
93
|
+
export interface UsbAlternateInterface {
|
|
55
94
|
alternateSetting: number
|
|
56
95
|
interfaceClass: number
|
|
57
96
|
interfaceSubclass: number
|
|
58
97
|
interfaceProtocol: number
|
|
59
98
|
interfaceName?: string
|
|
60
|
-
endpoints: Array<
|
|
99
|
+
endpoints: Array<UsbEndpoint>
|
|
61
100
|
}
|
|
62
101
|
|
|
63
|
-
export interface
|
|
102
|
+
export interface UsbConfiguration {
|
|
64
103
|
configurationValue: number
|
|
65
104
|
configurationName?: string
|
|
66
|
-
interfaces: Array<
|
|
105
|
+
interfaces: Array<UsbInterface>
|
|
67
106
|
}
|
|
68
107
|
|
|
69
108
|
export interface USBControlTransferParameters {
|
|
@@ -74,16 +113,16 @@ export interface USBControlTransferParameters {
|
|
|
74
113
|
index: number
|
|
75
114
|
}
|
|
76
115
|
|
|
77
|
-
export interface
|
|
116
|
+
export interface UsbEndpoint {
|
|
78
117
|
endpointNumber: number
|
|
79
118
|
direction: USBDirection
|
|
80
119
|
type: USBEndpointType
|
|
81
120
|
packetSize: number
|
|
82
121
|
}
|
|
83
122
|
|
|
84
|
-
export interface
|
|
123
|
+
export interface UsbInterface {
|
|
85
124
|
interfaceNumber: number
|
|
86
125
|
claimed: boolean
|
|
87
|
-
alternate:
|
|
88
|
-
alternates: Array<
|
|
126
|
+
alternate: UsbAlternateInterface
|
|
127
|
+
alternates: Array<UsbAlternateInterface>
|
|
89
128
|
}
|
package/index.js
CHANGED
|
@@ -77,8 +77,8 @@ function requireNative() {
|
|
|
77
77
|
try {
|
|
78
78
|
const binding = require('@node-usb/usb-android-arm64')
|
|
79
79
|
const bindingPackageVersion = require('@node-usb/usb-android-arm64/package.json').version
|
|
80
|
-
if (bindingPackageVersion !== '3.0.0-alpha.
|
|
81
|
-
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.
|
|
80
|
+
if (bindingPackageVersion !== '3.0.0-alpha.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
81
|
+
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
82
82
|
}
|
|
83
83
|
return binding
|
|
84
84
|
} catch (e) {
|
|
@@ -93,8 +93,8 @@ function requireNative() {
|
|
|
93
93
|
try {
|
|
94
94
|
const binding = require('@node-usb/usb-android-arm-eabi')
|
|
95
95
|
const bindingPackageVersion = require('@node-usb/usb-android-arm-eabi/package.json').version
|
|
96
|
-
if (bindingPackageVersion !== '3.0.0-alpha.
|
|
97
|
-
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.
|
|
96
|
+
if (bindingPackageVersion !== '3.0.0-alpha.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
97
|
+
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
98
98
|
}
|
|
99
99
|
return binding
|
|
100
100
|
} catch (e) {
|
|
@@ -114,8 +114,8 @@ function requireNative() {
|
|
|
114
114
|
try {
|
|
115
115
|
const binding = require('@node-usb/usb-win32-x64-gnu')
|
|
116
116
|
const bindingPackageVersion = require('@node-usb/usb-win32-x64-gnu/package.json').version
|
|
117
|
-
if (bindingPackageVersion !== '3.0.0-alpha.
|
|
118
|
-
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.
|
|
117
|
+
if (bindingPackageVersion !== '3.0.0-alpha.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
118
|
+
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
119
119
|
}
|
|
120
120
|
return binding
|
|
121
121
|
} catch (e) {
|
|
@@ -130,8 +130,8 @@ function requireNative() {
|
|
|
130
130
|
try {
|
|
131
131
|
const binding = require('@node-usb/usb-win32-x64-msvc')
|
|
132
132
|
const bindingPackageVersion = require('@node-usb/usb-win32-x64-msvc/package.json').version
|
|
133
|
-
if (bindingPackageVersion !== '3.0.0-alpha.
|
|
134
|
-
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.
|
|
133
|
+
if (bindingPackageVersion !== '3.0.0-alpha.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
134
|
+
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
135
135
|
}
|
|
136
136
|
return binding
|
|
137
137
|
} catch (e) {
|
|
@@ -147,8 +147,8 @@ function requireNative() {
|
|
|
147
147
|
try {
|
|
148
148
|
const binding = require('@node-usb/usb-win32-ia32-msvc')
|
|
149
149
|
const bindingPackageVersion = require('@node-usb/usb-win32-ia32-msvc/package.json').version
|
|
150
|
-
if (bindingPackageVersion !== '3.0.0-alpha.
|
|
151
|
-
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.
|
|
150
|
+
if (bindingPackageVersion !== '3.0.0-alpha.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
151
|
+
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
152
152
|
}
|
|
153
153
|
return binding
|
|
154
154
|
} catch (e) {
|
|
@@ -163,8 +163,8 @@ function requireNative() {
|
|
|
163
163
|
try {
|
|
164
164
|
const binding = require('@node-usb/usb-win32-arm64-msvc')
|
|
165
165
|
const bindingPackageVersion = require('@node-usb/usb-win32-arm64-msvc/package.json').version
|
|
166
|
-
if (bindingPackageVersion !== '3.0.0-alpha.
|
|
167
|
-
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.
|
|
166
|
+
if (bindingPackageVersion !== '3.0.0-alpha.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
167
|
+
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
168
168
|
}
|
|
169
169
|
return binding
|
|
170
170
|
} catch (e) {
|
|
@@ -182,8 +182,8 @@ function requireNative() {
|
|
|
182
182
|
try {
|
|
183
183
|
const binding = require('@node-usb/usb-darwin-universal')
|
|
184
184
|
const bindingPackageVersion = require('@node-usb/usb-darwin-universal/package.json').version
|
|
185
|
-
if (bindingPackageVersion !== '3.0.0-alpha.
|
|
186
|
-
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.
|
|
185
|
+
if (bindingPackageVersion !== '3.0.0-alpha.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
186
|
+
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
187
187
|
}
|
|
188
188
|
return binding
|
|
189
189
|
} catch (e) {
|
|
@@ -198,8 +198,8 @@ function requireNative() {
|
|
|
198
198
|
try {
|
|
199
199
|
const binding = require('@node-usb/usb-darwin-x64')
|
|
200
200
|
const bindingPackageVersion = require('@node-usb/usb-darwin-x64/package.json').version
|
|
201
|
-
if (bindingPackageVersion !== '3.0.0-alpha.
|
|
202
|
-
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.
|
|
201
|
+
if (bindingPackageVersion !== '3.0.0-alpha.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
202
|
+
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
203
203
|
}
|
|
204
204
|
return binding
|
|
205
205
|
} catch (e) {
|
|
@@ -214,8 +214,8 @@ function requireNative() {
|
|
|
214
214
|
try {
|
|
215
215
|
const binding = require('@node-usb/usb-darwin-arm64')
|
|
216
216
|
const bindingPackageVersion = require('@node-usb/usb-darwin-arm64/package.json').version
|
|
217
|
-
if (bindingPackageVersion !== '3.0.0-alpha.
|
|
218
|
-
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.
|
|
217
|
+
if (bindingPackageVersion !== '3.0.0-alpha.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
218
|
+
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
219
219
|
}
|
|
220
220
|
return binding
|
|
221
221
|
} catch (e) {
|
|
@@ -234,8 +234,8 @@ function requireNative() {
|
|
|
234
234
|
try {
|
|
235
235
|
const binding = require('@node-usb/usb-freebsd-x64')
|
|
236
236
|
const bindingPackageVersion = require('@node-usb/usb-freebsd-x64/package.json').version
|
|
237
|
-
if (bindingPackageVersion !== '3.0.0-alpha.
|
|
238
|
-
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.
|
|
237
|
+
if (bindingPackageVersion !== '3.0.0-alpha.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
238
|
+
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
239
239
|
}
|
|
240
240
|
return binding
|
|
241
241
|
} catch (e) {
|
|
@@ -250,8 +250,8 @@ function requireNative() {
|
|
|
250
250
|
try {
|
|
251
251
|
const binding = require('@node-usb/usb-freebsd-arm64')
|
|
252
252
|
const bindingPackageVersion = require('@node-usb/usb-freebsd-arm64/package.json').version
|
|
253
|
-
if (bindingPackageVersion !== '3.0.0-alpha.
|
|
254
|
-
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.
|
|
253
|
+
if (bindingPackageVersion !== '3.0.0-alpha.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
254
|
+
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
255
255
|
}
|
|
256
256
|
return binding
|
|
257
257
|
} catch (e) {
|
|
@@ -271,8 +271,8 @@ function requireNative() {
|
|
|
271
271
|
try {
|
|
272
272
|
const binding = require('@node-usb/usb-linux-x64-musl')
|
|
273
273
|
const bindingPackageVersion = require('@node-usb/usb-linux-x64-musl/package.json').version
|
|
274
|
-
if (bindingPackageVersion !== '3.0.0-alpha.
|
|
275
|
-
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.
|
|
274
|
+
if (bindingPackageVersion !== '3.0.0-alpha.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
275
|
+
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
276
276
|
}
|
|
277
277
|
return binding
|
|
278
278
|
} catch (e) {
|
|
@@ -287,8 +287,8 @@ function requireNative() {
|
|
|
287
287
|
try {
|
|
288
288
|
const binding = require('@node-usb/usb-linux-x64-gnu')
|
|
289
289
|
const bindingPackageVersion = require('@node-usb/usb-linux-x64-gnu/package.json').version
|
|
290
|
-
if (bindingPackageVersion !== '3.0.0-alpha.
|
|
291
|
-
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.
|
|
290
|
+
if (bindingPackageVersion !== '3.0.0-alpha.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
291
|
+
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
292
292
|
}
|
|
293
293
|
return binding
|
|
294
294
|
} catch (e) {
|
|
@@ -305,8 +305,8 @@ function requireNative() {
|
|
|
305
305
|
try {
|
|
306
306
|
const binding = require('@node-usb/usb-linux-arm64-musl')
|
|
307
307
|
const bindingPackageVersion = require('@node-usb/usb-linux-arm64-musl/package.json').version
|
|
308
|
-
if (bindingPackageVersion !== '3.0.0-alpha.
|
|
309
|
-
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.
|
|
308
|
+
if (bindingPackageVersion !== '3.0.0-alpha.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
309
|
+
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
310
310
|
}
|
|
311
311
|
return binding
|
|
312
312
|
} catch (e) {
|
|
@@ -321,8 +321,8 @@ function requireNative() {
|
|
|
321
321
|
try {
|
|
322
322
|
const binding = require('@node-usb/usb-linux-arm64-gnu')
|
|
323
323
|
const bindingPackageVersion = require('@node-usb/usb-linux-arm64-gnu/package.json').version
|
|
324
|
-
if (bindingPackageVersion !== '3.0.0-alpha.
|
|
325
|
-
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.
|
|
324
|
+
if (bindingPackageVersion !== '3.0.0-alpha.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
325
|
+
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
326
326
|
}
|
|
327
327
|
return binding
|
|
328
328
|
} catch (e) {
|
|
@@ -339,8 +339,8 @@ function requireNative() {
|
|
|
339
339
|
try {
|
|
340
340
|
const binding = require('@node-usb/usb-linux-arm-musleabihf')
|
|
341
341
|
const bindingPackageVersion = require('@node-usb/usb-linux-arm-musleabihf/package.json').version
|
|
342
|
-
if (bindingPackageVersion !== '3.0.0-alpha.
|
|
343
|
-
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.
|
|
342
|
+
if (bindingPackageVersion !== '3.0.0-alpha.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
343
|
+
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
344
344
|
}
|
|
345
345
|
return binding
|
|
346
346
|
} catch (e) {
|
|
@@ -355,8 +355,8 @@ function requireNative() {
|
|
|
355
355
|
try {
|
|
356
356
|
const binding = require('@node-usb/usb-linux-arm-gnueabihf')
|
|
357
357
|
const bindingPackageVersion = require('@node-usb/usb-linux-arm-gnueabihf/package.json').version
|
|
358
|
-
if (bindingPackageVersion !== '3.0.0-alpha.
|
|
359
|
-
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.
|
|
358
|
+
if (bindingPackageVersion !== '3.0.0-alpha.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
359
|
+
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
360
360
|
}
|
|
361
361
|
return binding
|
|
362
362
|
} catch (e) {
|
|
@@ -373,8 +373,8 @@ function requireNative() {
|
|
|
373
373
|
try {
|
|
374
374
|
const binding = require('@node-usb/usb-linux-loong64-musl')
|
|
375
375
|
const bindingPackageVersion = require('@node-usb/usb-linux-loong64-musl/package.json').version
|
|
376
|
-
if (bindingPackageVersion !== '3.0.0-alpha.
|
|
377
|
-
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.
|
|
376
|
+
if (bindingPackageVersion !== '3.0.0-alpha.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
377
|
+
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
378
378
|
}
|
|
379
379
|
return binding
|
|
380
380
|
} catch (e) {
|
|
@@ -389,8 +389,8 @@ function requireNative() {
|
|
|
389
389
|
try {
|
|
390
390
|
const binding = require('@node-usb/usb-linux-loong64-gnu')
|
|
391
391
|
const bindingPackageVersion = require('@node-usb/usb-linux-loong64-gnu/package.json').version
|
|
392
|
-
if (bindingPackageVersion !== '3.0.0-alpha.
|
|
393
|
-
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.
|
|
392
|
+
if (bindingPackageVersion !== '3.0.0-alpha.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
393
|
+
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
394
394
|
}
|
|
395
395
|
return binding
|
|
396
396
|
} catch (e) {
|
|
@@ -407,8 +407,8 @@ function requireNative() {
|
|
|
407
407
|
try {
|
|
408
408
|
const binding = require('@node-usb/usb-linux-riscv64-musl')
|
|
409
409
|
const bindingPackageVersion = require('@node-usb/usb-linux-riscv64-musl/package.json').version
|
|
410
|
-
if (bindingPackageVersion !== '3.0.0-alpha.
|
|
411
|
-
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.
|
|
410
|
+
if (bindingPackageVersion !== '3.0.0-alpha.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
411
|
+
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
412
412
|
}
|
|
413
413
|
return binding
|
|
414
414
|
} catch (e) {
|
|
@@ -423,8 +423,8 @@ function requireNative() {
|
|
|
423
423
|
try {
|
|
424
424
|
const binding = require('@node-usb/usb-linux-riscv64-gnu')
|
|
425
425
|
const bindingPackageVersion = require('@node-usb/usb-linux-riscv64-gnu/package.json').version
|
|
426
|
-
if (bindingPackageVersion !== '3.0.0-alpha.
|
|
427
|
-
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.
|
|
426
|
+
if (bindingPackageVersion !== '3.0.0-alpha.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
427
|
+
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
428
428
|
}
|
|
429
429
|
return binding
|
|
430
430
|
} catch (e) {
|
|
@@ -440,8 +440,8 @@ function requireNative() {
|
|
|
440
440
|
try {
|
|
441
441
|
const binding = require('@node-usb/usb-linux-ppc64-gnu')
|
|
442
442
|
const bindingPackageVersion = require('@node-usb/usb-linux-ppc64-gnu/package.json').version
|
|
443
|
-
if (bindingPackageVersion !== '3.0.0-alpha.
|
|
444
|
-
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.
|
|
443
|
+
if (bindingPackageVersion !== '3.0.0-alpha.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
444
|
+
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
445
445
|
}
|
|
446
446
|
return binding
|
|
447
447
|
} catch (e) {
|
|
@@ -456,8 +456,8 @@ function requireNative() {
|
|
|
456
456
|
try {
|
|
457
457
|
const binding = require('@node-usb/usb-linux-s390x-gnu')
|
|
458
458
|
const bindingPackageVersion = require('@node-usb/usb-linux-s390x-gnu/package.json').version
|
|
459
|
-
if (bindingPackageVersion !== '3.0.0-alpha.
|
|
460
|
-
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.
|
|
459
|
+
if (bindingPackageVersion !== '3.0.0-alpha.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
460
|
+
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
461
461
|
}
|
|
462
462
|
return binding
|
|
463
463
|
} catch (e) {
|
|
@@ -476,8 +476,8 @@ function requireNative() {
|
|
|
476
476
|
try {
|
|
477
477
|
const binding = require('@node-usb/usb-openharmony-arm64')
|
|
478
478
|
const bindingPackageVersion = require('@node-usb/usb-openharmony-arm64/package.json').version
|
|
479
|
-
if (bindingPackageVersion !== '3.0.0-alpha.
|
|
480
|
-
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.
|
|
479
|
+
if (bindingPackageVersion !== '3.0.0-alpha.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
480
|
+
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
481
481
|
}
|
|
482
482
|
return binding
|
|
483
483
|
} catch (e) {
|
|
@@ -492,8 +492,8 @@ function requireNative() {
|
|
|
492
492
|
try {
|
|
493
493
|
const binding = require('@node-usb/usb-openharmony-x64')
|
|
494
494
|
const bindingPackageVersion = require('@node-usb/usb-openharmony-x64/package.json').version
|
|
495
|
-
if (bindingPackageVersion !== '3.0.0-alpha.
|
|
496
|
-
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.
|
|
495
|
+
if (bindingPackageVersion !== '3.0.0-alpha.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
496
|
+
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
497
497
|
}
|
|
498
498
|
return binding
|
|
499
499
|
} catch (e) {
|
|
@@ -508,8 +508,8 @@ function requireNative() {
|
|
|
508
508
|
try {
|
|
509
509
|
const binding = require('@node-usb/usb-openharmony-arm')
|
|
510
510
|
const bindingPackageVersion = require('@node-usb/usb-openharmony-arm/package.json').version
|
|
511
|
-
if (bindingPackageVersion !== '3.0.0-alpha.
|
|
512
|
-
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.
|
|
511
|
+
if (bindingPackageVersion !== '3.0.0-alpha.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
512
|
+
throw new Error(`Native binding package version mismatch, expected 3.0.0-alpha.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
513
513
|
}
|
|
514
514
|
return binding
|
|
515
515
|
} catch (e) {
|
|
@@ -578,6 +578,6 @@ if (!nativeBinding) {
|
|
|
578
578
|
module.exports = nativeBinding
|
|
579
579
|
module.exports.Emitter = nativeBinding.Emitter
|
|
580
580
|
module.exports.UsbDevice = nativeBinding.UsbDevice
|
|
581
|
-
module.exports.
|
|
582
|
-
module.exports.
|
|
583
|
-
module.exports.
|
|
581
|
+
module.exports.nativeFindDeviceByIds = nativeBinding.nativeFindDeviceByIds
|
|
582
|
+
module.exports.nativeFindDeviceBySerial = nativeBinding.nativeFindDeviceBySerial
|
|
583
|
+
module.exports.nativeGetDevices = nativeBinding.nativeGetDevices
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "usb",
|
|
3
3
|
"description": "Library to access USB devices",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "3.0.0-alpha.
|
|
5
|
+
"version": "3.0.0-alpha.4",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"engines": {
|
|
8
8
|
"node": ">= 12.22.0 < 13 || >= 14.17.0 < 15 || >= 15.12.0 < 16 || >= 16.0.0"
|
|
@@ -57,7 +57,6 @@
|
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@napi-rs/cli": "^3.2.0",
|
|
60
|
-
"@types/node": "^25.0.10",
|
|
61
60
|
"coffeescript": "^2.7.0",
|
|
62
61
|
"mocha": "^11.7.5",
|
|
63
62
|
"typedoc": "^0.28.16",
|
|
@@ -66,6 +65,7 @@
|
|
|
66
65
|
"napi": {
|
|
67
66
|
"binaryName": "usb",
|
|
68
67
|
"packageName": "@node-usb/usb",
|
|
68
|
+
"dtsHeaderFile": "./header.d.ts",
|
|
69
69
|
"targets": [
|
|
70
70
|
"x86_64-pc-windows-msvc",
|
|
71
71
|
"x86_64-apple-darwin",
|
|
@@ -84,15 +84,15 @@
|
|
|
84
84
|
"index.js"
|
|
85
85
|
],
|
|
86
86
|
"optionalDependencies": {
|
|
87
|
-
"@node-usb/usb-win32-x64-msvc": "3.0.0-alpha.
|
|
88
|
-
"@node-usb/usb-darwin-x64": "3.0.0-alpha.
|
|
89
|
-
"@node-usb/usb-linux-x64-gnu": "3.0.0-alpha.
|
|
90
|
-
"@node-usb/usb-linux-x64-musl": "3.0.0-alpha.
|
|
91
|
-
"@node-usb/usb-linux-arm64-gnu": "3.0.0-alpha.
|
|
92
|
-
"@node-usb/usb-win32-ia32-msvc": "3.0.0-alpha.
|
|
93
|
-
"@node-usb/usb-linux-arm-gnueabihf": "3.0.0-alpha.
|
|
94
|
-
"@node-usb/usb-darwin-arm64": "3.0.0-alpha.
|
|
95
|
-
"@node-usb/usb-linux-arm64-musl": "3.0.0-alpha.
|
|
96
|
-
"@node-usb/usb-win32-arm64-msvc": "3.0.0-alpha.
|
|
87
|
+
"@node-usb/usb-win32-x64-msvc": "3.0.0-alpha.4",
|
|
88
|
+
"@node-usb/usb-darwin-x64": "3.0.0-alpha.4",
|
|
89
|
+
"@node-usb/usb-linux-x64-gnu": "3.0.0-alpha.4",
|
|
90
|
+
"@node-usb/usb-linux-x64-musl": "3.0.0-alpha.4",
|
|
91
|
+
"@node-usb/usb-linux-arm64-gnu": "3.0.0-alpha.4",
|
|
92
|
+
"@node-usb/usb-win32-ia32-msvc": "3.0.0-alpha.4",
|
|
93
|
+
"@node-usb/usb-linux-arm-gnueabihf": "3.0.0-alpha.4",
|
|
94
|
+
"@node-usb/usb-darwin-arm64": "3.0.0-alpha.4",
|
|
95
|
+
"@node-usb/usb-linux-arm64-musl": "3.0.0-alpha.4",
|
|
96
|
+
"@node-usb/usb-win32-arm64-msvc": "3.0.0-alpha.4"
|
|
97
97
|
}
|
|
98
98
|
}
|