usb 2.8.0 → 2.8.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 +11 -0
- package/README.md +8 -6
- package/dist/usb/bindings.d.ts +4 -0
- package/dist/usb/index.js +7 -3
- package/dist/usb/index.js.map +1 -1
- package/dist/webusb/index.d.ts +3 -3
- package/dist/webusb/index.js +49 -39
- package/dist/webusb/index.js.map +1 -1
- package/package.json +1 -1
- package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
- package/prebuilds/win32-ia32/node.napi.node +0 -0
- package/prebuilds/win32-x64/node.napi.node +0 -0
- package/test/webusb.coffee +12 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.8.2] - 2023-03-06
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- Added new `usb.pollHotplug` setting to allow users to force hotplug detection using polling - [`576`](https://github.com/node-usb/node-usb/pull/576) ([Rob Moran](https://github.com/thegecko))
|
|
7
|
+
|
|
8
|
+
## [2.8.1] - 2023-02-26
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- Reworked WebUSB options.allowedDevices to allow pre-authorisation using any filter - [`574`](https://github.com/node-usb/node-usb/pull/574) ([Rob Moran](https://github.com/thegecko))
|
|
12
|
+
- Updated requestDevice errors to use correct names - [`575`](https://github.com/node-usb/node-usb/pull/575) ([Rob Moran](https://github.com/thegecko))
|
|
13
|
+
|
|
3
14
|
## [2.8.0] - 2023-02-11
|
|
4
15
|
|
|
5
16
|
### Changed
|
package/README.md
CHANGED
|
@@ -136,9 +136,7 @@ import { webusb } from 'usb';
|
|
|
136
136
|
filters: [{}]
|
|
137
137
|
})
|
|
138
138
|
|
|
139
|
-
|
|
140
|
-
console.log(device); // WebUSB device
|
|
141
|
-
}
|
|
139
|
+
console.log(device); // WebUSB device
|
|
142
140
|
})();
|
|
143
141
|
```
|
|
144
142
|
|
|
@@ -157,9 +155,7 @@ import { WebUSB } from 'usb';
|
|
|
157
155
|
filters: [{}]
|
|
158
156
|
})
|
|
159
157
|
|
|
160
|
-
|
|
161
|
-
console.log(device); // WebUSB device
|
|
162
|
-
}
|
|
158
|
+
console.log(device); // WebUSB device
|
|
163
159
|
})();
|
|
164
160
|
```
|
|
165
161
|
|
|
@@ -294,6 +290,12 @@ Legacy usb object.
|
|
|
294
290
|
#### usb.LIBUSB_*
|
|
295
291
|
Constant properties from libusb
|
|
296
292
|
|
|
293
|
+
#### usb.getDeviceList()
|
|
294
|
+
Return a list of legacy `Device` objects for the USB devices attached to the system.
|
|
295
|
+
|
|
296
|
+
#### usb.pollHotplug
|
|
297
|
+
Force polling loop for hotplug events.
|
|
298
|
+
|
|
297
299
|
#### usb.setDebugLevel(level : int)
|
|
298
300
|
Set the libusb debug level (between 0 and 4)
|
|
299
301
|
|
package/dist/usb/bindings.d.ts
CHANGED
|
@@ -4,6 +4,10 @@ import type { DeviceDescriptor, ConfigDescriptor, BosDescriptor } from './descri
|
|
|
4
4
|
* Return a list of `Device` objects for the USB devices attached to the system.
|
|
5
5
|
*/
|
|
6
6
|
export declare function getDeviceList(): Device[];
|
|
7
|
+
/**
|
|
8
|
+
* Force polling loop for hotplug events
|
|
9
|
+
*/
|
|
10
|
+
export declare let pollHotplug: boolean;
|
|
7
11
|
export declare const INIT_ERROR: number;
|
|
8
12
|
export declare class LibUSBException extends Error {
|
|
9
13
|
errno: number;
|
package/dist/usb/index.js
CHANGED
|
@@ -18,14 +18,16 @@ if (usb.INIT_ERROR) {
|
|
|
18
18
|
console.warn('Failed to initialize libusb.');
|
|
19
19
|
}
|
|
20
20
|
Object.setPrototypeOf(usb, events_1.EventEmitter.prototype);
|
|
21
|
+
Object.defineProperty(usb, 'pollHotplug', {
|
|
22
|
+
value: false,
|
|
23
|
+
writable: true
|
|
24
|
+
});
|
|
21
25
|
Object.getOwnPropertyNames(device_1.ExtendedDevice.prototype).forEach(function (name) {
|
|
22
26
|
Object.defineProperty(usb.Device.prototype, name, Object.getOwnPropertyDescriptor(device_1.ExtendedDevice.prototype, name) || Object.create(null));
|
|
23
27
|
});
|
|
24
|
-
// Hotplug support
|
|
25
|
-
var hotplugSupported = usb._supportedHotplugEvents();
|
|
26
28
|
// Devices delta support for non-libusb hotplug events
|
|
27
|
-
// This methd needs to be used for attach/detach IDs (hotplugSupportType === 2) rather than a lookup because vid/pid are not unique
|
|
28
29
|
var hotPlugDevices = new Set();
|
|
30
|
+
// This method needs to be used for attach/detach IDs (hotplugSupportType === 2) rather than a lookup because vid/pid are not unique
|
|
29
31
|
var emitHotplugEvents = function () {
|
|
30
32
|
var e_1, _a, e_2, _b;
|
|
31
33
|
// Collect current devices
|
|
@@ -80,7 +82,9 @@ var pollHotplug = function (start) {
|
|
|
80
82
|
setTimeout(function () { return pollHotplug(); }, 500);
|
|
81
83
|
};
|
|
82
84
|
// Hotplug control
|
|
85
|
+
var hotplugSupported = 0;
|
|
83
86
|
var startHotplug = function () {
|
|
87
|
+
hotplugSupported = usb.pollHotplug ? 0 : usb._supportedHotplugEvents();
|
|
84
88
|
if (hotplugSupported !== 1) {
|
|
85
89
|
// Collect initial devices when not using libusb
|
|
86
90
|
hotPlugDevices = new Set(usb.getDeviceList());
|
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;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../tsc/usb/index.ts"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AW,GAAG;IAChB,IAAI,gBAAgB,EAAE;QAClB,yBAAyB;QACzB,GAAG,CAAC,qBAAqB,EAAE,CAAC;QAE5B,IAAI,gBAAgB,KAAK,CAAC,EAAE;YACxB,oCAAoC;YACpC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC;YACxC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC;SAC3C;KACJ;SAAM;QACH,eAAe;QACf,cAAc,GAAG,KAAK,CAAC;KAC1B;AACL,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,YAAY,EAAE,CAAC;KAClB;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,WAAW,EAAE,CAAC;KACjB;AACL,CAAC,CAAC,CAAC;AAEH,iBAAS,GAAG,CAAC"}
|
package/dist/webusb/index.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export declare class WebUSB implements USB {
|
|
|
32
32
|
private options;
|
|
33
33
|
protected emitter: EventEmitter;
|
|
34
34
|
protected knownDevices: Map<usb.Device, WebUSBDevice>;
|
|
35
|
-
protected
|
|
35
|
+
protected authorisedDevices: Set<USBDevice>;
|
|
36
36
|
constructor(options?: USBOptions);
|
|
37
37
|
private _onconnect;
|
|
38
38
|
set onconnect(fn: (ev: USBConnectionEvent) => void);
|
|
@@ -56,7 +56,7 @@ export declare class WebUSB implements USB {
|
|
|
56
56
|
getDevices(): Promise<USBDevice[]>;
|
|
57
57
|
private loadDevices;
|
|
58
58
|
private getWebDevice;
|
|
59
|
-
private
|
|
59
|
+
private quickFilter;
|
|
60
60
|
private filterDevice;
|
|
61
|
-
private
|
|
61
|
+
private isAuthorisedDevice;
|
|
62
62
|
}
|
package/dist/webusb/index.js
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
2
17
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
18
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
19
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -82,6 +97,15 @@ var getWebUsb = function () {
|
|
|
82
97
|
return new WebUSB();
|
|
83
98
|
};
|
|
84
99
|
exports.getWebUsb = getWebUsb;
|
|
100
|
+
var NamedError = /** @class */ (function (_super) {
|
|
101
|
+
__extends(NamedError, _super);
|
|
102
|
+
function NamedError(message, name) {
|
|
103
|
+
var _this = _super.call(this, message) || this;
|
|
104
|
+
_this.name = name;
|
|
105
|
+
return _this;
|
|
106
|
+
}
|
|
107
|
+
return NamedError;
|
|
108
|
+
}(Error));
|
|
85
109
|
var WebUSB = /** @class */ (function () {
|
|
86
110
|
function WebUSB(options) {
|
|
87
111
|
var _this = this;
|
|
@@ -89,7 +113,7 @@ var WebUSB = /** @class */ (function () {
|
|
|
89
113
|
this.options = options;
|
|
90
114
|
this.emitter = new events_1.EventEmitter();
|
|
91
115
|
this.knownDevices = new Map();
|
|
92
|
-
this.
|
|
116
|
+
this.authorisedDevices = new Set();
|
|
93
117
|
var deviceConnectCallback = function (device) { return __awaiter(_this, void 0, void 0, function () {
|
|
94
118
|
var webDevice, event_1;
|
|
95
119
|
return __generator(this, function (_a) {
|
|
@@ -98,7 +122,7 @@ var WebUSB = /** @class */ (function () {
|
|
|
98
122
|
case 1:
|
|
99
123
|
webDevice = _a.sent();
|
|
100
124
|
// When connected, emit an event if it is an allowed device
|
|
101
|
-
if (webDevice && this.
|
|
125
|
+
if (webDevice && this.isAuthorisedDevice(webDevice)) {
|
|
102
126
|
event_1 = {
|
|
103
127
|
type: 'connect',
|
|
104
128
|
device: webDevice
|
|
@@ -115,7 +139,7 @@ var WebUSB = /** @class */ (function () {
|
|
|
115
139
|
// When disconnected, emit an event if the device was a known allowed device
|
|
116
140
|
if (this.knownDevices.has(device)) {
|
|
117
141
|
webDevice = this.knownDevices.get(device);
|
|
118
|
-
if (webDevice && this.
|
|
142
|
+
if (webDevice && this.isAuthorisedDevice(webDevice)) {
|
|
119
143
|
event_2 = {
|
|
120
144
|
type: 'disconnect',
|
|
121
145
|
device: webDevice
|
|
@@ -231,9 +255,9 @@ var WebUSB = /** @class */ (function () {
|
|
|
231
255
|
return [4 /*yield*/, this.loadDevices(options.filters)];
|
|
232
256
|
case 1:
|
|
233
257
|
devices = _b.sent();
|
|
234
|
-
devices = devices.filter(function (device) { return _this.filterDevice(
|
|
258
|
+
devices = devices.filter(function (device) { return _this.filterDevice(device, options.filters); });
|
|
235
259
|
if (devices.length === 0) {
|
|
236
|
-
throw new
|
|
260
|
+
throw new NamedError('Failed to execute \'requestDevice\' on \'USB\': No device selected.', 'NotFoundError');
|
|
237
261
|
}
|
|
238
262
|
_b.label = 2;
|
|
239
263
|
case 2:
|
|
@@ -249,19 +273,13 @@ var WebUSB = /** @class */ (function () {
|
|
|
249
273
|
case 5:
|
|
250
274
|
device = _a;
|
|
251
275
|
if (!device) {
|
|
252
|
-
throw new
|
|
253
|
-
}
|
|
254
|
-
if (!this.isAllowedDevice(device)) {
|
|
255
|
-
this.allowedDevices.push({
|
|
256
|
-
vendorId: device.vendorId,
|
|
257
|
-
productId: device.productId,
|
|
258
|
-
serialNumber: device.serialNumber
|
|
259
|
-
});
|
|
276
|
+
throw new NamedError('Failed to execute \'requestDevice\' on \'USB\': No device selected.', 'NotFoundError');
|
|
260
277
|
}
|
|
278
|
+
this.authorisedDevices.add(device);
|
|
261
279
|
return [2 /*return*/, device];
|
|
262
280
|
case 6:
|
|
263
281
|
error_1 = _b.sent();
|
|
264
|
-
throw new
|
|
282
|
+
throw new NamedError('Failed to execute \'requestDevice\' on \'USB\': No device selected.', 'NotFoundError');
|
|
265
283
|
case 7: return [2 /*return*/];
|
|
266
284
|
}
|
|
267
285
|
});
|
|
@@ -278,18 +296,11 @@ var WebUSB = /** @class */ (function () {
|
|
|
278
296
|
return __generator(this, function (_a) {
|
|
279
297
|
switch (_a.label) {
|
|
280
298
|
case 0:
|
|
281
|
-
|
|
282
|
-
// Create pre-filters
|
|
283
|
-
preFilters = this.allowedDevices.map(function (device) { return ({
|
|
284
|
-
vendorId: device.vendorId || undefined,
|
|
285
|
-
productId: device.productId || undefined,
|
|
286
|
-
serialNumber: device.serialNumber || undefined
|
|
287
|
-
}); });
|
|
288
|
-
}
|
|
299
|
+
preFilters = this.options.allowAllDevices ? undefined : this.options.allowedDevices;
|
|
289
300
|
return [4 /*yield*/, this.loadDevices(preFilters)];
|
|
290
301
|
case 1:
|
|
291
302
|
devices = _a.sent();
|
|
292
|
-
return [2 /*return*/, devices.filter(function (device) { return _this.
|
|
303
|
+
return [2 /*return*/, devices.filter(function (device) { return _this.isAuthorisedDevice(device); })];
|
|
293
304
|
}
|
|
294
305
|
});
|
|
295
306
|
});
|
|
@@ -303,7 +314,7 @@ var WebUSB = /** @class */ (function () {
|
|
|
303
314
|
case 0:
|
|
304
315
|
devices = usb.getDeviceList();
|
|
305
316
|
// Pre-filter devices
|
|
306
|
-
devices = this.
|
|
317
|
+
devices = this.quickFilter(devices, preFilters);
|
|
307
318
|
refreshedKnownDevices = new Map();
|
|
308
319
|
_b.label = 1;
|
|
309
320
|
case 1:
|
|
@@ -370,7 +381,8 @@ var WebUSB = /** @class */ (function () {
|
|
|
370
381
|
});
|
|
371
382
|
});
|
|
372
383
|
};
|
|
373
|
-
|
|
384
|
+
// Undertake quick filter on devices before creating WebUSB devices if possible
|
|
385
|
+
WebUSB.prototype.quickFilter = function (devices, preFilters) {
|
|
374
386
|
if (!preFilters || !preFilters.length) {
|
|
375
387
|
return devices;
|
|
376
388
|
}
|
|
@@ -382,15 +394,17 @@ var WebUSB = /** @class */ (function () {
|
|
|
382
394
|
// Product
|
|
383
395
|
if (filter.productId && filter.productId !== device.deviceDescriptor.idProduct)
|
|
384
396
|
return false;
|
|
397
|
+
// Ignore Class, Subclass and Protocol as these need to check interfaces, too
|
|
385
398
|
// Ignore serial number for node-usb as it requires device connection
|
|
386
399
|
return true;
|
|
387
400
|
}); });
|
|
388
401
|
};
|
|
389
|
-
|
|
390
|
-
|
|
402
|
+
// Filter WebUSB devices
|
|
403
|
+
WebUSB.prototype.filterDevice = function (device, filters) {
|
|
404
|
+
if (!filters || !filters.length) {
|
|
391
405
|
return true;
|
|
392
406
|
}
|
|
393
|
-
return
|
|
407
|
+
return filters.some(function (filter) {
|
|
394
408
|
// Vendor
|
|
395
409
|
if (filter.vendorId && filter.vendorId !== device.vendorId)
|
|
396
410
|
return false;
|
|
@@ -434,21 +448,17 @@ var WebUSB = /** @class */ (function () {
|
|
|
434
448
|
return true;
|
|
435
449
|
});
|
|
436
450
|
};
|
|
437
|
-
|
|
451
|
+
// Check whether a device is authorised
|
|
452
|
+
WebUSB.prototype.isAuthorisedDevice = function (device) {
|
|
453
|
+
// All devices are authorised
|
|
438
454
|
if (this.options.allowAllDevices) {
|
|
439
455
|
return true;
|
|
440
456
|
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
&& device1.serialNumber === device2.serialNumber);
|
|
445
|
-
};
|
|
446
|
-
for (var i in this.allowedDevices) {
|
|
447
|
-
if (isSameDevice(device, this.allowedDevices[i])) {
|
|
448
|
-
return true;
|
|
449
|
-
}
|
|
457
|
+
// Check any allowed device filters
|
|
458
|
+
if (this.options.allowedDevices && this.filterDevice(device, this.options.allowedDevices)) {
|
|
459
|
+
return true;
|
|
450
460
|
}
|
|
451
|
-
return
|
|
461
|
+
return this.authorisedDevices.has(device);
|
|
452
462
|
};
|
|
453
463
|
return WebUSB;
|
|
454
464
|
}());
|
package/dist/webusb/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../tsc/webusb/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../tsc/webusb/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4BAA8B;AAC9B,iCAAsC;AACtC,iDAA+C;AA2B/C;;GAEG;AACI,IAAM,SAAS,GAAG;IACrB,IAAI,SAAS,IAAI,SAAS,CAAC,GAAG,EAAE;QAC5B,OAAO,SAAS,CAAC,GAAG,CAAC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AM,CAAC,YAAY,IAAI,MAAM,CAAC,YAAY,KAAK,MAAM,CAAC,cAAc;gBAAE,OAAO,KAAK,CAAC;YAEvF,WAAW;YACX,IAAI,MAAM,CAAC,YAAY,IAAI,MAAM,CAAC,YAAY,KAAK,MAAM,CAAC,cAAc;gBAAE,OAAO,KAAK,CAAC;YAEvF,SAAS;YACT,IAAI,MAAM,CAAC,YAAY,IAAI,MAAM,CAAC,YAAY,KAAK,MAAM,CAAC,YAAY;gBAAE,OAAO,KAAK,CAAC;YAErF,OAAO,IAAI,CAAC;QAChB,CAAC,CAAC,CAAC;IACP,CAAC;IAED,uCAAuC;IAC/B,mCAAkB,GAA1B,UAA2B,MAAiB;QACxC,6BAA6B;QAC7B,IAAI,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE;YAC9B,OAAO,IAAI,CAAC;SACf;QAED,mCAAmC;QACnC,IAAI,IAAI,CAAC,OAAO,CAAC,cAAc,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE;YACvF,OAAO,IAAI,CAAC;SACf;QAED,OAAO,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9C,CAAC;IACL,aAAC;AAAD,CAAC,AAzTD,IAyTC;AAzTY,wBAAM"}
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/test/webusb.coffee
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
assert = require('assert')
|
|
2
2
|
util = require('util')
|
|
3
3
|
webusb = require('../').webusb
|
|
4
|
+
WebUSB = require('../').WebUSB
|
|
4
5
|
|
|
5
6
|
if typeof gc is 'function'
|
|
6
7
|
# running with --expose-gc, do a sweep between tests so valgrind blames the right one
|
|
@@ -10,6 +11,17 @@ describe 'WebUSB Module', ->
|
|
|
10
11
|
it 'should describe basic constants', ->
|
|
11
12
|
assert.notEqual(webusb, undefined, "webusb must be undefined")
|
|
12
13
|
|
|
14
|
+
describe 'allowedDevices', ->
|
|
15
|
+
it 'should not list any devices by default', ->
|
|
16
|
+
l = await webusb.getDevices()
|
|
17
|
+
assert.equal(l.length, 0)
|
|
18
|
+
|
|
19
|
+
it 'should list allowed devices', ->
|
|
20
|
+
customWebusb = new WebUSB({ allowedDevices: [{ vendorId: 0x59e3 }] })
|
|
21
|
+
l = await customWebusb.getDevices()
|
|
22
|
+
assert.equal(l.length, 1)
|
|
23
|
+
assert.notEqual(l[0], undefined)
|
|
24
|
+
|
|
13
25
|
describe 'requestDevice', ->
|
|
14
26
|
it 'should return a device', ->
|
|
15
27
|
device = await webusb.requestDevice({ filters: [{ vendorId: 0x59e3 }] });
|