usb 2.2.0 → 2.4.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 (53) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +17 -3
  3. package/binding.gyp +3 -3
  4. package/dist/usb/index.js +7 -16
  5. package/dist/usb/index.js.map +1 -1
  6. package/dist/webusb/webusb-device.d.ts +0 -1
  7. package/dist/webusb/webusb-device.js +149 -243
  8. package/dist/webusb/webusb-device.js.map +1 -1
  9. package/libusb/.private/ci-container-build.sh +70 -0
  10. package/libusb/AUTHORS +10 -0
  11. package/libusb/ChangeLog +13 -0
  12. package/libusb/android/examples/unrooted_android.c +3 -4
  13. package/libusb/appveyor.yml +4 -0
  14. package/libusb/configure.ac +14 -1
  15. package/libusb/libusb/Makefile.am +1 -1
  16. package/libusb/libusb/core.c +17 -5
  17. package/libusb/libusb/hotplug.c +3 -0
  18. package/libusb/libusb/io.c +32 -8
  19. package/libusb/libusb/libusb.h +7 -0
  20. package/libusb/libusb/libusbi.h +22 -4
  21. package/libusb/libusb/os/darwin_usb.c +77 -20
  22. package/libusb/libusb/os/linux_usbfs.c +1 -1
  23. package/libusb/libusb/os/windows_common.c +14 -3
  24. package/libusb/libusb/os/windows_common.h +2 -1
  25. package/libusb/libusb/os/windows_winusb.c +30 -3
  26. package/libusb/libusb/version.h +1 -1
  27. package/libusb/libusb/version_nano.h +1 -1
  28. package/libusb/tests/Makefile.am +12 -1
  29. package/libusb/tests/umockdev.c +1175 -0
  30. package/package.json +6 -5
  31. package/prebuilds/android-arm/node.napi.armv7.node +0 -0
  32. package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
  33. package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
  34. package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
  35. package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
  36. package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
  37. package/prebuilds/linux-ia32/node.napi.node +0 -0
  38. package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
  39. package/prebuilds/linux-x64/node.napi.musl.node +0 -0
  40. package/prebuilds/win32-ia32/node.napi.node +0 -0
  41. package/prebuilds/win32-x64/node.napi.node +0 -0
  42. package/src/device.cc +20 -22
  43. package/src/node_usb.cc +93 -119
  44. package/src/node_usb.h +27 -15
  45. package/src/transfer.cc +0 -5
  46. package/test/usb.coffee +18 -7
  47. package/test/worker.cjs +9 -0
  48. package/tsc/usb/index.ts +5 -8
  49. package/tsc/webusb/webusb-device.ts +67 -124
  50. package/dist/webusb/mutex.d.ts +0 -22
  51. package/dist/webusb/mutex.js +0 -89
  52. package/dist/webusb/mutex.js.map +0 -1
  53. package/tsc/webusb/mutex.ts +0 -38
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.4.0] - 2022-05-02
4
+
5
+ ### Fixed
6
+ - Made addon context aware - [`512`](https://github.com/node-usb/node-usb/pull/512) ([Rob Moran](https://github.com/thegecko) & [Alba Mendez](https://github.com/mildsunrise))
7
+ - Fixed deprecation of `libusb_set_option` - [`510`](https://github.com/node-usb/node-usb/pull/510) ([Rob Moran](https://github.com/thegecko))
8
+
9
+ ### Changed
10
+ - **Breaking:** Updated to N-API version 6 (Node >=10.20.0 <11.x, >=12.17.0 <13.0, >=14.0.0) - [`509`](https://github.com/node-usb/node-usb/pull/509) ([Rob Moran](https://github.com/thegecko))
11
+
12
+ ### Added
13
+ - Added `rebuild` command - [`511`](https://github.com/node-usb/node-usb/pull/511) ([Rob Moran](https://github.com/thegecko))
14
+
15
+ ### Removed
16
+ - Removed `USE_POLL` build definition to simplify code - [`507`](https://github.com/node-usb/node-usb/pull/507) ([Rob Moran](https://github.com/thegecko))
17
+
18
+ ## [2.3.1] - 2022-04-11
19
+
20
+ ### Changed
21
+ - Removed device access mutex from WebUSB API - [`501`](https://github.com/node-usb/node-usb/pull/501) ([Rob Moran](https://github.com/thegecko))
22
+
23
+ ## [2.3.0] - 2022-04-11
24
+
25
+ ### Changed
26
+ - Changed libusb dependency to upstream v1.0.26 - [`505`](https://github.com/node-usb/node-usb/pull/505) ([Rob Moran](https://github.com/thegecko))
27
+ - Cleaned up Windows device polling method - [`496`](https://github.com/node-usb/node-usb/pull/496) ([Alba Mendez](https://github.com/mildsunrise))
28
+
3
29
  ## [2.2.0] - 2022-03-25
4
30
 
5
31
  ### Added
package/README.md CHANGED
@@ -10,9 +10,23 @@ This is a refactoring / rewrite of Christopher Klein's [node-usb](https://github
10
10
 
11
11
  # Prerequisites
12
12
 
13
- [Node.js >= v10.16.0](https://nodejs.org), which includes `npm`.
13
+ [Node.js >= v10.20.0](https://nodejs.org), which includes `npm`.
14
14
 
15
- On Windows, use [Zadig](http://zadig.akeo.ie/) to install the WinUSB driver for your USB device. Otherwise you will get `LIBUSB_ERROR_NOT_SUPPORTED` when attempting to open devices.
15
+ ## Windows
16
+
17
+ On Windows, if you get `LIBUSB_ERROR_NOT_SUPPORTED` when attempting to open your device, it's possible your device doesn't have a WinUSB driver for libusb to use.
18
+
19
+ You can install one using [Zadig](http://zadig.akeo.ie/) or another approach is to use the [UsbDK Backend](https://github.com/daynix/UsbDk) of libusb by immediately calling `usb.useUsbDkBackend()`.
20
+
21
+ Note that you cannot use multiple drivers on Windows as they get exclusive access to the device. So if you want to switch between drivers (e.g. using a printer with this software or the system), you will need to uninstall/install drivers as required.
22
+
23
+ ## Linux
24
+
25
+ On Linux, you'll need libudev to build libusb if a prebuild is not available. On Ubuntu/Debian:
26
+
27
+ ```bash
28
+ sudo apt-get install build-essential libudev-dev
29
+ ```
16
30
 
17
31
  # Installation
18
32
 
@@ -30,7 +44,7 @@ With `yarn`:
30
44
  yarn add usb
31
45
  ```
32
46
 
33
- __Note:__ the library is now written in `TypeScript`, so a separate types file is not longer required to be installed.
47
+ __Note:__ the library is now written in `TypeScript`, so a separate types file is not longer required to be installed (e.g. don't install `@types/usb`).
34
48
 
35
49
  # License
36
50
  [MIT](LICENSE.md)
package/binding.gyp CHANGED
@@ -26,13 +26,12 @@
26
26
  'defines': [
27
27
  '_FILE_OFFSET_BITS=64',
28
28
  '_LARGEFILE_SOURCE',
29
- 'NAPI_VERSION=<(napi_build_version)',
29
+ 'NAPI_VERSION=6',
30
30
  ],
31
31
  'include_dirs+': [
32
32
  'src/',
33
33
  "<!@(node -p \"require('node-addon-api').include\")"
34
34
  ],
35
-
36
35
  'conditions' : [
37
36
  ['use_system_libusb=="false" and OS!="freebsd"', {
38
37
  'dependencies': [
@@ -93,7 +92,8 @@
93
92
  'AdditionalOptions': [ '/EHsc' ],
94
93
  },
95
94
  },
96
- }]
95
+ }
96
+ ]
97
97
  ]
98
98
  },
99
99
  ]
package/dist/usb/index.js CHANGED
@@ -26,7 +26,7 @@ Object.getOwnPropertyNames(device_1.ExtendedDevice.prototype).forEach(function (
26
26
  var pollTimeout = 500;
27
27
  var hotplugSupported = usb._getLibusbCapability(usb.LIBUSB_CAP_HAS_HOTPLUG) > 0;
28
28
  var pollingHotplug = false;
29
- var pollDevices = [];
29
+ var pollDevices = new Set();
30
30
  var pollHotplug = function (start) {
31
31
  var e_1, _a, e_2, _b;
32
32
  if (start === void 0) { start = false; }
@@ -36,19 +36,15 @@ var pollHotplug = function (start) {
36
36
  else if (!pollingHotplug) {
37
37
  return;
38
38
  }
39
- var devices = usb.getDeviceList();
39
+ // Collect current devices
40
+ var devices = new Set(usb.getDeviceList());
40
41
  if (!start) {
41
- var _loop_1 = function (device) {
42
- var found = pollDevices.find(function (item) { return item.deviceAddress === device.deviceAddress; });
43
- if (!found) {
44
- usb.emit('attach', device);
45
- }
46
- };
47
42
  try {
48
43
  // Find attached devices
49
44
  for (var devices_1 = __values(devices), devices_1_1 = devices_1.next(); !devices_1_1.done; devices_1_1 = devices_1.next()) {
50
45
  var device = devices_1_1.value;
51
- _loop_1(device);
46
+ if (!pollDevices.has(device))
47
+ usb.emit('attach', device);
52
48
  }
53
49
  }
54
50
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -58,17 +54,12 @@ var pollHotplug = function (start) {
58
54
  }
59
55
  finally { if (e_1) throw e_1.error; }
60
56
  }
61
- var _loop_2 = function (device) {
62
- var found = devices.find(function (item) { return item.deviceAddress === device.deviceAddress; });
63
- if (!found) {
64
- usb.emit('detach', device);
65
- }
66
- };
67
57
  try {
68
58
  // Find detached devices
69
59
  for (var pollDevices_1 = __values(pollDevices), pollDevices_1_1 = pollDevices_1.next(); !pollDevices_1_1.done; pollDevices_1_1 = pollDevices_1.next()) {
70
60
  var device = pollDevices_1_1.value;
71
- _loop_2(device);
61
+ if (!devices.has(device))
62
+ usb.emit('detach', device);
72
63
  }
73
64
  }
74
65
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
@@ -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,IAAI,EAAE,MAAM,CAAC,wBAAwB,CAAC,uBAAc,CAAC,SAAS,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;AAC9I,CAAC,CAAC,CAAC;AA6BH,wEAAwE;AACxE,6CAA6C;AAC7C,IAAM,WAAW,GAAG,GAAG,CAAC;AACxB,IAAM,gBAAgB,GAAG,GAAG,CAAC,oBAAoB,CAAC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,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;aAClC;;;;;;;;;KACJ;IAED,WAAW,GAAG,OAAO,CAAC;IACtB,UAAU,CAAC;QACP,WAAW,EAAE,CAAC;IAClB,CAAC,EAAE,WAAW,CAAC,CAAC;AACpB,CAAC,CAAC;AAEF,GAAG,CAAC,EAAE,CAAC,aAAa,EAAE,UAAA,KAAK;IACvB,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,oBAAoB,EAAE,CAAC;SAC9B;aAAM;YACH,WAAW,CAAC,IAAI,CAAC,CAAC;SACrB;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"}
@@ -21,7 +21,6 @@ export declare class WebUSBDevice implements USBDevice {
21
21
  productName?: string | undefined;
22
22
  serialNumber?: string | undefined;
23
23
  configurations: USBConfiguration[];
24
- private deviceMutex;
25
24
  private constructor();
26
25
  get configuration(): USBConfiguration | undefined;
27
26
  get opened(): boolean;