@yume-chan/adb 1.1.0 → 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/CHANGELOG.md +28 -0
- package/LICENSE +1 -1
- package/esm/adb.d.ts +7 -6
- package/esm/adb.d.ts.map +1 -1
- package/esm/adb.js +22 -22
- package/esm/adb.js.map +1 -1
- package/esm/banner.js.map +1 -1
- package/esm/commands/base.d.ts +3 -2
- package/esm/commands/base.d.ts.map +1 -1
- package/esm/commands/base.js +6 -3
- package/esm/commands/base.js.map +1 -1
- package/esm/commands/framebuffer.d.ts +6 -6
- package/esm/commands/power.d.ts +2 -2
- package/esm/commands/power.d.ts.map +1 -1
- package/esm/commands/power.js +4 -4
- package/esm/commands/power.js.map +1 -1
- package/esm/commands/reverse.d.ts +3 -4
- package/esm/commands/reverse.d.ts.map +1 -1
- package/esm/commands/reverse.js +5 -10
- package/esm/commands/reverse.js.map +1 -1
- package/esm/commands/subprocess/index.d.ts +3 -2
- package/esm/commands/subprocess/index.d.ts.map +1 -1
- package/esm/commands/subprocess/index.js +3 -2
- package/esm/commands/subprocess/index.js.map +1 -1
- package/esm/commands/subprocess/none/index.d.ts +5 -0
- package/esm/commands/subprocess/none/index.d.ts.map +1 -0
- package/esm/commands/subprocess/none/index.js +5 -0
- package/esm/commands/subprocess/none/index.js.map +1 -0
- package/esm/commands/subprocess/none/process.d.ts +13 -0
- package/esm/commands/subprocess/none/process.d.ts.map +1 -0
- package/esm/commands/subprocess/none/process.js +36 -0
- package/esm/commands/subprocess/none/process.js.map +1 -0
- package/esm/commands/subprocess/none/pty.d.ts +15 -0
- package/esm/commands/subprocess/none/pty.d.ts.map +1 -0
- package/esm/commands/subprocess/none/pty.js +29 -0
- package/esm/commands/subprocess/none/pty.js.map +1 -0
- package/esm/commands/subprocess/none/service.d.ts +10 -0
- package/esm/commands/subprocess/none/service.d.ts.map +1 -0
- package/esm/commands/subprocess/none/service.js +32 -0
- package/esm/commands/subprocess/none/service.js.map +1 -0
- package/esm/commands/subprocess/none/spawner.d.ts +19 -0
- package/esm/commands/subprocess/none/spawner.d.ts.map +1 -0
- package/esm/commands/subprocess/none/spawner.js +26 -0
- package/esm/commands/subprocess/none/spawner.js.map +1 -0
- package/esm/commands/subprocess/pty.d.ts +10 -0
- package/esm/commands/subprocess/pty.d.ts.map +1 -0
- package/esm/commands/subprocess/pty.js +2 -0
- package/esm/commands/subprocess/pty.js.map +1 -0
- package/esm/commands/subprocess/service.d.ts +11 -0
- package/esm/commands/subprocess/service.d.ts.map +1 -0
- package/esm/commands/subprocess/service.js +25 -0
- package/esm/commands/subprocess/service.js.map +1 -0
- package/esm/commands/subprocess/shell/index.d.ts +6 -0
- package/esm/commands/subprocess/shell/index.d.ts.map +1 -0
- package/esm/commands/subprocess/shell/index.js +6 -0
- package/esm/commands/subprocess/shell/index.js.map +1 -0
- package/esm/commands/subprocess/shell/process.d.ts +15 -0
- package/esm/commands/subprocess/shell/process.d.ts.map +1 -0
- package/esm/commands/subprocess/{protocols/shell.js → shell/process.js} +27 -54
- package/esm/commands/subprocess/shell/process.js.map +1 -0
- package/esm/commands/subprocess/shell/pty.d.ts +15 -0
- package/esm/commands/subprocess/shell/pty.d.ts.map +1 -0
- package/esm/commands/subprocess/shell/pty.js +76 -0
- package/esm/commands/subprocess/shell/pty.js.map +1 -0
- package/esm/commands/subprocess/shell/service.d.ts +14 -0
- package/esm/commands/subprocess/shell/service.d.ts.map +1 -0
- package/esm/commands/subprocess/shell/service.js +41 -0
- package/esm/commands/subprocess/shell/service.js.map +1 -0
- package/esm/commands/subprocess/shell/shared.d.ts +19 -0
- package/esm/commands/subprocess/shell/shared.d.ts.map +1 -0
- package/esm/commands/subprocess/shell/shared.js +15 -0
- package/esm/commands/subprocess/shell/shared.js.map +1 -0
- package/esm/commands/subprocess/shell/spawner.d.ts +24 -0
- package/esm/commands/subprocess/shell/spawner.d.ts.map +1 -0
- package/esm/commands/subprocess/shell/spawner.js +38 -0
- package/esm/commands/subprocess/shell/spawner.js.map +1 -0
- package/esm/commands/subprocess/utils.d.ts +1 -0
- package/esm/commands/subprocess/utils.d.ts.map +1 -1
- package/esm/commands/subprocess/utils.js +37 -0
- package/esm/commands/subprocess/utils.js.map +1 -1
- package/esm/commands/sync/list.d.ts +12 -8
- package/esm/commands/sync/list.d.ts.map +1 -1
- package/esm/commands/sync/list.js +5 -7
- 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 +2 -7
- package/esm/commands/sync/pull.js.map +1 -1
- package/esm/commands/sync/push.d.ts +4 -4
- package/esm/commands/sync/request.d.ts +1 -1
- package/esm/commands/sync/response.d.ts +5 -5
- package/esm/commands/sync/response.d.ts.map +1 -1
- package/esm/commands/sync/response.js +2 -1
- package/esm/commands/sync/response.js.map +1 -1
- package/esm/commands/sync/stat.d.ts +4 -4
- package/esm/commands/sync/sync.d.ts +2 -2
- package/esm/commands/sync/sync.js +1 -1
- package/esm/commands/sync/sync.js.map +1 -1
- package/esm/commands/tcpip.d.ts +2 -2
- package/esm/commands/tcpip.js +2 -2
- package/esm/daemon/dispatcher.d.ts.map +1 -1
- package/esm/daemon/dispatcher.js.map +1 -1
- package/esm/daemon/packet.d.ts +6 -4
- package/esm/daemon/packet.d.ts.map +1 -1
- package/esm/daemon/packet.js +3 -5
- package/esm/daemon/packet.js.map +1 -1
- package/esm/daemon/socket.d.ts +2 -2
- package/esm/daemon/socket.d.ts.map +1 -1
- package/esm/daemon/socket.js +1 -1
- package/esm/daemon/socket.js.map +1 -1
- package/esm/device-observer.d.ts +4 -4
- package/esm/device-observer.d.ts.map +1 -1
- package/esm/server/client.d.ts +10 -38
- package/esm/server/client.d.ts.map +1 -1
- package/esm/server/client.js +9 -126
- package/esm/server/client.js.map +1 -1
- package/esm/server/commands/index.d.ts +3 -0
- package/esm/server/commands/index.d.ts.map +1 -0
- package/esm/server/commands/index.js +3 -0
- package/esm/server/commands/index.js.map +1 -0
- package/esm/server/commands/m-dns.d.ts +12 -0
- package/esm/server/commands/m-dns.d.ts.map +1 -0
- package/esm/server/commands/m-dns.js +38 -0
- package/esm/server/commands/m-dns.js.map +1 -0
- package/esm/server/commands/wireless.d.ts +27 -0
- package/esm/server/commands/wireless.d.ts.map +1 -0
- package/esm/server/commands/wireless.js +82 -0
- package/esm/server/commands/wireless.js.map +1 -0
- package/esm/server/observer.d.ts +2 -1
- package/esm/server/observer.d.ts.map +1 -1
- package/esm/server/observer.js +69 -47
- package/esm/server/observer.js.map +1 -1
- package/esm/server/stream.d.ts +1 -1
- package/esm/server/transport.d.ts.map +1 -1
- package/esm/server/transport.js +2 -2
- package/esm/server/transport.js.map +1 -1
- package/package.json +10 -10
- package/src/adb.ts +29 -28
- package/src/banner.ts +4 -4
- package/src/commands/base.ts +6 -3
- package/src/commands/power.ts +6 -6
- package/src/commands/reverse.ts +9 -12
- package/src/commands/subprocess/index.ts +3 -2
- package/src/commands/subprocess/none/index.ts +4 -0
- package/src/commands/subprocess/none/process.ts +56 -0
- package/src/commands/subprocess/none/pty.ts +45 -0
- package/src/commands/subprocess/none/service.ts +42 -0
- package/src/commands/subprocess/none/spawner.ts +68 -0
- package/src/commands/subprocess/pty.ts +15 -0
- package/src/commands/subprocess/service.ts +32 -0
- package/src/commands/subprocess/shell/index.ts +5 -0
- package/src/commands/subprocess/shell/process.ts +127 -0
- package/src/commands/subprocess/shell/pty.ts +112 -0
- package/src/commands/subprocess/shell/service.ts +58 -0
- package/src/commands/subprocess/shell/shared.ts +25 -0
- package/src/commands/subprocess/shell/spawner.ts +90 -0
- package/src/commands/subprocess/utils.ts +41 -0
- package/src/commands/sync/list.ts +7 -17
- package/src/commands/sync/pull.ts +2 -8
- package/src/commands/sync/response.ts +6 -4
- package/src/commands/sync/sync.ts +1 -1
- package/src/commands/tcpip.ts +2 -2
- package/src/daemon/dispatcher.ts +7 -4
- package/src/daemon/packet.ts +4 -8
- package/src/daemon/socket.ts +6 -6
- package/src/device-observer.ts +4 -4
- package/src/server/client.ts +23 -142
- package/src/server/commands/index.ts +2 -0
- package/src/server/commands/m-dns.ts +43 -0
- package/src/server/commands/wireless.ts +94 -0
- package/src/server/observer.ts +94 -66
- package/src/server/transport.ts +21 -20
- package/tsconfig.build.tsbuildinfo +1 -1
- package/esm/commands/subprocess/command.d.ts +0 -58
- package/esm/commands/subprocess/command.d.ts.map +0 -1
- package/esm/commands/subprocess/command.js +0 -89
- package/esm/commands/subprocess/command.js.map +0 -1
- package/esm/commands/subprocess/protocols/index.d.ts +0 -4
- package/esm/commands/subprocess/protocols/index.d.ts.map +0 -1
- package/esm/commands/subprocess/protocols/index.js +0 -4
- package/esm/commands/subprocess/protocols/index.js.map +0 -1
- package/esm/commands/subprocess/protocols/none.d.ts +0 -32
- package/esm/commands/subprocess/protocols/none.d.ts.map +0 -1
- package/esm/commands/subprocess/protocols/none.js +0 -61
- package/esm/commands/subprocess/protocols/none.js.map +0 -1
- package/esm/commands/subprocess/protocols/shell.d.ts +0 -42
- package/esm/commands/subprocess/protocols/shell.d.ts.map +0 -1
- package/esm/commands/subprocess/protocols/shell.js.map +0 -1
- package/esm/commands/subprocess/protocols/types.d.ts +0 -49
- package/esm/commands/subprocess/protocols/types.d.ts.map +0 -1
- package/esm/commands/subprocess/protocols/types.js +0 -2
- package/esm/commands/subprocess/protocols/types.js.map +0 -1
- package/src/commands/subprocess/command.ts +0 -141
- package/src/commands/subprocess/protocols/index.ts +0 -3
- package/src/commands/subprocess/protocols/none.ts +0 -81
- package/src/commands/subprocess/protocols/shell.ts +0 -171
- package/src/commands/subprocess/protocols/types.ts +0 -63
package/esm/server/observer.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { EventEmitter } from "@yume-chan/event";
|
|
1
|
+
import { EventEmitter, StickyEventEmitter } from "@yume-chan/event";
|
|
2
2
|
import { Ref } from "../utils/index.js";
|
|
3
3
|
import { AdbServerClient } from "./client.js";
|
|
4
|
-
function unorderedRemove(array, index) {
|
|
4
|
+
export function unorderedRemove(array, index) {
|
|
5
|
+
if (index < 0 || index >= array.length) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
5
8
|
array[index] = array[array.length - 1];
|
|
6
9
|
array.length -= 1;
|
|
7
10
|
}
|
|
@@ -14,36 +17,41 @@ export class AdbServerDeviceObserverOwner {
|
|
|
14
17
|
this.#client = client;
|
|
15
18
|
}
|
|
16
19
|
async #receive(stream) {
|
|
20
|
+
const response = await stream.readString();
|
|
21
|
+
const next = AdbServerClient.parseDeviceList(response);
|
|
22
|
+
const removed = this.current.slice();
|
|
23
|
+
const added = [];
|
|
24
|
+
for (const nextDevice of next) {
|
|
25
|
+
const index = removed.findIndex((device) => device.transportId === nextDevice.transportId);
|
|
26
|
+
if (index === -1) {
|
|
27
|
+
added.push(nextDevice);
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
unorderedRemove(removed, index);
|
|
31
|
+
}
|
|
32
|
+
this.current = next;
|
|
33
|
+
if (added.length) {
|
|
34
|
+
for (const observer of this.#observers) {
|
|
35
|
+
observer.onDeviceAdd.fire(added);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (removed.length) {
|
|
39
|
+
for (const observer of this.#observers) {
|
|
40
|
+
observer.onDeviceRemove.fire(removed);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
for (const observer of this.#observers) {
|
|
44
|
+
observer.onListChange.fire(this.current);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async #receiveLoop(stream) {
|
|
17
48
|
try {
|
|
18
49
|
while (true) {
|
|
19
|
-
|
|
20
|
-
const next = AdbServerClient.parseDeviceList(response);
|
|
21
|
-
const added = [];
|
|
22
|
-
for (const nextDevice of next) {
|
|
23
|
-
const index = this.current.findIndex((device) => device.transportId === nextDevice.transportId);
|
|
24
|
-
if (index === -1) {
|
|
25
|
-
added.push(nextDevice);
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
unorderedRemove(this.current, index);
|
|
29
|
-
}
|
|
30
|
-
if (added.length) {
|
|
31
|
-
for (const observer of this.#observers) {
|
|
32
|
-
observer.onDeviceAdd.fire(added);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
if (this.current.length) {
|
|
36
|
-
for (const observer of this.#observers) {
|
|
37
|
-
observer.onDeviceRemove.fire(this.current);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
this.current = next;
|
|
41
|
-
for (const observer of this.#observers) {
|
|
42
|
-
observer.onListChange.fire(this.current);
|
|
43
|
-
}
|
|
50
|
+
await this.#receive(stream);
|
|
44
51
|
}
|
|
45
52
|
}
|
|
46
53
|
catch (e) {
|
|
54
|
+
this.#stream = undefined;
|
|
47
55
|
for (const observer of this.#observers) {
|
|
48
56
|
observer.onError.fire(e);
|
|
49
57
|
}
|
|
@@ -53,7 +61,10 @@ export class AdbServerDeviceObserverOwner {
|
|
|
53
61
|
const stream = await this.#client.createConnection("host:track-devices-l",
|
|
54
62
|
// Each individual observer will ref depending on their options
|
|
55
63
|
{ unref: true });
|
|
56
|
-
|
|
64
|
+
// Set `current` and `onListChange` value before returning
|
|
65
|
+
await this.#receive(stream);
|
|
66
|
+
// Then start receive loop
|
|
67
|
+
void this.#receiveLoop(stream);
|
|
57
68
|
return stream;
|
|
58
69
|
}
|
|
59
70
|
async #handleObserverStop(stream) {
|
|
@@ -63,41 +74,52 @@ export class AdbServerDeviceObserverOwner {
|
|
|
63
74
|
}
|
|
64
75
|
}
|
|
65
76
|
async createObserver(options) {
|
|
66
|
-
|
|
67
|
-
throw options.signal.reason;
|
|
68
|
-
}
|
|
69
|
-
this.#stream ??= this.#connect();
|
|
70
|
-
const stream = await this.#stream;
|
|
71
|
-
if (options?.signal?.aborted) {
|
|
72
|
-
await this.#handleObserverStop(stream);
|
|
73
|
-
throw options.signal.reason;
|
|
74
|
-
}
|
|
77
|
+
options?.signal?.throwIfAborted();
|
|
75
78
|
const onDeviceAdd = new EventEmitter();
|
|
76
79
|
const onDeviceRemove = new EventEmitter();
|
|
77
|
-
const onListChange = new
|
|
78
|
-
const onError = new
|
|
80
|
+
const onListChange = new StickyEventEmitter();
|
|
81
|
+
const onError = new StickyEventEmitter();
|
|
79
82
|
const observer = { onDeviceAdd, onDeviceRemove, onListChange, onError };
|
|
83
|
+
// Register `observer` before `#connect`.
|
|
84
|
+
// So `#handleObserverStop` knows if there is any observer.
|
|
80
85
|
this.#observers.push(observer);
|
|
86
|
+
let stream;
|
|
87
|
+
if (!this.#stream) {
|
|
88
|
+
this.#stream = this.#connect();
|
|
89
|
+
try {
|
|
90
|
+
stream = await this.#stream;
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
this.#stream = undefined;
|
|
94
|
+
throw e;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
stream = await this.#stream;
|
|
99
|
+
onListChange.fire(this.current);
|
|
100
|
+
}
|
|
81
101
|
const ref = new Ref(options);
|
|
82
102
|
const stop = async () => {
|
|
83
|
-
|
|
84
|
-
if (index === -1) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
unorderedRemove(this.#observers, index);
|
|
103
|
+
unorderedRemove(this.#observers, this.#observers.indexOf(observer));
|
|
88
104
|
await this.#handleObserverStop(stream);
|
|
89
105
|
ref.unref();
|
|
90
106
|
};
|
|
91
|
-
options?.signal
|
|
107
|
+
if (options?.signal) {
|
|
108
|
+
if (options.signal.aborted) {
|
|
109
|
+
await stop();
|
|
110
|
+
throw options.signal.reason;
|
|
111
|
+
}
|
|
112
|
+
options.signal.addEventListener("abort", () => void stop());
|
|
113
|
+
}
|
|
92
114
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
93
|
-
const
|
|
115
|
+
const _this = this;
|
|
94
116
|
return {
|
|
95
117
|
onDeviceAdd: onDeviceAdd.event,
|
|
96
118
|
onDeviceRemove: onDeviceRemove.event,
|
|
97
119
|
onListChange: onListChange.event,
|
|
98
120
|
onError: onError.event,
|
|
99
121
|
get current() {
|
|
100
|
-
return
|
|
122
|
+
return _this.current;
|
|
101
123
|
},
|
|
102
124
|
stop,
|
|
103
125
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observer.js","sourceRoot":"","sources":["../../src/server/observer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"observer.js","sourceRoot":"","sources":["../../src/server/observer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEpE,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAExC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG9C,MAAM,UAAU,eAAe,CAAI,KAAU,EAAE,KAAa;IACxD,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;QACrC,OAAO;IACX,CAAC;IACD,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC;IACxC,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC;AACtB,CAAC;AAED,MAAM,OAAO,4BAA4B;IACrC,OAAO,GAAsC,EAAE,CAAC;IAEvC,OAAO,CAAkB;IAClC,OAAO,CAAuC;IAC9C,UAAU,GAKJ,EAAE,CAAC;IAET,YAAY,MAAuB;QAC/B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,MAAuB;QAClC,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,UAAU,EAAE,CAAC;QAC3C,MAAM,IAAI,GAAG,eAAe,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;QAEvD,MAAM,OAAO,GAAG,IAAI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OAAO,EAAE,OAAO,CAAC,KAAK;YACtB,IAAI,OAAO;gBACP,OAAO,KAAK,CAAC,OAAO,CAAC;YACzB,CAAC;YACD,IAAI;SACP,CAAC;IACN,CAAC;CACJ"}
|
package/esm/server/stream.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare class AdbServerStream {
|
|
|
11
11
|
release(): {
|
|
12
12
|
readable: import("@yume-chan/stream-extra").ReadableStream<Uint8Array<ArrayBufferLike>>;
|
|
13
13
|
writable: import("@yume-chan/stream-extra/esm/types.js").WritableStream<import("@yume-chan/stream-extra").MaybeConsumable<Uint8Array<ArrayBufferLike>>>;
|
|
14
|
-
closed: Promise<
|
|
14
|
+
closed: Promise<undefined>;
|
|
15
15
|
close: () => MaybePromiseLike<void>;
|
|
16
16
|
};
|
|
17
17
|
dispose(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/server/transport.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACR,wBAAwB,EACxB,SAAS,EACT,YAAY,EACf,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,eAAO,MAAM,2BAA2B,
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/server/transport.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACR,wBAAwB,EACxB,SAAS,EACT,YAAY,EACf,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,eAAO,MAAM,2BAA2B,cAoBhB,CAAC;AAEzB,qBAAa,kBAAmB,YAAW,YAAY;;IAGnD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAExB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAmB;IAElD,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAM3B,IAAI,YAAY,kBAEf;IAED,IAAI,cAAc,iBAIjB;gBAIG,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,SAAS,EACjB,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,OAAO,CAAC,IAAI,CAAC;IAUzB,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAS5C,gBAAgB,CAClB,OAAO,EAAE,wBAAwB,EACjC,OAAO,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,CAAC;IAIZ,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAInD,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIpC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAO/B"}
|
package/esm/server/transport.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PromiseResolver } from "@yume-chan/async";
|
|
2
2
|
import { AdbFeature } from "../features.js";
|
|
3
|
-
export const ADB_SERVER_DEFAULT_FEATURES = [
|
|
3
|
+
export const ADB_SERVER_DEFAULT_FEATURES = /* #__PURE__ */ (() => [
|
|
4
4
|
AdbFeature.ShellV2,
|
|
5
5
|
AdbFeature.Cmd,
|
|
6
6
|
AdbFeature.StatV2,
|
|
@@ -19,7 +19,7 @@ export const ADB_SERVER_DEFAULT_FEATURES = [
|
|
|
19
19
|
"sendrecv_v2_lz4",
|
|
20
20
|
"sendrecv_v2_zstd",
|
|
21
21
|
"sendrecv_v2_dry_run_send",
|
|
22
|
-
];
|
|
22
|
+
])();
|
|
23
23
|
export class AdbServerTransport {
|
|
24
24
|
#client;
|
|
25
25
|
serial;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../src/server/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAQnD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAI5C,MAAM,CAAC,MAAM,2BAA2B,GAAG;
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../src/server/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAQnD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAI5C,MAAM,CAAC,MAAM,2BAA2B,GAAG,eAAe,CAAC,CAAC,GAAG,EAAE,CAC7D;IACI,UAAU,CAAC,OAAO;IAClB,UAAU,CAAC,GAAG;IACd,UAAU,CAAC,MAAM;IACjB,UAAU,CAAC,MAAM;IACjB,UAAU,CAAC,cAAc;IACzB,MAAM;IACN,UAAU,CAAC,GAAG;IACd,yFAAyF;IACzF,gCAAgC;IAChC,8BAA8B;IAC9B,UAAU,CAAC,OAAO;IAClB,eAAe;IACf,WAAW;IACX,UAAU,CAAC,aAAa;IACxB,oBAAoB;IACpB,iBAAiB;IACjB,kBAAkB;IAClB,0BAA0B;CACb,CAAC,EAAE,CAAC;AAEzB,MAAM,OAAO,kBAAkB;IAC3B,OAAO,CAAkB;IAEhB,MAAM,CAAS;IAEf,WAAW,CAAS;IAEpB,cAAc,GAAW,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;IAEzC,MAAM,CAAY;IAE3B,QAAQ,GAAgB,EAAE,CAAC;IAE3B,OAAO,GAAG,IAAI,eAAe,EAAQ,CAAC;IACtC,aAAa,CAAgB;IAC7B,IAAI,YAAY;QACZ,OAAO,IAAI,CAAC,aAAa,CAAC;IAC9B,CAAC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M,MAAM,CAAC,KAAK,EAAE,CAAC;QACzB,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;QACzB,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yume-chan/adb",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "TypeScript implementation of Android Debug Bridge (ADB) protocol.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adb",
|
|
@@ -27,18 +27,18 @@
|
|
|
27
27
|
"sideEffects": false,
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@yume-chan/async": "^4.0.2",
|
|
30
|
-
"@yume-chan/event": "^
|
|
31
|
-
"@yume-chan/no-data-view": "^
|
|
32
|
-
"@yume-chan/stream-extra": "^
|
|
33
|
-
"@yume-chan/struct": "^
|
|
30
|
+
"@yume-chan/event": "^2.0.0",
|
|
31
|
+
"@yume-chan/no-data-view": "^2.0.0",
|
|
32
|
+
"@yume-chan/stream-extra": "^2.0.1",
|
|
33
|
+
"@yume-chan/struct": "^2.0.1"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@types/node": "^22.10
|
|
37
|
-
"prettier": "^3.
|
|
38
|
-
"typescript": "^5.
|
|
36
|
+
"@types/node": "^22.13.10",
|
|
37
|
+
"prettier": "^3.5.3",
|
|
38
|
+
"typescript": "^5.8.2",
|
|
39
39
|
"@yume-chan/eslint-config": "^1.0.0",
|
|
40
|
-
"@yume-chan/
|
|
41
|
-
"@yume-chan/
|
|
40
|
+
"@yume-chan/test-runner": "^1.0.0",
|
|
41
|
+
"@yume-chan/tsconfig": "^1.0.0"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "tsc -b tsconfig.build.json",
|
package/src/adb.ts
CHANGED
|
@@ -9,10 +9,10 @@ import type { AdbBanner } from "./banner.js";
|
|
|
9
9
|
import type { AdbFrameBuffer } from "./commands/index.js";
|
|
10
10
|
import {
|
|
11
11
|
AdbPower,
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
AdbReverseService,
|
|
13
|
+
AdbSubprocessService,
|
|
14
14
|
AdbSync,
|
|
15
|
-
|
|
15
|
+
AdbTcpIpService,
|
|
16
16
|
escapeArg,
|
|
17
17
|
framebuffer,
|
|
18
18
|
} from "./commands/index.js";
|
|
@@ -30,7 +30,7 @@ export interface AdbSocket
|
|
|
30
30
|
Closeable {
|
|
31
31
|
get service(): string;
|
|
32
32
|
|
|
33
|
-
get closed(): Promise<
|
|
33
|
+
get closed(): Promise<undefined>;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export type AdbIncomingSocketHandler = (
|
|
@@ -61,44 +61,47 @@ export interface AdbTransport extends Closeable {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
export class Adb implements Closeable {
|
|
64
|
-
readonly transport: AdbTransport;
|
|
64
|
+
readonly #transport: AdbTransport;
|
|
65
|
+
get transport(): AdbTransport {
|
|
66
|
+
return this.#transport;
|
|
67
|
+
}
|
|
65
68
|
|
|
66
69
|
get serial() {
|
|
67
|
-
return this
|
|
70
|
+
return this.#transport.serial;
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
get maxPayloadSize() {
|
|
71
|
-
return this
|
|
74
|
+
return this.#transport.maxPayloadSize;
|
|
72
75
|
}
|
|
73
76
|
|
|
74
77
|
get banner() {
|
|
75
|
-
return this
|
|
78
|
+
return this.#transport.banner;
|
|
76
79
|
}
|
|
77
80
|
|
|
78
81
|
get disconnected() {
|
|
79
|
-
return this
|
|
82
|
+
return this.#transport.disconnected;
|
|
80
83
|
}
|
|
81
84
|
|
|
82
85
|
public get clientFeatures() {
|
|
83
|
-
return this
|
|
86
|
+
return this.#transport.clientFeatures;
|
|
84
87
|
}
|
|
85
88
|
|
|
86
89
|
public get deviceFeatures() {
|
|
87
90
|
return this.banner.features;
|
|
88
91
|
}
|
|
89
92
|
|
|
90
|
-
readonly subprocess:
|
|
93
|
+
readonly subprocess: AdbSubprocessService;
|
|
91
94
|
readonly power: AdbPower;
|
|
92
|
-
readonly reverse:
|
|
93
|
-
readonly tcpip:
|
|
95
|
+
readonly reverse: AdbReverseService;
|
|
96
|
+
readonly tcpip: AdbTcpIpService;
|
|
94
97
|
|
|
95
98
|
constructor(transport: AdbTransport) {
|
|
96
|
-
this
|
|
99
|
+
this.#transport = transport;
|
|
97
100
|
|
|
98
|
-
this.subprocess = new
|
|
101
|
+
this.subprocess = new AdbSubprocessService(this);
|
|
99
102
|
this.power = new AdbPower(this);
|
|
100
|
-
this.reverse = new
|
|
101
|
-
this.tcpip = new
|
|
103
|
+
this.reverse = new AdbReverseService(this);
|
|
104
|
+
this.tcpip = new AdbTcpIpService(this);
|
|
102
105
|
}
|
|
103
106
|
|
|
104
107
|
canUseFeature(feature: AdbFeature): boolean {
|
|
@@ -112,7 +115,7 @@ export class Adb implements Closeable {
|
|
|
112
115
|
* Creates a new ADB Socket to the specified service or socket address.
|
|
113
116
|
*/
|
|
114
117
|
async createSocket(service: string): Promise<AdbSocket> {
|
|
115
|
-
return this
|
|
118
|
+
return this.#transport.connect(service);
|
|
116
119
|
}
|
|
117
120
|
|
|
118
121
|
async createSocketAndWait(service: string): Promise<string> {
|
|
@@ -122,15 +125,13 @@ export class Adb implements Closeable {
|
|
|
122
125
|
.pipeThrough(new ConcatStringStream());
|
|
123
126
|
}
|
|
124
127
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
"getprop",
|
|
128
|
-
|
|
129
|
-
]);
|
|
130
|
-
return stdout.trim();
|
|
128
|
+
getProp(key: string): Promise<string> {
|
|
129
|
+
return this.subprocess.noneProtocol
|
|
130
|
+
.spawnWaitText(["getprop", key])
|
|
131
|
+
.then((output) => output.trim());
|
|
131
132
|
}
|
|
132
133
|
|
|
133
|
-
|
|
134
|
+
rm(
|
|
134
135
|
filenames: string | string[],
|
|
135
136
|
options?: { recursive?: boolean; force?: boolean },
|
|
136
137
|
): Promise<string> {
|
|
@@ -150,8 +151,8 @@ export class Adb implements Closeable {
|
|
|
150
151
|
}
|
|
151
152
|
// https://android.googlesource.com/platform/packages/modules/adb/+/1a0fb8846d4e6b671c8aa7f137a8c21d7b248716/client/adb_install.cpp#984
|
|
152
153
|
args.push("</dev/null");
|
|
153
|
-
|
|
154
|
-
return
|
|
154
|
+
|
|
155
|
+
return this.subprocess.noneProtocol.spawnWaitText(args);
|
|
155
156
|
}
|
|
156
157
|
|
|
157
158
|
async sync(): Promise<AdbSync> {
|
|
@@ -164,6 +165,6 @@ export class Adb implements Closeable {
|
|
|
164
165
|
}
|
|
165
166
|
|
|
166
167
|
async close(): Promise<void> {
|
|
167
|
-
await this
|
|
168
|
+
await this.#transport.close();
|
|
168
169
|
}
|
|
169
170
|
}
|
package/src/banner.ts
CHANGED
|
@@ -51,22 +51,22 @@ export class AdbBanner {
|
|
|
51
51
|
return new AdbBanner(product, model, device, features);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
#product: string | undefined;
|
|
54
|
+
readonly #product: string | undefined;
|
|
55
55
|
get product() {
|
|
56
56
|
return this.#product;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
#model: string | undefined;
|
|
59
|
+
readonly #model: string | undefined;
|
|
60
60
|
get model() {
|
|
61
61
|
return this.#model;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
#device: string | undefined;
|
|
64
|
+
readonly #device: string | undefined;
|
|
65
65
|
get device() {
|
|
66
66
|
return this.#device;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
#features: AdbFeature[] = [];
|
|
69
|
+
readonly #features: AdbFeature[] = [];
|
|
70
70
|
get features() {
|
|
71
71
|
return this.#features;
|
|
72
72
|
}
|
package/src/commands/base.ts
CHANGED
|
@@ -2,11 +2,14 @@ import { AutoDisposable } from "@yume-chan/event";
|
|
|
2
2
|
|
|
3
3
|
import type { Adb } from "../adb.js";
|
|
4
4
|
|
|
5
|
-
export class
|
|
6
|
-
|
|
5
|
+
export class AdbServiceBase extends AutoDisposable {
|
|
6
|
+
readonly #adb: Adb;
|
|
7
|
+
get adb() {
|
|
8
|
+
return this.#adb;
|
|
9
|
+
}
|
|
7
10
|
|
|
8
11
|
constructor(adb: Adb) {
|
|
9
12
|
super();
|
|
10
|
-
this
|
|
13
|
+
this.#adb = adb;
|
|
11
14
|
}
|
|
12
15
|
}
|
package/src/commands/power.ts
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
// cspell: ignore keyevent
|
|
4
4
|
// cspell: ignore longpress
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { AdbServiceBase } from "./base.js";
|
|
7
7
|
|
|
8
|
-
export class AdbPower extends
|
|
8
|
+
export class AdbPower extends AdbServiceBase {
|
|
9
9
|
reboot(mode = "") {
|
|
10
10
|
return this.adb.createSocketAndWait(`reboot:${mode}`);
|
|
11
11
|
}
|
|
@@ -35,18 +35,18 @@ export class AdbPower extends AdbCommandBase {
|
|
|
35
35
|
return this.reboot("edl");
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
powerOff() {
|
|
39
|
-
return this.adb.subprocess.
|
|
38
|
+
powerOff(): Promise<string> {
|
|
39
|
+
return this.adb.subprocess.noneProtocol.spawnWaitText(["reboot", "-p"]);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
powerButton(longPress = false) {
|
|
42
|
+
powerButton(longPress = false): Promise<string> {
|
|
43
43
|
const args = ["input", "keyevent"];
|
|
44
44
|
if (longPress) {
|
|
45
45
|
args.push("--longpress");
|
|
46
46
|
}
|
|
47
47
|
args.push("POWER");
|
|
48
48
|
|
|
49
|
-
return this.adb.subprocess.
|
|
49
|
+
return this.adb.subprocess.noneProtocol.spawnWaitText(args);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/**
|
package/src/commands/reverse.ts
CHANGED
|
@@ -4,13 +4,16 @@ import { BufferedReadableStream } from "@yume-chan/stream-extra";
|
|
|
4
4
|
import {
|
|
5
5
|
encodeUtf8,
|
|
6
6
|
ExactReadableEndedError,
|
|
7
|
+
extend,
|
|
7
8
|
string,
|
|
8
9
|
struct,
|
|
9
10
|
} from "@yume-chan/struct";
|
|
10
11
|
|
|
11
|
-
import type {
|
|
12
|
+
import type { AdbIncomingSocketHandler } from "../adb.js";
|
|
12
13
|
import { hexToNumber, sequenceEqual } from "../utils/index.js";
|
|
13
14
|
|
|
15
|
+
import { AdbServiceBase } from "./base.js";
|
|
16
|
+
|
|
14
17
|
export interface AdbForwardListener {
|
|
15
18
|
deviceSerial: string;
|
|
16
19
|
|
|
@@ -49,11 +52,11 @@ export class AdbReverseNotSupportedError extends AdbReverseError {
|
|
|
49
52
|
}
|
|
50
53
|
}
|
|
51
54
|
|
|
52
|
-
const AdbReverseErrorResponse =
|
|
53
|
-
|
|
55
|
+
const AdbReverseErrorResponse = extend(
|
|
56
|
+
AdbReverseStringResponse,
|
|
57
|
+
{},
|
|
54
58
|
{
|
|
55
|
-
|
|
56
|
-
postDeserialize: (value) => {
|
|
59
|
+
postDeserialize(value) {
|
|
57
60
|
// https://issuetracker.google.com/issues/37066218
|
|
58
61
|
// ADB on Android <9 can't create reverse tunnels when connected wirelessly (ADB over Wi-Fi),
|
|
59
62
|
// and returns this confusing "more than one device/emulator" error.
|
|
@@ -81,15 +84,9 @@ function decimalToNumber(buffer: Uint8Array) {
|
|
|
81
84
|
|
|
82
85
|
const OKAY = encodeUtf8("OKAY");
|
|
83
86
|
|
|
84
|
-
export class
|
|
85
|
-
protected adb: Adb;
|
|
86
|
-
|
|
87
|
+
export class AdbReverseService extends AdbServiceBase {
|
|
87
88
|
readonly #deviceAddressToLocalAddress = new Map<string, string>();
|
|
88
89
|
|
|
89
|
-
constructor(adb: Adb) {
|
|
90
|
-
this.adb = adb;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
90
|
protected async createBufferedStream(service: string) {
|
|
94
91
|
const socket = await this.adb.createSocket(service);
|
|
95
92
|
return new BufferedReadableStream(socket.readable);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { MaybePromiseLike } from "@yume-chan/async";
|
|
2
|
+
import { PromiseResolver } from "@yume-chan/async";
|
|
3
|
+
import type {
|
|
4
|
+
AbortSignal,
|
|
5
|
+
MaybeConsumable,
|
|
6
|
+
ReadableStream,
|
|
7
|
+
WritableStream,
|
|
8
|
+
} from "@yume-chan/stream-extra";
|
|
9
|
+
|
|
10
|
+
import type { AdbSocket } from "../../../adb.js";
|
|
11
|
+
|
|
12
|
+
import type { AdbNoneProtocolProcess } from "./spawner.js";
|
|
13
|
+
|
|
14
|
+
export class AdbNoneProtocolProcessImpl implements AdbNoneProtocolProcess {
|
|
15
|
+
readonly #socket: AdbSocket;
|
|
16
|
+
|
|
17
|
+
get stdin(): WritableStream<MaybeConsumable<Uint8Array>> {
|
|
18
|
+
return this.#socket.writable;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
get output(): ReadableStream<Uint8Array> {
|
|
22
|
+
return this.#socket.readable;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
readonly #exited: Promise<undefined>;
|
|
26
|
+
get exited(): Promise<undefined> {
|
|
27
|
+
return this.#exited;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
constructor(socket: AdbSocket, signal?: AbortSignal) {
|
|
31
|
+
this.#socket = socket;
|
|
32
|
+
|
|
33
|
+
if (signal) {
|
|
34
|
+
// `signal` won't affect `this.output`
|
|
35
|
+
// So remaining data can still be read
|
|
36
|
+
// (call `controller.error` will discard all pending data)
|
|
37
|
+
|
|
38
|
+
const exited = new PromiseResolver<undefined>();
|
|
39
|
+
this.#socket.closed.then(
|
|
40
|
+
() => exited.resolve(undefined),
|
|
41
|
+
(e) => exited.reject(e),
|
|
42
|
+
);
|
|
43
|
+
signal.addEventListener("abort", () => {
|
|
44
|
+
exited.reject(signal.reason);
|
|
45
|
+
this.#socket.close();
|
|
46
|
+
});
|
|
47
|
+
this.#exited = exited.promise;
|
|
48
|
+
} else {
|
|
49
|
+
this.#exited = this.#socket.closed;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
kill(): MaybePromiseLike<void> {
|
|
54
|
+
return this.#socket.close();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { MaybePromiseLike } from "@yume-chan/async";
|
|
2
|
+
import type {
|
|
3
|
+
ReadableStream,
|
|
4
|
+
WritableStream,
|
|
5
|
+
WritableStreamDefaultWriter,
|
|
6
|
+
} from "@yume-chan/stream-extra";
|
|
7
|
+
import { MaybeConsumable } from "@yume-chan/stream-extra";
|
|
8
|
+
|
|
9
|
+
import type { AdbSocket } from "../../../adb.js";
|
|
10
|
+
import type { AdbPtyProcess } from "../pty.js";
|
|
11
|
+
|
|
12
|
+
export class AdbNoneProtocolPtyProcess implements AdbPtyProcess<undefined> {
|
|
13
|
+
readonly #socket: AdbSocket;
|
|
14
|
+
readonly #writer: WritableStreamDefaultWriter<MaybeConsumable<Uint8Array>>;
|
|
15
|
+
|
|
16
|
+
readonly #input: MaybeConsumable.WritableStream<Uint8Array>;
|
|
17
|
+
get input(): WritableStream<MaybeConsumable<Uint8Array>> {
|
|
18
|
+
return this.#input;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
get output(): ReadableStream<Uint8Array> {
|
|
22
|
+
return this.#socket.readable;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
get exited(): Promise<undefined> {
|
|
26
|
+
return this.#socket.closed;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
constructor(socket: AdbSocket) {
|
|
30
|
+
this.#socket = socket;
|
|
31
|
+
|
|
32
|
+
this.#writer = this.#socket.writable.getWriter();
|
|
33
|
+
this.#input = new MaybeConsumable.WritableStream<Uint8Array>({
|
|
34
|
+
write: (chunk) => this.#writer.write(chunk),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
sigint() {
|
|
39
|
+
return this.#writer.write(new Uint8Array([0x03]));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
kill(): MaybePromiseLike<void> {
|
|
43
|
+
return this.#socket.close();
|
|
44
|
+
}
|
|
45
|
+
}
|