@yume-chan/adb 0.0.10 → 0.0.13
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 +50 -0
- package/CHANGELOG.md +29 -1
- package/LICENSE +1 -1
- package/README.md +71 -51
- package/esm/adb.d.ts +48 -0
- package/esm/adb.d.ts.map +1 -0
- package/esm/adb.js +149 -136
- package/esm/adb.js.map +1 -1
- package/{dts → esm}/auth.d.ts +11 -11
- package/esm/auth.d.ts.map +1 -0
- package/esm/auth.js +72 -110
- package/esm/auth.js.map +1 -1
- package/esm/backend.d.ts +9 -0
- package/esm/backend.d.ts.map +1 -0
- package/{dts → esm}/commands/base.d.ts +1 -1
- package/esm/commands/base.d.ts.map +1 -0
- package/esm/commands/base.js +1 -0
- package/esm/commands/base.js.map +1 -1
- package/{dts → esm}/commands/framebuffer.d.ts +3 -3
- package/esm/commands/framebuffer.d.ts.map +1 -0
- package/esm/commands/framebuffer.js +15 -18
- package/esm/commands/framebuffer.js.map +1 -1
- package/esm/commands/index.d.ts +9 -0
- package/esm/commands/index.d.ts.map +1 -0
- package/esm/commands/index.js +8 -8
- package/esm/commands/index.js.map +1 -1
- package/esm/commands/install.d.ts +4 -0
- package/esm/commands/install.d.ts.map +1 -0
- package/esm/commands/install.js +19 -13
- package/esm/commands/install.js.map +1 -1
- package/esm/commands/power.d.ts +23 -0
- package/esm/commands/power.d.ts.map +1 -0
- package/esm/commands/power.js +45 -0
- package/esm/commands/power.js.map +1 -0
- package/{dts → esm}/commands/reverse.d.ts +3 -3
- package/esm/commands/reverse.d.ts.map +1 -0
- package/esm/commands/reverse.js +49 -60
- package/esm/commands/reverse.js.map +1 -1
- package/esm/commands/subprocess/index.d.ts +56 -0
- package/esm/commands/subprocess/index.d.ts.map +1 -0
- package/esm/commands/subprocess/index.js +88 -0
- package/esm/commands/subprocess/index.js.map +1 -0
- package/esm/commands/subprocess/legacy.d.ts +35 -0
- package/esm/commands/subprocess/legacy.d.ts.map +1 -0
- package/esm/commands/subprocess/legacy.js +53 -0
- package/esm/commands/subprocess/legacy.js.map +1 -0
- package/esm/commands/subprocess/protocol.d.ts +39 -0
- package/esm/commands/subprocess/protocol.d.ts.map +1 -0
- package/esm/commands/subprocess/protocol.js +157 -0
- package/esm/commands/subprocess/protocol.js.map +1 -0
- package/esm/commands/subprocess/protocols/index.d.ts +4 -0
- package/esm/commands/subprocess/protocols/index.d.ts.map +1 -0
- package/esm/commands/subprocess/protocols/index.js +4 -0
- package/esm/commands/subprocess/protocols/index.js.map +1 -0
- package/esm/commands/subprocess/protocols/none.d.ts +35 -0
- package/esm/commands/subprocess/protocols/none.d.ts.map +1 -0
- package/esm/commands/subprocess/protocols/none.js +53 -0
- package/esm/commands/subprocess/protocols/none.js.map +1 -0
- package/esm/commands/subprocess/protocols/shell.d.ts +39 -0
- package/esm/commands/subprocess/protocols/shell.d.ts.map +1 -0
- package/esm/commands/subprocess/protocols/shell.js +155 -0
- package/esm/commands/subprocess/protocols/shell.js.map +1 -0
- package/esm/commands/subprocess/protocols/types.d.ts +50 -0
- package/esm/commands/subprocess/protocols/types.d.ts.map +1 -0
- package/esm/commands/{shell → subprocess/protocols}/types.js +0 -0
- package/esm/commands/subprocess/protocols/types.js.map +1 -0
- package/esm/commands/subprocess/types.d.ts +50 -0
- package/esm/commands/subprocess/types.d.ts.map +1 -0
- package/esm/commands/subprocess/types.js +2 -0
- package/esm/commands/{shell → subprocess}/types.js.map +1 -1
- package/{dts/commands/shell → esm/commands/subprocess}/utils.d.ts +0 -0
- package/esm/commands/subprocess/utils.d.ts.map +1 -0
- package/esm/commands/{shell → subprocess}/utils.js +0 -0
- package/esm/commands/subprocess/utils.js.map +1 -0
- package/esm/commands/sync/index.d.ts +8 -0
- package/esm/commands/sync/index.d.ts.map +1 -0
- package/esm/commands/sync/index.js +7 -7
- package/esm/commands/sync/index.js.map +1 -1
- package/esm/commands/sync/list.d.ts +41 -0
- package/esm/commands/sync/list.d.ts.map +1 -0
- package/esm/commands/sync/list.js +52 -20
- package/esm/commands/sync/list.js.map +1 -1
- package/esm/commands/sync/pull.d.ts +11 -0
- package/esm/commands/sync/pull.d.ts.map +1 -0
- package/esm/commands/sync/pull.js +17 -11
- package/esm/commands/sync/pull.js.map +1 -1
- package/esm/commands/sync/push.d.ts +8 -0
- package/esm/commands/sync/push.d.ts.map +1 -0
- package/esm/commands/sync/push.js +19 -37
- package/esm/commands/sync/push.js.map +1 -1
- package/{dts → esm}/commands/sync/request.d.ts +4 -3
- package/esm/commands/sync/request.d.ts.map +1 -0
- package/esm/commands/sync/request.js +25 -27
- package/esm/commands/sync/request.js.map +1 -1
- package/{dts → esm}/commands/sync/response.d.ts +4 -3
- package/esm/commands/sync/response.d.ts.map +1 -0
- package/esm/commands/sync/response.js +17 -20
- package/esm/commands/sync/response.js.map +1 -1
- package/{dts → esm}/commands/sync/stat.d.ts +16 -4
- package/esm/commands/sync/stat.d.ts.map +1 -0
- package/esm/commands/sync/stat.js +38 -30
- package/esm/commands/sync/stat.js.map +1 -1
- package/esm/commands/sync/sync.d.ts +61 -0
- package/esm/commands/sync/sync.d.ts.map +1 -0
- package/esm/commands/sync/sync.js +122 -89
- package/esm/commands/sync/sync.js.map +1 -1
- package/{dts → esm}/commands/tcpip.d.ts +1 -1
- package/{dts → esm}/commands/tcpip.d.ts.map +1 -1
- package/esm/commands/tcpip.js +14 -19
- package/esm/commands/tcpip.js.map +1 -1
- package/esm/crypto.d.ts +37 -0
- package/esm/crypto.d.ts.map +1 -0
- package/esm/crypto.js +77 -62
- package/esm/crypto.js.map +1 -1
- package/esm/features.d.ts +8 -0
- package/esm/features.d.ts.map +1 -0
- package/esm/features.js +7 -3
- package/esm/features.js.map +1 -1
- package/esm/index.d.ts +11 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +10 -10
- package/esm/index.js.map +1 -1
- package/esm/packet.d.ts +47 -0
- package/esm/packet.d.ts.map +1 -0
- package/esm/packet.js +27 -52
- package/esm/packet.js.map +1 -1
- package/esm/socket/controller.d.ts +37 -0
- package/esm/socket/controller.d.ts.map +1 -0
- package/esm/socket/controller.js +52 -66
- package/esm/socket/controller.js.map +1 -1
- package/esm/socket/dispatcher.d.ts +44 -0
- package/esm/socket/dispatcher.d.ts.map +1 -0
- package/esm/socket/dispatcher.js +146 -165
- package/esm/socket/dispatcher.js.map +1 -1
- package/esm/socket/index.d.ts +3 -0
- package/esm/socket/index.d.ts.map +1 -0
- package/esm/socket/index.js +2 -6
- package/esm/socket/index.js.map +1 -1
- package/esm/socket/socket.d.ts +46 -0
- package/esm/socket/socket.d.ts.map +1 -0
- package/esm/socket/socket.js +77 -13
- package/esm/socket/socket.js.map +1 -1
- package/esm/stream/buffered.d.ts +35 -0
- package/esm/stream/buffered.d.ts.map +1 -0
- package/esm/stream/buffered.js +123 -0
- package/esm/stream/buffered.js.map +1 -0
- package/esm/stream/detect.bak.d.ts +240 -0
- package/esm/stream/detect.bak.d.ts.map +1 -0
- package/esm/stream/detect.bak.js +60 -0
- package/esm/stream/detect.bak.js.map +1 -0
- package/esm/stream/detect.d.ts +2 -0
- package/esm/stream/detect.d.ts.map +1 -0
- package/esm/stream/detect.js +5 -0
- package/esm/stream/detect.js.map +1 -0
- package/esm/stream/detect.native.d.ts +240 -0
- package/esm/stream/detect.native.d.ts.map +1 -0
- package/esm/stream/detect.native.js +60 -0
- package/esm/stream/detect.native.js.map +1 -0
- package/esm/stream/detect.polyfill.d.ts +18 -0
- package/esm/stream/detect.polyfill.d.ts.map +1 -0
- package/esm/stream/detect.polyfill.js +9 -0
- package/esm/stream/detect.polyfill.js.map +1 -0
- package/esm/stream/index.d.ts +4 -0
- package/esm/stream/index.d.ts.map +1 -0
- package/esm/stream/index.js +3 -2
- package/esm/stream/index.js.map +1 -1
- package/esm/stream/transform.d.ts +98 -0
- package/esm/stream/transform.d.ts.map +1 -0
- package/esm/stream/transform.js +402 -0
- package/esm/stream/transform.js.map +1 -0
- package/{dts → esm}/utils/auto-reset-event.d.ts +1 -1
- package/esm/utils/auto-reset-event.d.ts.map +1 -0
- package/esm/utils/auto-reset-event.js +2 -1
- package/esm/utils/auto-reset-event.js.map +1 -1
- package/esm/utils/base64.d.ts +5 -0
- package/esm/utils/base64.d.ts.map +1 -0
- package/esm/utils/base64.js +116 -80
- package/esm/utils/base64.js.map +1 -1
- package/esm/utils/encoding.d.ts +3 -0
- package/esm/utils/encoding.d.ts.map +1 -0
- package/esm/utils/encoding.js +1 -1
- package/esm/utils/encoding.js.map +1 -1
- package/esm/utils/index.d.ts +4 -0
- package/esm/utils/index.d.ts.map +1 -0
- package/esm/utils/index.js +3 -5
- package/esm/utils/index.js.map +1 -1
- package/package.json +50 -44
- package/src/adb.ts +177 -150
- package/src/auth.ts +37 -30
- package/src/backend.ts +3 -12
- package/src/commands/base.ts +1 -1
- package/src/commands/framebuffer.ts +4 -4
- package/src/commands/index.ts +8 -8
- package/src/commands/install.ts +24 -15
- package/src/commands/power.ts +54 -0
- package/src/commands/reverse.ts +10 -8
- package/src/commands/subprocess/index.ts +139 -0
- package/src/commands/subprocess/protocols/index.ts +3 -0
- package/src/commands/subprocess/protocols/none.ts +68 -0
- package/src/commands/subprocess/protocols/shell.ts +190 -0
- package/src/commands/subprocess/protocols/types.ts +59 -0
- package/src/commands/{shell → subprocess}/utils.ts +0 -0
- package/src/commands/sync/index.ts +7 -7
- package/src/commands/sync/list.ts +56 -9
- package/src/commands/sync/pull.ts +27 -18
- package/src/commands/sync/push.ts +25 -30
- package/src/commands/sync/request.ts +8 -7
- package/src/commands/sync/response.ts +12 -6
- package/src/commands/sync/stat.ts +43 -14
- package/src/commands/sync/sync.ts +102 -34
- package/src/commands/tcpip.ts +3 -3
- package/src/crypto.ts +95 -84
- package/src/features.ts +6 -2
- package/src/index.ts +11 -10
- package/src/packet.ts +49 -53
- package/src/socket/dispatcher.ts +110 -109
- package/src/socket/index.ts +2 -6
- package/src/socket/socket.ts +125 -17
- package/src/stream/buffered.ts +147 -0
- package/src/stream/detect.native.ts +362 -0
- package/src/stream/detect.polyfill.ts +28 -0
- package/src/stream/detect.ts +5 -0
- package/src/stream/index.ts +3 -2
- package/src/stream/transform.ts +483 -0
- package/src/utils/auto-reset-event.ts +1 -1
- package/src/utils/base64.ts +161 -129
- package/src/utils/index.ts +3 -5
- package/tsconfig.build.json +3 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.test.json +10 -0
- package/dts/adb.d.ts +0 -46
- package/dts/adb.d.ts.map +0 -1
- package/dts/auth.d.ts.map +0 -1
- package/dts/backend.d.ts +0 -13
- package/dts/backend.d.ts.map +0 -1
- package/dts/commands/base.d.ts.map +0 -1
- package/dts/commands/demo-mode.d.ts +0 -41
- package/dts/commands/demo-mode.d.ts.map +0 -1
- package/dts/commands/framebuffer.d.ts.map +0 -1
- package/dts/commands/index.d.ts +0 -9
- package/dts/commands/index.d.ts.map +0 -1
- package/dts/commands/install.d.ts +0 -3
- package/dts/commands/install.d.ts.map +0 -1
- package/dts/commands/reverse.d.ts.map +0 -1
- package/dts/commands/shell/index.d.ts +0 -46
- package/dts/commands/shell/index.d.ts.map +0 -1
- package/dts/commands/shell/legacy.d.ts +0 -38
- package/dts/commands/shell/legacy.d.ts.map +0 -1
- package/dts/commands/shell/protocol.d.ts +0 -45
- package/dts/commands/shell/protocol.d.ts.map +0 -1
- package/dts/commands/shell/types.d.ts +0 -47
- package/dts/commands/shell/types.d.ts.map +0 -1
- package/dts/commands/shell/utils.d.ts.map +0 -1
- package/dts/commands/sync/index.d.ts +0 -8
- package/dts/commands/sync/index.d.ts.map +0 -1
- package/dts/commands/sync/list.d.ts +0 -17
- package/dts/commands/sync/list.d.ts.map +0 -1
- package/dts/commands/sync/pull.d.ts +0 -11
- package/dts/commands/sync/pull.d.ts.map +0 -1
- package/dts/commands/sync/push.d.ts +0 -8
- package/dts/commands/sync/push.d.ts.map +0 -1
- package/dts/commands/sync/request.d.ts.map +0 -1
- package/dts/commands/sync/response.d.ts.map +0 -1
- package/dts/commands/sync/stat.d.ts.map +0 -1
- package/dts/commands/sync/sync.d.ts +0 -68
- package/dts/commands/sync/sync.d.ts.map +0 -1
- package/dts/crypto.d.ts +0 -24
- package/dts/crypto.d.ts.map +0 -1
- package/dts/features.d.ts +0 -6
- package/dts/features.d.ts.map +0 -1
- package/dts/index.d.ts +0 -11
- package/dts/index.d.ts.map +0 -1
- package/dts/packet.d.ts +0 -27
- package/dts/packet.d.ts.map +0 -1
- package/dts/socket/close-event-emitter.d.ts +0 -8
- package/dts/socket/close-event-emitter.d.ts.map +0 -1
- package/dts/socket/controller.d.ts +0 -43
- package/dts/socket/controller.d.ts.map +0 -1
- package/dts/socket/data-event-emitter.d.ts +0 -10
- package/dts/socket/data-event-emitter.d.ts.map +0 -1
- package/dts/socket/dispatcher.d.ts +0 -53
- package/dts/socket/dispatcher.d.ts.map +0 -1
- package/dts/socket/index.d.ts +0 -7
- package/dts/socket/index.d.ts.map +0 -1
- package/dts/socket/logger.d.ts +0 -9
- package/dts/socket/logger.d.ts.map +0 -1
- package/dts/socket/socket.d.ts +0 -22
- package/dts/socket/socket.d.ts.map +0 -1
- package/dts/stream/buffered-stream.d.ts +0 -28
- package/dts/stream/buffered-stream.d.ts.map +0 -1
- package/dts/stream/index.d.ts +0 -3
- package/dts/stream/index.d.ts.map +0 -1
- package/dts/stream/stream.d.ts +0 -15
- package/dts/stream/stream.d.ts.map +0 -1
- package/dts/utils/auto-reset-event.d.ts.map +0 -1
- package/dts/utils/base64.d.ts +0 -7
- package/dts/utils/base64.d.ts.map +0 -1
- package/dts/utils/chunk.d.ts +0 -3
- package/dts/utils/chunk.d.ts.map +0 -1
- package/dts/utils/encoding.d.ts +0 -3
- package/dts/utils/encoding.d.ts.map +0 -1
- package/dts/utils/event-queue.d.ts +0 -35
- package/dts/utils/event-queue.d.ts.map +0 -1
- package/dts/utils/index.d.ts +0 -6
- package/dts/utils/index.d.ts.map +0 -1
- package/esm/commands/demo-mode.js +0 -170
- package/esm/commands/demo-mode.js.map +0 -1
- package/esm/commands/shell/index.js +0 -62
- package/esm/commands/shell/index.js.map +0 -1
- package/esm/commands/shell/legacy.js +0 -49
- package/esm/commands/shell/legacy.js.map +0 -1
- package/esm/commands/shell/protocol.js +0 -106
- package/esm/commands/shell/protocol.js.map +0 -1
- package/esm/commands/shell/utils.js.map +0 -1
- package/esm/socket/close-event-emitter.js +0 -28
- package/esm/socket/close-event-emitter.js.map +0 -1
- package/esm/socket/data-event-emitter.js +0 -25
- package/esm/socket/data-event-emitter.js.map +0 -1
- package/esm/socket/logger.js +0 -2
- package/esm/socket/logger.js.map +0 -1
- package/esm/stream/buffered-stream.js +0 -67
- package/esm/stream/buffered-stream.js.map +0 -1
- package/esm/stream/stream.js +0 -41
- package/esm/stream/stream.js.map +0 -1
- package/esm/utils/chunk.js +0 -70
- package/esm/utils/chunk.js.map +0 -1
- package/esm/utils/event-queue.js +0 -104
- package/esm/utils/event-queue.js.map +0 -1
- package/src/commands/demo-mode.ts +0 -160
- package/src/commands/shell/index.ts +0 -87
- package/src/commands/shell/legacy.ts +0 -59
- package/src/commands/shell/protocol.ts +0 -121
- package/src/commands/shell/types.ts +0 -55
- package/src/socket/close-event-emitter.ts +0 -28
- package/src/socket/controller.ts +0 -105
- package/src/socket/data-event-emitter.ts +0 -27
- package/src/socket/logger.ts +0 -12
- package/src/stream/buffered-stream.ts +0 -92
- package/src/stream/stream.ts +0 -50
- package/src/utils/chunk.ts +0 -70
- package/src/utils/encoding.ts +0 -13
- package/src/utils/event-queue.ts +0 -145
package/esm/socket/dispatcher.js
CHANGED
|
@@ -1,78 +1,66 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AsyncOperationManager } from '@yume-chan/async';
|
|
1
|
+
import { AsyncOperationManager, PromiseResolver } from '@yume-chan/async';
|
|
3
2
|
import { AutoDisposable, EventEmitter } from '@yume-chan/event';
|
|
4
|
-
import { AdbCommand,
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
const
|
|
3
|
+
import { AdbCommand, calculateChecksum } from '../packet.js';
|
|
4
|
+
import { AbortController, WritableStream } from '../stream/index.js';
|
|
5
|
+
import { decodeUtf8, encodeUtf8 } from '../utils/index.js';
|
|
6
|
+
import { AdbSocketController } from './socket.js';
|
|
7
|
+
const EmptyUint8Array = new Uint8Array(0);
|
|
9
8
|
export class AdbPacketDispatcher extends AutoDisposable {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
this.appendNullToServiceString = true;
|
|
20
|
-
this.packetEvent = this.addDisposable(new EventEmitter());
|
|
21
|
-
this.incomingSocketEvent = this.addDisposable(new EventEmitter());
|
|
22
|
-
this.errorEvent = this.addDisposable(new EventEmitter());
|
|
23
|
-
this._running = false;
|
|
24
|
-
this.backend = backend;
|
|
25
|
-
this.logger = logger;
|
|
26
|
-
}
|
|
27
|
-
get onPacket() { return this.packetEvent.event; }
|
|
9
|
+
// ADB socket id starts from 1
|
|
10
|
+
// (0 means open failed)
|
|
11
|
+
initializers = new AsyncOperationManager(1);
|
|
12
|
+
sockets = new Map();
|
|
13
|
+
_writer;
|
|
14
|
+
options;
|
|
15
|
+
_disconnected = new PromiseResolver();
|
|
16
|
+
get disconnected() { return this._disconnected.promise; }
|
|
17
|
+
incomingSocketEvent = this.addDisposable(new EventEmitter());
|
|
28
18
|
get onIncomingSocket() { return this.incomingSocketEvent.event; }
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
(_b = (_a = this.logger) === null || _a === void 0 ? void 0 : _a.onIncomingPacket) === null || _b === void 0 ? void 0 : _b.call(_a, packet);
|
|
19
|
+
_abortController = new AbortController();
|
|
20
|
+
constructor(connection, options) {
|
|
21
|
+
super();
|
|
22
|
+
this.options = options;
|
|
23
|
+
connection.readable
|
|
24
|
+
.pipeTo(new WritableStream({
|
|
25
|
+
write: async (packet) => {
|
|
26
|
+
try {
|
|
38
27
|
switch (packet.command) {
|
|
39
28
|
case AdbCommand.OK:
|
|
40
29
|
this.handleOk(packet);
|
|
41
|
-
|
|
30
|
+
return;
|
|
42
31
|
case AdbCommand.Close:
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
await this.handleClose(packet);
|
|
33
|
+
return;
|
|
45
34
|
case AdbCommand.Write:
|
|
46
35
|
if (this.sockets.has(packet.arg1)) {
|
|
47
|
-
|
|
48
|
-
|
|
36
|
+
await this.sockets.get(packet.arg1).enqueue(packet.payload);
|
|
37
|
+
await this.sendPacket(AdbCommand.OK, packet.arg1, packet.arg0);
|
|
49
38
|
}
|
|
50
39
|
// Maybe the device is responding to a packet of last connection
|
|
51
40
|
// Just ignore it
|
|
52
|
-
|
|
41
|
+
return;
|
|
53
42
|
case AdbCommand.Open:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
const args = {
|
|
58
|
-
handled: false,
|
|
59
|
-
packet,
|
|
60
|
-
};
|
|
61
|
-
this.packetEvent.fire(args);
|
|
62
|
-
if (!args.handled) {
|
|
63
|
-
this.dispose();
|
|
64
|
-
throw new Error(`Unhandled packet with command '${packet.command}'`);
|
|
43
|
+
await this.handleOpen(packet);
|
|
44
|
+
return;
|
|
65
45
|
}
|
|
66
46
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return;
|
|
47
|
+
catch (e) {
|
|
48
|
+
// Throw error here will stop the pipe
|
|
49
|
+
// But won't close `readable` because of `preventCancel: true`
|
|
50
|
+
throw e;
|
|
72
51
|
}
|
|
73
|
-
|
|
74
|
-
|
|
52
|
+
},
|
|
53
|
+
}), {
|
|
54
|
+
preventCancel: false,
|
|
55
|
+
signal: this._abortController.signal,
|
|
56
|
+
})
|
|
57
|
+
.then(() => {
|
|
58
|
+
this.dispose();
|
|
59
|
+
}, (e) => {
|
|
60
|
+
this._disconnected.reject(e);
|
|
61
|
+
this.dispose();
|
|
75
62
|
});
|
|
63
|
+
this._writer = connection.writable.getWriter();
|
|
76
64
|
}
|
|
77
65
|
handleOk(packet) {
|
|
78
66
|
if (this.initializers.resolve(packet.arg1, packet.arg0)) {
|
|
@@ -89,126 +77,119 @@ export class AdbPacketDispatcher extends AutoDisposable {
|
|
|
89
77
|
// Tell the device to close the socket
|
|
90
78
|
this.sendPacket(AdbCommand.Close, packet.arg1, packet.arg0);
|
|
91
79
|
}
|
|
92
|
-
handleClose(packet) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
yield this.sendPacket(AdbCommand.Close, packet.arg1, packet.arg0);
|
|
111
|
-
}
|
|
112
|
-
socket.dispose();
|
|
113
|
-
this.sockets.delete(packet.arg1);
|
|
114
|
-
return;
|
|
80
|
+
async handleClose(packet) {
|
|
81
|
+
// From https://android.googlesource.com/platform/packages/modules/adb/+/65d18e2c1cc48b585811954892311b28a4c3d188/adb.cpp#459
|
|
82
|
+
/* According to protocol.txt, p->msg.arg0 might be 0 to indicate
|
|
83
|
+
* a failed OPEN only. However, due to a bug in previous ADB
|
|
84
|
+
* versions, CLOSE(0, remote-id, "") was also used for normal
|
|
85
|
+
* CLOSE() operations.
|
|
86
|
+
*/
|
|
87
|
+
// So don't return if `reject` didn't find a pending socket
|
|
88
|
+
if (packet.arg0 === 0 &&
|
|
89
|
+
this.initializers.reject(packet.arg1, new Error('Socket open failed'))) {
|
|
90
|
+
// Device failed to create the socket
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const socket = this.sockets.get(packet.arg1);
|
|
94
|
+
if (socket) {
|
|
95
|
+
// The device want to close the socket
|
|
96
|
+
if (!socket.closed) {
|
|
97
|
+
await this.sendPacket(AdbCommand.Close, packet.arg1, packet.arg0);
|
|
115
98
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
99
|
+
socket.dispose();
|
|
100
|
+
this.sockets.delete(packet.arg1);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
// Maybe the device is responding to a packet of last connection
|
|
104
|
+
// Just ignore it
|
|
119
105
|
}
|
|
120
|
-
handleOpen(packet) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
serviceString,
|
|
134
|
-
});
|
|
135
|
-
const socket = new AdbSocket(controller);
|
|
136
|
-
const args = {
|
|
137
|
-
handled: false,
|
|
138
|
-
packet,
|
|
139
|
-
serviceString,
|
|
140
|
-
socket,
|
|
141
|
-
};
|
|
142
|
-
this.incomingSocketEvent.fire(args);
|
|
143
|
-
if (args.handled) {
|
|
144
|
-
this.sockets.set(localId, controller);
|
|
145
|
-
yield this.sendPacket(AdbCommand.OK, localId, remoteId);
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
yield this.sendPacket(AdbCommand.Close, 0, remoteId);
|
|
149
|
-
}
|
|
106
|
+
async handleOpen(packet) {
|
|
107
|
+
// AsyncOperationManager doesn't support get and skip an ID
|
|
108
|
+
// Use `add` + `resolve` to simulate this behavior
|
|
109
|
+
const [localId] = this.initializers.add();
|
|
110
|
+
this.initializers.resolve(localId, undefined);
|
|
111
|
+
const remoteId = packet.arg0;
|
|
112
|
+
const serviceString = decodeUtf8(packet.payload);
|
|
113
|
+
const controller = new AdbSocketController({
|
|
114
|
+
dispatcher: this,
|
|
115
|
+
localId,
|
|
116
|
+
remoteId,
|
|
117
|
+
localCreated: false,
|
|
118
|
+
serviceString,
|
|
150
119
|
});
|
|
120
|
+
const args = {
|
|
121
|
+
handled: false,
|
|
122
|
+
packet,
|
|
123
|
+
serviceString,
|
|
124
|
+
socket: controller.socket,
|
|
125
|
+
};
|
|
126
|
+
this.incomingSocketEvent.fire(args);
|
|
127
|
+
if (args.handled) {
|
|
128
|
+
this.sockets.set(localId, controller);
|
|
129
|
+
await this.sendPacket(AdbCommand.OK, localId, remoteId);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
await this.sendPacket(AdbCommand.Close, 0, remoteId);
|
|
133
|
+
}
|
|
151
134
|
}
|
|
152
|
-
|
|
153
|
-
this.
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
localId,
|
|
167
|
-
remoteId,
|
|
168
|
-
localCreated: true,
|
|
169
|
-
serviceString,
|
|
170
|
-
});
|
|
171
|
-
this.sockets.set(controller.localId, controller);
|
|
172
|
-
return new AdbSocket(controller);
|
|
135
|
+
async createSocket(serviceString) {
|
|
136
|
+
if (this.options.appendNullToServiceString) {
|
|
137
|
+
serviceString += '\0';
|
|
138
|
+
}
|
|
139
|
+
const [localId, initializer] = this.initializers.add();
|
|
140
|
+
await this.sendPacket(AdbCommand.Open, localId, 0, serviceString);
|
|
141
|
+
// Fulfilled by `handleOk`
|
|
142
|
+
const remoteId = await initializer;
|
|
143
|
+
const controller = new AdbSocketController({
|
|
144
|
+
dispatcher: this,
|
|
145
|
+
localId,
|
|
146
|
+
remoteId,
|
|
147
|
+
localCreated: true,
|
|
148
|
+
serviceString,
|
|
173
149
|
});
|
|
150
|
+
this.sockets.set(localId, controller);
|
|
151
|
+
return controller.socket;
|
|
174
152
|
}
|
|
175
|
-
sendPacket(packetOrCommand, arg0, arg1, payload =
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
init = {
|
|
184
|
-
command: packetOrCommand,
|
|
185
|
-
arg0: arg0,
|
|
186
|
-
arg1: arg1,
|
|
187
|
-
payload: typeof payload === 'string' ? encodeUtf8(payload) : payload,
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
if (init.payload &&
|
|
191
|
-
init.payload.byteLength > this.maxPayloadSize) {
|
|
192
|
-
throw new Error('payload too large');
|
|
193
|
-
}
|
|
194
|
-
try {
|
|
195
|
-
// `AdbPacket.write` writes each packet in two parts
|
|
196
|
-
// Use a lock to prevent packets been interlaced
|
|
197
|
-
yield this.sendLock.wait();
|
|
198
|
-
(_b = (_a = this.logger) === null || _a === void 0 ? void 0 : _a.onOutgoingPacket) === null || _b === void 0 ? void 0 : _b.call(_a, init);
|
|
199
|
-
yield AdbPacket.write(init, this.calculateChecksum, this.backend);
|
|
200
|
-
}
|
|
201
|
-
finally {
|
|
202
|
-
this.sendLock.notify();
|
|
153
|
+
async sendPacket(packetOrCommand, arg0, arg1, payload = EmptyUint8Array) {
|
|
154
|
+
let init;
|
|
155
|
+
if (arg0 === undefined) {
|
|
156
|
+
init = packetOrCommand;
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
if (typeof payload === 'string') {
|
|
160
|
+
payload = encodeUtf8(payload);
|
|
203
161
|
}
|
|
204
|
-
|
|
162
|
+
init = {
|
|
163
|
+
command: packetOrCommand,
|
|
164
|
+
arg0: arg0,
|
|
165
|
+
arg1: arg1,
|
|
166
|
+
payload,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
if (init.payload &&
|
|
170
|
+
init.payload.byteLength > this.options.maxPayloadSize) {
|
|
171
|
+
throw new Error('payload too large');
|
|
172
|
+
}
|
|
173
|
+
if (this.options.calculateChecksum) {
|
|
174
|
+
calculateChecksum(init);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
init.checksum = 0;
|
|
178
|
+
}
|
|
179
|
+
await this._writer.write(init);
|
|
205
180
|
}
|
|
206
181
|
dispose() {
|
|
207
|
-
this._running = false;
|
|
208
182
|
for (const socket of this.sockets.values()) {
|
|
209
183
|
socket.dispose();
|
|
210
184
|
}
|
|
211
185
|
this.sockets.clear();
|
|
186
|
+
try {
|
|
187
|
+
// Stop pipes
|
|
188
|
+
this._abortController.abort();
|
|
189
|
+
}
|
|
190
|
+
catch { }
|
|
191
|
+
this._writer.releaseLock();
|
|
192
|
+
this._disconnected.resolve();
|
|
212
193
|
super.dispose();
|
|
213
194
|
}
|
|
214
195
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatcher.js","sourceRoot":"","sources":["../../src/socket/dispatcher.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dispatcher.js","sourceRoot":"","sources":["../../src/socket/dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAA0C,MAAM,cAAc,CAAC;AACrG,OAAO,EAAE,eAAe,EAAE,cAAc,EAA0D,MAAM,oBAAoB,CAAC;AAC7H,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAa,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAY7D,MAAM,eAAe,GAAG,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC;AAc1C,MAAM,OAAO,mBAAoB,SAAQ,cAAc;IACnD,8BAA8B;IAC9B,wBAAwB;IACP,YAAY,GAAG,IAAI,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAC5C,OAAO,GAAG,IAAI,GAAG,EAA+B,CAAC;IAE1D,OAAO,CAA8C;IAE7C,OAAO,CAA6B;IAE5C,aAAa,GAAG,IAAI,eAAe,EAAQ,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A6B;gBACtC,IAAI,EAAE,IAAc;gBACpB,IAAI,EAAE,IAAc;gBACpB,OAAO;aACV,CAAC;SACL;QAED,IAAI,IAAI,CAAC,OAAO;YACZ,IAAI,CAAC,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,EAAE;YACvD,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;SACxC;QAED,IAAI,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE;YAChC,iBAAiB,CAAC,IAAI,CAAC,CAAC;SAC3B;aAAM;YACF,IAAsB,CAAC,QAAQ,GAAG,CAAC,CAAC;SACxC;QAED,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAqB,CAAC,CAAC;IACpD,CAAC;IAEe,OAAO;QACnB,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE;YACxC,MAAM,CAAC,OAAO,EAAE,CAAC;SACpB;QACD,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QAErB,IAAI;YACA,aAAa;YACb,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;SACjC;QAAC,MAAM,GAAG;QAEX,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;QAE3B,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC;QAE7B,KAAK,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/socket/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC"}
|
package/esm/socket/index.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './data-event-emitter';
|
|
4
|
-
export * from './dispatcher';
|
|
5
|
-
export * from './logger';
|
|
6
|
-
export * from './socket';
|
|
1
|
+
export * from './socket.js';
|
|
2
|
+
export * from './dispatcher.js';
|
|
7
3
|
//# sourceMappingURL=index.js.map
|
package/esm/socket/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/socket/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/socket/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type ReadableStream, type ReadableWritablePair, type WritableStream } from '../stream/index.js';
|
|
2
|
+
import type { AdbPacketDispatcher } from './dispatcher.js';
|
|
3
|
+
export interface AdbSocketInfo {
|
|
4
|
+
localId: number;
|
|
5
|
+
remoteId: number;
|
|
6
|
+
localCreated: boolean;
|
|
7
|
+
serviceString: string;
|
|
8
|
+
}
|
|
9
|
+
export interface AdbSocketConstructionOptions extends AdbSocketInfo {
|
|
10
|
+
dispatcher: AdbPacketDispatcher;
|
|
11
|
+
highWaterMark?: number | undefined;
|
|
12
|
+
}
|
|
13
|
+
export declare class AdbSocketController implements AdbSocketInfo, ReadableWritablePair<Uint8Array, Uint8Array> {
|
|
14
|
+
private readonly dispatcher;
|
|
15
|
+
readonly localId: number;
|
|
16
|
+
readonly remoteId: number;
|
|
17
|
+
readonly localCreated: boolean;
|
|
18
|
+
readonly serviceString: string;
|
|
19
|
+
private _factory;
|
|
20
|
+
private _readable;
|
|
21
|
+
private _readableController;
|
|
22
|
+
get readable(): ReadableStream<Uint8Array>;
|
|
23
|
+
private _writePromise;
|
|
24
|
+
readonly writable: WritableStream<Uint8Array>;
|
|
25
|
+
private _closed;
|
|
26
|
+
get closed(): boolean;
|
|
27
|
+
private _socket;
|
|
28
|
+
get socket(): AdbSocket;
|
|
29
|
+
constructor(options: AdbSocketConstructionOptions);
|
|
30
|
+
enqueue(packet: Uint8Array): Promise<void>;
|
|
31
|
+
ack(): void;
|
|
32
|
+
close(): Promise<void>;
|
|
33
|
+
dispose(): void;
|
|
34
|
+
}
|
|
35
|
+
export declare class AdbSocket implements AdbSocketInfo, ReadableWritablePair<Uint8Array, Uint8Array> {
|
|
36
|
+
private _controller;
|
|
37
|
+
get localId(): number;
|
|
38
|
+
get remoteId(): number;
|
|
39
|
+
get localCreated(): boolean;
|
|
40
|
+
get serviceString(): string;
|
|
41
|
+
get readable(): ReadableStream<Uint8Array>;
|
|
42
|
+
get writable(): WritableStream<Uint8Array>;
|
|
43
|
+
constructor(controller: AdbSocketController);
|
|
44
|
+
close(): Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=socket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socket.d.ts","sourceRoot":"","sources":["../../src/socket/socket.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiF,KAAK,cAAc,EAAE,KAAK,oBAAoB,EAAE,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACxL,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAE3D,MAAM,WAAW,aAAa;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IAEjB,YAAY,EAAE,OAAO,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,4BAA6B,SAAQ,aAAa;IAC/D,UAAU,EAAE,mBAAmB,CAAC;IAEhC,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACtC;AAED,qBAAa,mBAAoB,YAAW,aAAa,EAAE,oBAAoB,CAAC,UAAU,EAAE,UAAU,CAAC;IACnG,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAuB;IAElD,SAAgB,OAAO,EAAG,MAAM,CAAC;IACjC,SAAgB,QAAQ,EAAG,MAAM,CAAC;IAClC,SAAgB,YAAY,EAAG,OAAO,CAAC;IACvC,SAAgB,aAAa,EAAG,MAAM,CAAC;IAEvC,OAAO,CAAC,QAAQ,CAA8C;IAE9D,OAAO,CAAC,SAAS,CAA6B;IAC9C,OAAO,CAAC,mBAAmB,CAA4C;IACvE,IAAW,QAAQ,+BAA6B;IAEhD,OAAO,CAAC,aAAa,CAAoC;IACzD,SAAgB,QAAQ,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;IAErD,OAAO,CAAC,OAAO,CAAS;IACxB,IAAW,MAAM,YAA2B;IAE5C,OAAO,CAAC,OAAO,CAAY;IAC3B,IAAW,MAAM,cAA2B;gBAEzB,OAAO,EAAE,4BAA4B;IAwC3C,OAAO,CAAC,MAAM,EAAE,UAAU;IAIhC,GAAG;IAIG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAiB5B,OAAO;CAQjB;AAED,qBAAa,SAAU,YAAW,aAAa,EAAE,oBAAoB,CAAC,UAAU,EAAE,UAAU,CAAC;IACzF,OAAO,CAAC,WAAW,CAAsB;IAEzC,IAAW,OAAO,IAAI,MAAM,CAAqC;IACjE,IAAW,QAAQ,IAAI,MAAM,CAAsC;IACnE,IAAW,YAAY,IAAI,OAAO,CAA0C;IAC5E,IAAW,aAAa,IAAI,MAAM,CAA2C;IAE7E,IAAW,QAAQ,IAAI,cAAc,CAAC,UAAU,CAAC,CAAsC;IACvF,IAAW,QAAQ,IAAI,cAAc,CAAC,UAAU,CAAC,CAAsC;gBAEpE,UAAU,EAAE,mBAAmB;IAI3C,KAAK;CAGf"}
|
package/esm/socket/socket.js
CHANGED
|
@@ -1,20 +1,84 @@
|
|
|
1
|
+
import { PromiseResolver } from "@yume-chan/async";
|
|
2
|
+
import { AdbCommand } from '../packet.js';
|
|
3
|
+
import { ChunkStream, DuplexStreamFactory, pipeFrom } from '../stream/index.js';
|
|
4
|
+
export class AdbSocketController {
|
|
5
|
+
dispatcher;
|
|
6
|
+
localId;
|
|
7
|
+
remoteId;
|
|
8
|
+
localCreated;
|
|
9
|
+
serviceString;
|
|
10
|
+
_factory;
|
|
11
|
+
_readable;
|
|
12
|
+
_readableController;
|
|
13
|
+
get readable() { return this._readable; }
|
|
14
|
+
_writePromise;
|
|
15
|
+
writable;
|
|
16
|
+
_closed = false;
|
|
17
|
+
get closed() { return this._closed; }
|
|
18
|
+
_socket;
|
|
19
|
+
get socket() { return this._socket; }
|
|
20
|
+
constructor(options) {
|
|
21
|
+
Object.assign(this, options);
|
|
22
|
+
// Check this image to help you understand the stream graph
|
|
23
|
+
// cspell: disable-next-line
|
|
24
|
+
// https://www.plantuml.com/plantuml/png/TL0zoeGm4ErpYc3l5JxyS0yWM6mX5j4C6p4cxcJ25ejttuGX88ZftizxUKmJI275pGhXl0PP_UkfK_CAz5Z2hcWsW9Ny2fdU4C1f5aSchFVxA8vJjlTPRhqZzDQMRB7AklwJ0xXtX0ZSKH1h24ghoKAdGY23FhxC4nS2pDvxzIvxb-8THU0XlEQJ-ZB7SnXTAvc_LhOckhMdLBnbtndpb-SB7a8q2SRD_W00
|
|
25
|
+
this._factory = new DuplexStreamFactory({
|
|
26
|
+
close: async () => {
|
|
27
|
+
await this.close();
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
this._readable = this._factory.createPushReadable(controller => {
|
|
31
|
+
this._readableController = controller;
|
|
32
|
+
}, {
|
|
33
|
+
highWaterMark: options.highWaterMark ?? 16 * 1024,
|
|
34
|
+
size(chunk) { return chunk.byteLength; }
|
|
35
|
+
});
|
|
36
|
+
this.writable = pipeFrom(this._factory.createWritable({
|
|
37
|
+
write: async (chunk) => {
|
|
38
|
+
// Wait for an ack packet
|
|
39
|
+
this._writePromise = new PromiseResolver();
|
|
40
|
+
await this.dispatcher.sendPacket(AdbCommand.Write, this.localId, this.remoteId, chunk);
|
|
41
|
+
await this._writePromise.promise;
|
|
42
|
+
},
|
|
43
|
+
}), new ChunkStream(this.dispatcher.options.maxPayloadSize));
|
|
44
|
+
this._socket = new AdbSocket(this);
|
|
45
|
+
}
|
|
46
|
+
async enqueue(packet) {
|
|
47
|
+
await this._readableController.enqueue(packet);
|
|
48
|
+
}
|
|
49
|
+
ack() {
|
|
50
|
+
this._writePromise?.resolve();
|
|
51
|
+
}
|
|
52
|
+
async close() {
|
|
53
|
+
// Error out the pending writes
|
|
54
|
+
this._writePromise?.reject(new Error('Socket closed'));
|
|
55
|
+
if (!this._closed) {
|
|
56
|
+
this._closed = true;
|
|
57
|
+
// Only send close packet when `close` is called before `dispose`
|
|
58
|
+
// (the client initiated the close)
|
|
59
|
+
await this.dispatcher.sendPacket(AdbCommand.Close, this.localId, this.remoteId);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
dispose() {
|
|
63
|
+
this._closed = true;
|
|
64
|
+
this._factory.close();
|
|
65
|
+
// Close `writable` side
|
|
66
|
+
this.close();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
1
69
|
export class AdbSocket {
|
|
70
|
+
_controller;
|
|
71
|
+
get localId() { return this._controller.localId; }
|
|
72
|
+
get remoteId() { return this._controller.remoteId; }
|
|
73
|
+
get localCreated() { return this._controller.localCreated; }
|
|
74
|
+
get serviceString() { return this._controller.serviceString; }
|
|
75
|
+
get readable() { return this._controller.readable; }
|
|
76
|
+
get writable() { return this._controller.writable; }
|
|
2
77
|
constructor(controller) {
|
|
3
|
-
this.
|
|
4
|
-
}
|
|
5
|
-
get backend() { return this.controller.backend; }
|
|
6
|
-
get localId() { return this.controller.localId; }
|
|
7
|
-
get remoteId() { return this.controller.remoteId; }
|
|
8
|
-
get localCreated() { return this.controller.localCreated; }
|
|
9
|
-
get serviceString() { return this.controller.serviceString; }
|
|
10
|
-
get closed() { return this.controller.closed; }
|
|
11
|
-
get onData() { return this.controller.dataEvent.event; }
|
|
12
|
-
get onClose() { return this.controller.onClose; }
|
|
13
|
-
write(data) {
|
|
14
|
-
return this.controller.write(data);
|
|
78
|
+
this._controller = controller;
|
|
15
79
|
}
|
|
16
80
|
close() {
|
|
17
|
-
return this.
|
|
81
|
+
return this._controller.close();
|
|
18
82
|
}
|
|
19
83
|
}
|
|
20
84
|
//# sourceMappingURL=socket.js.map
|
package/esm/socket/socket.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"socket.js","sourceRoot":"","sources":["../../src/socket/socket.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"socket.js","sourceRoot":"","sources":["../../src/socket/socket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,QAAQ,EAA0G,MAAM,oBAAoB,CAAC;AAiBxL,MAAM,OAAO,mBAAmB;IACX,UAAU,CAAuB;IAElC,OAAO,CAAU;IACjB,QAAQ,CAAU;IAClB,YAAY,CAAW;IACvB,aAAa,CAAU;IAE/B,QAAQ,CAA8C;IAEtD,SAAS,CAA6B;IACtC,mBAAmB,CAA4C;IACvE,IAAW,QAAQ,KAAK,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAExC,aAAa,CAAoC;IACzC,QAAQ,CAA6B;IAE7C,OAAO,GAAG,KAAK,CAAC;IACxB,IAAW,MAAM,KAAK,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAEpC,OAAO,CAAY;IAC3B,IAAW,MAAM,KAAK,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAE5C,YAAmB,OAAqC;QACpD,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAE7B,2DAA2D;QAC3D,4BAA4B;QAC5B,6QAA6Q;QAE7Q,IAAI,CAAC,QAAQ,GAAG,IAAI,mBAAmB,CAAyB;YAC5D,KAAK,EAAE,KAAK,IAAI,EAAE;gBACd,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;YACvB,CAAC;SACJ,CAAC,CAAC;QA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YACf,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;YAEpB,iEAAiE;YACjE,mCAAmC;YACnC,MAAM,IAAI,CAAC,UAAU,CAAC,UAAU,CAC5B,UAAU,CAAC,KAAK,EAChB,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,QAAQ,CAChB,CAAC;SACL;IACL,CAAC;IAEM,OAAO;QACV,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QAEpB,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QAEtB,wBAAwB;QACxB,IAAI,CAAC,KAAK,EAAE,CAAC;IACjB,CAAC;CACJ;AAED,MAAM,OAAO,SAAS;IACV,WAAW,CAAsB;IAEzC,IAAW,OAAO,KAAa,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;IACjE,IAAW,QAAQ,KAAa,OAAO,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC;IACnE,IAAW,YAAY,KAAc,OAAO,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC;IAC5E,IAAW,aAAa,KAAa,OAAO,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC;IAE7E,IAAW,QAAQ,KAAiC,OAAO,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC;IACvF,IAAW,QAAQ,KAAiC,OAAO,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEvF,YAAmB,UAA+B;QAC9C,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAClC,CAAC;IAEM,KAAK;QACR,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;IACpC,CAAC;CACJ"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { StructAsyncDeserializeStream } from '@yume-chan/struct';
|
|
2
|
+
import type { AdbSocket, AdbSocketInfo } from '../socket/index.js';
|
|
3
|
+
import type { ReadableStream, ReadableStreamDefaultReader } from './detect.js';
|
|
4
|
+
export declare class BufferedStreamEndedError extends Error {
|
|
5
|
+
constructor();
|
|
6
|
+
}
|
|
7
|
+
export declare class BufferedStream {
|
|
8
|
+
private buffer;
|
|
9
|
+
protected readonly stream: ReadableStream<Uint8Array>;
|
|
10
|
+
protected readonly reader: ReadableStreamDefaultReader<Uint8Array>;
|
|
11
|
+
constructor(stream: ReadableStream<Uint8Array>);
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param length
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
read(length: number): Promise<Uint8Array>;
|
|
18
|
+
/**
|
|
19
|
+
* Return a readable stream with unconsumed data (if any) and
|
|
20
|
+
* all data from the wrapped stream.
|
|
21
|
+
* @returns A `ReadableStream`
|
|
22
|
+
*/
|
|
23
|
+
release(): ReadableStream<Uint8Array>;
|
|
24
|
+
close(): void;
|
|
25
|
+
}
|
|
26
|
+
export declare class AdbBufferedStream extends BufferedStream implements AdbSocketInfo, StructAsyncDeserializeStream {
|
|
27
|
+
protected readonly socket: AdbSocket;
|
|
28
|
+
get localId(): number;
|
|
29
|
+
get remoteId(): number;
|
|
30
|
+
get localCreated(): boolean;
|
|
31
|
+
get serviceString(): string;
|
|
32
|
+
get writable(): import("web-streams-polyfill").WritableStream<Uint8Array>;
|
|
33
|
+
constructor(socket: AdbSocket);
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=buffered.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffered.d.ts","sourceRoot":"","sources":["../../src/stream/buffered.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAG/E,qBAAa,wBAAyB,SAAQ,KAAK;;CAOlD;AAED,qBAAa,cAAc;IACvB,OAAO,CAAC,MAAM,CAAyB;IAEvC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;IAEtD,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,2BAA2B,CAAC,UAAU,CAAC,CAAC;gBAEhD,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC;IAKrD;;;;OAIG;IACU,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IA4DtD;;;;OAIG;IACI,OAAO,IAAI,cAAc,CAAC,UAAU,CAAC;IA6BrC,KAAK;CAGf;AAED,qBAAa,iBACT,SAAQ,cACR,YAAW,aAAa,EAAE,4BAA4B;IACtD,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;IAErC,IAAW,OAAO,WAAkC;IACpD,IAAW,QAAQ,WAAmC;IACtD,IAAW,YAAY,YAAuC;IAC9D,IAAW,aAAa,WAAwC;IAEhE,IAAW,QAAQ,8DAAmC;gBAEnC,MAAM,EAAE,SAAS;CAIvC"}
|