usb 2.4.3 → 2.5.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.
- package/.gitmodules +2 -2
- package/CHANGELOG.md +5 -0
- package/README.md +34 -0
- package/binding.gyp +48 -25
- package/dist/usb/bindings.d.ts +1 -0
- package/dist/usb/index.d.ts +2 -0
- package/dist/usb/index.js +25 -13
- package/dist/usb/index.js.map +1 -1
- package/package.json +1 -1
- package/prebuilds/android-arm/node.napi.armv7.node +0 -0
- package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
- package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
- package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
- package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
- package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
- package/prebuilds/linux-ia32/node.napi.node +0 -0
- package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
- package/prebuilds/linux-x64/node.napi.musl.node +0 -0
- package/prebuilds/win32-ia32/node.napi.node +0 -0
- package/prebuilds/win32-x64/node.napi.node +0 -0
- package/src/device.cc +309 -309
- package/src/helpers.h +36 -36
- package/src/hotplug/hotplug.h +22 -0
- package/src/hotplug/libusb.cc +91 -0
- package/src/hotplug/windows.cc +160 -0
- package/src/node_usb.cc +246 -282
- package/src/node_usb.h +64 -67
- package/src/thread_name.cc +1 -1
- package/src/transfer.cc +114 -114
- package/test/usb.coffee +178 -178
- package/test/webusb.coffee +140 -140
- package/tsc/usb/bindings.ts +1 -0
- package/tsc/usb/index.ts +30 -12
package/.gitmodules
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
[submodule "libusb"]
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
path = libusb
|
|
3
|
+
url = https://github.com/libusb/libusb.git
|
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -547,6 +547,40 @@ Restore (re-reference) the hotplug events unreferenced by `unrefHotplugEvents()`
|
|
|
547
547
|
#### usb.unrefHotplugEvents();
|
|
548
548
|
Listening to events will prevent the process to exit. By calling this function, hotplug events will be unreferenced by the event loop, allowing the process to exit even when listening for the `attach` and `detach` events.
|
|
549
549
|
|
|
550
|
+
# Migrating from node-usb-detection
|
|
551
|
+
|
|
552
|
+
If you have been referred here by `node-usb-detection`, the following may be helpful for you to update your existing code.
|
|
553
|
+
|
|
554
|
+
## usbDetect.startMonitoring() & usbDetect.stopMonitoring()
|
|
555
|
+
|
|
556
|
+
There is no direct equivalent to these methods. This is handled automatically for you when you add and remove event listeners.
|
|
557
|
+
|
|
558
|
+
You may find `usb.unrefHotplugEvents()` useful as it is intended to help with exit conditions.
|
|
559
|
+
|
|
560
|
+
## usbDetect.find()
|
|
561
|
+
|
|
562
|
+
You can instead use `usb.getDeviceList()`. Be aware that this will do an enumeration to find all of the devices, and not look at a cache of the known devices. If you call it too often it may have a performance impact.
|
|
563
|
+
|
|
564
|
+
To find a specific device by vid and pid, call `usb.findByIds`. e.g. `usb.findByIds(0x12, 0x34)`.
|
|
565
|
+
|
|
566
|
+
## usbDetect.on('add', function(device) { ... })
|
|
567
|
+
|
|
568
|
+
These should be changed to `usb.on('attach', function(device) { ... })`.
|
|
569
|
+
|
|
570
|
+
There is no equivalent to filter based on the vid or pid, instead you should do a check inside the callback you provide.
|
|
571
|
+
The contents of the device object has also changed.
|
|
572
|
+
|
|
573
|
+
## usbDetect.on('remove', function(device) { ... })
|
|
574
|
+
|
|
575
|
+
These should be changed to `usb.on('detach', function(device) { ... })`.
|
|
576
|
+
|
|
577
|
+
There is no equivalent to filter based on the vid or pid, instead you should do a check inside the callback you provide.
|
|
578
|
+
The contents of the device object has also changed.
|
|
579
|
+
|
|
580
|
+
## usbDetect.on('change', function(device) { ... })
|
|
581
|
+
|
|
582
|
+
There is no direct equivalent to this. Instead you can listen to both `attach` and `detach` to get the same behaviour.
|
|
583
|
+
|
|
550
584
|
# Development
|
|
551
585
|
The library is based on native bindings wrapping the [libusb](https://github.com/libusb/libusb) library.
|
|
552
586
|
|
package/binding.gyp
CHANGED
|
@@ -1,25 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
'variables': {
|
|
3
3
|
'use_udev%': 1,
|
|
4
|
-
'use_system_libusb%': 'false'
|
|
4
|
+
'use_system_libusb%': 'false'
|
|
5
5
|
},
|
|
6
6
|
'targets': [
|
|
7
7
|
{
|
|
8
8
|
'target_name': 'usb_bindings',
|
|
9
|
-
'cflags!': [
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
'cflags!': [
|
|
10
|
+
'-fno-exceptions'
|
|
11
|
+
],
|
|
12
|
+
'cflags_cc!': [
|
|
13
|
+
'-fno-exceptions'
|
|
14
|
+
],
|
|
15
|
+
'xcode_settings': {
|
|
16
|
+
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
|
|
12
17
|
'CLANG_CXX_LIBRARY': 'libc++',
|
|
13
|
-
'MACOSX_DEPLOYMENT_TARGET': '10.7'
|
|
18
|
+
'MACOSX_DEPLOYMENT_TARGET': '10.7'
|
|
14
19
|
},
|
|
15
20
|
'msvs_settings': {
|
|
16
|
-
'VCCLCompilerTool': {
|
|
21
|
+
'VCCLCompilerTool': {
|
|
22
|
+
'ExceptionHandling': 1
|
|
23
|
+
}
|
|
17
24
|
},
|
|
18
25
|
'sources': [
|
|
19
|
-
'
|
|
20
|
-
'
|
|
21
|
-
'
|
|
22
|
-
'
|
|
26
|
+
'src/node_usb.cc',
|
|
27
|
+
'src/device.cc',
|
|
28
|
+
'src/transfer.cc',
|
|
29
|
+
'src/thread_name.cc'
|
|
23
30
|
],
|
|
24
31
|
'cflags_cc': [
|
|
25
32
|
'-std=c++14'
|
|
@@ -27,7 +34,7 @@
|
|
|
27
34
|
'defines': [
|
|
28
35
|
'_FILE_OFFSET_BITS=64',
|
|
29
36
|
'_LARGEFILE_SOURCE',
|
|
30
|
-
'NAPI_VERSION=6'
|
|
37
|
+
'NAPI_VERSION=6'
|
|
31
38
|
],
|
|
32
39
|
'include_dirs+': [
|
|
33
40
|
'src/',
|
|
@@ -37,7 +44,7 @@
|
|
|
37
44
|
['use_system_libusb=="false" and OS!="freebsd"', {
|
|
38
45
|
'dependencies': [
|
|
39
46
|
'libusb.gypi:libusb',
|
|
40
|
-
]
|
|
47
|
+
]
|
|
41
48
|
}],
|
|
42
49
|
['use_system_libusb=="true" or OS=="freebsd"', {
|
|
43
50
|
'include_dirs+': [
|
|
@@ -45,7 +52,7 @@
|
|
|
45
52
|
],
|
|
46
53
|
'libraries': [
|
|
47
54
|
'<!@(pkg-config libusb-1.0 --libs)'
|
|
48
|
-
]
|
|
55
|
+
]
|
|
49
56
|
}],
|
|
50
57
|
['OS=="mac"', {
|
|
51
58
|
'xcode_settings': {
|
|
@@ -62,40 +69,56 @@
|
|
|
62
69
|
'-arch arm64'
|
|
63
70
|
],
|
|
64
71
|
'SDKROOT': 'macosx',
|
|
65
|
-
'MACOSX_DEPLOYMENT_TARGET': '10.7'
|
|
66
|
-
}
|
|
72
|
+
'MACOSX_DEPLOYMENT_TARGET': '10.7'
|
|
73
|
+
}
|
|
74
|
+
}],
|
|
75
|
+
['OS!="win"', {
|
|
76
|
+
'sources': [
|
|
77
|
+
'src/hotplug/libusb.cc'
|
|
78
|
+
],
|
|
67
79
|
}],
|
|
68
80
|
['OS=="win"', {
|
|
81
|
+
'sources': [
|
|
82
|
+
'src/hotplug/windows.cc'
|
|
83
|
+
],
|
|
69
84
|
'defines':[
|
|
70
85
|
'WIN32_LEAN_AND_MEAN'
|
|
71
86
|
],
|
|
87
|
+
'libraries': [
|
|
88
|
+
'cfgmgr32.lib'
|
|
89
|
+
],
|
|
72
90
|
'default_configuration': 'Debug',
|
|
73
91
|
'configurations': {
|
|
74
92
|
'Debug': {
|
|
75
|
-
'defines': [
|
|
93
|
+
'defines': [
|
|
94
|
+
'DEBUG',
|
|
95
|
+
'_DEBUG'
|
|
96
|
+
],
|
|
76
97
|
'msvs_settings': {
|
|
77
98
|
'VCCLCompilerTool': {
|
|
78
99
|
'RuntimeLibrary': 1, # static debug
|
|
79
|
-
}
|
|
80
|
-
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
81
102
|
},
|
|
82
103
|
'Release': {
|
|
83
|
-
'defines': [
|
|
104
|
+
'defines': [
|
|
105
|
+
'NDEBUG'
|
|
106
|
+
],
|
|
84
107
|
'msvs_settings': {
|
|
85
108
|
'VCCLCompilerTool': {
|
|
86
109
|
'RuntimeLibrary': 0, # static release
|
|
87
|
-
}
|
|
88
|
-
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
89
112
|
}
|
|
90
113
|
},
|
|
91
114
|
'msvs_settings': {
|
|
92
115
|
'VCCLCompilerTool': {
|
|
93
|
-
'AdditionalOptions': [ '/EHsc' ]
|
|
94
|
-
}
|
|
95
|
-
}
|
|
116
|
+
'AdditionalOptions': [ '/EHsc' ]
|
|
117
|
+
}
|
|
118
|
+
}
|
|
96
119
|
}
|
|
97
120
|
]
|
|
98
121
|
]
|
|
99
|
-
}
|
|
122
|
+
}
|
|
100
123
|
]
|
|
101
124
|
}
|
package/dist/usb/bindings.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare function setDebugLevel(level: number): void;
|
|
|
17
17
|
* Use USBDK Backend (Windows only)
|
|
18
18
|
*/
|
|
19
19
|
export declare function useUsbDkBackend(): void;
|
|
20
|
+
export declare function _supportedHotplugEvents(): number;
|
|
20
21
|
export declare function _enableHotplugEvents(): void;
|
|
21
22
|
export declare function _disableHotplugEvents(): void;
|
|
22
23
|
export declare function _getLibusbCapability(capability: number): number;
|
package/dist/usb/index.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ declare module './bindings' {
|
|
|
10
10
|
interface DeviceEvents extends EventListeners<DeviceEvents> {
|
|
11
11
|
attach: Device;
|
|
12
12
|
detach: Device;
|
|
13
|
+
attachIds: undefined;
|
|
14
|
+
detachIds: undefined;
|
|
13
15
|
}
|
|
14
16
|
function addListener<K extends keyof DeviceEvents>(event: K, listener: (arg: DeviceEvents[K]) => void): void;
|
|
15
17
|
function removeListener<K extends keyof DeviceEvents>(event: K, listener: (arg: DeviceEvents[K]) => void): void;
|
package/dist/usb/index.js
CHANGED
|
@@ -21,21 +21,13 @@ Object.setPrototypeOf(usb, events_1.EventEmitter.prototype);
|
|
|
21
21
|
Object.getOwnPropertyNames(device_1.ExtendedDevice.prototype).forEach(function (name) {
|
|
22
22
|
Object.defineProperty(usb.Device.prototype, name, Object.getOwnPropertyDescriptor(device_1.ExtendedDevice.prototype, name) || Object.create(null));
|
|
23
23
|
});
|
|
24
|
-
// Polling mechanism for discovering device changes
|
|
25
|
-
// https://github.com/libusb/libusb/issues/86
|
|
24
|
+
// Polling mechanism for discovering device changes where hotplug detection is not available
|
|
26
25
|
var pollTimeout = 500;
|
|
27
|
-
var hotplugSupported = usb.
|
|
26
|
+
var hotplugSupported = usb._supportedHotplugEvents();
|
|
28
27
|
var pollingHotplug = false;
|
|
29
28
|
var pollDevices = new Set();
|
|
30
|
-
var
|
|
29
|
+
var pollHotplugOnce = function (start) {
|
|
31
30
|
var e_1, _a, e_2, _b;
|
|
32
|
-
if (start === void 0) { start = false; }
|
|
33
|
-
if (start) {
|
|
34
|
-
pollingHotplug = true;
|
|
35
|
-
}
|
|
36
|
-
else if (!pollingHotplug) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
31
|
// Collect current devices
|
|
40
32
|
var devices = new Set(usb.getDeviceList());
|
|
41
33
|
if (!start) {
|
|
@@ -71,10 +63,30 @@ var pollHotplug = function (start) {
|
|
|
71
63
|
}
|
|
72
64
|
}
|
|
73
65
|
pollDevices = devices;
|
|
66
|
+
};
|
|
67
|
+
var pollHotplugLoop = function (start) {
|
|
68
|
+
if (start === void 0) { start = false; }
|
|
69
|
+
if (start) {
|
|
70
|
+
pollingHotplug = true;
|
|
71
|
+
}
|
|
72
|
+
else if (!pollingHotplug) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
pollHotplugOnce(start);
|
|
74
76
|
setTimeout(function () {
|
|
75
|
-
|
|
77
|
+
pollHotplugLoop();
|
|
76
78
|
}, pollTimeout);
|
|
77
79
|
};
|
|
80
|
+
var hotplugModeIsIdsOnly = hotplugSupported === 2;
|
|
81
|
+
if (hotplugModeIsIdsOnly) {
|
|
82
|
+
// The hotplug backend doesnt emit 'attach' or 'detach', so we need to do some conversion
|
|
83
|
+
var hotplugEventConversion = function () {
|
|
84
|
+
// Future: This might want a debounce, to avoid doing multiple polls when attaching a usb hub or something
|
|
85
|
+
pollHotplugOnce(false);
|
|
86
|
+
};
|
|
87
|
+
usb.on('attachIds', hotplugEventConversion);
|
|
88
|
+
usb.on('detachIds', hotplugEventConversion);
|
|
89
|
+
}
|
|
78
90
|
usb.on('newListener', function (event) {
|
|
79
91
|
if (event !== 'attach' && event !== 'detach') {
|
|
80
92
|
return;
|
|
@@ -85,7 +97,7 @@ usb.on('newListener', function (event) {
|
|
|
85
97
|
usb._enableHotplugEvents();
|
|
86
98
|
}
|
|
87
99
|
else {
|
|
88
|
-
|
|
100
|
+
pollHotplugLoop(true);
|
|
89
101
|
}
|
|
90
102
|
}
|
|
91
103
|
});
|
package/dist/usb/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../tsc/usb/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iCAAsC;AACtC,mCAA0C;AAC1C,gCAAkC;AAElC,IAAI,GAAG,CAAC,UAAU,EAAE;IAChB,+BAA+B;IAC/B,OAAO,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;CAChD;AAED,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,qBAAY,CAAC,SAAS,CAAC,CAAC;AAEnD,MAAM,CAAC,mBAAmB,CAAC,uBAAc,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,UAAA,IAAI;IAC7D,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,EAAE,IAA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AAQ,CAAC,GAAG,GAAG,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAChF,IAAI,aAAa,KAAK,CAAC,EAAE;QACrB,IAAI,gBAAgB,EAAE;YAClB,GAAG,CAAC,oBAAoB,EAAE,CAAC;SAC9B;aAAM;YACH,eAAe,CAAC,IAAI,CAAC,CAAC;SACzB;KACJ;AACL,CAAC,CAAC,CAAC;AAEH,GAAG,CAAC,EAAE,CAAC,gBAAgB,EAAE,UAAA,KAAK;IAC1B,IAAI,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,QAAQ,EAAE;QAC1C,OAAO;KACV;IACD,IAAM,aAAa,GAAG,GAAG,CAAC,aAAa,CAAC,QAAQ,CAAC,GAAG,GAAG,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAChF,IAAI,aAAa,KAAK,CAAC,EAAE;QACrB,IAAI,gBAAgB,EAAE;YAClB,GAAG,CAAC,qBAAqB,EAAE,CAAC;SAC/B;aAAM;YACH,cAAc,GAAG,KAAK,CAAC;SAC1B;KACJ;AACL,CAAC,CAAC,CAAC;AAEH,iBAAS,GAAG,CAAC"}
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|