usb 2.9.0 → 2.11.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/CHANGELOG.md +10 -0
- package/README.md +6 -0
- package/binding.gyp +1 -1
- package/dist/index.js +35 -113
- package/dist/index.js.map +1 -1
- package/dist/usb/bindings.js +2 -2
- package/dist/usb/bindings.js.map +1 -1
- package/dist/usb/capability.js +3 -4
- package/dist/usb/capability.js.map +1 -1
- package/dist/usb/device.js +101 -123
- package/dist/usb/device.js.map +1 -1
- package/dist/usb/endpoint.d.ts +2 -1
- package/dist/usb/endpoint.js +74 -98
- package/dist/usb/endpoint.js.map +1 -1
- package/dist/usb/index.js +26 -59
- package/dist/usb/index.js.map +1 -1
- package/dist/usb/interface.js +41 -44
- package/dist/usb/interface.js.map +1 -1
- package/dist/webusb/index.js +169 -355
- package/dist/webusb/index.js.map +1 -1
- package/dist/webusb/webusb-device.js +367 -751
- package/dist/webusb/webusb-device.js.map +1 -1
- package/package.json +5 -5
- 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 +5 -3
- package/test/usb.coffee +25 -4
- package/test/worker.cjs +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.11.0] - 2023-10-02
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- Allow use of close on a closed device - [`676`](https://github.com/node-usb/node-usb/pull/676) ([Julien Vanier](https://github.com/monkbroc))
|
|
7
|
+
|
|
8
|
+
## [2.10.0] - 2023-08-22
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- Fixed using callbacks in startPolling - [`631`](https://github.com/node-usb/node-usb/pull/631) ([Tim Strazzere](https://github.com/strazzere))
|
|
12
|
+
|
|
3
13
|
## [2.9.0] - 2023-03-16
|
|
4
14
|
|
|
5
15
|
### Changed
|
package/README.md
CHANGED
|
@@ -20,6 +20,8 @@ You can install one using [Zadig](http://zadig.akeo.ie/) or another approach is
|
|
|
20
20
|
|
|
21
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
22
|
|
|
23
|
+
For further info, check [How to use libusb on Windows](https://github.com/libusb/libusb/wiki/Windows#user-content-How_to_use_libusb_on_Windows) in the libusb's wiki.
|
|
24
|
+
|
|
23
25
|
## Linux
|
|
24
26
|
|
|
25
27
|
On Linux, you'll need libudev to build libusb if a prebuild is not available. On Ubuntu/Debian:
|
|
@@ -28,6 +30,10 @@ On Linux, you'll need libudev to build libusb if a prebuild is not available. On
|
|
|
28
30
|
sudo apt-get install build-essential libudev-dev
|
|
29
31
|
```
|
|
30
32
|
|
|
33
|
+
# Troubleshooting
|
|
34
|
+
|
|
35
|
+
For libusb issues, please refer to the FAQ at https://github.com/libusb/libusb/wiki/FAQ
|
|
36
|
+
|
|
31
37
|
# Installation
|
|
32
38
|
|
|
33
39
|
Native modules are bundled using `prebuildify`, so installation should be as simple as installing the package.
|
package/binding.gyp
CHANGED
package/dist/index.js
CHANGED
|
@@ -9,136 +9,58 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
9
9
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
-
function step(op) {
|
|
26
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
-
while (_) try {
|
|
28
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
-
switch (op[0]) {
|
|
31
|
-
case 0: case 1: t = op; break;
|
|
32
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
-
default:
|
|
36
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
-
if (t[2]) _.ops.pop();
|
|
41
|
-
_.trys.pop(); continue;
|
|
42
|
-
}
|
|
43
|
-
op = body.call(thisArg, _);
|
|
44
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
var __values = (this && this.__values) || function(o) {
|
|
49
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
50
|
-
if (m) return m.call(o);
|
|
51
|
-
if (o && typeof o.length === "number") return {
|
|
52
|
-
next: function () {
|
|
53
|
-
if (o && i >= o.length) o = void 0;
|
|
54
|
-
return { value: o && o[i++], done: !o };
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
58
|
-
};
|
|
59
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
60
13
|
exports.LibUSBException = exports.useUsbDkBackend = exports.getDeviceList = exports.Transfer = exports.Device = exports.webusb = exports.findBySerialNumber = exports.findByIds = exports.usb = void 0;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
14
|
+
const util_1 = require("util");
|
|
15
|
+
const webusb_1 = require("./webusb");
|
|
16
|
+
const usb = require("./usb");
|
|
64
17
|
exports.usb = usb;
|
|
65
18
|
/**
|
|
66
19
|
* Convenience method to get the first device with the specified VID and PID, or `undefined` if no such device is present.
|
|
67
20
|
* @param vid
|
|
68
21
|
* @param pid
|
|
69
22
|
*/
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return devices.find(
|
|
23
|
+
const findByIds = (vid, pid) => {
|
|
24
|
+
const devices = usb.getDeviceList();
|
|
25
|
+
return devices.find(item => item.deviceDescriptor.idVendor === vid && item.deviceDescriptor.idProduct === pid);
|
|
73
26
|
};
|
|
74
27
|
exports.findByIds = findByIds;
|
|
75
28
|
/**
|
|
76
29
|
* Convenience method to get the device with the specified serial number, or `undefined` if no such device is present.
|
|
77
30
|
* @param serialNumber
|
|
78
31
|
*/
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (
|
|
99
|
-
device.
|
|
100
|
-
}
|
|
101
|
-
getStringDescriptor = util_1.promisify(device.getStringDescriptor).bind(device);
|
|
102
|
-
return [4 /*yield*/, getStringDescriptor(device.deviceDescriptor.iSerialNumber)];
|
|
103
|
-
case 4:
|
|
104
|
-
buffer = _c.sent();
|
|
105
|
-
if (buffer && buffer.toString() === serialNumber) {
|
|
106
|
-
return [2 /*return*/, device];
|
|
107
|
-
}
|
|
108
|
-
return [3 /*break*/, 7];
|
|
109
|
-
case 5:
|
|
110
|
-
_a = _c.sent();
|
|
111
|
-
return [3 /*break*/, 7];
|
|
112
|
-
case 6:
|
|
113
|
-
try {
|
|
114
|
-
if (opened(device)) {
|
|
115
|
-
device.close();
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
catch (_d) {
|
|
119
|
-
// Ignore any errors, device may be a system device or inaccessible
|
|
120
|
-
}
|
|
121
|
-
return [7 /*endfinally*/];
|
|
122
|
-
case 7:
|
|
123
|
-
devices_1_1 = devices_1.next();
|
|
124
|
-
return [3 /*break*/, 2];
|
|
125
|
-
case 8: return [3 /*break*/, 11];
|
|
126
|
-
case 9:
|
|
127
|
-
e_1_1 = _c.sent();
|
|
128
|
-
e_1 = { error: e_1_1 };
|
|
129
|
-
return [3 /*break*/, 11];
|
|
130
|
-
case 10:
|
|
131
|
-
try {
|
|
132
|
-
if (devices_1_1 && !devices_1_1.done && (_b = devices_1.return)) _b.call(devices_1);
|
|
32
|
+
const findBySerialNumber = async (serialNumber) => {
|
|
33
|
+
const devices = usb.getDeviceList();
|
|
34
|
+
const opened = (device) => !!device.interfaces;
|
|
35
|
+
for (const device of devices) {
|
|
36
|
+
try {
|
|
37
|
+
if (!opened(device)) {
|
|
38
|
+
device.open();
|
|
39
|
+
}
|
|
40
|
+
const getStringDescriptor = util_1.promisify(device.getStringDescriptor).bind(device);
|
|
41
|
+
const buffer = await getStringDescriptor(device.deviceDescriptor.iSerialNumber);
|
|
42
|
+
if (buffer && buffer.toString() === serialNumber) {
|
|
43
|
+
return device;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// Ignore any errors, device may be a system device or inaccessible
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
try {
|
|
51
|
+
if (opened(device)) {
|
|
52
|
+
device.close();
|
|
133
53
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
// Ignore any errors, device may be a system device or inaccessible
|
|
57
|
+
}
|
|
137
58
|
}
|
|
138
|
-
}
|
|
139
|
-
|
|
59
|
+
}
|
|
60
|
+
return undefined;
|
|
61
|
+
};
|
|
140
62
|
exports.findBySerialNumber = findBySerialNumber;
|
|
141
|
-
|
|
63
|
+
const webusb = new webusb_1.WebUSB();
|
|
142
64
|
exports.webusb = webusb;
|
|
143
65
|
// Usb types
|
|
144
66
|
var usb_1 = require("./usb");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../tsc/index.ts"],"names":[],"mappings":"
|
|
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AChB,MAAM,CAAC,KAAK,EAAE,CAAC;iBAClB;aACJ;YAAC,MAAM;gBACJ,mEAAmE;aACtE;SACJ;KACJ;IAED,OAAO,SAAS,CAAC;AACrB,CAAC,CAAC;AAUE,gDAAkB;AARtB,MAAM,MAAM,GAAG,IAAI,eAAM,EAAE,CAAC;AAWxB,wBAAM;AAGV,YAAY;AACZ,6BAAwG;AAA/F,6FAAA,MAAM,OAAA;AAAE,+FAAA,QAAQ,OAAA;AAAgB,oGAAA,aAAa,OAAA;AAAE,sGAAA,eAAe,OAAA;AAAE,sGAAA,eAAe,OAAA;AACxF,mDAAiC;AACjC,oDAAkC;AAClC,iDAA+B;AAC/B,kDAAgC;AAEhC,eAAe;AACf,2CAAyB;AACzB,yDAAuC"}
|
package/dist/usb/bindings.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
// Eric Brody <https://github.com/underscorebrody>
|
|
4
4
|
// Rob Moran <https://github.com/thegecko>
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
6
|
+
const path_1 = require("path");
|
|
7
7
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
8
|
-
|
|
8
|
+
const usb = require('node-gyp-build')(path_1.join(__dirname, '..', '..'));
|
|
9
9
|
module.exports = usb;
|
|
10
10
|
//# sourceMappingURL=bindings.js.map
|
package/dist/usb/bindings.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bindings.js","sourceRoot":"","sources":["../../tsc/usb/bindings.ts"],"names":[],"mappings":";AAAA,+CAA+C;AAC/C,mDAAmD;AACnD,2CAA2C;;AAE3C
|
|
1
|
+
{"version":3,"file":"bindings.js","sourceRoot":"","sources":["../../tsc/usb/bindings.ts"],"names":[],"mappings":";AAAA,+CAA+C;AAC/C,mDAAmD;AACnD,2CAA2C;;AAE3C,+BAA4B;AAG5B,uDAAuD;AACvD,MAAM,GAAG,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC,WAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AACnE,MAAM,CAAC,OAAO,GAAG,GAAG,CAAC"}
|
package/dist/usb/capability.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Capability = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
class Capability {
|
|
5
|
+
constructor(device, id) {
|
|
6
6
|
this.device = device;
|
|
7
7
|
this.id = id;
|
|
8
8
|
if (!device._bosDescriptor) {
|
|
@@ -12,7 +12,6 @@ var Capability = /** @class */ (function () {
|
|
|
12
12
|
this.type = this.descriptor.bDevCapabilityType;
|
|
13
13
|
this.data = this.descriptor.dev_capability_data;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
}());
|
|
15
|
+
}
|
|
17
16
|
exports.Capability = Capability;
|
|
18
17
|
//# sourceMappingURL=capability.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capability.js","sourceRoot":"","sources":["../../tsc/usb/capability.ts"],"names":[],"mappings":";;;AAGA;
|
|
1
|
+
{"version":3,"file":"capability.js","sourceRoot":"","sources":["../../tsc/usb/capability.ts"],"names":[],"mappings":";;;AAGA,MAAa,UAAU;IAUnB,YAAsB,MAAc,EAAY,EAAU;QAApC,WAAM,GAAN,MAAM,CAAQ;QAAY,OAAE,GAAF,EAAE,CAAQ;QACtD,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE;YACxB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;SAC9C;QACD,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,cAAc,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC9D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,kBAAkB,CAAC;QAC/C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC;IACpD,CAAC;CACJ;AAlBD,gCAkBC"}
|