usb 2.5.2-alpha.1 → 2.6.0

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/index.d.ts +10 -6
  3. package/dist/index.js +27 -11
  4. package/dist/index.js.map +1 -1
  5. package/dist/usb/endpoint.js +3 -1
  6. package/dist/usb/endpoint.js.map +1 -1
  7. package/dist/webusb/index.js +40 -24
  8. package/dist/webusb/index.js.map +1 -1
  9. package/dist/webusb/webusb-device.d.ts +1 -1
  10. package/dist/webusb/webusb-device.js +24 -30
  11. package/dist/webusb/webusb-device.js.map +1 -1
  12. package/package.json +12 -12
  13. package/prebuilds/android-arm/node.napi.armv7.node +0 -0
  14. package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
  15. package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
  16. package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
  17. package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
  18. package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
  19. package/prebuilds/linux-ia32/node.napi.node +0 -0
  20. package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
  21. package/prebuilds/linux-x64/node.napi.musl.node +0 -0
  22. package/prebuilds/win32-ia32/node.napi.node +0 -0
  23. package/prebuilds/win32-x64/node.napi.node +0 -0
  24. package/.eslintignore +0 -4
  25. package/.eslintrc.json +0 -87
  26. package/.gitattributes +0 -1
  27. package/.gitmodules +0 -3
  28. package/.vscode/launch.json +0 -15
  29. package/.vscode/tasks.json +0 -23
  30. package/libusb/.gitattributes +0 -7
  31. package/libusb/msvc/.gitattributes +0 -3
  32. package/tsc/index.ts +0 -75
  33. package/tsc/usb/bindings.ts +0 -310
  34. package/tsc/usb/capability.ts +0 -22
  35. package/tsc/usb/descriptors.ts +0 -180
  36. package/tsc/usb/device.ts +0 -331
  37. package/tsc/usb/endpoint.ts +0 -229
  38. package/tsc/usb/index.ts +0 -149
  39. package/tsc/usb/interface.ts +0 -167
  40. package/tsc/webusb/index.ts +0 -374
  41. package/tsc/webusb/webusb-device.ts +0 -490
  42. package/tsconfig.json +0 -17
  43. package/typedoc.json +0 -9
package/.eslintrc.json DELETED
@@ -1,87 +0,0 @@
1
- {
2
- "parser": "@typescript-eslint/parser",
3
- "plugins": [
4
- "@typescript-eslint"
5
- ],
6
- "extends": [
7
- // https://eslint.org/docs/rules/
8
- "eslint:recommended",
9
- // https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin
10
- "plugin:@typescript-eslint/recommended"
11
- ],
12
- "rules": {
13
- "@typescript-eslint/no-empty-interface": [
14
- "warn"
15
- ],
16
- "@typescript-eslint/no-this-alias": [
17
- "warn"
18
- ],
19
- "@typescript-eslint/no-unused-vars": [
20
- "warn",
21
- {
22
- "argsIgnorePattern": "^_"
23
- }
24
- ],
25
- "block-spacing": [
26
- "error",
27
- "always"
28
- ],
29
- "brace-style": [
30
- "error",
31
- "1tbs",
32
- {
33
- "allowSingleLine": true
34
- }
35
- ],
36
- "eol-last": [
37
- "error"
38
- ],
39
- "indent": [
40
- "error",
41
- 4,
42
- {
43
- "SwitchCase": 1
44
- }
45
- ],
46
- "linebreak-style": [
47
- "error",
48
- "unix"
49
- ],
50
- "no-console": [
51
- "warn"
52
- ],
53
- "no-constant-condition": [
54
- "error",
55
- {
56
- "checkLoops": false
57
- }
58
- ],
59
- "no-trailing-spaces": [
60
- "error"
61
- ],
62
- "object-curly-spacing": [
63
- "error",
64
- "always"
65
- ],
66
- "quotes": [
67
- "error",
68
- "single"
69
- ],
70
- "semi": [
71
- "error",
72
- "always"
73
- ]
74
- },
75
- "env": {
76
- "commonjs": true,
77
- "es6": true,
78
- "node": true
79
- },
80
- "parserOptions": {
81
- "ecmaVersion": 12,
82
- "sourceType": "module",
83
- "project": [
84
- "./tsconfig.json"
85
- ]
86
- }
87
- }
package/.gitattributes DELETED
@@ -1 +0,0 @@
1
- * -text
package/.gitmodules DELETED
@@ -1,3 +0,0 @@
1
- [submodule "libusb"]
2
- path = libusb
3
- url = https://github.com/libusb/libusb.git
@@ -1,15 +0,0 @@
1
- {
2
- // Use IntelliSense to learn about possible attributes.
3
- // Hover to view descriptions of existing attributes.
4
- // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
- "version": "0.2.0",
6
- "configurations": [
7
- {
8
- "name": "Full Test",
9
- "type": "node-terminal",
10
- "request": "launch",
11
- "preLaunchTask": "test",
12
- "command": "exit 0",
13
- }
14
- ]
15
- }
@@ -1,23 +0,0 @@
1
- {
2
- "tasks": [
3
- {
4
- "label": "compile",
5
- "type": "npm",
6
- "script": "compile"
7
- },
8
- {
9
- "label": "watch",
10
- "type": "npm",
11
- "script": "watch",
12
- "group": {
13
- "kind": "build",
14
- "isDefault": true
15
- }
16
- },
17
- {
18
- "label": "test",
19
- "type": "npm",
20
- "script": "full-test"
21
- }
22
- ]
23
- }
@@ -1,7 +0,0 @@
1
- *.ac eol=lf
2
- *.am eol=lf
3
- *.bat eol=crlf
4
- *.sh eol=lf
5
- .gitattributes export-ignore
6
- .gitignore export-ignore
7
- INSTALL_WIN.txt eol=crlf
@@ -1,3 +0,0 @@
1
- *.sln eol=crlf
2
- *.vcxproj eol=crlf
3
- *.vcxproj.filters eol=crlf
package/tsc/index.ts DELETED
@@ -1,75 +0,0 @@
1
- import { promisify } from 'util';
2
- import { WebUSB, getWebUsb } from './webusb';
3
- import { WebUSBDevice } from './webusb/webusb-device';
4
- import * as usb from './usb';
5
-
6
- const webusb = new WebUSB();
7
- const getDeviceList = usb.getDeviceList;
8
- const useUsbDkBackend = usb.useUsbDkBackend;
9
-
10
- /**
11
- * Convenience method to get the first device with the specified VID and PID, or `undefined` if no such device is present.
12
- * @param vid
13
- * @param pid
14
- */
15
- const findByIds = (vid: number, pid: number): usb.Device | undefined => {
16
- const devices = usb.getDeviceList();
17
- return devices.find(item => item.deviceDescriptor.idVendor === vid && item.deviceDescriptor.idProduct === pid);
18
- };
19
-
20
- /**
21
- * Convenience method to get the device with the specified serial number, or `undefined` if no such device is present.
22
- * @param serialNumber
23
- */
24
- const findBySerialNumber = async (serialNumber: string): Promise<usb.Device | undefined> => {
25
- const devices = usb.getDeviceList();
26
- const opened = (device: usb.Device): boolean => !!device.interfaces;
27
-
28
- for (const device of devices) {
29
- try {
30
- if (!opened(device)) {
31
- device.open();
32
- }
33
-
34
- const getStringDescriptor = promisify(device.getStringDescriptor).bind(device);
35
- const buffer = await getStringDescriptor(device.deviceDescriptor.iSerialNumber);
36
-
37
- if (buffer && buffer.toString() === serialNumber) {
38
- return device;
39
- }
40
- } catch {
41
- // Ignore any errors, device may be a system device or inaccessible
42
- } finally {
43
- try {
44
- if (opened(device)) {
45
- device.close();
46
- }
47
- } catch {
48
- // Ignore any errors, device may be a system device or inaccessible
49
- }
50
- }
51
- }
52
-
53
- return undefined;
54
- };
55
-
56
- export {
57
- // Core usb object for quick access
58
- usb,
59
-
60
- // Convenience methods
61
- useUsbDkBackend,
62
- getDeviceList,
63
- findByIds,
64
- findBySerialNumber,
65
- getWebUsb,
66
-
67
- // Default WebUSB object (mimics navigator.usb)
68
- webusb,
69
-
70
- // WebUSB class for creating custom webusb instances
71
- WebUSB,
72
-
73
- // WebUSB Device class for turning a legacy usb.Device into a webusb device
74
- WebUSBDevice
75
- };
@@ -1,310 +0,0 @@
1
- // Definitions from DefinitelyTyped, thanks to:
2
- // Eric Brody <https://github.com/underscorebrody>
3
- // Rob Moran <https://github.com/thegecko>
4
-
5
- import { join } from 'path';
6
- import type { DeviceDescriptor, ConfigDescriptor, BosDescriptor } from './descriptors';
7
-
8
- /* eslint-disable @typescript-eslint/no-var-requires */
9
- const usb = require('node-gyp-build')(join(__dirname, '..', '..'));
10
- module.exports = usb;
11
-
12
- /**
13
- * Return a list of `Device` objects for the USB devices attached to the system.
14
- */
15
- export declare function getDeviceList(): Device[];
16
-
17
- export declare const INIT_ERROR: number;
18
-
19
- export declare class LibUSBException extends Error {
20
- errno: number;
21
- }
22
-
23
- /**
24
- * Set the libusb debug level (between 0 and 4)
25
- * @param level libusb debug level (between 0 and 4)
26
- */
27
- export declare function setDebugLevel(level: number): void;
28
-
29
- /**
30
- * Use USBDK Backend (Windows only)
31
- */
32
- export declare function useUsbDkBackend(): void;
33
-
34
- export declare function _supportedHotplugEvents(): number;
35
- export declare function _enableHotplugEvents(): void;
36
- export declare function _disableHotplugEvents(): void;
37
- export declare function _getLibusbCapability(capability: number): number;
38
-
39
- /**
40
- * Restore (re-reference) the hotplug events unreferenced by `unrefHotplugEvents()`
41
- */
42
- export declare function refHotplugEvents(): void;
43
-
44
- /**
45
- * Unreference the hotplug events from the event loop, allowing the process to exit even when listening for the `attach` and `detach` events
46
- */
47
- export declare function unrefHotplugEvents(): void;
48
-
49
- /** Represents a USB transfer */
50
- export declare class Transfer {
51
- constructor(device: Device, endpointAddr: number, type: number, timeout: number, callback: (error: LibUSBException, buf: Buffer, actual: number) => void);
52
-
53
- /**
54
- * (Re-)submit the transfer.
55
- *
56
- * @param buffer Buffer where data will be written (for IN transfers) or read from (for OUT transfers).
57
- */
58
- submit(buffer: Buffer, callback?: (error: LibUSBException | undefined, buffer: Buffer, actualLength: number) => void): Transfer;
59
-
60
- /**
61
- * Cancel the transfer.
62
- *
63
- * Returns `true` if the transfer was canceled, `false` if it wasn't in pending state.
64
- */
65
- cancel(): boolean;
66
- }
67
-
68
- /** Represents a USB device. */
69
- export declare class Device {
70
- /** Integer USB device number */
71
- busNumber: number;
72
-
73
- /** Integer USB device address */
74
- deviceAddress: number;
75
-
76
- /** Array containing the USB device port numbers, or `undefined` if not supported on this platform. */
77
- portNumbers: number[];
78
-
79
- /** Object with properties for the fields of the device descriptor. */
80
- deviceDescriptor: DeviceDescriptor;
81
-
82
- _bosDescriptor?: BosDescriptor;
83
-
84
- __open(): void;
85
- __close(): void;
86
- __getParent(): Device;
87
- __getConfigDescriptor(): ConfigDescriptor;
88
- __getAllConfigDescriptors(): ConfigDescriptor[];
89
- __setConfiguration(desired: number, callback: (error?: LibUSBException) => void): void;
90
- __clearHalt(addr: number, callback: (error?: LibUSBException) => void): void;
91
- __setInterface(addr: number, altSetting: number, callback: (error?: LibUSBException) => void): void;
92
- __claimInterface(addr: number): void;
93
- __releaseInterface(addr: number, callback: (error?: LibUSBException) => void): void;
94
- __detachKernelDriver(addr: number): void;
95
- __attachKernelDriver(addr: number): void;
96
- __isKernelDriverActive(addr: number): boolean;
97
-
98
- /**
99
- * Performs a reset of the device. Callback is called when complete.
100
- *
101
- * The device must be open to use this method.
102
- * @param callback
103
- */
104
- reset(callback: (error?: LibUSBException) => void): void;
105
- }
106
-
107
- /**
108
- * In the context of a \ref libusb_device_descriptor "device descriptor",
109
- * this bDeviceClass value indicates that each interface specifies its
110
- * own class information and all interfaces operate independently.
111
- */
112
- export declare const LIBUSB_CLASS_PER_INTERFACE: number;
113
- /** Audio class */
114
- export declare const LIBUSB_CLASS_AUDIO: number;
115
- /** Communications class */
116
- export declare const LIBUSB_CLASS_COMM: number;
117
- /** Human Interface Device class */
118
- export declare const LIBUSB_CLASS_HID: number;
119
- /** Printer class */
120
- export declare const LIBUSB_CLASS_PRINTER: number;
121
- /** Image class */
122
- export declare const LIBUSB_CLASS_PTP: number;
123
- /** Mass storage class */
124
- export declare const LIBUSB_CLASS_MASS_STORAGE: number;
125
- /** Hub class */
126
- export declare const LIBUSB_CLASS_HUB: number;
127
- /** Data class */
128
- export declare const LIBUSB_CLASS_DATA: number;
129
- /** Wireless class */
130
- export declare const LIBUSB_CLASS_WIRELESS: number;
131
- /** Application class */
132
- export declare const LIBUSB_CLASS_APPLICATION: number;
133
- /** Class is vendor-specific */
134
- export declare const LIBUSB_CLASS_VENDOR_SPEC: number;
135
-
136
- // libusb_standard_request
137
- /** Request status of the specific recipient */
138
- export declare const LIBUSB_REQUEST_GET_STATUS: number;
139
- /** Clear or disable a specific feature */
140
- export declare const LIBUSB_REQUEST_CLEAR_FEATURE: number;
141
- /** Set or enable a specific feature */
142
- export declare const LIBUSB_REQUEST_SET_FEATURE: number;
143
- /** Set device address for all future accesses */
144
- export declare const LIBUSB_REQUEST_SET_ADDRESS: number;
145
- /** Get the specified descriptor */
146
- export declare const LIBUSB_REQUEST_GET_DESCRIPTOR: number;
147
- /** Used to update existing descriptors or add new descriptors */
148
- export declare const LIBUSB_REQUEST_SET_DESCRIPTOR: number;
149
- /** Get the current device configuration value */
150
- export declare const LIBUSB_REQUEST_GET_CONFIGURATION: number;
151
- /** Set device configuration */
152
- export declare const LIBUSB_REQUEST_SET_CONFIGURATION: number;
153
- /** Return the selected alternate setting for the specified interface */
154
- export declare const LIBUSB_REQUEST_GET_INTERFACE: number;
155
- /** Select an alternate interface for the specified interface */
156
- export declare const LIBUSB_REQUEST_SET_INTERFACE: number;
157
- /** Set then report an endpoint's synchronization frame */
158
- export declare const LIBUSB_REQUEST_SYNCH_FRAME: number;
159
-
160
- // libusb_descriptor_type
161
- /** Device descriptor. See libusb_device_descriptor. */
162
- export declare const LIBUSB_DT_DEVICE: number;
163
- /** Configuration descriptor. See libusb_config_descriptor. */
164
- export declare const LIBUSB_DT_CONFIG: number;
165
- /** String descriptor */
166
- export declare const LIBUSB_DT_STRING: number;
167
- export declare const LIBUSB_DT_BOS: number;
168
- /** Interface descriptor. See libusb_interface_descriptor. */
169
- export declare const LIBUSB_DT_INTERFACE: number;
170
- /** Endpoint descriptor. See libusb_endpoint_descriptor. */
171
- export declare const LIBUSB_DT_ENDPOINT: number;
172
- /** HID descriptor */
173
- export declare const LIBUSB_DT_HID: number;
174
- /** HID report descriptor */
175
- export declare const LIBUSB_DT_REPORT: number;
176
- /** Physical descriptor */
177
- export declare const LIBUSB_DT_PHYSICAL: number;
178
- /** Hub descriptor */
179
- export declare const LIBUSB_DT_HUB: number;
180
-
181
- // libusb_endpoint_direction
182
- /** In: device-to-host */
183
- export declare const LIBUSB_ENDPOINT_IN: number;
184
- /** Out: host-to-device */
185
- export declare const LIBUSB_ENDPOINT_OUT: number;
186
-
187
- // libusb_transfer_type
188
- /** Control endpoint */
189
- export declare const LIBUSB_TRANSFER_TYPE_CONTROL: number;
190
- /** Isochronous endpoint */
191
- export declare const LIBUSB_TRANSFER_TYPE_ISOCHRONOUS: number;
192
- /** Bulk endpoint */
193
- export declare const LIBUSB_TRANSFER_TYPE_BULK: number;
194
- /** Interrupt endpoint */
195
- export declare const LIBUSB_TRANSFER_TYPE_INTERRUPT: number;
196
-
197
- // libusb_iso_sync_type
198
- /** No synchronization */
199
- export declare const LIBUSB_ISO_SYNC_TYPE_NONE: number;
200
- /** Asynchronous */
201
- export declare const LIBUSB_ISO_SYNC_TYPE_ASYNC: number;
202
- /** Adaptive */
203
- export declare const LIBUSB_ISO_SYNC_TYPE_ADAPTIVE: number;
204
- /** Synchronous */
205
- export declare const LIBUSB_ISO_SYNC_TYPE_SYNC: number;
206
-
207
- // libusb_iso_usage_type
208
- /** Data endpoint */
209
- export declare const LIBUSB_ISO_USAGE_TYPE_DATA: number;
210
- /** Feedback endpoint */
211
- export declare const LIBUSB_ISO_USAGE_TYPE_FEEDBACK: number;
212
- /** Implicit feedback Data endpoint */
213
- export declare const LIBUSB_ISO_USAGE_TYPE_IMPLICIT: number;
214
-
215
- // libusb_transfer_status
216
- /**
217
- * Transfer completed without error. Note that this does not indicate
218
- * that the entire amount of requested data was transferred.
219
- */
220
- export declare const LIBUSB_TRANSFER_COMPLETED: number;
221
- /** Transfer failed */
222
- export declare const LIBUSB_TRANSFER_ERROR: number;
223
- /** Transfer timed out */
224
- export declare const LIBUSB_TRANSFER_TIMED_OUT: number;
225
- /** Transfer was cancelled */
226
- export declare const LIBUSB_TRANSFER_CANCELLED: number;
227
- /**
228
- * For bulk/interrupt endpoints: halt condition detected (endpoint
229
- * stalled). For control endpoints: control request not supported.
230
- */
231
- export declare const LIBUSB_TRANSFER_STALL: number;
232
- /** Device was disconnected */
233
- export declare const LIBUSB_TRANSFER_NO_DEVICE: number;
234
- /** Device sent more data than requested */
235
- export declare const LIBUSB_TRANSFER_OVERFLOW: number;
236
-
237
- // libusb_transfer_flags
238
- /** Report short frames as errors */
239
- export declare const LIBUSB_TRANSFER_SHORT_NOT_OK: number;
240
- /**
241
- * Automatically free() transfer buffer during libusb_free_transfer().
242
- * Note that buffers allocated with libusb_dev_mem_alloc() should not
243
- * be attempted freed in this way, since free() is not an appropriate
244
- * way to release such memory.
245
- */
246
- export declare const LIBUSB_TRANSFER_FREE_BUFFER: number;
247
- /**
248
- * Automatically call libusb_free_transfer() after callback returns.
249
- * If this flag is set, it is illegal to call libusb_free_transfer()
250
- * from your transfer callback, as this will result in a double-free
251
- * when this flag is acted upon.
252
- */
253
- export declare const LIBUSB_TRANSFER_FREE_TRANSFER: number;
254
-
255
- // libusb_request_type
256
- /** Standard */
257
- export declare const LIBUSB_REQUEST_TYPE_STANDARD: number;
258
- /** Class */
259
- export declare const LIBUSB_REQUEST_TYPE_CLASS: number;
260
- /** Vendor */
261
- export declare const LIBUSB_REQUEST_TYPE_VENDOR: number;
262
- /** Reserved */
263
- export declare const LIBUSB_REQUEST_TYPE_RESERVED: number;
264
-
265
- // libusb_request_recipient
266
- /** Device */
267
- export declare const LIBUSB_RECIPIENT_DEVICE: number;
268
- /** Interface */
269
- export declare const LIBUSB_RECIPIENT_INTERFACE: number;
270
- /** Endpoint */
271
- export declare const LIBUSB_RECIPIENT_ENDPOINT: number;
272
- /** Other */
273
- export declare const LIBUSB_RECIPIENT_OTHER: number;
274
-
275
- export declare const LIBUSB_CONTROL_SETUP_SIZE: number;
276
- export declare const LIBUSB_DT_BOS_SIZE: number;
277
-
278
- // libusb_capability
279
- export declare const LIBUSB_CAP_HAS_CAPABILITY: number;
280
- export declare const LIBUSB_CAP_HAS_HOTPLUG: number;
281
- export declare const LIBUSB_CAP_HAS_HID_ACCESS: number;
282
- export declare const LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER: number;
283
-
284
- // libusb_error
285
- /** Input/output error */
286
- export declare const LIBUSB_ERROR_IO: number;
287
- /** Invalid parameter */
288
- export declare const LIBUSB_ERROR_INVALID_PARAM: number;
289
- /** Access denied (insufficient permissions) */
290
- export declare const LIBUSB_ERROR_ACCESS: number;
291
- /** No such device (it may have been disconnected) */
292
- export declare const LIBUSB_ERROR_NO_DEVICE: number;
293
- /** Entity not found */
294
- export declare const LIBUSB_ERROR_NOT_FOUND: number;
295
- /** Resource busy */
296
- export declare const LIBUSB_ERROR_BUSY: number;
297
- /** Operation timed out */
298
- export declare const LIBUSB_ERROR_TIMEOUT: number;
299
- /** Overflow */
300
- export declare const LIBUSB_ERROR_OVERFLOW: number;
301
- /** Pipe error */
302
- export declare const LIBUSB_ERROR_PIPE: number;
303
- /** System call interrupted (perhaps due to signal) */
304
- export declare const LIBUSB_ERROR_INTERRUPTED: number;
305
- /** Insufficient memory */
306
- export declare const LIBUSB_ERROR_NO_MEM: number;
307
- /** Operation not supported or unimplemented on this platform */
308
- export declare const LIBUSB_ERROR_NOT_SUPPORTED: number;
309
- /** Other error */
310
- export declare const LIBUSB_ERROR_OTHER: number;
@@ -1,22 +0,0 @@
1
- import type { Device } from './bindings';
2
- import { CapabilityDescriptor } from './descriptors';
3
-
4
- export class Capability {
5
- /** Object with fields from the capability descriptor -- see libusb documentation or USB spec. */
6
- public descriptor: CapabilityDescriptor;
7
-
8
- /** Integer capability type. */
9
- public type: number;
10
-
11
- /** Buffer capability data. */
12
- public data: Buffer;
13
-
14
- constructor(protected device: Device, protected id: number) {
15
- if (!device._bosDescriptor) {
16
- throw new Error('bosDescriptor not found');
17
- }
18
- this.descriptor = device._bosDescriptor.capabilities[this.id];
19
- this.type = this.descriptor.bDevCapabilityType;
20
- this.data = this.descriptor.dev_capability_data;
21
- }
22
- }