@yume-chan/adb 0.0.24 → 1.1.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 +42 -1
- package/README.md +4 -1
- package/esm/adb.d.ts +13 -7
- package/esm/adb.d.ts.map +1 -1
- package/esm/adb.js +3 -0
- package/esm/adb.js.map +1 -1
- package/esm/banner.d.ts +7 -6
- package/esm/banner.d.ts.map +1 -1
- package/esm/banner.js +6 -7
- package/esm/banner.js.map +1 -1
- package/esm/commands/framebuffer.d.ts +63 -34
- package/esm/commands/framebuffer.d.ts.map +1 -1
- package/esm/commands/framebuffer.js +35 -33
- package/esm/commands/framebuffer.js.map +1 -1
- package/esm/commands/reverse.d.ts +12 -12
- package/esm/commands/reverse.d.ts.map +1 -1
- package/esm/commands/reverse.js +39 -30
- package/esm/commands/reverse.js.map +1 -1
- package/esm/commands/subprocess/protocols/none.d.ts.map +1 -1
- package/esm/commands/subprocess/protocols/none.js +3 -5
- package/esm/commands/subprocess/protocols/none.js.map +1 -1
- package/esm/commands/subprocess/protocols/shell.d.ts +20 -12
- package/esm/commands/subprocess/protocols/shell.d.ts.map +1 -1
- package/esm/commands/subprocess/protocols/shell.js +16 -21
- package/esm/commands/subprocess/protocols/shell.js.map +1 -1
- package/esm/commands/subprocess/protocols/types.d.ts +6 -6
- package/esm/commands/subprocess/protocols/types.d.ts.map +1 -1
- package/esm/commands/sync/list.d.ts +49 -27
- package/esm/commands/sync/list.d.ts.map +1 -1
- package/esm/commands/sync/list.js +9 -9
- package/esm/commands/sync/list.js.map +1 -1
- package/esm/commands/sync/pull.d.ts +7 -6
- package/esm/commands/sync/pull.d.ts.map +1 -1
- package/esm/commands/sync/pull.js +3 -5
- package/esm/commands/sync/pull.js.map +1 -1
- package/esm/commands/sync/push.d.ts +22 -16
- package/esm/commands/sync/push.d.ts.map +1 -1
- package/esm/commands/sync/push.js +12 -16
- package/esm/commands/sync/push.js.map +1 -1
- package/esm/commands/sync/request.d.ts +19 -17
- package/esm/commands/sync/request.d.ts.map +1 -1
- package/esm/commands/sync/request.js +14 -18
- package/esm/commands/sync/request.js.map +1 -1
- package/esm/commands/sync/response.d.ts +18 -18
- package/esm/commands/sync/response.d.ts.map +1 -1
- package/esm/commands/sync/response.js +20 -19
- package/esm/commands/sync/response.js.map +1 -1
- package/esm/commands/sync/socket.d.ts +1 -1
- package/esm/commands/sync/socket.js +2 -2
- package/esm/commands/sync/socket.js.map +1 -1
- package/esm/commands/sync/stat.d.ts +75 -51
- package/esm/commands/sync/stat.d.ts.map +1 -1
- package/esm/commands/sync/stat.js +73 -67
- package/esm/commands/sync/stat.js.map +1 -1
- package/esm/commands/sync/sync.d.ts +14 -14
- package/esm/commands/sync/sync.d.ts.map +1 -1
- package/esm/commands/sync/sync.js +4 -7
- package/esm/commands/sync/sync.js.map +1 -1
- package/esm/commands/tcpip.d.ts +0 -1
- package/esm/commands/tcpip.d.ts.map +1 -1
- package/esm/commands/tcpip.js +8 -8
- package/esm/commands/tcpip.js.map +1 -1
- package/esm/daemon/auth.d.ts +8 -7
- package/esm/daemon/auth.d.ts.map +1 -1
- package/esm/daemon/auth.js +7 -8
- package/esm/daemon/auth.js.map +1 -1
- package/esm/daemon/crypto.d.ts +1 -1
- package/esm/daemon/crypto.d.ts.map +1 -1
- package/esm/daemon/crypto.js +1 -0
- package/esm/daemon/crypto.js.map +1 -1
- package/esm/daemon/device.d.ts +2 -2
- package/esm/daemon/device.d.ts.map +1 -1
- package/esm/daemon/dispatcher.js +6 -6
- package/esm/daemon/dispatcher.js.map +1 -1
- package/esm/daemon/packet.d.ts +46 -30
- package/esm/daemon/packet.d.ts.map +1 -1
- package/esm/daemon/packet.js +24 -21
- package/esm/daemon/packet.js.map +1 -1
- package/esm/daemon/socket.d.ts +1 -6
- package/esm/daemon/socket.d.ts.map +1 -1
- package/esm/daemon/socket.js +4 -27
- package/esm/daemon/socket.js.map +1 -1
- package/esm/daemon/transport.d.ts +14 -14
- package/esm/daemon/transport.d.ts.map +1 -1
- package/esm/daemon/transport.js +6 -8
- package/esm/daemon/transport.js.map +1 -1
- package/esm/device-observer.d.ts +10 -0
- package/esm/device-observer.d.ts.map +1 -0
- package/esm/device-observer.js +2 -0
- package/esm/device-observer.js.map +1 -0
- package/esm/features.d.ts +12 -11
- package/esm/features.d.ts.map +1 -1
- package/esm/features.js +11 -12
- package/esm/features.js.map +1 -1
- package/esm/index.d.ts +1 -0
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -1
- package/esm/server/client.d.ts +33 -35
- package/esm/server/client.d.ts.map +1 -1
- package/esm/server/client.js +136 -201
- package/esm/server/client.js.map +1 -1
- package/esm/server/index.d.ts +2 -0
- package/esm/server/index.d.ts.map +1 -1
- package/esm/server/index.js +2 -0
- package/esm/server/index.js.map +1 -1
- package/esm/server/observer.d.ts +8 -0
- package/esm/server/observer.d.ts.map +1 -0
- package/esm/server/observer.js +106 -0
- package/esm/server/observer.js.map +1 -0
- package/esm/server/stream.d.ts +19 -0
- package/esm/server/stream.d.ts.map +1 -0
- package/esm/server/stream.js +77 -0
- package/esm/server/stream.js.map +1 -0
- package/esm/server/transport.d.ts +3 -4
- package/esm/server/transport.d.ts.map +1 -1
- package/esm/server/transport.js +16 -16
- package/esm/server/transport.js.map +1 -1
- package/esm/utils/base64.d.ts.map +1 -1
- package/esm/utils/base64.js +19 -16
- package/esm/utils/base64.js.map +1 -1
- package/esm/utils/index.d.ts +1 -0
- package/esm/utils/index.d.ts.map +1 -1
- package/esm/utils/index.js +1 -0
- package/esm/utils/index.js.map +1 -1
- package/esm/utils/no-op.d.ts.map +1 -1
- package/esm/utils/no-op.js +1 -0
- package/esm/utils/no-op.js.map +1 -1
- package/esm/utils/ref.d.ts +18 -0
- package/esm/utils/ref.d.ts.map +1 -0
- package/esm/utils/ref.js +29 -0
- package/esm/utils/ref.js.map +1 -0
- package/package.json +13 -16
- package/src/adb.ts +13 -7
- package/src/banner.ts +8 -6
- package/src/commands/framebuffer.ts +44 -35
- package/src/commands/reverse.ts +49 -31
- package/src/commands/subprocess/protocols/none.ts +3 -5
- package/src/commands/subprocess/protocols/shell.ts +26 -24
- package/src/commands/subprocess/protocols/types.ts +6 -6
- package/src/commands/sync/list.ts +20 -13
- package/src/commands/sync/pull.ts +8 -7
- package/src/commands/sync/push.ts +20 -16
- package/src/commands/sync/request.ts +18 -19
- package/src/commands/sync/response.ts +28 -29
- package/src/commands/sync/socket.ts +2 -2
- package/src/commands/sync/stat.ts +93 -71
- package/src/commands/sync/sync.ts +4 -8
- package/src/commands/tcpip.ts +8 -8
- package/src/daemon/auth.ts +11 -9
- package/src/daemon/crypto.ts +2 -0
- package/src/daemon/device.ts +2 -2
- package/src/daemon/dispatcher.ts +6 -6
- package/src/daemon/packet.ts +37 -25
- package/src/daemon/socket.ts +4 -27
- package/src/daemon/transport.ts +36 -35
- package/src/device-observer.ts +10 -0
- package/src/features.ts +13 -11
- package/src/index.ts +1 -0
- package/src/server/client.ts +181 -242
- package/src/server/index.ts +2 -0
- package/src/server/observer.ts +144 -0
- package/src/server/stream.ts +100 -0
- package/src/server/transport.ts +18 -17
- package/src/utils/base64.ts +26 -18
- package/src/utils/index.ts +1 -0
- package/src/utils/no-op.ts +1 -0
- package/src/utils/ref.ts +37 -0
- package/tsconfig.build.json +1 -12
- package/tsconfig.build.tsbuildinfo +1 -1
- package/CHANGELOG.json +0 -298
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { EventEmitter } from "@yume-chan/event";
|
|
2
|
+
|
|
3
|
+
import { Ref } from "../utils/index.js";
|
|
4
|
+
|
|
5
|
+
import { AdbServerClient } from "./client.js";
|
|
6
|
+
import type { AdbServerStream } from "./stream.js";
|
|
7
|
+
|
|
8
|
+
function unorderedRemove<T>(array: T[], index: number) {
|
|
9
|
+
array[index] = array[array.length - 1]!;
|
|
10
|
+
array.length -= 1;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class AdbServerDeviceObserverOwner {
|
|
14
|
+
current: AdbServerClient.Device[] = [];
|
|
15
|
+
|
|
16
|
+
#client: AdbServerClient;
|
|
17
|
+
#stream: Promise<AdbServerStream> | undefined;
|
|
18
|
+
#observers: {
|
|
19
|
+
onDeviceAdd: EventEmitter<AdbServerClient.Device[]>;
|
|
20
|
+
onDeviceRemove: EventEmitter<AdbServerClient.Device[]>;
|
|
21
|
+
onListChange: EventEmitter<AdbServerClient.Device[]>;
|
|
22
|
+
onError: EventEmitter<Error>;
|
|
23
|
+
}[] = [];
|
|
24
|
+
|
|
25
|
+
constructor(client: AdbServerClient) {
|
|
26
|
+
this.#client = client;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async #receive(stream: AdbServerStream) {
|
|
30
|
+
try {
|
|
31
|
+
while (true) {
|
|
32
|
+
const response = await stream.readString();
|
|
33
|
+
const next = AdbServerClient.parseDeviceList(response);
|
|
34
|
+
|
|
35
|
+
const added: AdbServerClient.Device[] = [];
|
|
36
|
+
for (const nextDevice of next) {
|
|
37
|
+
const index = this.current.findIndex(
|
|
38
|
+
(device) =>
|
|
39
|
+
device.transportId === nextDevice.transportId,
|
|
40
|
+
);
|
|
41
|
+
if (index === -1) {
|
|
42
|
+
added.push(nextDevice);
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
unorderedRemove(this.current, index);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (added.length) {
|
|
50
|
+
for (const observer of this.#observers) {
|
|
51
|
+
observer.onDeviceAdd.fire(added);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (this.current.length) {
|
|
55
|
+
for (const observer of this.#observers) {
|
|
56
|
+
observer.onDeviceRemove.fire(this.current);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
this.current = next;
|
|
61
|
+
for (const observer of this.#observers) {
|
|
62
|
+
observer.onListChange.fire(this.current);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
} catch (e) {
|
|
66
|
+
for (const observer of this.#observers) {
|
|
67
|
+
observer.onError.fire(e as Error);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async #connect() {
|
|
73
|
+
const stream = await this.#client.createConnection(
|
|
74
|
+
"host:track-devices-l",
|
|
75
|
+
// Each individual observer will ref depending on their options
|
|
76
|
+
{ unref: true },
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
void this.#receive(stream);
|
|
80
|
+
|
|
81
|
+
return stream;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async #handleObserverStop(stream: AdbServerStream) {
|
|
85
|
+
if (this.#observers.length === 0) {
|
|
86
|
+
this.#stream = undefined;
|
|
87
|
+
await stream.dispose();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async createObserver(
|
|
92
|
+
options?: AdbServerClient.ServerConnectionOptions,
|
|
93
|
+
): Promise<AdbServerClient.DeviceObserver> {
|
|
94
|
+
if (options?.signal?.aborted) {
|
|
95
|
+
throw options.signal.reason;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
this.#stream ??= this.#connect();
|
|
99
|
+
const stream = await this.#stream;
|
|
100
|
+
|
|
101
|
+
if (options?.signal?.aborted) {
|
|
102
|
+
await this.#handleObserverStop(stream);
|
|
103
|
+
throw options.signal.reason;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const onDeviceAdd = new EventEmitter<AdbServerClient.Device[]>();
|
|
107
|
+
const onDeviceRemove = new EventEmitter<AdbServerClient.Device[]>();
|
|
108
|
+
const onListChange = new EventEmitter<AdbServerClient.Device[]>();
|
|
109
|
+
const onError = new EventEmitter<Error>();
|
|
110
|
+
|
|
111
|
+
const observer = { onDeviceAdd, onDeviceRemove, onListChange, onError };
|
|
112
|
+
this.#observers.push(observer);
|
|
113
|
+
|
|
114
|
+
const ref = new Ref(options);
|
|
115
|
+
|
|
116
|
+
const stop = async () => {
|
|
117
|
+
const index = self.#observers.indexOf(observer);
|
|
118
|
+
if (index === -1) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
unorderedRemove(this.#observers, index);
|
|
123
|
+
|
|
124
|
+
await this.#handleObserverStop(stream);
|
|
125
|
+
|
|
126
|
+
ref.unref();
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
options?.signal?.addEventListener("abort", () => void stop());
|
|
130
|
+
|
|
131
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
132
|
+
const self = this;
|
|
133
|
+
return {
|
|
134
|
+
onDeviceAdd: onDeviceAdd.event,
|
|
135
|
+
onDeviceRemove: onDeviceRemove.event,
|
|
136
|
+
onListChange: onListChange.event,
|
|
137
|
+
onError: onError.event,
|
|
138
|
+
get current() {
|
|
139
|
+
return self.current;
|
|
140
|
+
},
|
|
141
|
+
stop,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { MaybePromiseLike } from "@yume-chan/async";
|
|
2
|
+
import type { WritableStreamDefaultWriter } from "@yume-chan/stream-extra";
|
|
3
|
+
import {
|
|
4
|
+
BufferedReadableStream,
|
|
5
|
+
tryCancel,
|
|
6
|
+
tryClose,
|
|
7
|
+
} from "@yume-chan/stream-extra";
|
|
8
|
+
import {
|
|
9
|
+
bipedal,
|
|
10
|
+
decodeUtf8,
|
|
11
|
+
encodeUtf8,
|
|
12
|
+
TextDecoder,
|
|
13
|
+
} from "@yume-chan/struct";
|
|
14
|
+
|
|
15
|
+
import { hexToNumber, sequenceEqual, write4HexDigits } from "../utils/index.js";
|
|
16
|
+
|
|
17
|
+
import type { AdbServerClient } from "./client.js";
|
|
18
|
+
|
|
19
|
+
const OKAY = encodeUtf8("OKAY");
|
|
20
|
+
export const FAIL = encodeUtf8("FAIL");
|
|
21
|
+
|
|
22
|
+
export class AdbServerStream {
|
|
23
|
+
#connection: AdbServerClient.ServerConnection;
|
|
24
|
+
#buffered: BufferedReadableStream;
|
|
25
|
+
#writer: WritableStreamDefaultWriter<Uint8Array>;
|
|
26
|
+
|
|
27
|
+
constructor(connection: AdbServerClient.ServerConnection) {
|
|
28
|
+
this.#connection = connection;
|
|
29
|
+
this.#buffered = new BufferedReadableStream(connection.readable);
|
|
30
|
+
this.#writer = connection.writable.getWriter();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
readExactly(length: number): MaybePromiseLike<Uint8Array> {
|
|
34
|
+
return this.#buffered.readExactly(length);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
readString = bipedal(function* (this: AdbServerStream, then) {
|
|
38
|
+
const data = yield* then(this.readExactly(4));
|
|
39
|
+
const length = hexToNumber(data);
|
|
40
|
+
if (length === 0) {
|
|
41
|
+
return "";
|
|
42
|
+
} else {
|
|
43
|
+
const decoder = new TextDecoder();
|
|
44
|
+
let result = "";
|
|
45
|
+
const iterator = this.#buffered.iterateExactly(length);
|
|
46
|
+
while (true) {
|
|
47
|
+
const { done, value } = iterator.next();
|
|
48
|
+
if (done) {
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
result += decoder.decode(yield* then(value), { stream: true });
|
|
52
|
+
}
|
|
53
|
+
result += decoder.decode();
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
async readOkay(): Promise<void> {
|
|
59
|
+
const response = await this.readExactly(4);
|
|
60
|
+
if (sequenceEqual(response, OKAY)) {
|
|
61
|
+
// `OKAY` is followed by data length and data
|
|
62
|
+
// But different services want to parse the data differently
|
|
63
|
+
// So don't read the data here
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (sequenceEqual(response, FAIL)) {
|
|
68
|
+
const reason = await this.readString();
|
|
69
|
+
throw new Error(reason);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
throw new Error(`Unexpected response: ${decodeUtf8(response)}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async writeString(value: string): Promise<void> {
|
|
76
|
+
// TODO: investigate using `encodeUtf8("0000" + value)` then modifying the length
|
|
77
|
+
// That way allocates a new string (hopefully only a rope) instead of a new buffer
|
|
78
|
+
const encoded = encodeUtf8(value);
|
|
79
|
+
const buffer = new Uint8Array(4 + encoded.length);
|
|
80
|
+
write4HexDigits(buffer, 0, encoded.length);
|
|
81
|
+
buffer.set(encoded, 4);
|
|
82
|
+
await this.#writer.write(buffer);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
release() {
|
|
86
|
+
this.#writer.releaseLock();
|
|
87
|
+
return {
|
|
88
|
+
readable: this.#buffered.release(),
|
|
89
|
+
writable: this.#connection.writable,
|
|
90
|
+
closed: this.#connection.closed,
|
|
91
|
+
close: () => this.#connection.close(),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async dispose() {
|
|
96
|
+
void tryCancel(this.#buffered);
|
|
97
|
+
void tryClose(this.#writer);
|
|
98
|
+
await this.#connection.close();
|
|
99
|
+
}
|
|
100
|
+
}
|
package/src/server/transport.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { PromiseResolver } from "@yume-chan/async";
|
|
2
|
-
import { AbortController } from "@yume-chan/stream-extra";
|
|
3
|
-
import type { ValueOrPromise } from "@yume-chan/struct";
|
|
4
2
|
|
|
5
3
|
import type {
|
|
6
4
|
AdbIncomingSocketHandler,
|
|
@@ -44,9 +42,13 @@ export class AdbServerTransport implements AdbTransport {
|
|
|
44
42
|
|
|
45
43
|
readonly banner: AdbBanner;
|
|
46
44
|
|
|
45
|
+
#sockets: AdbSocket[] = [];
|
|
46
|
+
|
|
47
47
|
#closed = new PromiseResolver<void>();
|
|
48
|
-
#
|
|
49
|
-
|
|
48
|
+
#disconnected: Promise<void>;
|
|
49
|
+
get disconnected() {
|
|
50
|
+
return this.#disconnected;
|
|
51
|
+
}
|
|
50
52
|
|
|
51
53
|
get clientFeatures() {
|
|
52
54
|
// No need to get host features (features supported by ADB server)
|
|
@@ -54,33 +56,29 @@ export class AdbServerTransport implements AdbTransport {
|
|
|
54
56
|
return ADB_SERVER_DEFAULT_FEATURES;
|
|
55
57
|
}
|
|
56
58
|
|
|
59
|
+
// eslint-disable-next-line @typescript-eslint/max-params
|
|
57
60
|
constructor(
|
|
58
61
|
client: AdbServerClient,
|
|
59
62
|
serial: string,
|
|
60
63
|
banner: AdbBanner,
|
|
61
64
|
transportId: bigint,
|
|
65
|
+
disconnected: Promise<void>,
|
|
62
66
|
) {
|
|
63
67
|
this.#client = client;
|
|
64
68
|
this.serial = serial;
|
|
65
69
|
this.banner = banner;
|
|
66
70
|
this.transportId = transportId;
|
|
67
71
|
|
|
68
|
-
this
|
|
69
|
-
this.#closed.promise,
|
|
70
|
-
client.waitFor({ transportId }, "disconnect", {
|
|
71
|
-
signal: this.#waitAbortController.signal,
|
|
72
|
-
unref: true,
|
|
73
|
-
}),
|
|
74
|
-
]);
|
|
72
|
+
this.#disconnected = Promise.race([this.#closed.promise, disconnected]);
|
|
75
73
|
}
|
|
76
74
|
|
|
77
75
|
async connect(service: string): Promise<AdbSocket> {
|
|
78
|
-
|
|
79
|
-
{
|
|
80
|
-
transportId: this.transportId,
|
|
81
|
-
},
|
|
76
|
+
const socket = await this.#client.createDeviceConnection(
|
|
77
|
+
{ transportId: this.transportId },
|
|
82
78
|
service,
|
|
83
79
|
);
|
|
80
|
+
this.#sockets.push(socket);
|
|
81
|
+
return socket;
|
|
84
82
|
}
|
|
85
83
|
|
|
86
84
|
async addReverseTunnel(
|
|
@@ -98,8 +96,11 @@ export class AdbServerTransport implements AdbTransport {
|
|
|
98
96
|
await this.#client.connector.clearReverseTunnels();
|
|
99
97
|
}
|
|
100
98
|
|
|
101
|
-
close():
|
|
99
|
+
async close(): Promise<void> {
|
|
100
|
+
for (const socket of this.#sockets) {
|
|
101
|
+
await socket.close();
|
|
102
|
+
}
|
|
103
|
+
this.#sockets.length = 0;
|
|
102
104
|
this.#closed.resolve();
|
|
103
|
-
this.#waitAbortController.abort();
|
|
104
105
|
}
|
|
105
106
|
}
|
package/src/utils/base64.ts
CHANGED
|
@@ -1,23 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
const [charToIndex, indexToChar, paddingChar] = /* #__PURE__ */ (() => {
|
|
2
|
+
// Array is faster than object literal or `Map`
|
|
3
|
+
const charToIndex: number[] = [];
|
|
4
|
+
const indexToChar: number[] = [];
|
|
5
|
+
const paddingChar = "=".charCodeAt(0);
|
|
6
|
+
|
|
7
|
+
function addRange(start: string, end: string) {
|
|
8
|
+
const charCodeStart = start.charCodeAt(0);
|
|
9
|
+
const charCodeEnd = end.charCodeAt(0);
|
|
10
|
+
|
|
11
|
+
for (
|
|
12
|
+
let charCode = charCodeStart;
|
|
13
|
+
charCode <= charCodeEnd;
|
|
14
|
+
charCode += 1
|
|
15
|
+
) {
|
|
16
|
+
charToIndex[charCode] = indexToChar.length;
|
|
17
|
+
indexToChar.push(charCode);
|
|
18
|
+
}
|
|
13
19
|
}
|
|
14
|
-
}
|
|
15
20
|
|
|
16
|
-
addRange("A", "Z");
|
|
17
|
-
addRange("a", "z");
|
|
18
|
-
addRange("0", "9");
|
|
19
|
-
addRange("+", "+");
|
|
20
|
-
addRange("/", "/");
|
|
21
|
+
addRange("A", "Z");
|
|
22
|
+
addRange("a", "z");
|
|
23
|
+
addRange("0", "9");
|
|
24
|
+
addRange("+", "+");
|
|
25
|
+
addRange("/", "/");
|
|
26
|
+
|
|
27
|
+
return [charToIndex, indexToChar, paddingChar];
|
|
28
|
+
})();
|
|
21
29
|
|
|
22
30
|
/**
|
|
23
31
|
* Calculate the required length of the output buffer for the given input length.
|
package/src/utils/index.ts
CHANGED
package/src/utils/no-op.ts
CHANGED
package/src/utils/ref.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
interface GlobalExtension {
|
|
2
|
+
setInterval: (callback: () => void, delay: number) => number;
|
|
3
|
+
clearInterval: (id: number) => void;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const { setInterval, clearInterval } = globalThis as unknown as GlobalExtension;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* An object to keep current Node.js process alive even when no code is running.
|
|
10
|
+
*
|
|
11
|
+
* Does nothing in Web environments.
|
|
12
|
+
*
|
|
13
|
+
* Note that it does't have reference counting. Calling `unref` will
|
|
14
|
+
* remove the ref no matter how many times `ref` has been previously called, and vice versa.
|
|
15
|
+
* This is the same as how Node.js works.
|
|
16
|
+
*/
|
|
17
|
+
export class Ref {
|
|
18
|
+
#intervalId: number | undefined;
|
|
19
|
+
|
|
20
|
+
constructor(options?: { unref?: boolean | undefined }) {
|
|
21
|
+
if (!options?.unref) {
|
|
22
|
+
this.ref();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
ref() {
|
|
27
|
+
// `setInterval` can keep current Node.js alive, the delay value doesn't matter
|
|
28
|
+
this.#intervalId = setInterval(() => {}, 60 * 1000);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
unref() {
|
|
32
|
+
if (this.#intervalId) {
|
|
33
|
+
clearInterval(this.#intervalId);
|
|
34
|
+
this.#intervalId = undefined;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
package/tsconfig.build.json
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends": "./node_modules/@yume-chan/tsconfig/tsconfig.base.json"
|
|
3
|
-
"references": [
|
|
4
|
-
{
|
|
5
|
-
"path": "../event/tsconfig.build.json"
|
|
6
|
-
},
|
|
7
|
-
{
|
|
8
|
-
"path": "../stream-extra/tsconfig.build.json"
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
"path": "../struct/tsconfig.build.json"
|
|
12
|
-
}
|
|
13
|
-
]
|
|
2
|
+
"extends": "./node_modules/@yume-chan/tsconfig/tsconfig.base.json"
|
|
14
3
|
}
|