@yume-chan/adb-daemon-webusb 0.0.24 → 1.0.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 +37 -1
- package/README.md +6 -3
- package/esm/device.d.ts +11 -14
- package/esm/device.d.ts.map +1 -1
- package/esm/device.js +43 -52
- package/esm/device.js.map +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/esm/manager.d.ts +6 -25
- package/esm/manager.d.ts.map +1 -1
- package/esm/manager.js +30 -60
- package/esm/manager.js.map +1 -1
- package/esm/observer.d.ts +17 -0
- package/esm/observer.d.ts.map +1 -0
- package/esm/observer.js +54 -0
- package/esm/observer.js.map +1 -0
- package/esm/utils.d.ts +22 -5
- package/esm/utils.d.ts.map +1 -1
- package/esm/utils.js +76 -5
- package/esm/utils.js.map +1 -1
- package/package.json +13 -9
- package/src/device.ts +53 -65
- package/src/index.ts +1 -1
- package/src/manager.ts +49 -75
- package/src/observer.ts +90 -0
- package/src/utils.ts +142 -18
- package/tsconfig.build.json +2 -13
- package/tsconfig.build.tsbuildinfo +1 -1
- package/CHANGELOG.json +0 -199
- package/esm/watcher.d.ts +0 -7
- package/esm/watcher.d.ts.map +0 -1
- package/esm/watcher.js +0 -21
- package/esm/watcher.js.map +0 -1
- package/src/watcher.ts +0 -28
package/CHANGELOG.md
CHANGED
|
@@ -1,13 +1,36 @@
|
|
|
1
1
|
# Change Log - @yume-chan/adb-daemon-webusb
|
|
2
2
|
|
|
3
|
+
## 1.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 53688d3: Use PNPM workspace and Changesets to manage the monorepo.
|
|
8
|
+
|
|
9
|
+
Because Changesets doesn't support alpha versions (`0.x.x`), this version is `1.0.0`. Future versions will follow SemVer rules, for example, breaking API changes will introduce a new major version.
|
|
10
|
+
|
|
11
|
+
- c68e216: Accept exclusionFilters in getDevices and DeviceObserver
|
|
12
|
+
- db8466f: Accept standard `USBDeviceFilter` type and fill in default interface filters automatically
|
|
13
|
+
- db8466f: Throw `DeviceBusyError` when interface can't be claimed
|
|
14
|
+
- Updated dependencies [53688d3]
|
|
15
|
+
- Updated dependencies [db8466f]
|
|
16
|
+
- Updated dependencies [db8466f]
|
|
17
|
+
- Updated dependencies [ea5002b]
|
|
18
|
+
- Updated dependencies [db8466f]
|
|
19
|
+
- @yume-chan/stream-extra@1.0.1
|
|
20
|
+
- @yume-chan/struct@1.0.1
|
|
21
|
+
- @yume-chan/event@1.0.1
|
|
22
|
+
- @yume-chan/adb@1.0.1
|
|
23
|
+
|
|
3
24
|
This log was last generated on Tue, 18 Jun 2024 02:49:43 GMT and should not be manually modified.
|
|
4
25
|
|
|
5
26
|
## 0.0.24
|
|
27
|
+
|
|
6
28
|
Tue, 18 Jun 2024 02:49:43 GMT
|
|
7
29
|
|
|
8
30
|
_Version update only_
|
|
9
31
|
|
|
10
32
|
## 0.0.23
|
|
33
|
+
|
|
11
34
|
Thu, 21 Mar 2024 03:15:10 GMT
|
|
12
35
|
|
|
13
36
|
### Updates
|
|
@@ -15,6 +38,7 @@ Thu, 21 Mar 2024 03:15:10 GMT
|
|
|
15
38
|
- Fix `AdbDaemonWebUsbDeviceManager.getDevices` doesn't match auto-generated serial number against `filters.serialNumber` (if the device doesn't have a serial number)
|
|
16
39
|
|
|
17
40
|
## 0.0.22
|
|
41
|
+
|
|
18
42
|
Wed, 13 Dec 2023 05:57:27 GMT
|
|
19
43
|
|
|
20
44
|
### Updates
|
|
@@ -24,11 +48,13 @@ Wed, 13 Dec 2023 05:57:27 GMT
|
|
|
24
48
|
- `AdbDaemonWebUsbDevice` will generate a fake serial number from vid and pid if the device serial number is empty
|
|
25
49
|
|
|
26
50
|
## 0.0.21
|
|
51
|
+
|
|
27
52
|
Fri, 25 Aug 2023 14:05:18 GMT
|
|
28
53
|
|
|
29
54
|
_Version update only_
|
|
30
55
|
|
|
31
56
|
## 0.0.20
|
|
57
|
+
|
|
32
58
|
Mon, 05 Jun 2023 02:51:41 GMT
|
|
33
59
|
|
|
34
60
|
### Updates
|
|
@@ -40,6 +66,7 @@ Mon, 05 Jun 2023 02:51:41 GMT
|
|
|
40
66
|
- Add `filters` parameter to `AdbDaemonWebUsbDeviceManager#getDevices`. The filtration is manually implemented because WebUSB's `getDevice` API doesn't support filters.
|
|
41
67
|
|
|
42
68
|
## 0.0.19
|
|
69
|
+
|
|
43
70
|
Sun, 09 Apr 2023 05:55:33 GMT
|
|
44
71
|
|
|
45
72
|
### Updates
|
|
@@ -48,6 +75,7 @@ Sun, 09 Apr 2023 05:55:33 GMT
|
|
|
48
75
|
- Add the `AdbWebUsbBackendManager` class to simplify the usage with custom WebUSB implementations (for example the `usb` NPM package).
|
|
49
76
|
|
|
50
77
|
## 0.0.18
|
|
78
|
+
|
|
51
79
|
Wed, 25 Jan 2023 21:33:49 GMT
|
|
52
80
|
|
|
53
81
|
### Updates
|
|
@@ -55,6 +83,7 @@ Wed, 25 Jan 2023 21:33:49 GMT
|
|
|
55
83
|
- Add an option to specify USB filters
|
|
56
84
|
|
|
57
85
|
## 0.0.17
|
|
86
|
+
|
|
58
87
|
Tue, 18 Oct 2022 09:32:30 GMT
|
|
59
88
|
|
|
60
89
|
### Updates
|
|
@@ -62,6 +91,7 @@ Tue, 18 Oct 2022 09:32:30 GMT
|
|
|
62
91
|
- Update to use new stream util package
|
|
63
92
|
|
|
64
93
|
## 0.0.16
|
|
94
|
+
|
|
65
95
|
Sat, 28 May 2022 03:56:37 GMT
|
|
66
96
|
|
|
67
97
|
### Updates
|
|
@@ -69,6 +99,7 @@ Sat, 28 May 2022 03:56:37 GMT
|
|
|
69
99
|
- Upgrade TypeScript to 4.7.2 to enable Node.js ESM
|
|
70
100
|
|
|
71
101
|
## 0.0.15
|
|
102
|
+
|
|
72
103
|
Mon, 02 May 2022 04:18:01 GMT
|
|
73
104
|
|
|
74
105
|
### Updates
|
|
@@ -76,11 +107,13 @@ Mon, 02 May 2022 04:18:01 GMT
|
|
|
76
107
|
- Improve connection lifecycle handling
|
|
77
108
|
|
|
78
109
|
## 0.0.14
|
|
110
|
+
|
|
79
111
|
Sat, 30 Apr 2022 14:05:48 GMT
|
|
80
112
|
|
|
81
113
|
_Version update only_
|
|
82
114
|
|
|
83
115
|
## 0.0.13
|
|
116
|
+
|
|
84
117
|
Thu, 28 Apr 2022 01:23:53 GMT
|
|
85
118
|
|
|
86
119
|
### Updates
|
|
@@ -88,11 +121,13 @@ Thu, 28 Apr 2022 01:23:53 GMT
|
|
|
88
121
|
- Workaround an issue in Chrome where `transferIn` never returns `babble` on Windows
|
|
89
122
|
|
|
90
123
|
## 0.0.12
|
|
124
|
+
|
|
91
125
|
Sun, 03 Apr 2022 11:18:47 GMT
|
|
92
126
|
|
|
93
127
|
_Version update only_
|
|
94
128
|
|
|
95
129
|
## 0.0.11
|
|
130
|
+
|
|
96
131
|
Sun, 03 Apr 2022 10:54:15 GMT
|
|
97
132
|
|
|
98
133
|
### Updates
|
|
@@ -102,6 +137,7 @@ Sun, 03 Apr 2022 10:54:15 GMT
|
|
|
102
137
|
- Update license year
|
|
103
138
|
|
|
104
139
|
## 0.0.10
|
|
140
|
+
|
|
105
141
|
Sun, 09 Jan 2022 15:52:20 GMT
|
|
106
142
|
|
|
107
143
|
### Updates
|
|
@@ -109,7 +145,7 @@ Sun, 09 Jan 2022 15:52:20 GMT
|
|
|
109
145
|
- Remove `encodeUtf8()` and `decodeUtf8()` from `AdbBackend`
|
|
110
146
|
|
|
111
147
|
## 0.0.9
|
|
148
|
+
|
|
112
149
|
Sun, 09 Jan 2022 15:50:20 GMT
|
|
113
150
|
|
|
114
151
|
_Initial release_
|
|
115
|
-
|
package/README.md
CHANGED
|
@@ -15,8 +15,11 @@
|
|
|
15
15
|
<a href="https://github.com/yume-chan/ya-webadb/releases">
|
|
16
16
|
<img alt="GitHub release" src="https://img.shields.io/github/v/release/yume-chan/ya-webadb?logo=github">
|
|
17
17
|
</a>
|
|
18
|
-
<a href="https://
|
|
19
|
-
<img alt="
|
|
18
|
+
<a href="https://bundlephobia.com/package/@yume-chan/adb-daemon-webusb">
|
|
19
|
+
<img alt="Package Size" src="https://img.shields.io/bundlephobia/minzip/%40yume-chan%2Fadb-daemon-webusb">
|
|
20
|
+
</a>
|
|
21
|
+
<a href="https://www.npmjs.com/package/@yume-chan/adb-daemon-webusb">
|
|
22
|
+
<img alt="npm" src="https://img.shields.io/npm/dm/%40yume-chan/adb-daemon-webusb?logo=npm">
|
|
20
23
|
</a>
|
|
21
24
|
<a href="https://discord.gg/26k3ttC2PN">
|
|
22
25
|
<img alt="Discord" src="https://img.shields.io/discord/1120215514732564502?logo=discord&logoColor=%23ffffff&label=Discord">
|
|
@@ -27,7 +30,7 @@ This package is part of [Tango ADB](https://github.com/yume-chan/ya-webadb). Gen
|
|
|
27
30
|
|
|
28
31
|
## Documentation
|
|
29
32
|
|
|
30
|
-
Check the latest documentation at https://
|
|
33
|
+
Check the latest documentation at https://docs.tangoapp.dev/tango/daemon/usb/
|
|
31
34
|
|
|
32
35
|
## Sponsors
|
|
33
36
|
|
package/esm/device.d.ts
CHANGED
|
@@ -1,30 +1,23 @@
|
|
|
1
|
-
/// <reference types="w3c-web-usb" />
|
|
2
1
|
import type { AdbDaemonDevice, AdbPacketData, AdbPacketInit } from "@yume-chan/adb";
|
|
3
2
|
import type { Consumable, ReadableWritablePair, WritableStream } from "@yume-chan/stream-extra";
|
|
4
3
|
import { ReadableStream } from "@yume-chan/stream-extra";
|
|
5
|
-
import type {
|
|
4
|
+
import type { UsbInterfaceFilter, UsbInterfaceIdentifier } from "./utils.js";
|
|
6
5
|
/**
|
|
7
6
|
* The default filter for ADB devices, as defined by Google.
|
|
8
7
|
*/
|
|
9
|
-
export declare const
|
|
8
|
+
export declare const AdbDefaultInterfaceFilter: {
|
|
10
9
|
readonly classCode: 255;
|
|
11
10
|
readonly subclassCode: 66;
|
|
12
11
|
readonly protocolCode: 1;
|
|
13
12
|
};
|
|
13
|
+
export declare function mergeDefaultAdbInterfaceFilter(filters: USBDeviceFilter[] | undefined): (USBDeviceFilter & UsbInterfaceFilter)[];
|
|
14
14
|
export declare class AdbDaemonWebUsbConnection implements ReadableWritablePair<AdbPacketData, Consumable<AdbPacketInit>> {
|
|
15
15
|
#private;
|
|
16
16
|
get device(): AdbDaemonWebUsbDevice;
|
|
17
17
|
get inEndpoint(): USBEndpoint;
|
|
18
18
|
get outEndpoint(): USBEndpoint;
|
|
19
19
|
get readable(): ReadableStream<AdbPacketData>;
|
|
20
|
-
get writable(): WritableStream<Consumable<
|
|
21
|
-
command: number;
|
|
22
|
-
arg0: number;
|
|
23
|
-
arg1: number;
|
|
24
|
-
checksum: number;
|
|
25
|
-
magic: number;
|
|
26
|
-
payload: Uint8Array;
|
|
27
|
-
}>>;
|
|
20
|
+
get writable(): WritableStream<Consumable<AdbPacketInit>>;
|
|
28
21
|
constructor(device: AdbDaemonWebUsbDevice, inEndpoint: USBEndpoint, outEndpoint: USBEndpoint, usbManager: USB);
|
|
29
22
|
}
|
|
30
23
|
export declare class AdbDaemonWebUsbDevice implements AdbDaemonDevice {
|
|
@@ -38,11 +31,15 @@ export declare class AdbDaemonWebUsbDevice implements AdbDaemonDevice {
|
|
|
38
31
|
* @param device The `USBDevice` instance obtained elsewhere.
|
|
39
32
|
* @param filters The filters to use when searching for ADB interface. Defaults to {@link ADB_DEFAULT_DEVICE_FILTER}.
|
|
40
33
|
*/
|
|
41
|
-
constructor(device: USBDevice,
|
|
34
|
+
constructor(device: USBDevice, interface_: UsbInterfaceIdentifier, usbManager: USB);
|
|
42
35
|
/**
|
|
43
|
-
*
|
|
44
|
-
* @returns The pair of `AdbPacket` streams.
|
|
36
|
+
* Open the device and create a new connection to the ADB Daemon.
|
|
45
37
|
*/
|
|
46
38
|
connect(): Promise<AdbDaemonWebUsbConnection>;
|
|
47
39
|
}
|
|
40
|
+
export declare namespace AdbDaemonWebUsbDevice {
|
|
41
|
+
class DeviceBusyError extends Error {
|
|
42
|
+
constructor(cause?: Error);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
48
45
|
//# sourceMappingURL=device.d.ts.map
|
package/esm/device.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"device.d.ts","sourceRoot":"","sources":["../src/device.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"device.d.ts","sourceRoot":"","sources":["../src/device.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,eAAe,EACf,aAAa,EACb,aAAa,EAChB,MAAM,gBAAgB,CAAC;AAMxB,OAAO,KAAK,EACR,UAAU,EACV,oBAAoB,EACpB,cAAc,EACjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAGH,cAAc,EAEjB,MAAM,yBAAyB,CAAC;AAIjC,OAAO,KAAK,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAG7E;;GAEG;AACH,eAAO,MAAM,yBAAyB;;;;CAIC,CAAC;AAExC,wBAAgB,8BAA8B,CAC1C,OAAO,EAAE,eAAe,EAAE,GAAG,SAAS,GACvC,CAAC,eAAe,GAAG,kBAAkB,CAAC,EAAE,CAa1C;AAyBD,qBAAa,yBACT,YAAW,oBAAoB,CAAC,aAAa,EAAE,UAAU,CAAC,aAAa,CAAC,CAAC;;IAGzE,IAAI,MAAM,0BAET;IAGD,IAAI,UAAU,gBAEb;IAGD,IAAI,WAAW,gBAEd;IAGD,IAAI,QAAQ,kCAEX;IAGD,IAAI,QAAQ,8CAEX;gBAGG,MAAM,EAAE,qBAAqB,EAC7B,UAAU,EAAE,WAAW,EACvB,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,GAAG;CAiJtB;AAED,qBAAa,qBAAsB,YAAW,eAAe;;IAKzD,IAAI,GAAG,cAEN;IAGD,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;;;OAKG;gBAEC,MAAM,EAAE,SAAS,EACjB,UAAU,EAAE,sBAAsB,EAClC,UAAU,EAAE,GAAG;IAqDnB;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,yBAAyB,CAAC;CAStD;AAED,yBAAiB,qBAAqB,CAAC;IACnC,MAAa,eAAgB,SAAQ,KAAK;oBAC1B,KAAK,CAAC,EAAE,KAAK;KAK5B;CACJ"}
|
package/esm/device.js
CHANGED
|
@@ -1,49 +1,27 @@
|
|
|
1
1
|
import { AdbPacketHeader, AdbPacketSerializeStream, unreachable, } from "@yume-chan/adb";
|
|
2
2
|
import { DuplexStreamFactory, MaybeConsumable, ReadableStream, pipeFrom, } from "@yume-chan/stream-extra";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { EmptyUint8Array } from "@yume-chan/struct";
|
|
4
|
+
import { findUsbEndpoints, getSerialNumber, isErrorName } from "./utils.js";
|
|
5
5
|
/**
|
|
6
6
|
* The default filter for ADB devices, as defined by Google.
|
|
7
7
|
*/
|
|
8
|
-
export const
|
|
8
|
+
export const AdbDefaultInterfaceFilter = {
|
|
9
9
|
classCode: 0xff,
|
|
10
10
|
subclassCode: 0x42,
|
|
11
11
|
protocolCode: 1,
|
|
12
12
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
for (const endpoint of endpoints) {
|
|
25
|
-
switch (endpoint.direction) {
|
|
26
|
-
case "in":
|
|
27
|
-
inEndpoint = endpoint;
|
|
28
|
-
if (outEndpoint) {
|
|
29
|
-
return { inEndpoint, outEndpoint };
|
|
30
|
-
}
|
|
31
|
-
break;
|
|
32
|
-
case "out":
|
|
33
|
-
outEndpoint = endpoint;
|
|
34
|
-
if (inEndpoint) {
|
|
35
|
-
return { inEndpoint, outEndpoint };
|
|
36
|
-
}
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
if (!inEndpoint) {
|
|
41
|
-
throw new TypeError("No input endpoint found.");
|
|
13
|
+
export function mergeDefaultAdbInterfaceFilter(filters) {
|
|
14
|
+
if (!filters || filters.length === 0) {
|
|
15
|
+
return [AdbDefaultInterfaceFilter];
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
return filters.map((filter) => ({
|
|
19
|
+
...filter,
|
|
20
|
+
classCode: filter.classCode ?? AdbDefaultInterfaceFilter.classCode,
|
|
21
|
+
subclassCode: filter.subclassCode ?? AdbDefaultInterfaceFilter.subclassCode,
|
|
22
|
+
protocolCode: filter.protocolCode ?? AdbDefaultInterfaceFilter.protocolCode,
|
|
23
|
+
}));
|
|
42
24
|
}
|
|
43
|
-
if (!outEndpoint) {
|
|
44
|
-
throw new TypeError("No output endpoint found.");
|
|
45
|
-
}
|
|
46
|
-
throw new Error("unreachable");
|
|
47
25
|
}
|
|
48
26
|
class Uint8ArrayExactReadable {
|
|
49
27
|
#data;
|
|
@@ -129,7 +107,7 @@ export class AdbDaemonWebUsbConnection {
|
|
|
129
107
|
// we need to send an empty packet to indicate the end,
|
|
130
108
|
// so the OS will send it to the device immediately.
|
|
131
109
|
if (zeroMask && (chunk.length & zeroMask) === 0) {
|
|
132
|
-
await device.raw.transferOut(outEndpoint.endpointNumber,
|
|
110
|
+
await device.raw.transferOut(outEndpoint.endpointNumber, EmptyUint8Array);
|
|
133
111
|
}
|
|
134
112
|
}
|
|
135
113
|
catch (e) {
|
|
@@ -162,7 +140,7 @@ export class AdbDaemonWebUsbConnection {
|
|
|
162
140
|
packet.payload = new Uint8Array(result.data.buffer);
|
|
163
141
|
}
|
|
164
142
|
else {
|
|
165
|
-
packet.payload =
|
|
143
|
+
packet.payload = EmptyUint8Array;
|
|
166
144
|
}
|
|
167
145
|
return packet;
|
|
168
146
|
}
|
|
@@ -170,7 +148,7 @@ export class AdbDaemonWebUsbConnection {
|
|
|
170
148
|
catch (e) {
|
|
171
149
|
// On Windows, disconnecting the device will cause `NetworkError` to be thrown,
|
|
172
150
|
// even before the `disconnect` event is fired.
|
|
173
|
-
//
|
|
151
|
+
// Wait a little while and check if the device is still connected.
|
|
174
152
|
// https://github.com/WICG/webusb/issues/219
|
|
175
153
|
if (isErrorName(e, "NetworkError")) {
|
|
176
154
|
await new Promise((resolve) => {
|
|
@@ -181,16 +159,13 @@ export class AdbDaemonWebUsbConnection {
|
|
|
181
159
|
if (closed) {
|
|
182
160
|
return undefined;
|
|
183
161
|
}
|
|
184
|
-
else {
|
|
185
|
-
throw e;
|
|
186
|
-
}
|
|
187
162
|
}
|
|
188
163
|
throw e;
|
|
189
164
|
}
|
|
190
165
|
}
|
|
191
166
|
}
|
|
192
167
|
export class AdbDaemonWebUsbDevice {
|
|
193
|
-
#
|
|
168
|
+
#interface;
|
|
194
169
|
#usbManager;
|
|
195
170
|
#raw;
|
|
196
171
|
get raw() {
|
|
@@ -209,17 +184,17 @@ export class AdbDaemonWebUsbDevice {
|
|
|
209
184
|
* @param device The `USBDevice` instance obtained elsewhere.
|
|
210
185
|
* @param filters The filters to use when searching for ADB interface. Defaults to {@link ADB_DEFAULT_DEVICE_FILTER}.
|
|
211
186
|
*/
|
|
212
|
-
constructor(device,
|
|
187
|
+
constructor(device, interface_, usbManager) {
|
|
213
188
|
this.#raw = device;
|
|
214
189
|
this.#serial = getSerialNumber(device);
|
|
215
|
-
this.#
|
|
190
|
+
this.#interface = interface_;
|
|
216
191
|
this.#usbManager = usbManager;
|
|
217
192
|
}
|
|
218
193
|
async #claimInterface() {
|
|
219
194
|
if (!this.#raw.opened) {
|
|
220
195
|
await this.#raw.open();
|
|
221
196
|
}
|
|
222
|
-
const { configuration, interface_, alternate } =
|
|
197
|
+
const { configuration, interface_, alternate } = this.#interface;
|
|
223
198
|
if (this.#raw.configuration?.configurationValue !==
|
|
224
199
|
configuration.configurationValue) {
|
|
225
200
|
// Note: Switching configuration is not supported on Windows,
|
|
@@ -227,21 +202,37 @@ export class AdbDaemonWebUsbDevice {
|
|
|
227
202
|
await this.#raw.selectConfiguration(configuration.configurationValue);
|
|
228
203
|
}
|
|
229
204
|
if (!interface_.claimed) {
|
|
230
|
-
|
|
205
|
+
try {
|
|
206
|
+
await this.#raw.claimInterface(interface_.interfaceNumber);
|
|
207
|
+
}
|
|
208
|
+
catch (e) {
|
|
209
|
+
if (isErrorName(e, "NetworkError")) {
|
|
210
|
+
throw new AdbDaemonWebUsbDevice.DeviceBusyError(e);
|
|
211
|
+
}
|
|
212
|
+
throw e;
|
|
213
|
+
}
|
|
231
214
|
}
|
|
232
215
|
if (interface_.alternate.alternateSetting !== alternate.alternateSetting) {
|
|
233
216
|
await this.#raw.selectAlternateInterface(interface_.interfaceNumber, alternate.alternateSetting);
|
|
234
217
|
}
|
|
235
|
-
|
|
236
|
-
return [inEndpoint, outEndpoint];
|
|
218
|
+
return findUsbEndpoints(alternate.endpoints);
|
|
237
219
|
}
|
|
238
220
|
/**
|
|
239
|
-
*
|
|
240
|
-
* @returns The pair of `AdbPacket` streams.
|
|
221
|
+
* Open the device and create a new connection to the ADB Daemon.
|
|
241
222
|
*/
|
|
242
223
|
async connect() {
|
|
243
|
-
const
|
|
224
|
+
const { inEndpoint, outEndpoint } = await this.#claimInterface();
|
|
244
225
|
return new AdbDaemonWebUsbConnection(this, inEndpoint, outEndpoint, this.#usbManager);
|
|
245
226
|
}
|
|
246
227
|
}
|
|
228
|
+
(function (AdbDaemonWebUsbDevice) {
|
|
229
|
+
class DeviceBusyError extends Error {
|
|
230
|
+
constructor(cause) {
|
|
231
|
+
super("The device is already in used by another program", {
|
|
232
|
+
cause,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
AdbDaemonWebUsbDevice.DeviceBusyError = DeviceBusyError;
|
|
237
|
+
})(AdbDaemonWebUsbDevice || (AdbDaemonWebUsbDevice = {}));
|
|
247
238
|
//# sourceMappingURL=device.js.map
|
package/esm/device.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"device.js","sourceRoot":"","sources":["../src/device.ts"],"names":[],"mappings":"AAKA,OAAO,EACH,eAAe,EACf,wBAAwB,EACxB,WAAW,GACd,MAAM,gBAAgB,CAAC;AAMxB,OAAO,EACH,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,QAAQ,GACX,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"device.js","sourceRoot":"","sources":["../src/device.ts"],"names":[],"mappings":"AAKA,OAAO,EACH,eAAe,EACf,wBAAwB,EACxB,WAAW,GACd,MAAM,gBAAgB,CAAC;AAMxB,OAAO,EACH,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,QAAQ,GACX,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE5E;;GAEG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACrC,SAAS,EAAE,IAAI;IACf,YAAY,EAAE,IAAI;IAClB,YAAY,EAAE,CAAC;CACoB,CAAC;AAExC,MAAM,UAAU,8BAA8B,CAC1C,OAAsC;IAEtC,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACnC,OAAO,CAAC,yBAAyB,CAAC,CAAC;IACvC,CAAC;SAAM,CAAC;QACJ,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;YAC5B,GAAG,MAAM;YACT,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,yBAAyB,CAAC,SAAS;YAClE,YAAY,EACR,MAAM,CAAC,YAAY,IAAI,yBAAyB,CAAC,YAAY;YACjE,YAAY,EACR,MAAM,CAAC,YAAY,IAAI,yBAAyB,CA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,CACpC,UAAU,CAAC,eAAe,EAC1B,SAAS,CAAC,gBAAgB,CAC7B,CAAC;QACN,CAAC;QAED,OAAO,gBAAgB,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IACjD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAO;QACT,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,GAAG,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;QACjE,OAAO,IAAI,yBAAyB,CAChC,IAAI,EACJ,UAAU,EACV,WAAW,EACX,IAAI,CAAC,WAAW,CACnB,CAAC;IACN,CAAC;CACJ;AAED,WAAiB,qBAAqB;IAClC,MAAa,eAAgB,SAAQ,KAAK;QACtC,YAAY,KAAa;YACrB,KAAK,CAAC,kDAAkD,EAAE;gBACtD,KAAK;aACR,CAAC,CAAC;QACP,CAAC;KACJ;IANY,qCAAe,kBAM3B,CAAA;AACL,CAAC,EARgB,qBAAqB,KAArB,qBAAqB,QAQrC"}
|
package/esm/index.d.ts
CHANGED
package/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC"}
|
package/esm/index.js
CHANGED
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC"}
|
package/esm/manager.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
/// <reference types="w3c-web-usb" />
|
|
2
1
|
import { AdbDaemonWebUsbDevice } from "./device.js";
|
|
3
|
-
import
|
|
2
|
+
import { AdbDaemonWebUsbDeviceObserver } from "./observer.js";
|
|
4
3
|
export declare namespace AdbDaemonWebUsbDeviceManager {
|
|
5
4
|
interface RequestDeviceOptions {
|
|
6
|
-
filters?:
|
|
5
|
+
filters?: USBDeviceFilter[] | undefined;
|
|
7
6
|
exclusionFilters?: USBDeviceFilter[] | undefined;
|
|
8
7
|
}
|
|
9
8
|
}
|
|
@@ -21,31 +20,13 @@ export declare class AdbDaemonWebUsbDeviceManager {
|
|
|
21
20
|
*/
|
|
22
21
|
constructor(usbManager: USB);
|
|
23
22
|
/**
|
|
24
|
-
*
|
|
25
|
-
* This is a convince method for `usb.requestDevice()`.
|
|
26
|
-
* @param filters
|
|
27
|
-
* The filters to apply to the device list.
|
|
28
|
-
*
|
|
29
|
-
* It must have `classCode`, `subclassCode` and `protocolCode` fields for selecting the ADB interface,
|
|
30
|
-
* but might also have `vendorId`, `productId` or `serialNumber` fields to limit the displayed device list.
|
|
31
|
-
*
|
|
32
|
-
* Defaults to {@link ADB_DEFAULT_DEVICE_FILTER}.
|
|
33
|
-
* @returns An {@link AdbDaemonWebUsbDevice} instance if the user selected a device,
|
|
34
|
-
* or `undefined` if the user cancelled the device picker.
|
|
23
|
+
* Call `USB#requestDevice()` to prompt the user to select a device.
|
|
35
24
|
*/
|
|
36
25
|
requestDevice(options?: AdbDaemonWebUsbDeviceManager.RequestDeviceOptions): Promise<AdbDaemonWebUsbDevice | undefined>;
|
|
37
26
|
/**
|
|
38
|
-
* Get all connected and
|
|
39
|
-
* This is a convince method for `usb.getDevices()`.
|
|
40
|
-
* @param filters
|
|
41
|
-
* The filters to apply to the device list.
|
|
42
|
-
*
|
|
43
|
-
* It must have `classCode`, `subclassCode` and `protocolCode` fields for selecting the ADB interface,
|
|
44
|
-
* but might also have `vendorId`, `productId` or `serialNumber` fields to limit the device list.
|
|
45
|
-
*
|
|
46
|
-
* Defaults to {@link ADB_DEFAULT_DEVICE_FILTER}.
|
|
47
|
-
* @returns An array of {@link AdbDaemonWebUsbDevice} instances for all connected and authenticated devices.
|
|
27
|
+
* Get all connected and requested devices that match the specified filters.
|
|
48
28
|
*/
|
|
49
|
-
getDevices(
|
|
29
|
+
getDevices(options?: AdbDaemonWebUsbDeviceManager.RequestDeviceOptions): Promise<AdbDaemonWebUsbDevice[]>;
|
|
30
|
+
trackDevices(options?: AdbDaemonWebUsbDeviceManager.RequestDeviceOptions): AdbDaemonWebUsbDeviceObserver;
|
|
50
31
|
}
|
|
51
32
|
//# sourceMappingURL=manager.d.ts.map
|
package/esm/manager.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../src/manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../src/manager.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,qBAAqB,EAExB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,6BAA6B,EAAE,MAAM,eAAe,CAAC;AAG9D,yBAAiB,4BAA4B,CAAC;IAC1C,UAAiB,oBAAoB;QACjC,OAAO,CAAC,EAAE,eAAe,EAAE,GAAG,SAAS,CAAC;QACxC,gBAAgB,CAAC,EAAE,eAAe,EAAE,GAAG,SAAS,CAAC;KACpD;CACJ;AAED,qBAAa,4BAA4B;;IACrC;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,OAAO,2CAIH;IAIpB;;;OAGG;gBACS,UAAU,EAAE,GAAG;IAI3B;;OAEG;IACG,aAAa,CACf,OAAO,GAAE,4BAA4B,CAAC,oBAAyB,GAChE,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;IAmC7C;;OAEG;IACG,UAAU,CACZ,OAAO,GAAE,4BAA4B,CAAC,oBAAyB,GAChE,OAAO,CAAC,qBAAqB,EAAE,CAAC;IA0BnC,YAAY,CACR,OAAO,GAAE,4BAA4B,CAAC,oBAAyB,GAChE,6BAA6B;CAGnC"}
|
package/esm/manager.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { AdbDaemonWebUsbDevice, mergeDefaultAdbInterfaceFilter, } from "./device.js";
|
|
2
|
+
import { AdbDaemonWebUsbDeviceObserver } from "./observer.js";
|
|
3
|
+
import { isErrorName, matchFilters } from "./utils.js";
|
|
3
4
|
export class AdbDaemonWebUsbDeviceManager {
|
|
4
5
|
/**
|
|
5
6
|
* Gets the instance of {@link AdbDaemonWebUsbDeviceManager} using browser WebUSB implementation.
|
|
@@ -19,28 +20,22 @@ export class AdbDaemonWebUsbDeviceManager {
|
|
|
19
20
|
this.#usbManager = usbManager;
|
|
20
21
|
}
|
|
21
22
|
/**
|
|
22
|
-
*
|
|
23
|
-
* This is a convince method for `usb.requestDevice()`.
|
|
24
|
-
* @param filters
|
|
25
|
-
* The filters to apply to the device list.
|
|
26
|
-
*
|
|
27
|
-
* It must have `classCode`, `subclassCode` and `protocolCode` fields for selecting the ADB interface,
|
|
28
|
-
* but might also have `vendorId`, `productId` or `serialNumber` fields to limit the displayed device list.
|
|
29
|
-
*
|
|
30
|
-
* Defaults to {@link ADB_DEFAULT_DEVICE_FILTER}.
|
|
31
|
-
* @returns An {@link AdbDaemonWebUsbDevice} instance if the user selected a device,
|
|
32
|
-
* or `undefined` if the user cancelled the device picker.
|
|
23
|
+
* Call `USB#requestDevice()` to prompt the user to select a device.
|
|
33
24
|
*/
|
|
34
25
|
async requestDevice(options = {}) {
|
|
35
|
-
|
|
36
|
-
options.filters = [ADB_DEFAULT_DEVICE_FILTER];
|
|
37
|
-
}
|
|
38
|
-
else if (options.filters.length === 0) {
|
|
39
|
-
throw new TypeError("filters must not be empty");
|
|
40
|
-
}
|
|
26
|
+
const filters = mergeDefaultAdbInterfaceFilter(options.filters);
|
|
41
27
|
try {
|
|
42
|
-
const device = await this.#usbManager.requestDevice(
|
|
43
|
-
|
|
28
|
+
const device = await this.#usbManager.requestDevice({
|
|
29
|
+
filters,
|
|
30
|
+
exclusionFilters: options.exclusionFilters,
|
|
31
|
+
});
|
|
32
|
+
const interface_ = matchFilters(device, filters, options.exclusionFilters);
|
|
33
|
+
if (!interface_) {
|
|
34
|
+
// `#usbManager` doesn't support `exclusionFilters`,
|
|
35
|
+
// selected device is invalid
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
return new AdbDaemonWebUsbDevice(device, interface_, this.#usbManager);
|
|
44
39
|
}
|
|
45
40
|
catch (e) {
|
|
46
41
|
// No device selected
|
|
@@ -51,48 +46,23 @@ export class AdbDaemonWebUsbDeviceManager {
|
|
|
51
46
|
}
|
|
52
47
|
}
|
|
53
48
|
/**
|
|
54
|
-
* Get all connected and
|
|
55
|
-
* This is a convince method for `usb.getDevices()`.
|
|
56
|
-
* @param filters
|
|
57
|
-
* The filters to apply to the device list.
|
|
58
|
-
*
|
|
59
|
-
* It must have `classCode`, `subclassCode` and `protocolCode` fields for selecting the ADB interface,
|
|
60
|
-
* but might also have `vendorId`, `productId` or `serialNumber` fields to limit the device list.
|
|
61
|
-
*
|
|
62
|
-
* Defaults to {@link ADB_DEFAULT_DEVICE_FILTER}.
|
|
63
|
-
* @returns An array of {@link AdbDaemonWebUsbDevice} instances for all connected and authenticated devices.
|
|
49
|
+
* Get all connected and requested devices that match the specified filters.
|
|
64
50
|
*/
|
|
65
|
-
async getDevices(
|
|
66
|
-
|
|
67
|
-
throw new TypeError("filters must not be empty");
|
|
68
|
-
}
|
|
51
|
+
async getDevices(options = {}) {
|
|
52
|
+
const filters = mergeDefaultAdbInterfaceFilter(options.filters);
|
|
69
53
|
const devices = await this.#usbManager.getDevices();
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
if ("productId" in filter &&
|
|
78
|
-
device.productId !== filter.productId) {
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
if ("serialNumber" in filter &&
|
|
82
|
-
getSerialNumber(device) !== filter.serialNumber) {
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
try {
|
|
86
|
-
findUsbAlternateInterface(device, filters);
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
catch {
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
54
|
+
// filter map
|
|
55
|
+
const result = [];
|
|
56
|
+
for (const device of devices) {
|
|
57
|
+
const interface_ = matchFilters(device, filters, options.exclusionFilters);
|
|
58
|
+
if (interface_) {
|
|
59
|
+
result.push(new AdbDaemonWebUsbDevice(device, interface_, this.#usbManager));
|
|
92
60
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
trackDevices(options = {}) {
|
|
65
|
+
return new AdbDaemonWebUsbDeviceObserver(this.#usbManager, options);
|
|
96
66
|
}
|
|
97
67
|
}
|
|
98
68
|
//# sourceMappingURL=manager.js.map
|
package/esm/manager.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../src/manager.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../src/manager.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,qBAAqB,EACrB,8BAA8B,GACjC,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,6BAA6B,EAAE,MAAM,eAAe,CAAC;AA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