@yume-chan/adb-daemon-webusb 0.0.23 → 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 +43 -2
- package/LICENSE +1 -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 +46 -56
- 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 -11
- package/src/device.ts +56 -71
- 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 -193
- 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,8 +1,36 @@
|
|
|
1
1
|
# Change Log - @yume-chan/adb-daemon-webusb
|
|
2
2
|
|
|
3
|
-
|
|
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
|
+
|
|
24
|
+
This log was last generated on Tue, 18 Jun 2024 02:49:43 GMT and should not be manually modified.
|
|
25
|
+
|
|
26
|
+
## 0.0.24
|
|
27
|
+
|
|
28
|
+
Tue, 18 Jun 2024 02:49:43 GMT
|
|
29
|
+
|
|
30
|
+
_Version update only_
|
|
4
31
|
|
|
5
32
|
## 0.0.23
|
|
33
|
+
|
|
6
34
|
Thu, 21 Mar 2024 03:15:10 GMT
|
|
7
35
|
|
|
8
36
|
### Updates
|
|
@@ -10,6 +38,7 @@ Thu, 21 Mar 2024 03:15:10 GMT
|
|
|
10
38
|
- Fix `AdbDaemonWebUsbDeviceManager.getDevices` doesn't match auto-generated serial number against `filters.serialNumber` (if the device doesn't have a serial number)
|
|
11
39
|
|
|
12
40
|
## 0.0.22
|
|
41
|
+
|
|
13
42
|
Wed, 13 Dec 2023 05:57:27 GMT
|
|
14
43
|
|
|
15
44
|
### Updates
|
|
@@ -19,11 +48,13 @@ Wed, 13 Dec 2023 05:57:27 GMT
|
|
|
19
48
|
- `AdbDaemonWebUsbDevice` will generate a fake serial number from vid and pid if the device serial number is empty
|
|
20
49
|
|
|
21
50
|
## 0.0.21
|
|
51
|
+
|
|
22
52
|
Fri, 25 Aug 2023 14:05:18 GMT
|
|
23
53
|
|
|
24
54
|
_Version update only_
|
|
25
55
|
|
|
26
56
|
## 0.0.20
|
|
57
|
+
|
|
27
58
|
Mon, 05 Jun 2023 02:51:41 GMT
|
|
28
59
|
|
|
29
60
|
### Updates
|
|
@@ -35,6 +66,7 @@ Mon, 05 Jun 2023 02:51:41 GMT
|
|
|
35
66
|
- Add `filters` parameter to `AdbDaemonWebUsbDeviceManager#getDevices`. The filtration is manually implemented because WebUSB's `getDevice` API doesn't support filters.
|
|
36
67
|
|
|
37
68
|
## 0.0.19
|
|
69
|
+
|
|
38
70
|
Sun, 09 Apr 2023 05:55:33 GMT
|
|
39
71
|
|
|
40
72
|
### Updates
|
|
@@ -43,6 +75,7 @@ Sun, 09 Apr 2023 05:55:33 GMT
|
|
|
43
75
|
- Add the `AdbWebUsbBackendManager` class to simplify the usage with custom WebUSB implementations (for example the `usb` NPM package).
|
|
44
76
|
|
|
45
77
|
## 0.0.18
|
|
78
|
+
|
|
46
79
|
Wed, 25 Jan 2023 21:33:49 GMT
|
|
47
80
|
|
|
48
81
|
### Updates
|
|
@@ -50,6 +83,7 @@ Wed, 25 Jan 2023 21:33:49 GMT
|
|
|
50
83
|
- Add an option to specify USB filters
|
|
51
84
|
|
|
52
85
|
## 0.0.17
|
|
86
|
+
|
|
53
87
|
Tue, 18 Oct 2022 09:32:30 GMT
|
|
54
88
|
|
|
55
89
|
### Updates
|
|
@@ -57,6 +91,7 @@ Tue, 18 Oct 2022 09:32:30 GMT
|
|
|
57
91
|
- Update to use new stream util package
|
|
58
92
|
|
|
59
93
|
## 0.0.16
|
|
94
|
+
|
|
60
95
|
Sat, 28 May 2022 03:56:37 GMT
|
|
61
96
|
|
|
62
97
|
### Updates
|
|
@@ -64,6 +99,7 @@ Sat, 28 May 2022 03:56:37 GMT
|
|
|
64
99
|
- Upgrade TypeScript to 4.7.2 to enable Node.js ESM
|
|
65
100
|
|
|
66
101
|
## 0.0.15
|
|
102
|
+
|
|
67
103
|
Mon, 02 May 2022 04:18:01 GMT
|
|
68
104
|
|
|
69
105
|
### Updates
|
|
@@ -71,11 +107,13 @@ Mon, 02 May 2022 04:18:01 GMT
|
|
|
71
107
|
- Improve connection lifecycle handling
|
|
72
108
|
|
|
73
109
|
## 0.0.14
|
|
110
|
+
|
|
74
111
|
Sat, 30 Apr 2022 14:05:48 GMT
|
|
75
112
|
|
|
76
113
|
_Version update only_
|
|
77
114
|
|
|
78
115
|
## 0.0.13
|
|
116
|
+
|
|
79
117
|
Thu, 28 Apr 2022 01:23:53 GMT
|
|
80
118
|
|
|
81
119
|
### Updates
|
|
@@ -83,11 +121,13 @@ Thu, 28 Apr 2022 01:23:53 GMT
|
|
|
83
121
|
- Workaround an issue in Chrome where `transferIn` never returns `babble` on Windows
|
|
84
122
|
|
|
85
123
|
## 0.0.12
|
|
124
|
+
|
|
86
125
|
Sun, 03 Apr 2022 11:18:47 GMT
|
|
87
126
|
|
|
88
127
|
_Version update only_
|
|
89
128
|
|
|
90
129
|
## 0.0.11
|
|
130
|
+
|
|
91
131
|
Sun, 03 Apr 2022 10:54:15 GMT
|
|
92
132
|
|
|
93
133
|
### Updates
|
|
@@ -97,6 +137,7 @@ Sun, 03 Apr 2022 10:54:15 GMT
|
|
|
97
137
|
- Update license year
|
|
98
138
|
|
|
99
139
|
## 0.0.10
|
|
140
|
+
|
|
100
141
|
Sun, 09 Jan 2022 15:52:20 GMT
|
|
101
142
|
|
|
102
143
|
### Updates
|
|
@@ -104,7 +145,7 @@ Sun, 09 Jan 2022 15:52:20 GMT
|
|
|
104
145
|
- Remove `encodeUtf8()` and `decodeUtf8()` from `AdbBackend`
|
|
105
146
|
|
|
106
147
|
## 0.0.9
|
|
148
|
+
|
|
107
149
|
Sun, 09 Jan 2022 15:50:20 GMT
|
|
108
150
|
|
|
109
151
|
_Initial release_
|
|
110
|
-
|
package/LICENSE
CHANGED
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
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { DuplexStreamFactory, MaybeConsumable, ReadableStream, pipeFrom, } from "@yume-chan/stream-extra";
|
|
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 Error("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 Error("No output endpoint found.");
|
|
45
|
-
}
|
|
46
|
-
throw new Error("unreachable");
|
|
47
25
|
}
|
|
48
26
|
class Uint8ArrayExactReadable {
|
|
49
27
|
#data;
|
|
@@ -120,7 +98,7 @@ export class AdbDaemonWebUsbConnection {
|
|
|
120
98
|
},
|
|
121
99
|
}, { highWaterMark: 0 }));
|
|
122
100
|
const zeroMask = outEndpoint.packetSize - 1;
|
|
123
|
-
this.#writable = pipeFrom(duplex.createWritable(new
|
|
101
|
+
this.#writable = pipeFrom(duplex.createWritable(new MaybeConsumable.WritableStream({
|
|
124
102
|
write: async (chunk) => {
|
|
125
103
|
try {
|
|
126
104
|
await device.raw.transferOut(outEndpoint.endpointNumber, chunk);
|
|
@@ -128,9 +106,8 @@ export class AdbDaemonWebUsbConnection {
|
|
|
128
106
|
// If the payload size is a multiple of the packet size,
|
|
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
|
-
if (zeroMask &&
|
|
132
|
-
(
|
|
133
|
-
await device.raw.transferOut(outEndpoint.endpointNumber, EMPTY_UINT8_ARRAY);
|
|
109
|
+
if (zeroMask && (chunk.length & zeroMask) === 0) {
|
|
110
|
+
await device.raw.transferOut(outEndpoint.endpointNumber, EmptyUint8Array);
|
|
134
111
|
}
|
|
135
112
|
}
|
|
136
113
|
catch (e) {
|
|
@@ -163,7 +140,7 @@ export class AdbDaemonWebUsbConnection {
|
|
|
163
140
|
packet.payload = new Uint8Array(result.data.buffer);
|
|
164
141
|
}
|
|
165
142
|
else {
|
|
166
|
-
packet.payload =
|
|
143
|
+
packet.payload = EmptyUint8Array;
|
|
167
144
|
}
|
|
168
145
|
return packet;
|
|
169
146
|
}
|
|
@@ -171,7 +148,7 @@ export class AdbDaemonWebUsbConnection {
|
|
|
171
148
|
catch (e) {
|
|
172
149
|
// On Windows, disconnecting the device will cause `NetworkError` to be thrown,
|
|
173
150
|
// even before the `disconnect` event is fired.
|
|
174
|
-
//
|
|
151
|
+
// Wait a little while and check if the device is still connected.
|
|
175
152
|
// https://github.com/WICG/webusb/issues/219
|
|
176
153
|
if (isErrorName(e, "NetworkError")) {
|
|
177
154
|
await new Promise((resolve) => {
|
|
@@ -182,16 +159,13 @@ export class AdbDaemonWebUsbConnection {
|
|
|
182
159
|
if (closed) {
|
|
183
160
|
return undefined;
|
|
184
161
|
}
|
|
185
|
-
else {
|
|
186
|
-
throw e;
|
|
187
|
-
}
|
|
188
162
|
}
|
|
189
163
|
throw e;
|
|
190
164
|
}
|
|
191
165
|
}
|
|
192
166
|
}
|
|
193
167
|
export class AdbDaemonWebUsbDevice {
|
|
194
|
-
#
|
|
168
|
+
#interface;
|
|
195
169
|
#usbManager;
|
|
196
170
|
#raw;
|
|
197
171
|
get raw() {
|
|
@@ -210,17 +184,17 @@ export class AdbDaemonWebUsbDevice {
|
|
|
210
184
|
* @param device The `USBDevice` instance obtained elsewhere.
|
|
211
185
|
* @param filters The filters to use when searching for ADB interface. Defaults to {@link ADB_DEFAULT_DEVICE_FILTER}.
|
|
212
186
|
*/
|
|
213
|
-
constructor(device,
|
|
187
|
+
constructor(device, interface_, usbManager) {
|
|
214
188
|
this.#raw = device;
|
|
215
189
|
this.#serial = getSerialNumber(device);
|
|
216
|
-
this.#
|
|
190
|
+
this.#interface = interface_;
|
|
217
191
|
this.#usbManager = usbManager;
|
|
218
192
|
}
|
|
219
193
|
async #claimInterface() {
|
|
220
194
|
if (!this.#raw.opened) {
|
|
221
195
|
await this.#raw.open();
|
|
222
196
|
}
|
|
223
|
-
const { configuration, interface_, alternate } =
|
|
197
|
+
const { configuration, interface_, alternate } = this.#interface;
|
|
224
198
|
if (this.#raw.configuration?.configurationValue !==
|
|
225
199
|
configuration.configurationValue) {
|
|
226
200
|
// Note: Switching configuration is not supported on Windows,
|
|
@@ -228,21 +202,37 @@ export class AdbDaemonWebUsbDevice {
|
|
|
228
202
|
await this.#raw.selectConfiguration(configuration.configurationValue);
|
|
229
203
|
}
|
|
230
204
|
if (!interface_.claimed) {
|
|
231
|
-
|
|
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
|
+
}
|
|
232
214
|
}
|
|
233
215
|
if (interface_.alternate.alternateSetting !== alternate.alternateSetting) {
|
|
234
216
|
await this.#raw.selectAlternateInterface(interface_.interfaceNumber, alternate.alternateSetting);
|
|
235
217
|
}
|
|
236
|
-
|
|
237
|
-
return [inEndpoint, outEndpoint];
|
|
218
|
+
return findUsbEndpoints(alternate.endpoints);
|
|
238
219
|
}
|
|
239
220
|
/**
|
|
240
|
-
*
|
|
241
|
-
* @returns The pair of `AdbPacket` streams.
|
|
221
|
+
* Open the device and create a new connection to the ADB Daemon.
|
|
242
222
|
*/
|
|
243
223
|
async connect() {
|
|
244
|
-
const
|
|
224
|
+
const { inEndpoint, outEndpoint } = await this.#claimInterface();
|
|
245
225
|
return new AdbDaemonWebUsbConnection(this, inEndpoint, outEndpoint, this.#usbManager);
|
|
246
226
|
}
|
|
247
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 = {}));
|
|
248
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,
|
|
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,CAA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AAC,UAAU,CAAC,eAAe,CAAC,CAAC;YAC/D,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACT,IAAI,WAAW,CAAC,CAAC,EAAE,cAAc,CAAC,EAAE,CAAC;oBACjC,MAAM,IAAI,qBAAqB,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;gBACvD,CAAC;gBAED,MAAM,CAAC,CAAC;YACZ,CAAC;QACL,CAAC;QAED,IACI,UAAU,CAAC,SAAS,CAAC,gBAAgB,KAAK,SAAS,CAAC,gBAAgB,EACtE,CAAC;YACC,MAAM,IAAI,CAAC,IAAI,CAAC,wBAAwB,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
|