@yume-chan/adb 0.0.17 → 0.0.18
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.json +6 -0
- package/CHANGELOG.md +6 -1
- package/LICENSE +1 -1
- package/esm/adb.d.ts +6 -6
- package/esm/adb.d.ts.map +1 -1
- package/esm/adb.js +55 -35
- package/esm/adb.js.map +1 -1
- package/esm/auth.d.ts +4 -4
- package/esm/auth.d.ts.map +1 -1
- package/esm/auth.js +6 -6
- package/esm/auth.js.map +1 -1
- package/esm/backend.d.ts +3 -3
- package/esm/backend.d.ts.map +1 -1
- package/esm/commands/base.d.ts +2 -2
- package/esm/commands/base.d.ts.map +1 -1
- package/esm/commands/base.js +1 -1
- package/esm/commands/framebuffer.d.ts +7 -7
- package/esm/commands/framebuffer.d.ts.map +1 -1
- package/esm/commands/framebuffer.js +32 -33
- package/esm/commands/framebuffer.js.map +1 -1
- package/esm/commands/install.d.ts +2 -2
- package/esm/commands/install.d.ts.map +1 -1
- package/esm/commands/install.js +12 -6
- package/esm/commands/install.js.map +1 -1
- package/esm/commands/power.d.ts +1 -1
- package/esm/commands/power.d.ts.map +1 -1
- package/esm/commands/power.js +14 -10
- package/esm/commands/power.js.map +1 -1
- package/esm/commands/reverse.d.ts +3 -3
- package/esm/commands/reverse.d.ts.map +1 -1
- package/esm/commands/reverse.js +14 -12
- package/esm/commands/reverse.js.map +1 -1
- package/esm/commands/subprocess/command.d.ts +2 -2
- package/esm/commands/subprocess/command.d.ts.map +1 -1
- package/esm/commands/subprocess/command.js +14 -16
- package/esm/commands/subprocess/command.js.map +1 -1
- package/esm/commands/subprocess/protocols/none.d.ts +4 -4
- package/esm/commands/subprocess/protocols/none.d.ts.map +1 -1
- package/esm/commands/subprocess/protocols/none.js.map +1 -1
- package/esm/commands/subprocess/protocols/shell.d.ts +4 -4
- package/esm/commands/subprocess/protocols/shell.d.ts.map +1 -1
- package/esm/commands/subprocess/protocols/shell.js +23 -15
- package/esm/commands/subprocess/protocols/shell.js.map +1 -1
- package/esm/commands/subprocess/protocols/types.d.ts +4 -4
- package/esm/commands/subprocess/protocols/types.d.ts.map +1 -1
- package/esm/commands/sync/list.d.ts +6 -6
- package/esm/commands/sync/list.d.ts.map +1 -1
- package/esm/commands/sync/list.js +23 -11
- package/esm/commands/sync/list.js.map +1 -1
- package/esm/commands/sync/pull.d.ts +4 -4
- package/esm/commands/sync/pull.d.ts.map +1 -1
- package/esm/commands/sync/pull.js +12 -11
- package/esm/commands/sync/pull.js.map +1 -1
- package/esm/commands/sync/push.d.ts +3 -3
- package/esm/commands/sync/push.d.ts.map +1 -1
- package/esm/commands/sync/push.js +6 -7
- package/esm/commands/sync/push.js.map +1 -1
- package/esm/commands/sync/request.d.ts +4 -4
- package/esm/commands/sync/request.d.ts.map +1 -1
- package/esm/commands/sync/request.js +7 -7
- package/esm/commands/sync/request.js.map +1 -1
- package/esm/commands/sync/response.d.ts +4 -4
- package/esm/commands/sync/response.d.ts.map +1 -1
- package/esm/commands/sync/response.js +7 -7
- package/esm/commands/sync/response.js.map +1 -1
- package/esm/commands/sync/stat.d.ts +5 -5
- package/esm/commands/sync/stat.d.ts.map +1 -1
- package/esm/commands/sync/stat.js +37 -27
- package/esm/commands/sync/stat.js.map +1 -1
- package/esm/commands/sync/sync.d.ts +6 -6
- package/esm/commands/sync/sync.d.ts.map +1 -1
- package/esm/commands/sync/sync.js +20 -19
- package/esm/commands/sync/sync.js.map +1 -1
- package/esm/crypto.d.ts.map +1 -1
- package/esm/crypto.js +25 -15
- package/esm/crypto.js.map +1 -1
- package/esm/index.d.ts +9 -9
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +9 -9
- package/esm/index.js.map +1 -1
- package/esm/packet.d.ts +8 -8
- package/esm/packet.d.ts.map +1 -1
- package/esm/packet.js +14 -12
- package/esm/packet.js.map +1 -1
- package/esm/socket/dispatcher.d.ts +6 -6
- package/esm/socket/dispatcher.d.ts.map +1 -1
- package/esm/socket/dispatcher.js +22 -19
- package/esm/socket/dispatcher.js.map +1 -1
- package/esm/socket/socket.d.ts +4 -4
- package/esm/socket/socket.d.ts.map +1 -1
- package/esm/socket/socket.js +37 -17
- package/esm/socket/socket.js.map +1 -1
- package/esm/utils/auto-reset-event.d.ts +1 -1
- package/esm/utils/auto-reset-event.d.ts.map +1 -1
- package/esm/utils/auto-reset-event.js +2 -2
- package/esm/utils/base64.d.ts.map +1 -1
- package/esm/utils/base64.js +30 -29
- package/esm/utils/base64.js.map +1 -1
- package/package.json +16 -13
- package/src/adb.ts +133 -84
- package/src/auth.ts +27 -19
- package/src/backend.ts +6 -4
- package/src/commands/base.ts +2 -2
- package/src/commands/framebuffer.ts +37 -41
- package/src/commands/install.ts +19 -11
- package/src/commands/power.ts +15 -11
- package/src/commands/reverse.ts +48 -29
- package/src/commands/subprocess/command.ts +24 -21
- package/src/commands/subprocess/protocols/none.ts +4 -3
- package/src/commands/subprocess/protocols/shell.ts +65 -33
- package/src/commands/subprocess/protocols/types.ts +8 -5
- package/src/commands/sync/list.ts +51 -24
- package/src/commands/sync/pull.ts +51 -34
- package/src/commands/sync/push.ts +25 -11
- package/src/commands/sync/request.ts +20 -22
- package/src/commands/sync/response.ts +31 -25
- package/src/commands/sync/stat.ts +78 -55
- package/src/commands/sync/sync.ts +47 -26
- package/src/crypto.ts +60 -32
- package/src/index.ts +9 -10
- package/src/packet.ts +40 -30
- package/src/socket/dispatcher.ts +115 -78
- package/src/socket/socket.ts +68 -27
- package/src/utils/auto-reset-event.ts +3 -3
- package/src/utils/base64.ts +51 -41
- package/tsconfig.build.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
package/src/socket/dispatcher.ts
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
|
-
import { AsyncOperationManager, PromiseResolver } from
|
|
2
|
-
import type
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { AsyncOperationManager, PromiseResolver } from "@yume-chan/async";
|
|
2
|
+
import { type RemoveEventListener } from "@yume-chan/event";
|
|
3
|
+
import {
|
|
4
|
+
AbortController,
|
|
5
|
+
WritableStream,
|
|
6
|
+
type ReadableWritablePair,
|
|
7
|
+
type WritableStreamDefaultWriter,
|
|
8
|
+
} from "@yume-chan/stream-extra";
|
|
9
|
+
import { EMPTY_UINT8_ARRAY, type ValueOrPromise } from "@yume-chan/struct";
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
AdbCommand,
|
|
13
|
+
calculateChecksum,
|
|
14
|
+
type AdbPacketData,
|
|
15
|
+
type AdbPacketInit,
|
|
16
|
+
} from "../packet.js";
|
|
17
|
+
import { decodeUtf8, encodeUtf8 } from "../utils/index.js";
|
|
18
|
+
|
|
19
|
+
import { AdbSocketController, type AdbSocket } from "./socket.js";
|
|
9
20
|
|
|
10
21
|
export interface AdbPacketDispatcherOptions {
|
|
11
22
|
calculateChecksum: boolean;
|
|
@@ -19,7 +30,9 @@ export interface AdbPacketDispatcherOptions {
|
|
|
19
30
|
maxPayloadSize: number;
|
|
20
31
|
}
|
|
21
32
|
|
|
22
|
-
export type AdbIncomingSocketHandler = (
|
|
33
|
+
export type AdbIncomingSocketHandler = (
|
|
34
|
+
socket: AdbSocket
|
|
35
|
+
) => ValueOrPromise<boolean>;
|
|
23
36
|
|
|
24
37
|
export interface Closeable {
|
|
25
38
|
close(): ValueOrPromise<void>;
|
|
@@ -50,7 +63,9 @@ export class AdbPacketDispatcher implements Closeable {
|
|
|
50
63
|
|
|
51
64
|
private _closed = false;
|
|
52
65
|
private _disconnected = new PromiseResolver<void>();
|
|
53
|
-
public get disconnected() {
|
|
66
|
+
public get disconnected() {
|
|
67
|
+
return this._disconnected.promise;
|
|
68
|
+
}
|
|
54
69
|
|
|
55
70
|
private _incomingSocketHandlers: Set<AdbIncomingSocketHandler> = new Set();
|
|
56
71
|
|
|
@@ -63,53 +78,68 @@ export class AdbPacketDispatcher implements Closeable {
|
|
|
63
78
|
this.options = options;
|
|
64
79
|
|
|
65
80
|
connection.readable
|
|
66
|
-
.pipeTo(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
case AdbCommand.Close:
|
|
73
|
-
await this.handleClose(packet);
|
|
74
|
-
break;
|
|
75
|
-
case AdbCommand.Write:
|
|
76
|
-
if (this.sockets.has(packet.arg1)) {
|
|
77
|
-
await this.sockets.get(packet.arg1)!.enqueue(packet.payload);
|
|
78
|
-
await this.sendPacket(AdbCommand.OK, packet.arg1, packet.arg0);
|
|
81
|
+
.pipeTo(
|
|
82
|
+
new WritableStream({
|
|
83
|
+
write: async (packet) => {
|
|
84
|
+
switch (packet.command) {
|
|
85
|
+
case AdbCommand.OK:
|
|
86
|
+
this.handleOk(packet);
|
|
79
87
|
break;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
case AdbCommand.Close:
|
|
89
|
+
await this.handleClose(packet);
|
|
90
|
+
break;
|
|
91
|
+
case AdbCommand.Write:
|
|
92
|
+
if (this.sockets.has(packet.arg1)) {
|
|
93
|
+
await this.sockets
|
|
94
|
+
.get(packet.arg1)!
|
|
95
|
+
.enqueue(packet.payload);
|
|
96
|
+
await this.sendPacket(
|
|
97
|
+
AdbCommand.OK,
|
|
98
|
+
packet.arg1,
|
|
99
|
+
packet.arg0
|
|
100
|
+
);
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
throw new Error(
|
|
104
|
+
`Unknown local socket id: ${packet.arg1}`
|
|
105
|
+
);
|
|
106
|
+
case AdbCommand.Open:
|
|
107
|
+
await this.handleOpen(packet);
|
|
108
|
+
break;
|
|
109
|
+
default:
|
|
110
|
+
// Junk data may only appear in the authentication phase,
|
|
111
|
+
// since the dispatcher only works after authentication,
|
|
112
|
+
// all packets should have a valid command.
|
|
113
|
+
// (although it's possible that Adb added new commands in the future)
|
|
114
|
+
throw new Error(
|
|
115
|
+
`Unknown command: ${packet.command.toString(
|
|
116
|
+
16
|
|
117
|
+
)}`
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
}),
|
|
122
|
+
{
|
|
123
|
+
// There are multiple reasons for the pipe to stop,
|
|
124
|
+
// (device disconnection, protocol error, or user abortion)
|
|
125
|
+
// if the underlying streams are still open,
|
|
126
|
+
// it's still possible to create another ADB connection.
|
|
127
|
+
// So don't close `readable` here.
|
|
128
|
+
preventCancel: true,
|
|
129
|
+
signal: this._abortController.signal,
|
|
130
|
+
}
|
|
131
|
+
)
|
|
132
|
+
.then(
|
|
133
|
+
() => {
|
|
134
|
+
this.dispose();
|
|
92
135
|
},
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
// So don't close `readable` here.
|
|
99
|
-
preventCancel: true,
|
|
100
|
-
signal: this._abortController.signal,
|
|
101
|
-
})
|
|
102
|
-
.then(() => {
|
|
103
|
-
this.dispose();
|
|
104
|
-
}, (e) => {
|
|
105
|
-
// https://github.com/MattiasBuelens/web-streams-polyfill/issues/115
|
|
106
|
-
// `e` is always `AbortError` (instead of what I give in `abortController.abort()`)
|
|
107
|
-
// so we can't check if `e` is a real error.
|
|
108
|
-
if (!this._closed) {
|
|
109
|
-
this._disconnected.reject(e);
|
|
136
|
+
(e) => {
|
|
137
|
+
if (!this._closed) {
|
|
138
|
+
this._disconnected.reject(e);
|
|
139
|
+
}
|
|
140
|
+
this.dispose();
|
|
110
141
|
}
|
|
111
|
-
|
|
112
|
-
});
|
|
142
|
+
);
|
|
113
143
|
|
|
114
144
|
this._writer = connection.writable.getWriter();
|
|
115
145
|
}
|
|
@@ -129,13 +159,18 @@ export class AdbPacketDispatcher implements Closeable {
|
|
|
129
159
|
|
|
130
160
|
// Maybe the device is responding to a packet of last connection
|
|
131
161
|
// Tell the device to close the socket
|
|
132
|
-
this.sendPacket(AdbCommand.Close, packet.arg1, packet.arg0);
|
|
162
|
+
void this.sendPacket(AdbCommand.Close, packet.arg1, packet.arg0);
|
|
133
163
|
}
|
|
134
164
|
|
|
135
165
|
private async handleClose(packet: AdbPacketData) {
|
|
136
166
|
// If the socket is still pending
|
|
137
|
-
if (
|
|
138
|
-
|
|
167
|
+
if (
|
|
168
|
+
packet.arg0 === 0 &&
|
|
169
|
+
this.initializers.reject(
|
|
170
|
+
packet.arg1,
|
|
171
|
+
new Error("Socket open failed")
|
|
172
|
+
)
|
|
173
|
+
) {
|
|
139
174
|
// Device failed to create the socket
|
|
140
175
|
// (unknown service string, failed to execute command, etc.)
|
|
141
176
|
// it doesn't break the connection,
|
|
@@ -156,9 +191,13 @@ export class AdbPacketDispatcher implements Closeable {
|
|
|
156
191
|
if (socket) {
|
|
157
192
|
// The device want to close the socket
|
|
158
193
|
if (!socket.closed) {
|
|
159
|
-
await this.sendPacket(
|
|
194
|
+
await this.sendPacket(
|
|
195
|
+
AdbCommand.Close,
|
|
196
|
+
packet.arg1,
|
|
197
|
+
packet.arg0
|
|
198
|
+
);
|
|
160
199
|
}
|
|
161
|
-
socket.dispose();
|
|
200
|
+
await socket.dispose();
|
|
162
201
|
this.sockets.delete(packet.arg1);
|
|
163
202
|
return;
|
|
164
203
|
}
|
|
@@ -173,7 +212,9 @@ export class AdbPacketDispatcher implements Closeable {
|
|
|
173
212
|
* @param handler A function to call with new incoming sockets. It must return `true` if it accepts the socket.
|
|
174
213
|
* @returns A function to remove the handler.
|
|
175
214
|
*/
|
|
176
|
-
public onIncomingSocket(
|
|
215
|
+
public onIncomingSocket(
|
|
216
|
+
handler: AdbIncomingSocketHandler
|
|
217
|
+
): RemoveEventListener {
|
|
177
218
|
this._incomingSocketHandlers.add(handler);
|
|
178
219
|
const remove = () => {
|
|
179
220
|
this._incomingSocketHandlers.delete(handler);
|
|
@@ -212,16 +253,11 @@ export class AdbPacketDispatcher implements Closeable {
|
|
|
212
253
|
|
|
213
254
|
public async createSocket(serviceString: string): Promise<AdbSocket> {
|
|
214
255
|
if (this.options.appendNullToServiceString) {
|
|
215
|
-
serviceString +=
|
|
256
|
+
serviceString += "\0";
|
|
216
257
|
}
|
|
217
258
|
|
|
218
259
|
const [localId, initializer] = this.initializers.add<number>();
|
|
219
|
-
await this.sendPacket(
|
|
220
|
-
AdbCommand.Open,
|
|
221
|
-
localId,
|
|
222
|
-
0,
|
|
223
|
-
serviceString
|
|
224
|
-
);
|
|
260
|
+
await this.sendPacket(AdbCommand.Open, localId, 0, serviceString);
|
|
225
261
|
|
|
226
262
|
// Fulfilled by `handleOk`
|
|
227
263
|
const remoteId = await initializer;
|
|
@@ -248,27 +284,29 @@ export class AdbPacketDispatcher implements Closeable {
|
|
|
248
284
|
packetOrCommand: AdbPacketInit | AdbCommand,
|
|
249
285
|
arg0?: number,
|
|
250
286
|
arg1?: number,
|
|
251
|
-
payload: string | Uint8Array = EMPTY_UINT8_ARRAY
|
|
287
|
+
payload: string | Uint8Array = EMPTY_UINT8_ARRAY
|
|
252
288
|
): Promise<void> {
|
|
253
289
|
let init: AdbPacketData;
|
|
254
290
|
if (arg0 === undefined) {
|
|
255
291
|
init = packetOrCommand as AdbPacketInit;
|
|
256
292
|
} else {
|
|
257
|
-
if (typeof payload ===
|
|
293
|
+
if (typeof payload === "string") {
|
|
258
294
|
payload = encodeUtf8(payload);
|
|
259
295
|
}
|
|
260
296
|
|
|
261
297
|
init = {
|
|
262
298
|
command: packetOrCommand as AdbCommand,
|
|
263
|
-
arg0: arg0
|
|
299
|
+
arg0: arg0,
|
|
264
300
|
arg1: arg1 as number,
|
|
265
301
|
payload,
|
|
266
302
|
};
|
|
267
303
|
}
|
|
268
304
|
|
|
269
|
-
if (
|
|
270
|
-
init.payload
|
|
271
|
-
|
|
305
|
+
if (
|
|
306
|
+
init.payload &&
|
|
307
|
+
init.payload.byteLength > this.options.maxPayloadSize
|
|
308
|
+
) {
|
|
309
|
+
throw new Error("payload too large");
|
|
272
310
|
}
|
|
273
311
|
|
|
274
312
|
if (this.options.calculateChecksum) {
|
|
@@ -284,10 +322,7 @@ export class AdbPacketDispatcher implements Closeable {
|
|
|
284
322
|
public async close() {
|
|
285
323
|
// Send `CLSE` packets for all sockets
|
|
286
324
|
await Promise.all(
|
|
287
|
-
Array.from(
|
|
288
|
-
this.sockets.values(),
|
|
289
|
-
socket => socket.close(),
|
|
290
|
-
)
|
|
325
|
+
Array.from(this.sockets.values(), (socket) => socket.close())
|
|
291
326
|
);
|
|
292
327
|
|
|
293
328
|
// Stop receiving
|
|
@@ -302,7 +337,9 @@ export class AdbPacketDispatcher implements Closeable {
|
|
|
302
337
|
|
|
303
338
|
private dispose() {
|
|
304
339
|
for (const socket of this.sockets.values()) {
|
|
305
|
-
socket.dispose()
|
|
340
|
+
socket.dispose().catch((e) => {
|
|
341
|
+
void e;
|
|
342
|
+
});
|
|
306
343
|
}
|
|
307
344
|
|
|
308
345
|
this._disconnected.resolve();
|
package/src/socket/socket.ts
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
import { PromiseResolver } from
|
|
2
|
-
import type
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { PromiseResolver } from "@yume-chan/async";
|
|
2
|
+
import { type Disposable } from "@yume-chan/event";
|
|
3
|
+
import {
|
|
4
|
+
ChunkStream,
|
|
5
|
+
DuplexStreamFactory,
|
|
6
|
+
PushReadableStream,
|
|
7
|
+
WritableStream,
|
|
8
|
+
pipeFrom,
|
|
9
|
+
type PushReadableStreamController,
|
|
10
|
+
type ReadableStream,
|
|
11
|
+
type ReadableWritablePair,
|
|
12
|
+
} from "@yume-chan/stream-extra";
|
|
13
|
+
|
|
14
|
+
import { AdbCommand } from "../packet.js";
|
|
15
|
+
|
|
16
|
+
import { type AdbPacketDispatcher, type Closeable } from "./dispatcher.js";
|
|
7
17
|
|
|
8
18
|
export interface AdbSocketInfo {
|
|
9
19
|
localId: number;
|
|
@@ -19,7 +29,13 @@ export interface AdbSocketConstructionOptions extends AdbSocketInfo {
|
|
|
19
29
|
highWaterMark?: number | undefined;
|
|
20
30
|
}
|
|
21
31
|
|
|
22
|
-
export class AdbSocketController
|
|
32
|
+
export class AdbSocketController
|
|
33
|
+
implements
|
|
34
|
+
AdbSocketInfo,
|
|
35
|
+
ReadableWritablePair<Uint8Array, Uint8Array>,
|
|
36
|
+
Closeable,
|
|
37
|
+
Disposable
|
|
38
|
+
{
|
|
23
39
|
private readonly dispatcher!: AdbPacketDispatcher;
|
|
24
40
|
|
|
25
41
|
public readonly localId!: number;
|
|
@@ -31,7 +47,9 @@ export class AdbSocketController implements AdbSocketInfo, ReadableWritablePair<
|
|
|
31
47
|
|
|
32
48
|
private _readable: ReadableStream<Uint8Array>;
|
|
33
49
|
private _readableController!: PushReadableStreamController<Uint8Array>;
|
|
34
|
-
public get readable() {
|
|
50
|
+
public get readable() {
|
|
51
|
+
return this._readable;
|
|
52
|
+
}
|
|
35
53
|
|
|
36
54
|
private _writePromise: PromiseResolver<void> | undefined;
|
|
37
55
|
public readonly writable: WritableStream<Uint8Array>;
|
|
@@ -42,10 +60,14 @@ export class AdbSocketController implements AdbSocketInfo, ReadableWritablePair<
|
|
|
42
60
|
*
|
|
43
61
|
* It's only used by dispatcher to avoid sending another `CLSE` packet to remote.
|
|
44
62
|
*/
|
|
45
|
-
public get closed() {
|
|
63
|
+
public get closed() {
|
|
64
|
+
return this._closed;
|
|
65
|
+
}
|
|
46
66
|
|
|
47
67
|
private _socket: AdbSocket;
|
|
48
|
-
public get socket() {
|
|
68
|
+
public get socket() {
|
|
69
|
+
return this._socket;
|
|
70
|
+
}
|
|
49
71
|
|
|
50
72
|
public constructor(options: AdbSocketConstructionOptions) {
|
|
51
73
|
Object.assign(this, options);
|
|
@@ -69,17 +91,22 @@ export class AdbSocketController implements AdbSocketInfo, ReadableWritablePair<
|
|
|
69
91
|
},
|
|
70
92
|
dispose: () => {
|
|
71
93
|
// Error out the pending writes
|
|
72
|
-
this._writePromise?.reject(new Error(
|
|
94
|
+
this._writePromise?.reject(new Error("Socket closed"));
|
|
73
95
|
},
|
|
74
96
|
});
|
|
75
97
|
|
|
76
98
|
this._readable = this._duplex.wrapReadable(
|
|
77
|
-
new PushReadableStream(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
99
|
+
new PushReadableStream(
|
|
100
|
+
(controller) => {
|
|
101
|
+
this._readableController = controller;
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
highWaterMark: options.highWaterMark ?? 16 * 1024,
|
|
105
|
+
size(chunk) {
|
|
106
|
+
return chunk.byteLength;
|
|
107
|
+
},
|
|
108
|
+
}
|
|
109
|
+
)
|
|
83
110
|
);
|
|
84
111
|
|
|
85
112
|
this.writable = pipeFrom(
|
|
@@ -95,8 +122,8 @@ export class AdbSocketController implements AdbSocketInfo, ReadableWritablePair<
|
|
|
95
122
|
chunk
|
|
96
123
|
);
|
|
97
124
|
await this._writePromise.promise;
|
|
98
|
-
}
|
|
99
|
-
})
|
|
125
|
+
},
|
|
126
|
+
})
|
|
100
127
|
),
|
|
101
128
|
new ChunkStream(this.dispatcher.options.maxPayloadSize)
|
|
102
129
|
);
|
|
@@ -123,7 +150,7 @@ export class AdbSocketController implements AdbSocketInfo, ReadableWritablePair<
|
|
|
123
150
|
}
|
|
124
151
|
|
|
125
152
|
public dispose() {
|
|
126
|
-
this._duplex.dispose();
|
|
153
|
+
return this._duplex.dispose();
|
|
127
154
|
}
|
|
128
155
|
}
|
|
129
156
|
|
|
@@ -135,16 +162,30 @@ export class AdbSocketController implements AdbSocketInfo, ReadableWritablePair<
|
|
|
135
162
|
* `socket.writable.abort()`, `socket.writable.getWriter().abort()`,
|
|
136
163
|
* `socket.writable.close()` or `socket.writable.getWriter().close()`.
|
|
137
164
|
*/
|
|
138
|
-
export class AdbSocket
|
|
165
|
+
export class AdbSocket
|
|
166
|
+
implements AdbSocketInfo, ReadableWritablePair<Uint8Array, Uint8Array>
|
|
167
|
+
{
|
|
139
168
|
private _controller: AdbSocketController;
|
|
140
169
|
|
|
141
|
-
public get localId(): number {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
public get
|
|
170
|
+
public get localId(): number {
|
|
171
|
+
return this._controller.localId;
|
|
172
|
+
}
|
|
173
|
+
public get remoteId(): number {
|
|
174
|
+
return this._controller.remoteId;
|
|
175
|
+
}
|
|
176
|
+
public get localCreated(): boolean {
|
|
177
|
+
return this._controller.localCreated;
|
|
178
|
+
}
|
|
179
|
+
public get serviceString(): string {
|
|
180
|
+
return this._controller.serviceString;
|
|
181
|
+
}
|
|
145
182
|
|
|
146
|
-
public get readable(): ReadableStream<Uint8Array> {
|
|
147
|
-
|
|
183
|
+
public get readable(): ReadableStream<Uint8Array> {
|
|
184
|
+
return this._controller.readable;
|
|
185
|
+
}
|
|
186
|
+
public get writable(): WritableStream<Uint8Array> {
|
|
187
|
+
return this._controller.writable;
|
|
188
|
+
}
|
|
148
189
|
|
|
149
190
|
public constructor(controller: AdbSocketController) {
|
|
150
191
|
this._controller = controller;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PromiseResolver } from
|
|
2
|
-
import type
|
|
1
|
+
import { PromiseResolver } from "@yume-chan/async";
|
|
2
|
+
import { type Disposable } from "@yume-chan/event";
|
|
3
3
|
|
|
4
4
|
export class AutoResetEvent implements Disposable {
|
|
5
5
|
private readonly list: PromiseResolver<void>[] = [];
|
|
@@ -34,7 +34,7 @@ export class AutoResetEvent implements Disposable {
|
|
|
34
34
|
|
|
35
35
|
public dispose() {
|
|
36
36
|
for (const item of this.list) {
|
|
37
|
-
item.reject(new Error(
|
|
37
|
+
item.reject(new Error("The AutoResetEvent has been disposed"));
|
|
38
38
|
}
|
|
39
39
|
this.list.length = 0;
|
|
40
40
|
}
|