usb 2.0.0-alpha.2 → 2.0.1
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 +1 -1
- package/CHANGELOG.md +81 -0
- package/README.md +570 -0
- package/binding.gyp +2 -2
- package/dist/usb/bindings.d.ts +13 -0
- package/dist/usb/bindings.js +2 -1
- package/dist/usb/bindings.js.map +1 -1
- package/dist/usb/index.js +86 -2
- package/dist/usb/index.js.map +1 -1
- package/dist/usb/interface.js.map +1 -1
- package/dist/webusb/index.d.ts +28 -19
- package/dist/webusb/index.js +152 -66
- package/dist/webusb/index.js.map +1 -1
- package/dist/webusb/webusb-device.d.ts +1 -1
- package/dist/webusb/webusb-device.js +9 -4
- package/dist/webusb/webusb-device.js.map +1 -1
- package/libusb/.private/pre-commit.sh +7 -1
- package/libusb/.travis.yml +49 -0
- package/libusb/AUTHORS +44 -3
- package/libusb/Brewfile +4 -0
- package/libusb/ChangeLog +74 -2
- package/libusb/README.md +32 -0
- package/libusb/TODO +1 -1
- package/libusb/Xcode/common.xcconfig +12 -0
- package/libusb/Xcode/config.h +25 -0
- package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +959 -1
- package/libusb/android/README +4 -2
- package/libusb/android/config.h +75 -0
- package/libusb/appveyor.yml +41 -0
- package/libusb/appveyor_cygwin.bat +11 -0
- package/libusb/appveyor_minGW.bat +19 -0
- package/libusb/autogen.sh +1 -1
- package/libusb/bootstrap.sh +3 -16
- package/libusb/configure.ac +108 -80
- package/libusb/doc/doxygen.cfg.in +1785 -739
- package/libusb/examples/Makefile.am +1 -1
- package/libusb/examples/dpfp.c +3 -1
- package/libusb/examples/dpfp_threaded.c +23 -10
- package/libusb/examples/ezusb.c +3 -3
- package/libusb/examples/ezusb.h +2 -2
- package/libusb/examples/fxload.c +31 -9
- package/libusb/examples/hotplugtest.c +35 -7
- package/libusb/examples/listdevs.c +3 -1
- package/libusb/examples/sam3u_benchmark.c +3 -3
- package/libusb/examples/testlibusb.c +277 -0
- package/libusb/examples/xusb.c +40 -34
- package/libusb/libusb/Makefile.am +49 -23
- package/libusb/libusb/core.c +855 -457
- package/libusb/libusb/descriptor.c +72 -78
- package/libusb/libusb/hotplug.c +122 -76
- package/libusb/libusb/hotplug.h +42 -25
- package/libusb/libusb/io.c +625 -390
- package/libusb/libusb/libusb-1.0.def +12 -0
- package/libusb/libusb/libusb.h +218 -150
- package/libusb/libusb/libusbi.h +346 -176
- package/libusb/libusb/os/darwin_usb.c +604 -319
- package/libusb/libusb/os/darwin_usb.h +61 -20
- package/libusb/libusb/os/haiku_pollfs.cpp +367 -0
- package/libusb/libusb/os/haiku_usb.h +113 -0
- package/libusb/libusb/os/haiku_usb_backend.cpp +533 -0
- package/libusb/libusb/os/haiku_usb_raw.cpp +267 -0
- package/libusb/libusb/os/haiku_usb_raw.h +188 -0
- package/libusb/libusb/os/linux_netlink.c +186 -146
- package/libusb/libusb/os/linux_udev.c +36 -14
- package/libusb/libusb/os/linux_usbfs.c +426 -225
- package/libusb/libusb/os/linux_usbfs.h +5 -3
- package/libusb/libusb/os/netbsd_usb.c +21 -77
- package/libusb/libusb/os/openbsd_usb.c +32 -115
- package/libusb/libusb/os/poll_posix.c +38 -5
- package/libusb/libusb/os/poll_posix.h +3 -0
- package/libusb/libusb/os/poll_windows.c +277 -626
- package/libusb/libusb/os/poll_windows.h +11 -44
- package/libusb/libusb/os/sunos_usb.c +1695 -0
- package/libusb/libusb/os/sunos_usb.h +80 -0
- package/libusb/libusb/os/threads_posix.c +24 -26
- package/libusb/libusb/os/threads_posix.h +73 -21
- package/libusb/libusb/os/threads_windows.c +71 -157
- package/libusb/libusb/os/threads_windows.h +68 -44
- package/libusb/libusb/os/wince_usb.c +276 -420
- package/libusb/libusb/os/wince_usb.h +23 -28
- package/libusb/libusb/os/windows_common.h +78 -58
- package/libusb/libusb/os/windows_nt_common.c +1010 -0
- package/libusb/libusb/os/windows_nt_common.h +110 -0
- package/libusb/libusb/os/windows_nt_shared_types.h +147 -0
- package/libusb/libusb/os/windows_usbdk.c +830 -0
- package/libusb/libusb/os/windows_usbdk.h +103 -0
- package/libusb/libusb/os/windows_winusb.c +4391 -0
- package/libusb/libusb/os/windows_winusb.h +783 -0
- package/libusb/libusb/strerror.c +41 -7
- package/libusb/libusb/sync.c +41 -13
- package/libusb/libusb/version.h +1 -1
- package/libusb/libusb/version_nano.h +1 -1
- package/libusb/libusb-1.0.pc.in +1 -1
- package/libusb/msvc/appveyor.bat +27 -0
- package/libusb/msvc/config.h +5 -4
- package/libusb/msvc/ddk_build.cmd +87 -43
- package/libusb/msvc/fxload_2010.vcxproj +24 -104
- package/libusb/msvc/fxload_2012.vcxproj +24 -107
- package/libusb/msvc/fxload_2013.vcxproj +24 -107
- package/libusb/msvc/fxload_2015.vcxproj +91 -0
- package/libusb/msvc/fxload_2017.vcxproj +114 -0
- package/libusb/msvc/fxload_sources +1 -1
- package/libusb/msvc/getopt_2010.vcxproj +16 -75
- package/libusb/msvc/getopt_2012.vcxproj +16 -79
- package/libusb/msvc/getopt_2013.vcxproj +16 -79
- package/libusb/msvc/getopt_2015.vcxproj +73 -0
- package/libusb/msvc/getopt_2017.vcxproj +98 -0
- package/libusb/msvc/getopt_sources +6 -2
- package/libusb/msvc/hotplugtest_2010.vcxproj +18 -99
- package/libusb/msvc/hotplugtest_2012.vcxproj +18 -102
- package/libusb/msvc/hotplugtest_2013.vcxproj +18 -102
- package/libusb/msvc/hotplugtest_2015.vcxproj +83 -0
- package/libusb/msvc/hotplugtest_2017.vcxproj +106 -0
- package/libusb/msvc/hotplugtest_sources +1 -1
- package/libusb/msvc/libusb_2005.sln +20 -20
- package/libusb/msvc/libusb_2010.sln +57 -46
- package/libusb/msvc/libusb_2012.sln +57 -46
- package/libusb/msvc/libusb_2013.sln +57 -50
- package/libusb/msvc/libusb_2015.sln +59 -52
- package/libusb/msvc/libusb_2017.sln +186 -0
- package/libusb/msvc/libusb_dll.dsp +2 -2
- package/libusb/msvc/libusb_dll_2005.vcproj +30 -2
- package/libusb/msvc/libusb_dll_2010.vcxproj +26 -90
- package/libusb/msvc/libusb_dll_2012.vcxproj +28 -96
- package/libusb/msvc/libusb_dll_2013.vcxproj +28 -96
- package/libusb/msvc/libusb_dll_2015.vcxproj +107 -0
- package/libusb/msvc/libusb_dll_2017.vcxproj +134 -0
- package/libusb/msvc/libusb_dll_wince.vcproj +9 -1
- package/libusb/msvc/libusb_sources +10 -5
- package/libusb/msvc/libusb_static.dsp +2 -2
- package/libusb/msvc/libusb_static_2005.vcproj +32 -4
- package/libusb/msvc/libusb_static_2010.vcxproj +24 -83
- package/libusb/msvc/libusb_static_2012.vcxproj +25 -87
- package/libusb/msvc/libusb_static_2013.vcxproj +25 -87
- package/libusb/msvc/libusb_static_2015.vcxproj +98 -0
- package/libusb/msvc/libusb_static_2017.vcxproj +117 -0
- package/libusb/msvc/libusb_static_wince.vcproj +20 -26
- package/libusb/msvc/libusb_wince.sln +88 -88
- package/libusb/msvc/listdevs_2010.vcxproj +16 -99
- package/libusb/msvc/listdevs_2012.vcxproj +16 -102
- package/libusb/msvc/listdevs_2013.vcxproj +16 -102
- package/libusb/msvc/listdevs_2015.vcxproj +83 -0
- package/libusb/msvc/listdevs_2017.vcxproj +106 -0
- package/libusb/msvc/listdevs_sources +2 -1
- package/libusb/msvc/stress_2010.vcxproj +20 -101
- package/libusb/msvc/stress_2012.vcxproj +20 -104
- package/libusb/msvc/stress_2013.vcxproj +20 -104
- package/libusb/msvc/stress_2015.vcxproj +87 -0
- package/libusb/msvc/stress_2017.vcxproj +110 -0
- package/libusb/msvc/stress_sources +21 -0
- package/libusb/msvc/testlibusb_2010.vcxproj +82 -0
- package/libusb/msvc/testlibusb_2012.vcxproj +83 -0
- package/libusb/msvc/testlibusb_2013.vcxproj +83 -0
- package/libusb/msvc/testlibusb_2015.vcxproj +83 -0
- package/libusb/msvc/testlibusb_2017.vcxproj +106 -0
- package/libusb/msvc/testlibusb_sources +20 -0
- package/libusb/msvc/xusb_2010.vcxproj +17 -98
- package/libusb/msvc/xusb_2012.vcxproj +17 -101
- package/libusb/msvc/xusb_2013.vcxproj +17 -101
- package/libusb/msvc/xusb_2015.vcxproj +83 -0
- package/libusb/msvc/xusb_2017.vcxproj +106 -0
- package/libusb/msvc/xusb_sources +1 -1
- package/libusb/tests/stress.c +2 -2
- package/libusb/tests/testlib.c +0 -4
- package/libusb/travis-autogen.sh +39 -0
- package/libusb.gypi +13 -2
- package/package.json +23 -13
- 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 +7 -7
- package/src/node_usb.cc +43 -1
- package/src/uv_async_queue.h +33 -25
- package/test/usb.coffee +6 -0
- package/tsc/index.ts +1 -1
- package/tsc/usb/bindings.ts +19 -1
- package/tsc/usb/index.ts +67 -19
- package/tsc/usb/interface.ts +2 -2
- package/tsc/webusb/index.ts +187 -75
- package/tsc/webusb/webusb-device.ts +19 -15
- package/.github/workflows/prebuild.yml +0 -48
- package/Readme.md +0 -339
- package/dist/webusb/typed-event-target.d.ts +0 -11
- package/dist/webusb/typed-event-target.js +0 -21
- package/dist/webusb/typed-event-target.js.map +0 -1
- package/docs/assets/css/main.css +0 -2660
- package/docs/assets/images/icons.png +0 -0
- package/docs/assets/images/icons@2x.png +0 -0
- package/docs/assets/images/widgets.png +0 -0
- package/docs/assets/images/widgets@2x.png +0 -0
- package/docs/assets/js/main.js +0 -248
- package/docs/assets/js/search.js +0 -1
- package/docs/classes/usb_bindings.device.html +0 -1338
- package/docs/classes/usb_bindings.libusbexception.html +0 -234
- package/docs/classes/usb_bindings.transfer.html +0 -344
- package/docs/classes/usb_capability.capability.html +0 -297
- package/docs/classes/usb_device.extendeddevice.html +0 -766
- package/docs/classes/usb_endpoint.endpoint.html +0 -472
- package/docs/classes/usb_endpoint.inendpoint.html +0 -766
- package/docs/classes/usb_endpoint.outendpoint.html +0 -582
- package/docs/classes/usb_interface.interface.html +0 -648
- package/docs/classes/webusb.webusb-1.html +0 -615
- package/docs/classes/webusb_mutex.mutex.html +0 -270
- package/docs/classes/webusb_typed_event_target.typedeventtarget.html +0 -443
- package/docs/classes/webusb_webusb_device.webusbdevice.html +0 -904
- package/docs/index.html +0 -500
- package/docs/interfaces/usb.deviceevents.html +0 -242
- package/docs/interfaces/usb_descriptors.bosdescriptor.html +0 -293
- package/docs/interfaces/usb_descriptors.capabilitydescriptor.html +0 -274
- package/docs/interfaces/usb_descriptors.configdescriptor.html +0 -388
- package/docs/interfaces/usb_descriptors.devicedescriptor.html +0 -464
- package/docs/interfaces/usb_descriptors.endpointdescriptor.html +0 -370
- package/docs/interfaces/usb_descriptors.interfacedescriptor.html +0 -407
- package/docs/interfaces/webusb.usboptions.html +0 -226
- package/docs/modules/index.html +0 -304
- package/docs/modules/usb.html +0 -173
- package/docs/modules/usb_bindings.html +0 -2248
- package/docs/modules/usb_capability.html +0 -156
- package/docs/modules/usb_descriptors.html +0 -176
- package/docs/modules/usb_device.html +0 -156
- package/docs/modules/usb_endpoint.html +0 -164
- package/docs/modules/usb_interface.html +0 -156
- package/docs/modules/webusb.html +0 -165
- package/docs/modules/webusb_mutex.html +0 -156
- package/docs/modules/webusb_typed_event_target.html +0 -156
- package/docs/modules/webusb_webusb_device.html +0 -156
- package/docs/modules.html +0 -156
- package/libusb/INSTALL +0 -234
- package/libusb/README +0 -28
- package/libusb/libusb/os/windows_usb.c +0 -5347
- package/libusb/libusb/os/windows_usb.h +0 -971
- package/libusb/msvc/fxload_2010.vcxproj.filters +0 -25
- package/libusb/msvc/fxload_2012.vcxproj.filters +0 -25
- package/libusb/msvc/getopt_2010.vcxproj.filters +0 -26
- package/libusb/msvc/getopt_2012.vcxproj.filters +0 -26
- package/libusb/msvc/hotplugtest_2010.vcxproj.filters +0 -14
- package/libusb/msvc/hotplugtest_2012.vcxproj.filters +0 -14
- package/libusb/msvc/libusb_dll_2010.vcxproj.filters +0 -81
- package/libusb/msvc/libusb_dll_2012.vcxproj.filters +0 -84
- package/libusb/msvc/libusb_static_2010.vcxproj.filters +0 -74
- package/libusb/msvc/libusb_static_2012.vcxproj.filters +0 -74
- package/libusb/msvc/listdevs_2010.vcxproj.filters +0 -14
- package/libusb/msvc/listdevs_2012.vcxproj.filters +0 -14
- package/libusb/msvc/stress_2010.vcxproj.filters +0 -25
- package/libusb/msvc/stress_2012.vcxproj.filters +0 -25
- package/libusb/msvc/xusb_2010.vcxproj.filters +0 -14
- package/libusb/msvc/xusb_2012.vcxproj.filters +0 -14
- package/tsc/webusb/typed-event-target.ts +0 -23
package/dist/usb/bindings.js
CHANGED
|
@@ -3,7 +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
|
+
var path_1 = require("path");
|
|
6
7
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
7
|
-
var usb = require('
|
|
8
|
+
var usb = require('node-gyp-build')(path_1.join(__dirname, '..', '..'));
|
|
8
9
|
module.exports = usb;
|
|
9
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;;
|
|
1
|
+
{"version":3,"file":"bindings.js","sourceRoot":"","sources":["../../tsc/usb/bindings.ts"],"names":[],"mappings":";AAAA,+CAA+C;AAC/C,mDAAmD;AACnD,2CAA2C;;AAE3C,6BAA4B;AAG5B,uDAAuD;AACvD,IAAM,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/index.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __values = (this && this.__values) || function(o) {
|
|
3
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
|
+
if (m) return m.call(o);
|
|
5
|
+
if (o && typeof o.length === "number") return {
|
|
6
|
+
next: function () {
|
|
7
|
+
if (o && i >= o.length) o = void 0;
|
|
8
|
+
return { value: o && o[i++], done: !o };
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
+
};
|
|
2
13
|
var events_1 = require("events");
|
|
3
14
|
var device_1 = require("./device");
|
|
4
15
|
var usb = require("./bindings");
|
|
@@ -10,13 +21,81 @@ Object.setPrototypeOf(usb, events_1.EventEmitter.prototype);
|
|
|
10
21
|
Object.getOwnPropertyNames(device_1.ExtendedDevice.prototype).forEach(function (name) {
|
|
11
22
|
Object.defineProperty(usb.Device.prototype, name, Object.getOwnPropertyDescriptor(device_1.ExtendedDevice.prototype, name) || Object.create(null));
|
|
12
23
|
});
|
|
24
|
+
// Polling mechanism for discovering device changes until this is fixed:
|
|
25
|
+
// https://github.com/libusb/libusb/issues/86
|
|
26
|
+
var pollTimeout = 500;
|
|
27
|
+
var hotplugSupported = usb._getLibusbCapability(usb.LIBUSB_CAP_HAS_HOTPLUG) > 0;
|
|
28
|
+
var pollingHotplug = false;
|
|
29
|
+
var pollDevices = [];
|
|
30
|
+
var pollHotplug = function (start) {
|
|
31
|
+
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
|
+
var devices = usb.getDeviceList();
|
|
40
|
+
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
|
+
try {
|
|
48
|
+
// Find attached devices
|
|
49
|
+
for (var devices_1 = __values(devices), devices_1_1 = devices_1.next(); !devices_1_1.done; devices_1_1 = devices_1.next()) {
|
|
50
|
+
var device = devices_1_1.value;
|
|
51
|
+
_loop_1(device);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
55
|
+
finally {
|
|
56
|
+
try {
|
|
57
|
+
if (devices_1_1 && !devices_1_1.done && (_a = devices_1.return)) _a.call(devices_1);
|
|
58
|
+
}
|
|
59
|
+
finally { if (e_1) throw e_1.error; }
|
|
60
|
+
}
|
|
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
|
+
try {
|
|
68
|
+
// Find detached devices
|
|
69
|
+
for (var pollDevices_1 = __values(pollDevices), pollDevices_1_1 = pollDevices_1.next(); !pollDevices_1_1.done; pollDevices_1_1 = pollDevices_1.next()) {
|
|
70
|
+
var device = pollDevices_1_1.value;
|
|
71
|
+
_loop_2(device);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
75
|
+
finally {
|
|
76
|
+
try {
|
|
77
|
+
if (pollDevices_1_1 && !pollDevices_1_1.done && (_b = pollDevices_1.return)) _b.call(pollDevices_1);
|
|
78
|
+
}
|
|
79
|
+
finally { if (e_2) throw e_2.error; }
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
pollDevices = devices;
|
|
83
|
+
setTimeout(function () {
|
|
84
|
+
pollHotplug();
|
|
85
|
+
}, pollTimeout);
|
|
86
|
+
};
|
|
13
87
|
usb.on('newListener', function (event) {
|
|
14
88
|
if (event !== 'attach' && event !== 'detach') {
|
|
15
89
|
return;
|
|
16
90
|
}
|
|
17
91
|
var listenerCount = usb.listenerCount('attach') + usb.listenerCount('detach');
|
|
18
92
|
if (listenerCount === 0) {
|
|
19
|
-
|
|
93
|
+
if (hotplugSupported) {
|
|
94
|
+
usb._enableHotplugEvents();
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
pollHotplug(true);
|
|
98
|
+
}
|
|
20
99
|
}
|
|
21
100
|
});
|
|
22
101
|
usb.on('removeListener', function (event) {
|
|
@@ -25,7 +104,12 @@ usb.on('removeListener', function (event) {
|
|
|
25
104
|
}
|
|
26
105
|
var listenerCount = usb.listenerCount('attach') + usb.listenerCount('detach');
|
|
27
106
|
if (listenerCount === 0) {
|
|
28
|
-
|
|
107
|
+
if (hotplugSupported) {
|
|
108
|
+
usb._disableHotplugEvents();
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
pollingHotplug = false;
|
|
112
|
+
}
|
|
29
113
|
}
|
|
30
114
|
});
|
|
31
115
|
module.exports = usb;
|
package/dist/usb/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../tsc/usb/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../tsc/usb/index.ts"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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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interface.js","sourceRoot":"","sources":["../../tsc/usb/interface.ts"],"names":[],"mappings":";;;AAAA,uCAAyE;AAEzE,uCAA+D;AAE/D;IAaI,mBAAsB,MAAc,EAAY,EAAU;QAApC,WAAM,GAAN,MAAM,CAAQ;QAAY,OAAE,GAAF,EAAE,CAAQ;QAT1D,wCAAwC;QACjC,eAAU,GAAG,CAAC,CAAC;QASlB,IAAI,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC;IAES,2BAAO,GAAjB;QACI,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE;YAC/B,OAAO;SACV;QAED,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACpF,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,UAAU,CAAC,gBAAgB,CAAC;QACxD,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;QACpB,IAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC;QAC7C,KAAK,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"interface.js","sourceRoot":"","sources":["../../tsc/usb/interface.ts"],"names":[],"mappings":";;;AAAA,uCAAyE;AAEzE,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AC,CAAC;IACvD,CAAC;IAED;;;;OAIG;IACI,sCAAkB,GAAzB;QACI,OAAO,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACrD,CAAC;IAED;;;;OAIG;IACI,sCAAkB,GAAzB;QACI,OAAO,IAAI,CAAC,MAAM,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACrD,CAAC;IAED;;;;;;OAMG;IACI,iCAAa,GAApB,UAAqB,UAAkB,EAAE,QAAuD;QAAhG,iBAUC;QATG,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,EAAE,UAAU,EAAE,UAAA,KAAK;YACjD,IAAI,CAAC,KAAK,EAAE;gBACR,KAAI,CAAC,UAAU,GAAG,UAAU,CAAC;gBAC7B,KAAI,CAAC,OAAO,EAAE,CAAC;aAClB;YACD,IAAI,QAAQ,EAAE;gBACV,QAAQ,CAAC,IAAI,CAAC,KAAI,EAAE,KAAK,CAAC,CAAC;aAC9B;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;;;;OAKG;IACI,4BAAQ,GAAf,UAAgB,IAAY;QACxB,IAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAA,IAAI,IAAI,OAAA,IAAI,CAAC,OAAO,KAAK,IAAI,EAArB,CAAqB,CAAC,CAAC;QACpE,IAAI,CAAC,QAAQ,EAAE;YACX,MAAM,IAAI,KAAK,CAAC,qCAAmC,IAAM,CAAC,CAAC;SAC9D;QAED,OAAO,QAAQ,CAAC;IACpB,CAAC;IACL,gBAAC;AAAD,CAAC,AAvKD,IAuKC;AAvKY,8BAAS"}
|
package/dist/webusb/index.d.ts
CHANGED
|
@@ -1,33 +1,42 @@
|
|
|
1
1
|
/// <reference types="w3c-web-usb" />
|
|
2
|
-
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { EventEmitter } from 'events';
|
|
3
4
|
/**
|
|
4
5
|
* USB Options
|
|
5
6
|
*/
|
|
6
7
|
export interface USBOptions {
|
|
7
8
|
/**
|
|
8
|
-
*
|
|
9
|
+
* Optional `device found` callback function to allow the user to select a device
|
|
9
10
|
*/
|
|
10
|
-
devicesFound?: (devices:
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* @hidden
|
|
14
|
-
*/
|
|
15
|
-
export declare type USBEvents = {
|
|
11
|
+
devicesFound?: (devices: USBDevice[]) => Promise<USBDevice | void>;
|
|
16
12
|
/**
|
|
17
|
-
*
|
|
13
|
+
* Optional array of preconfigured allowed devices
|
|
18
14
|
*/
|
|
19
|
-
|
|
15
|
+
allowedDevices?: USBDeviceFilter[];
|
|
20
16
|
/**
|
|
21
|
-
*
|
|
17
|
+
* Optional flag to automatically allow all devices
|
|
22
18
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
allowAllDevices?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Optional timeout (in milliseconds) to use for the device control transfers
|
|
22
|
+
*/
|
|
23
|
+
deviceTimeout?: number;
|
|
24
|
+
}
|
|
25
|
+
export declare class WebUSB implements USB {
|
|
26
26
|
private options;
|
|
27
|
-
|
|
27
|
+
protected emitter: EventEmitter;
|
|
28
|
+
protected knownDevices: Map<string, USBDevice>;
|
|
29
|
+
protected allowedDevices: USBDeviceFilter[];
|
|
28
30
|
constructor(options?: USBOptions);
|
|
29
|
-
|
|
30
|
-
set
|
|
31
|
+
private _onconnect;
|
|
32
|
+
set onconnect(fn: (ev: USBConnectionEvent) => void);
|
|
33
|
+
private _ondisconnect;
|
|
34
|
+
set ondisconnect(fn: (ev: USBConnectionEvent) => void);
|
|
35
|
+
addEventListener(type: 'connect' | 'disconnect', listener: (this: this, ev: USBConnectionEvent) => void): void;
|
|
36
|
+
addEventListener(type: 'connect' | 'disconnect', listener: EventListener): void;
|
|
37
|
+
removeEventListener(type: 'connect' | 'disconnect', callback: (this: this, ev: USBConnectionEvent) => void): void;
|
|
38
|
+
removeEventListener(type: 'connect' | 'disconnect', callback: EventListener): void;
|
|
39
|
+
dispatchEvent(_event: Event): boolean;
|
|
31
40
|
/**
|
|
32
41
|
* Requests a single Web USB device
|
|
33
42
|
* @param options The options to use when scanning
|
|
@@ -41,7 +50,7 @@ export declare class WebUSB extends TypedEventTarget<USBEvents> implements USB {
|
|
|
41
50
|
getDevices(): Promise<USBDevice[]>;
|
|
42
51
|
private loadDevices;
|
|
43
52
|
private preFilterDevices;
|
|
44
|
-
private isSameDevice;
|
|
45
|
-
private replaceAllowedDevice;
|
|
46
53
|
private filterDevice;
|
|
54
|
+
private getDeviceId;
|
|
55
|
+
private isAllowedDevice;
|
|
47
56
|
}
|
package/dist/webusb/index.js
CHANGED
|
@@ -1,19 +1,4 @@
|
|
|
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
|
-
})();
|
|
17
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -64,31 +49,120 @@ var __values = (this && this.__values) || function(o) {
|
|
|
64
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
50
|
exports.WebUSB = void 0;
|
|
66
51
|
var usb = require("../usb");
|
|
52
|
+
var events_1 = require("events");
|
|
67
53
|
var webusb_device_1 = require("./webusb-device");
|
|
68
|
-
var
|
|
69
|
-
var WebUSB = /** @class */ (function (_super) {
|
|
70
|
-
__extends(WebUSB, _super);
|
|
54
|
+
var WebUSB = /** @class */ (function () {
|
|
71
55
|
function WebUSB(options) {
|
|
56
|
+
var _this = this;
|
|
72
57
|
if (options === void 0) { options = {}; }
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
58
|
+
this.options = options;
|
|
59
|
+
this.emitter = new events_1.EventEmitter();
|
|
60
|
+
this.knownDevices = new Map();
|
|
61
|
+
this.allowedDevices = options.allowedDevices || [];
|
|
62
|
+
var deviceConnectCallback = function (device) { return __awaiter(_this, void 0, void 0, function () {
|
|
63
|
+
var webDevice, deviceId, event_1;
|
|
64
|
+
return __generator(this, function (_a) {
|
|
65
|
+
switch (_a.label) {
|
|
66
|
+
case 0: return [4 /*yield*/, webusb_device_1.WebUSBDevice.createInstance(device)];
|
|
67
|
+
case 1:
|
|
68
|
+
webDevice = _a.sent();
|
|
69
|
+
// When connected, emit an event if it is an allowed device
|
|
70
|
+
if (webDevice && this.isAllowedDevice(webDevice)) {
|
|
71
|
+
deviceId = this.getDeviceId(device);
|
|
72
|
+
if (deviceId) {
|
|
73
|
+
this.knownDevices.set(deviceId, webDevice);
|
|
74
|
+
}
|
|
75
|
+
event_1 = {
|
|
76
|
+
type: 'connect',
|
|
77
|
+
device: webDevice
|
|
78
|
+
};
|
|
79
|
+
this.emitter.emit('connect', event_1);
|
|
80
|
+
}
|
|
81
|
+
return [2 /*return*/];
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}); };
|
|
85
|
+
var deviceDisconnectCallback = function (device) { return __awaiter(_this, void 0, void 0, function () {
|
|
86
|
+
var deviceId, webDevice, event_2;
|
|
87
|
+
return __generator(this, function (_a) {
|
|
88
|
+
deviceId = this.getDeviceId(device);
|
|
89
|
+
// When disconnected, emit an event if the device was a known allowed device
|
|
90
|
+
if (deviceId !== undefined && this.knownDevices.has(deviceId)) {
|
|
91
|
+
webDevice = this.knownDevices.get(deviceId);
|
|
92
|
+
if (webDevice && this.isAllowedDevice(webDevice)) {
|
|
93
|
+
event_2 = {
|
|
94
|
+
type: 'disconnect',
|
|
95
|
+
device: webDevice
|
|
96
|
+
};
|
|
97
|
+
this.emitter.emit('disconnect', event_2);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return [2 /*return*/];
|
|
101
|
+
});
|
|
102
|
+
}); };
|
|
103
|
+
this.emitter.on('newListener', function (event) {
|
|
104
|
+
var listenerCount = _this.emitter.listenerCount(event);
|
|
105
|
+
if (listenerCount !== 0) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (event === 'connect') {
|
|
109
|
+
usb.addListener('attach', deviceConnectCallback);
|
|
110
|
+
}
|
|
111
|
+
else if (event === 'disconnect') {
|
|
112
|
+
usb.addListener('detach', deviceDisconnectCallback);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
this.emitter.on('removeListener', function (event) {
|
|
116
|
+
var listenerCount = _this.emitter.listenerCount(event);
|
|
117
|
+
if (listenerCount !== 0) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (event === 'connect') {
|
|
121
|
+
usb.removeListener('attach', deviceConnectCallback);
|
|
122
|
+
}
|
|
123
|
+
else if (event === 'disconnect') {
|
|
124
|
+
usb.removeListener('detach', deviceDisconnectCallback);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
77
127
|
}
|
|
78
128
|
Object.defineProperty(WebUSB.prototype, "onconnect", {
|
|
79
|
-
set: function (
|
|
80
|
-
this.
|
|
129
|
+
set: function (fn) {
|
|
130
|
+
if (this._onconnect) {
|
|
131
|
+
this.removeEventListener('connect', this._onconnect);
|
|
132
|
+
this._onconnect = undefined;
|
|
133
|
+
}
|
|
134
|
+
if (fn) {
|
|
135
|
+
this._onconnect = fn;
|
|
136
|
+
this.addEventListener('connect', this._onconnect);
|
|
137
|
+
}
|
|
81
138
|
},
|
|
82
139
|
enumerable: false,
|
|
83
140
|
configurable: true
|
|
84
141
|
});
|
|
85
142
|
Object.defineProperty(WebUSB.prototype, "ondisconnect", {
|
|
86
|
-
set: function (
|
|
87
|
-
this.
|
|
143
|
+
set: function (fn) {
|
|
144
|
+
if (this._ondisconnect) {
|
|
145
|
+
this.removeEventListener('disconnect', this._ondisconnect);
|
|
146
|
+
this._ondisconnect = undefined;
|
|
147
|
+
}
|
|
148
|
+
if (fn) {
|
|
149
|
+
this._ondisconnect = fn;
|
|
150
|
+
this.addEventListener('disconnect', this._ondisconnect);
|
|
151
|
+
}
|
|
88
152
|
},
|
|
89
153
|
enumerable: false,
|
|
90
154
|
configurable: true
|
|
91
155
|
});
|
|
156
|
+
WebUSB.prototype.addEventListener = function (type, listener) {
|
|
157
|
+
this.emitter.addListener(type, listener);
|
|
158
|
+
};
|
|
159
|
+
WebUSB.prototype.removeEventListener = function (type, callback) {
|
|
160
|
+
this.emitter.removeListener(type, callback);
|
|
161
|
+
};
|
|
162
|
+
WebUSB.prototype.dispatchEvent = function (_event) {
|
|
163
|
+
// Don't dispatch from here
|
|
164
|
+
return false;
|
|
165
|
+
};
|
|
92
166
|
/**
|
|
93
167
|
* Requests a single Web USB device
|
|
94
168
|
* @param options The options to use when scanning
|
|
@@ -151,7 +225,7 @@ var WebUSB = /** @class */ (function (_super) {
|
|
|
151
225
|
if (!device) {
|
|
152
226
|
throw new Error('selected device not found');
|
|
153
227
|
}
|
|
154
|
-
if (!this.
|
|
228
|
+
if (!this.isAllowedDevice(device)) {
|
|
155
229
|
this.allowedDevices.push({
|
|
156
230
|
vendorId: device.vendorId,
|
|
157
231
|
productId: device.productId,
|
|
@@ -178,39 +252,32 @@ var WebUSB = /** @class */ (function (_super) {
|
|
|
178
252
|
return __generator(this, function (_a) {
|
|
179
253
|
switch (_a.label) {
|
|
180
254
|
case 0:
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
255
|
+
if (!this.options.allowAllDevices) {
|
|
256
|
+
// Create pre-filters
|
|
257
|
+
preFilters = this.allowedDevices.map(function (device) { return ({
|
|
258
|
+
vendorId: device.vendorId || undefined,
|
|
259
|
+
productId: device.productId || undefined,
|
|
260
|
+
serialNumber: device.serialNumber || undefined
|
|
261
|
+
}); });
|
|
262
|
+
}
|
|
186
263
|
return [4 /*yield*/, this.loadDevices(preFilters)];
|
|
187
264
|
case 1:
|
|
188
265
|
devices = _a.sent();
|
|
189
|
-
|
|
190
|
-
for (var i in _this.allowedDevices) {
|
|
191
|
-
if (_this.isSameDevice(device, _this.allowedDevices[i])) {
|
|
192
|
-
return true;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
return false;
|
|
196
|
-
});
|
|
197
|
-
return [2 /*return*/, devices];
|
|
266
|
+
return [2 /*return*/, devices.filter(function (device) { return _this.isAllowedDevice(device); })];
|
|
198
267
|
}
|
|
199
268
|
});
|
|
200
269
|
});
|
|
201
270
|
};
|
|
202
271
|
WebUSB.prototype.loadDevices = function (preFilters) {
|
|
203
272
|
return __awaiter(this, void 0, void 0, function () {
|
|
204
|
-
var devices, webDevices, devices_1, devices_1_1, device, webDevice, e_1_1;
|
|
273
|
+
var devices, webDevices, devices_1, devices_1_1, device, webDevice, deviceId, e_1_1;
|
|
205
274
|
var e_1, _a;
|
|
206
275
|
return __generator(this, function (_b) {
|
|
207
276
|
switch (_b.label) {
|
|
208
277
|
case 0:
|
|
209
278
|
devices = usb.getDeviceList();
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
devices = this.preFilterDevices(devices, preFilters);
|
|
213
|
-
}
|
|
279
|
+
// Pre-filter devices
|
|
280
|
+
devices = this.preFilterDevices(devices, preFilters);
|
|
214
281
|
webDevices = [];
|
|
215
282
|
_b.label = 1;
|
|
216
283
|
case 1:
|
|
@@ -220,10 +287,19 @@ var WebUSB = /** @class */ (function (_super) {
|
|
|
220
287
|
case 2:
|
|
221
288
|
if (!!devices_1_1.done) return [3 /*break*/, 5];
|
|
222
289
|
device = devices_1_1.value;
|
|
290
|
+
if (this.options.deviceTimeout) {
|
|
291
|
+
device.timeout = this.options.deviceTimeout;
|
|
292
|
+
}
|
|
223
293
|
return [4 /*yield*/, webusb_device_1.WebUSBDevice.createInstance(device)];
|
|
224
294
|
case 3:
|
|
225
295
|
webDevice = _b.sent();
|
|
226
|
-
|
|
296
|
+
if (webDevice) {
|
|
297
|
+
webDevices.push(webDevice);
|
|
298
|
+
deviceId = this.getDeviceId(device);
|
|
299
|
+
if (deviceId) {
|
|
300
|
+
this.knownDevices.set(deviceId, webDevice);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
227
303
|
_b.label = 4;
|
|
228
304
|
case 4:
|
|
229
305
|
devices_1_1 = devices_1.next();
|
|
@@ -245,6 +321,9 @@ var WebUSB = /** @class */ (function (_super) {
|
|
|
245
321
|
});
|
|
246
322
|
};
|
|
247
323
|
WebUSB.prototype.preFilterDevices = function (devices, preFilters) {
|
|
324
|
+
if (!preFilters || !preFilters.length) {
|
|
325
|
+
return devices;
|
|
326
|
+
}
|
|
248
327
|
// Just pre-filter on vid/pid
|
|
249
328
|
return devices.filter(function (device) { return preFilters.some(function (filter) {
|
|
250
329
|
// Vendor
|
|
@@ -257,25 +336,10 @@ var WebUSB = /** @class */ (function (_super) {
|
|
|
257
336
|
return true;
|
|
258
337
|
}); });
|
|
259
338
|
};
|
|
260
|
-
WebUSB.prototype.isSameDevice = function (device1, device2) {
|
|
261
|
-
return (device1.productId === device2.productId
|
|
262
|
-
&& device1.vendorId === device2.vendorId
|
|
263
|
-
&& device1.serialNumber === device2.serialNumber);
|
|
264
|
-
};
|
|
265
|
-
WebUSB.prototype.replaceAllowedDevice = function (device) {
|
|
266
|
-
for (var i in this.allowedDevices) {
|
|
267
|
-
if (this.isSameDevice(device, this.allowedDevices[i])) {
|
|
268
|
-
this.allowedDevices[i] = {
|
|
269
|
-
vendorId: device.vendorId,
|
|
270
|
-
productId: device.productId,
|
|
271
|
-
serialNumber: device.serialNumber
|
|
272
|
-
};
|
|
273
|
-
return true;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
return false;
|
|
277
|
-
};
|
|
278
339
|
WebUSB.prototype.filterDevice = function (options, device) {
|
|
340
|
+
if (!options.filters || !options.filters.length) {
|
|
341
|
+
return true;
|
|
342
|
+
}
|
|
279
343
|
return options.filters.some(function (filter) {
|
|
280
344
|
// Vendor
|
|
281
345
|
if (filter.vendorId && filter.vendorId !== device.vendorId)
|
|
@@ -320,7 +384,29 @@ var WebUSB = /** @class */ (function (_super) {
|
|
|
320
384
|
return true;
|
|
321
385
|
});
|
|
322
386
|
};
|
|
387
|
+
WebUSB.prototype.getDeviceId = function (device) {
|
|
388
|
+
if (device.busNumber === undefined || device.deviceAddress === undefined) {
|
|
389
|
+
return undefined;
|
|
390
|
+
}
|
|
391
|
+
return device.busNumber + "." + device.deviceAddress;
|
|
392
|
+
};
|
|
393
|
+
WebUSB.prototype.isAllowedDevice = function (device) {
|
|
394
|
+
if (this.options.allowAllDevices) {
|
|
395
|
+
return true;
|
|
396
|
+
}
|
|
397
|
+
var isSameDevice = function (device1, device2) {
|
|
398
|
+
return (device1.productId === device2.productId
|
|
399
|
+
&& device1.vendorId === device2.vendorId
|
|
400
|
+
&& device1.serialNumber === device2.serialNumber);
|
|
401
|
+
};
|
|
402
|
+
for (var i in this.allowedDevices) {
|
|
403
|
+
if (isSameDevice(device, this.allowedDevices[i])) {
|
|
404
|
+
return true;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
return false;
|
|
408
|
+
};
|
|
323
409
|
return WebUSB;
|
|
324
|
-
}(
|
|
410
|
+
}());
|
|
325
411
|
exports.WebUSB = WebUSB;
|
|
326
412
|
//# sourceMappingURL=index.js.map
|
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;IAMI,gBAAoB,OAAwB;QAA5C,iBAmEC;QAnEmB,wBAAA,EAAA,YAAwB;QAAxB,YAAO,GAAP,OAAO,CAAiB;QAJlC,YAAO,GAAG,IAAI,qBAAY,EAAE,CAAC;QAC7B,iBAAY,GAA2B,IAAI,GAAG,EAAE,CAAC;QAIvD,IAAI,CAAC,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,EAAE,CAAC;QAEnD,IAAM,qBAAqB,GAAG,UAAO,MAAkB;;;;4BACjC,qBAAM,4BAAY,CAAC,cAAc,CAAC,MAAM,CAAC,EAAA;;wBAArD,SAAS,GAAG,SAAyC;wBAE3D,2DAA2D;wBAC3D,IAAI,SAAS,IAAI,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,EAAE;4BACxC,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;4BAC1C,IAAI,QAAQ,EAAE;gCACV,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;6BAC9C;4BAEK,UAAQ;gCACV,IAAI,EAAE,SAAS;gCACf,MAAM,EAAE,SAAS;6BACpB,CAAC;4BAEF,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,OAAK,CAAC,CAAC;yBACvC;;;;aACJ,CAAC;QAEF,IAAM,wBAAwB,GAAG,UAAO,MAAkB;;;gBAChD,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,M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AAY,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;QAC1D,CAAC,CAAC;QAEF,KAAK,IAAM,CAAC,IAAI,IAAI,CAAC,cAAc,EAAE;YACjC,IAAI,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,EAAE;gBAC9C,OAAO,IAAI,CAAC;aACf;SACJ;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;IACL,aAAC;AAAD,CAAC,AA7UD,IA6UC;AA7UY,wBAAM"}
|
|
@@ -5,7 +5,7 @@ import * as usb from '../usb';
|
|
|
5
5
|
*/
|
|
6
6
|
export declare class WebUSBDevice implements USBDevice {
|
|
7
7
|
private device;
|
|
8
|
-
static createInstance(device: usb.Device): Promise<WebUSBDevice>;
|
|
8
|
+
static createInstance(device: usb.Device): Promise<WebUSBDevice | undefined>;
|
|
9
9
|
readonly usbVersionMajor: number;
|
|
10
10
|
readonly usbVersionMinor: number;
|
|
11
11
|
readonly usbVersionSubminor: number;
|
|
@@ -79,15 +79,20 @@ var WebUSBDevice = /** @class */ (function () {
|
|
|
79
79
|
}
|
|
80
80
|
WebUSBDevice.createInstance = function (device) {
|
|
81
81
|
return __awaiter(this, void 0, void 0, function () {
|
|
82
|
-
var instance;
|
|
83
|
-
return __generator(this, function (
|
|
84
|
-
switch (
|
|
82
|
+
var instance, _a;
|
|
83
|
+
return __generator(this, function (_b) {
|
|
84
|
+
switch (_b.label) {
|
|
85
85
|
case 0:
|
|
86
|
+
_b.trys.push([0, 2, , 3]);
|
|
86
87
|
instance = new WebUSBDevice(device);
|
|
87
88
|
return [4 /*yield*/, instance.initialize()];
|
|
88
89
|
case 1:
|
|
89
|
-
|
|
90
|
+
_b.sent();
|
|
90
91
|
return [2 /*return*/, instance];
|
|
92
|
+
case 2:
|
|
93
|
+
_a = _b.sent();
|
|
94
|
+
return [2 /*return*/, undefined];
|
|
95
|
+
case 3: return [2 /*return*/];
|
|
91
96
|
}
|
|
92
97
|
});
|
|
93
98
|
});
|