usb 1.8.1-libusb.6 → 1.9.2
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/CHANGELOG.md +73 -0
- package/{Readme.md → README.md} +6 -0
- package/package.json +2 -2
- 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 +6 -6
- package/src/node_usb.cc +23 -1
- package/src/uv_async_queue.h +33 -25
- package/usb.js +9 -7
- package/index.js +0 -20
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [1.9.2] - 2021-12-05
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- Fixed exit delay and hang by moving queue start/stop to device open/close - [`460`](https://github.com/node-usb/node-usb/pull/460) ([MikeColeGuru](https://github.com/MikeColeGuru))
|
|
7
|
+
|
|
8
|
+
## [1.9.1] - 2021-11-14
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- Reverted fix for exit delay fixing a segfault issue it introduced - [`456`](https://github.com/node-usb/node-usb/pull/456) ([Rob Moran](https://github.com/thegecko))
|
|
12
|
+
|
|
13
|
+
## [1.9.0] - 2021-11-08
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
- Changed libusb dependency to upstream v1.0.23 - [`453`](https://github.com/node-usb/node-usb/pull/453) ([Rob Moran](https://github.com/thegecko))
|
|
17
|
+
|
|
18
|
+
## [1.8.1] - 2021-11-08
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
- Added functionality to ref/unref the hotplug events - [`455`](https://github.com/node-usb/node-usb/pull/455) ([Guilherme Francescon](https://github.com/gfcittolin))
|
|
22
|
+
- Added CHANGELOG - [`454`](https://github.com/node-usb/node-usb/pull/454) ([Rob Moran](https://github.com/thegecko))
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
- Fixed delay when exiting program - [`455`](https://github.com/node-usb/node-usb/pull/455) ([Rob Moran](https://github.com/thegecko))
|
|
26
|
+
|
|
27
|
+
## [1.8.0] - 2021-10-14
|
|
28
|
+
|
|
29
|
+
### Added
|
|
30
|
+
- Added prebuildify and GitHub action for native binaries - [`450`](https://github.com/node-usb/node-usb/pull/450) ([Rob Moran](https://github.com/thegecko))
|
|
31
|
+
|
|
32
|
+
### Fixed
|
|
33
|
+
- Fixed crash after wake on Windows when using Electron - [`451`](https://github.com/node-usb/node-usb/pull/451) ([Rob Moran](https://github.com/thegecko))
|
|
34
|
+
- Fixed invalid initial refs - [`445`](https://github.com/node-usb/node-usb/pull/445) ([Alba Mendez](https://github.com/mildsunrise))
|
|
35
|
+
|
|
36
|
+
### Changed
|
|
37
|
+
- Changed GitHub organisation to [node-usb](https://github.com/node-usb) - [`447`](https://github.com/node-usb/node-usb/pull/447) ([Rob Moran](https://github.com/thegecko))
|
|
38
|
+
|
|
39
|
+
## [1.7.2] - 2021-08-30
|
|
40
|
+
|
|
41
|
+
### Fixed
|
|
42
|
+
- Fixed crash when exiting on MacOS with Electron 9 - [`440`](https://github.com/node-usb/node-usb/pull/440) ([Daniel Main](https://github.com/danielmain))
|
|
43
|
+
|
|
44
|
+
### Changed
|
|
45
|
+
- **Breaking:** Changed minimum Node.js version to `10` - [`428`](https://github.com/node-usb/node-usb/pull/428) ([Rob Moran](https://github.com/thegecko))
|
|
46
|
+
|
|
47
|
+
## [1.7.1] - 2021-05-08
|
|
48
|
+
|
|
49
|
+
### Fixed
|
|
50
|
+
- Fixed compiler warnings - [`419`](https://github.com/node-usb/node-usb/pull/419) ([Joel Purra](https://github.com/joelpurra))
|
|
51
|
+
|
|
52
|
+
## [1.7.0] - 2021-04-10
|
|
53
|
+
|
|
54
|
+
### Changed
|
|
55
|
+
- Changed native support to use Node Addon API - [`399`](https://github.com/node-usb/node-usb/pull/399) ([Georg Vienna](https://github.com/geovie))
|
|
56
|
+
|
|
57
|
+
## [1.6.5] - 2021-02-14
|
|
58
|
+
|
|
59
|
+
### Changed
|
|
60
|
+
- Changed prebuild for Electron 12 beta to nightly - [`410`](https://github.com/node-usb/node-usb/pull/410) ([Piotr Rogowski](https://github.com/karniv00l))
|
|
61
|
+
|
|
62
|
+
### Removed
|
|
63
|
+
- Removed `portNumbers` test on arm64 - [`408`](https://github.com/node-usb/node-usb/pull/408) ([Rob Moran](https://github.com/thegecko))
|
|
64
|
+
|
|
65
|
+
## [1.6.4] - 2021-01-30
|
|
66
|
+
|
|
67
|
+
### Added
|
|
68
|
+
- Added prebuild for Electron 10 and 12 beta - [`407`](https://github.com/node-usb/node-usb/pull/407) ([Rob Moran](https://github.com/thegecko))
|
|
69
|
+
- Added prebuild for Electron 9 - [`362`](https://github.com/node-usb/node-usb/pull/362) (Luke Whyte)
|
|
70
|
+
|
|
71
|
+
### Changed
|
|
72
|
+
- Changed to GitHub Actions for prebuild workflow - [`404`](https://github.com/node-usb/node-usb/pull/404) ([Rob Moran](https://github.com/thegecko))
|
|
73
|
+
- Changed Node.js 13 prebuild target to Node.js 14 - [`374`](https://github.com/node-usb/node-usb/pull/374) ([Micah Zoltu](https://github.com/MicahZoltu))
|
package/{Readme.md → README.md}
RENAMED
|
@@ -304,6 +304,12 @@ Attaches a callback to plugging in a `device`.
|
|
|
304
304
|
### usb.on('detach', function(device) { ... });
|
|
305
305
|
Attaches a callback to unplugging a `device`.
|
|
306
306
|
|
|
307
|
+
### usb.refHotplugEvents();
|
|
308
|
+
Restore (re-reference) the hotplug events unreferenced by `unrefHotplugEvents()`
|
|
309
|
+
|
|
310
|
+
### usb.unrefHotplugEvents();
|
|
311
|
+
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.
|
|
312
|
+
|
|
307
313
|
|
|
308
314
|
Development and testing
|
|
309
315
|
=======================
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "usb",
|
|
3
3
|
"description": "Library to access USB devices",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.9.2",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=10.16.0"
|
|
7
7
|
},
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"coffeescript": "~2.4.1",
|
|
58
|
-
"mocha": "^
|
|
58
|
+
"mocha": "^9.1.3",
|
|
59
59
|
"node-gyp": "^7.1.2",
|
|
60
60
|
"prebuildify": "^4.2.1",
|
|
61
61
|
"prebuildify-ci": "^1.0.5",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/src/device.cc
CHANGED
|
@@ -19,18 +19,12 @@ Device::Device(const Napi::CallbackInfo & info) : Napi::ObjectWrap<Device>(info)
|
|
|
19
19
|
device = info[0].As<Napi::External<libusb_device>>().Data();
|
|
20
20
|
libusb_ref_device(device);
|
|
21
21
|
byPtr.insert(std::make_pair(device, this));
|
|
22
|
-
#ifndef USE_POLL
|
|
23
|
-
completionQueue.start(info.Env());
|
|
24
|
-
#endif
|
|
25
22
|
DEBUG_LOG("Created device %p", this);
|
|
26
23
|
Constructor(info);
|
|
27
24
|
}
|
|
28
25
|
|
|
29
26
|
Device::~Device(){
|
|
30
27
|
DEBUG_LOG("Freed device %p", this);
|
|
31
|
-
#ifndef USE_POLL
|
|
32
|
-
completionQueue.stop();
|
|
33
|
-
#endif
|
|
34
28
|
byPtr.erase(device);
|
|
35
29
|
libusb_close(device_handle);
|
|
36
30
|
libusb_unref_device(device);
|
|
@@ -194,6 +188,9 @@ Napi::Value Device::Open(const Napi::CallbackInfo& info) {
|
|
|
194
188
|
ENTER_METHOD(Device, 0);
|
|
195
189
|
if (!self->device_handle){
|
|
196
190
|
CHECK_USB(libusb_open(self->device, &self->device_handle));
|
|
191
|
+
#ifndef USE_POLL
|
|
192
|
+
completionQueue.start(info.Env());
|
|
193
|
+
#endif
|
|
197
194
|
}
|
|
198
195
|
return env.Undefined();
|
|
199
196
|
}
|
|
@@ -203,6 +200,9 @@ Napi::Value Device::Close(const Napi::CallbackInfo& info) {
|
|
|
203
200
|
if (self->canClose()){
|
|
204
201
|
libusb_close(self->device_handle);
|
|
205
202
|
self->device_handle = NULL;
|
|
203
|
+
#ifndef USE_POLL
|
|
204
|
+
completionQueue.stop();
|
|
205
|
+
#endif
|
|
206
206
|
}else{
|
|
207
207
|
THROW_ERROR("Can't close device with a pending request");
|
|
208
208
|
}
|
package/src/node_usb.cc
CHANGED
|
@@ -7,6 +7,8 @@ Napi::Value GetDeviceList(const Napi::CallbackInfo& info);
|
|
|
7
7
|
Napi::Value GetLibusbCapability(const Napi::CallbackInfo& info);
|
|
8
8
|
Napi::Value EnableHotplugEvents(const Napi::CallbackInfo& info);
|
|
9
9
|
Napi::Value DisableHotplugEvents(const Napi::CallbackInfo& info);
|
|
10
|
+
Napi::Value RefHotplugEvents(const Napi::CallbackInfo& info);
|
|
11
|
+
Napi::Value UnrefHotplugEvents(const Napi::CallbackInfo& info);
|
|
10
12
|
void initConstants(Napi::Object target);
|
|
11
13
|
|
|
12
14
|
libusb_context* usb_context;
|
|
@@ -17,6 +19,7 @@ struct HotPlug {
|
|
|
17
19
|
|
|
18
20
|
#ifdef USE_POLL
|
|
19
21
|
#include <poll.h>
|
|
22
|
+
#include <uv.h>
|
|
20
23
|
#include <sys/time.h>
|
|
21
24
|
|
|
22
25
|
std::map<int, uv_poll_t*> pollByFD;
|
|
@@ -98,6 +101,8 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
|
|
98
101
|
exports.Set("_getLibusbCapability", Napi::Function::New(env, GetLibusbCapability));
|
|
99
102
|
exports.Set("_enableHotplugEvents", Napi::Function::New(env, EnableHotplugEvents));
|
|
100
103
|
exports.Set("_disableHotplugEvents", Napi::Function::New(env, DisableHotplugEvents));
|
|
104
|
+
exports.Set("refHotplugEvents", Napi::Function::New(env, RefHotplugEvents));
|
|
105
|
+
exports.Set("unrefHotplugEvents", Napi::Function::New(env, UnrefHotplugEvents));
|
|
101
106
|
return exports;
|
|
102
107
|
}
|
|
103
108
|
|
|
@@ -212,10 +217,27 @@ Napi::Value DisableHotplugEvents(const Napi::CallbackInfo& info) {
|
|
|
212
217
|
return env.Undefined();
|
|
213
218
|
}
|
|
214
219
|
|
|
220
|
+
Napi::Value RefHotplugEvents(const Napi::CallbackInfo& info) {
|
|
221
|
+
Napi::Env env = info.Env();
|
|
222
|
+
Napi::HandleScope scope(env);
|
|
223
|
+
if (hotplugEnabled) {
|
|
224
|
+
hotplugQueue.ref(env);
|
|
225
|
+
}
|
|
226
|
+
return env.Undefined();
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
Napi::Value UnrefHotplugEvents(const Napi::CallbackInfo& info) {
|
|
230
|
+
Napi::Env env = info.Env();
|
|
231
|
+
Napi::HandleScope scope(env);
|
|
232
|
+
if (hotplugEnabled) {
|
|
233
|
+
hotplugQueue.unref(env);
|
|
234
|
+
}
|
|
235
|
+
return env.Undefined();
|
|
236
|
+
}
|
|
237
|
+
|
|
215
238
|
#define DEFINE_CONSTANT(OBJ, VALUE) \
|
|
216
239
|
OBJ.DefineProperty(Napi::PropertyDescriptor::Value(#VALUE, Napi::Number::New(OBJ.Env(), VALUE), static_cast<napi_property_attributes>(napi_enumerable | napi_configurable)));
|
|
217
240
|
|
|
218
|
-
|
|
219
241
|
void initConstants(Napi::Object target){
|
|
220
242
|
DEFINE_CONSTANT(target, LIBUSB_CLASS_PER_INTERFACE);
|
|
221
243
|
DEFINE_CONSTANT(target, LIBUSB_CLASS_AUDIO);
|
package/src/uv_async_queue.h
CHANGED
|
@@ -3,31 +3,39 @@
|
|
|
3
3
|
|
|
4
4
|
template <class T>
|
|
5
5
|
class UVQueue{
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
6
|
+
public:
|
|
7
|
+
typedef void (*fptr)(T);
|
|
8
|
+
|
|
9
|
+
Napi::ThreadSafeFunction tsfn;
|
|
10
|
+
|
|
11
|
+
UVQueue(fptr cb): callback(cb) {}
|
|
12
|
+
|
|
13
|
+
void start(Napi::Env env) {
|
|
14
|
+
Napi::Function empty_func = Napi::Function::New(env, [](const Napi::CallbackInfo& cb) {});
|
|
15
|
+
tsfn = Napi::ThreadSafeFunction::New(env, empty_func, "libusb", 0, 1);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
void stop() {
|
|
19
|
+
tsfn.Release();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
void ref(Napi::Env env) {
|
|
23
|
+
tsfn.Ref(env);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
void unref(Napi::Env env) {
|
|
27
|
+
tsfn.Unref(env);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
void post(T value){
|
|
31
|
+
auto cb = callback;
|
|
32
|
+
tsfn.BlockingCall( value, [cb](Napi::Env _env, Napi::Function _jsCallback, T val) {
|
|
33
|
+
cb(val);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private:
|
|
38
|
+
fptr callback;
|
|
31
39
|
};
|
|
32
40
|
|
|
33
41
|
#endif
|
package/usb.js
CHANGED
|
@@ -14,6 +14,8 @@ if (usb.INIT_ERROR) {
|
|
|
14
14
|
usb.getDeviceList = function () { return []; };
|
|
15
15
|
usb._enableHotplugEvents = function () { };
|
|
16
16
|
usb._disableHotplugEvents = function () { };
|
|
17
|
+
usb.refHotplugEvents = function () { };
|
|
18
|
+
usb.unrefHotplugEvents = function () { };
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
Object.keys(events.EventEmitter.prototype).forEach(function (key) {
|
|
@@ -508,12 +510,12 @@ OutEndpoint.prototype.transferWithZLP = function (buf, cb) {
|
|
|
508
510
|
}
|
|
509
511
|
}
|
|
510
512
|
|
|
511
|
-
// Polling mechanism for discovering
|
|
513
|
+
// Polling mechanism for discovering device changes until this is fixed:
|
|
512
514
|
// https://github.com/libusb/libusb/issues/86
|
|
513
|
-
exports.
|
|
515
|
+
exports._pollTimeout = 500;
|
|
514
516
|
var hotplugSupported = usb._getLibusbCapability(usb.LIBUSB_CAP_HAS_HOTPLUG) > 0;
|
|
515
517
|
var pollingHotplug = false;
|
|
516
|
-
var
|
|
518
|
+
var pollDevices = [];
|
|
517
519
|
function pollHotplug(start) {
|
|
518
520
|
if (start) {
|
|
519
521
|
pollingHotplug = true;
|
|
@@ -526,14 +528,14 @@ function pollHotplug(start) {
|
|
|
526
528
|
if (!start) {
|
|
527
529
|
// Find attached devices
|
|
528
530
|
for (var device of devices) {
|
|
529
|
-
var found =
|
|
531
|
+
var found = pollDevices.find(item => item.deviceAddress === device.deviceAddress);
|
|
530
532
|
if (!found) {
|
|
531
533
|
usb.emit('attach', device);
|
|
532
534
|
}
|
|
533
535
|
}
|
|
534
536
|
|
|
535
537
|
// Find detached devices
|
|
536
|
-
for (var device of
|
|
538
|
+
for (var device of pollDevices) {
|
|
537
539
|
var found = devices.find(item => item.deviceAddress === device.deviceAddress);
|
|
538
540
|
if (!found) {
|
|
539
541
|
usb.emit('detach', device);
|
|
@@ -541,10 +543,10 @@ function pollHotplug(start) {
|
|
|
541
543
|
}
|
|
542
544
|
}
|
|
543
545
|
|
|
544
|
-
|
|
546
|
+
pollDevices = devices;
|
|
545
547
|
setTimeout(() => {
|
|
546
548
|
pollHotplug();
|
|
547
|
-
}, exports.
|
|
549
|
+
}, exports._pollTimeout);
|
|
548
550
|
}
|
|
549
551
|
|
|
550
552
|
var hotplugListeners = 0;
|
package/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const usb = require('./');
|
|
2
|
-
|
|
3
|
-
const a = d => console.log('a', d);
|
|
4
|
-
const d = d => console.log('d', d);
|
|
5
|
-
|
|
6
|
-
console.log('listening');
|
|
7
|
-
usb.on('attach', a);
|
|
8
|
-
usb.on('detach', d);
|
|
9
|
-
|
|
10
|
-
setTimeout(() => {
|
|
11
|
-
console.log('ignoring');
|
|
12
|
-
usb.off('attach', a);
|
|
13
|
-
usb.off('detach', d);
|
|
14
|
-
|
|
15
|
-
setTimeout(() => {
|
|
16
|
-
console.log('listening');
|
|
17
|
-
usb.on('attach', a);
|
|
18
|
-
usb.on('detach', d);
|
|
19
|
-
}, 5000);
|
|
20
|
-
}, 5000);
|