@yume-chan/adb 0.0.18 → 0.0.20
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 +54 -0
- package/CHANGELOG.md +25 -1
- package/README.md +220 -103
- package/esm/adb.d.ts +43 -60
- package/esm/adb.d.ts.map +1 -1
- package/esm/adb.js +68 -249
- package/esm/adb.js.map +1 -1
- package/esm/banner.d.ts +17 -0
- package/esm/banner.d.ts.map +1 -0
- package/esm/banner.js +67 -0
- package/esm/banner.js.map +1 -0
- package/esm/commands/base.d.ts +6 -6
- package/esm/commands/base.d.ts.map +1 -1
- package/esm/commands/base.js +8 -8
- package/esm/commands/framebuffer.d.ts +53 -53
- package/esm/commands/framebuffer.d.ts.map +1 -1
- package/esm/commands/framebuffer.js +46 -46
- package/esm/commands/framebuffer.js.map +1 -1
- package/esm/commands/index.d.ts +7 -8
- package/esm/commands/index.d.ts.map +1 -1
- package/esm/commands/index.js +7 -8
- package/esm/commands/index.js.map +1 -1
- package/esm/commands/power.d.ts +22 -22
- package/esm/commands/power.js +48 -48
- package/esm/commands/reverse.d.ts +40 -28
- package/esm/commands/reverse.d.ts.map +1 -1
- package/esm/commands/reverse.js +130 -100
- package/esm/commands/reverse.js.map +1 -1
- package/esm/commands/subprocess/command.d.ts +57 -51
- package/esm/commands/subprocess/command.d.ts.map +1 -1
- package/esm/commands/subprocess/command.js +86 -80
- package/esm/commands/subprocess/command.js.map +1 -1
- package/esm/commands/subprocess/index.d.ts +3 -3
- package/esm/commands/subprocess/index.js +3 -3
- package/esm/commands/subprocess/protocols/index.d.ts +3 -3
- package/esm/commands/subprocess/protocols/index.js +3 -3
- package/esm/commands/subprocess/protocols/none.d.ts +30 -35
- package/esm/commands/subprocess/protocols/none.d.ts.map +1 -1
- package/esm/commands/subprocess/protocols/none.js +65 -55
- package/esm/commands/subprocess/protocols/none.js.map +1 -1
- package/esm/commands/subprocess/protocols/shell.d.ts +33 -38
- package/esm/commands/subprocess/protocols/shell.d.ts.map +1 -1
- package/esm/commands/subprocess/protocols/shell.js +172 -162
- package/esm/commands/subprocess/protocols/shell.js.map +1 -1
- package/esm/commands/subprocess/protocols/types.d.ts +48 -49
- package/esm/commands/subprocess/protocols/types.d.ts.map +1 -1
- package/esm/commands/subprocess/protocols/types.js +1 -1
- package/esm/commands/subprocess/utils.d.ts +1 -1
- package/esm/commands/subprocess/utils.js +18 -18
- package/esm/commands/sync/index.d.ts +8 -7
- package/esm/commands/sync/index.d.ts.map +1 -1
- package/esm/commands/sync/index.js +8 -7
- package/esm/commands/sync/index.js.map +1 -1
- package/esm/commands/sync/list.d.ts +42 -40
- package/esm/commands/sync/list.d.ts.map +1 -1
- package/esm/commands/sync/list.js +67 -47
- package/esm/commands/sync/list.js.map +1 -1
- package/esm/commands/sync/pull.d.ts +13 -11
- package/esm/commands/sync/pull.d.ts.map +1 -1
- package/esm/commands/sync/pull.js +35 -37
- package/esm/commands/sync/pull.js.map +1 -1
- package/esm/commands/sync/push.d.ts +57 -7
- package/esm/commands/sync/push.d.ts.map +1 -1
- package/esm/commands/sync/push.js +89 -22
- package/esm/commands/sync/push.js.map +1 -1
- package/esm/commands/sync/request.d.ts +26 -23
- package/esm/commands/sync/request.d.ts.map +1 -1
- package/esm/commands/sync/request.js +40 -42
- package/esm/commands/sync/request.js.map +1 -1
- package/esm/commands/sync/response.d.ts +19 -19
- package/esm/commands/sync/response.d.ts.map +1 -1
- package/esm/commands/sync/response.js +54 -54
- package/esm/commands/sync/response.js.map +1 -1
- package/esm/commands/sync/socket.d.ts +22 -0
- package/esm/commands/sync/socket.d.ts.map +1 -0
- package/esm/commands/sync/socket.js +69 -0
- package/esm/commands/sync/socket.js.map +1 -0
- package/esm/commands/sync/stat.d.ts +72 -72
- package/esm/commands/sync/stat.d.ts.map +1 -1
- package/esm/commands/sync/stat.js +116 -104
- package/esm/commands/sync/stat.js.map +1 -1
- package/esm/commands/sync/sync.d.ts +65 -60
- package/esm/commands/sync/sync.d.ts.map +1 -1
- package/esm/commands/sync/sync.js +123 -149
- package/esm/commands/sync/sync.js.map +1 -1
- package/esm/commands/tcpip.d.ts +5 -5
- package/esm/commands/tcpip.d.ts.map +1 -1
- package/esm/commands/tcpip.js +20 -18
- package/esm/commands/tcpip.js.map +1 -1
- package/esm/{auth.d.ts → daemon/auth.d.ts} +50 -51
- package/esm/daemon/auth.d.ts.map +1 -0
- package/esm/{auth.js → daemon/auth.js} +95 -96
- package/esm/daemon/auth.js.map +1 -0
- package/esm/daemon/connection.d.ts +11 -0
- package/esm/daemon/connection.d.ts.map +1 -0
- package/esm/daemon/connection.js +2 -0
- package/esm/daemon/connection.js.map +1 -0
- package/esm/{crypto.d.ts → daemon/crypto.d.ts} +36 -36
- package/esm/daemon/crypto.d.ts.map +1 -0
- package/esm/{crypto.js → daemon/crypto.js} +244 -248
- package/esm/daemon/crypto.js.map +1 -0
- package/esm/daemon/device.d.ts +9 -0
- package/esm/daemon/device.d.ts.map +1 -0
- package/esm/daemon/device.js +2 -0
- package/esm/daemon/device.js.map +1 -0
- package/esm/daemon/dispatcher.d.ts +42 -0
- package/esm/daemon/dispatcher.d.ts.map +1 -0
- package/esm/{socket → daemon}/dispatcher.js +225 -234
- package/esm/daemon/dispatcher.js.map +1 -0
- package/esm/daemon/index.d.ts +8 -0
- package/esm/daemon/index.d.ts.map +1 -0
- package/esm/daemon/index.js +8 -0
- package/esm/daemon/index.js.map +1 -0
- package/esm/{packet.d.ts → daemon/packet.d.ts} +45 -46
- package/esm/daemon/packet.d.ts.map +1 -0
- package/esm/{packet.js → daemon/packet.js} +43 -48
- package/esm/daemon/packet.js.map +1 -0
- package/esm/daemon/socket.d.ts +58 -0
- package/esm/daemon/socket.d.ts.map +1 -0
- package/esm/{socket → daemon}/socket.js +121 -118
- package/esm/daemon/socket.js.map +1 -0
- package/esm/daemon/transport.d.ts +45 -0
- package/esm/daemon/transport.d.ts.map +1 -0
- package/esm/daemon/transport.js +184 -0
- package/esm/daemon/transport.js.map +1 -0
- package/esm/features.d.ts +10 -7
- package/esm/features.d.ts.map +1 -1
- package/esm/features.js +13 -10
- package/esm/features.js.map +1 -1
- package/esm/index.d.ts +7 -9
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +7 -9
- package/esm/index.js.map +1 -1
- package/esm/server/client.d.ts +78 -0
- package/esm/server/client.d.ts.map +1 -0
- package/esm/server/client.js +329 -0
- package/esm/server/client.js.map +1 -0
- package/esm/server/index.d.ts +3 -0
- package/esm/server/index.d.ts.map +1 -0
- package/esm/server/index.js +3 -0
- package/esm/server/index.js.map +1 -0
- package/esm/server/transport.d.ts +19 -0
- package/esm/server/transport.d.ts.map +1 -0
- package/esm/server/transport.js +44 -0
- package/esm/server/transport.js.map +1 -0
- package/esm/utils/auto-reset-event.d.ts +8 -9
- package/esm/utils/auto-reset-event.d.ts.map +1 -1
- package/esm/utils/auto-reset-event.js +33 -33
- package/esm/utils/auto-reset-event.js.map +1 -1
- package/esm/utils/base64.d.ts +27 -27
- package/esm/utils/base64.js +246 -246
- package/esm/utils/base64.js.map +1 -1
- package/esm/utils/conditional-variable.d.ts +8 -0
- package/esm/utils/conditional-variable.d.ts.map +1 -0
- package/esm/utils/conditional-variable.js +34 -0
- package/esm/utils/conditional-variable.js.map +1 -0
- package/esm/utils/hex.d.ts +3 -0
- package/esm/utils/hex.d.ts.map +1 -0
- package/esm/utils/hex.js +55 -0
- package/esm/utils/hex.js.map +1 -0
- package/esm/utils/index.d.ts +6 -3
- package/esm/utils/index.d.ts.map +1 -1
- package/esm/utils/index.js +6 -3
- package/esm/utils/index.js.map +1 -1
- package/esm/utils/no-op.d.ts +7 -0
- package/esm/utils/no-op.d.ts.map +1 -0
- package/esm/utils/no-op.js +12 -0
- package/esm/utils/no-op.js.map +1 -0
- package/package.json +14 -12
- package/src/adb.ts +47 -248
- package/src/banner.ts +82 -0
- package/src/commands/base.ts +1 -1
- package/src/commands/framebuffer.ts +4 -4
- package/src/commands/index.ts +7 -8
- package/src/commands/power.ts +2 -2
- package/src/commands/reverse.ts +90 -70
- package/src/commands/subprocess/command.ts +12 -4
- package/src/commands/subprocess/index.ts +3 -3
- package/src/commands/subprocess/protocols/index.ts +3 -3
- package/src/commands/subprocess/protocols/none.ts +36 -23
- package/src/commands/subprocess/protocols/shell.ts +94 -74
- package/src/commands/subprocess/protocols/types.ts +7 -7
- package/src/commands/subprocess/utils.ts +1 -1
- package/src/commands/sync/index.ts +8 -7
- package/src/commands/sync/list.ts +44 -25
- package/src/commands/sync/pull.ts +40 -45
- package/src/commands/sync/push.ts +158 -39
- package/src/commands/sync/request.ts +21 -16
- package/src/commands/sync/response.ts +10 -9
- package/src/commands/sync/socket.ts +99 -0
- package/src/commands/sync/stat.ts +47 -42
- package/src/commands/sync/sync.ts +73 -116
- package/src/commands/tcpip.ts +9 -7
- package/src/{auth.ts → daemon/auth.ts} +24 -23
- package/src/{crypto.ts → daemon/crypto.ts} +25 -33
- package/src/daemon/device.ts +14 -0
- package/src/{socket → daemon}/dispatcher.ts +95 -117
- package/src/daemon/index.ts +7 -0
- package/src/daemon/packet.ts +75 -0
- package/src/{socket → daemon}/socket.ts +71 -56
- package/src/daemon/transport.ts +269 -0
- package/src/features.ts +9 -6
- package/src/index.ts +3 -5
- package/src/server/client.ts +476 -0
- package/src/server/index.ts +2 -0
- package/src/server/transport.ts +77 -0
- package/src/utils/auto-reset-event.ts +14 -15
- package/src/utils/conditional-variable.ts +45 -0
- package/src/utils/hex.ts +58 -0
- package/src/utils/index.ts +6 -3
- package/src/utils/no-op.ts +12 -0
- package/tsconfig.build.json +12 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/esm/auth.d.ts.map +0 -1
- package/esm/auth.js.map +0 -1
- package/esm/backend.d.ts +0 -9
- package/esm/backend.d.ts.map +0 -1
- package/esm/backend.js +0 -2
- package/esm/backend.js.map +0 -1
- package/esm/commands/install.d.ts +0 -4
- package/esm/commands/install.d.ts.map +0 -1
- package/esm/commands/install.js +0 -29
- package/esm/commands/install.js.map +0 -1
- package/esm/crypto.d.ts.map +0 -1
- package/esm/crypto.js.map +0 -1
- package/esm/packet.d.ts.map +0 -1
- package/esm/packet.js.map +0 -1
- package/esm/socket/dispatcher.d.ts +0 -60
- package/esm/socket/dispatcher.d.ts.map +0 -1
- package/esm/socket/dispatcher.js.map +0 -1
- package/esm/socket/index.d.ts +0 -3
- package/esm/socket/index.d.ts.map +0 -1
- package/esm/socket/index.js +0 -3
- package/esm/socket/index.js.map +0 -1
- package/esm/socket/socket.d.ts +0 -60
- package/esm/socket/socket.d.ts.map +0 -1
- package/esm/socket/socket.js.map +0 -1
- package/src/backend.ts +0 -14
- package/src/commands/install.ts +0 -40
- package/src/packet.ts +0 -90
- package/src/socket/index.ts +0 -2
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import { BufferedReadableStream } from "@yume-chan/stream-extra";
|
|
2
|
-
import Struct from "@yume-chan/struct";
|
|
3
|
-
const Version = new Struct({ littleEndian: true }).uint32("version");
|
|
4
|
-
export const AdbFrameBufferV1 = new Struct({ littleEndian: true })
|
|
5
|
-
.uint32("bpp")
|
|
6
|
-
.uint32("size")
|
|
7
|
-
.uint32("width")
|
|
8
|
-
.uint32("height")
|
|
9
|
-
.uint32("red_offset")
|
|
10
|
-
.uint32("red_length")
|
|
11
|
-
.uint32("blue_offset")
|
|
12
|
-
.uint32("blue_length")
|
|
13
|
-
.uint32("green_offset")
|
|
14
|
-
.uint32("green_length")
|
|
15
|
-
.uint32("alpha_offset")
|
|
16
|
-
.uint32("alpha_length")
|
|
17
|
-
.uint8Array("data", { lengthField: "size" });
|
|
18
|
-
export const AdbFrameBufferV2 = new Struct({ littleEndian: true })
|
|
19
|
-
.uint32("bpp")
|
|
20
|
-
.uint32("colorSpace")
|
|
21
|
-
.uint32("size")
|
|
22
|
-
.uint32("width")
|
|
23
|
-
.uint32("height")
|
|
24
|
-
.uint32("red_offset")
|
|
25
|
-
.uint32("red_length")
|
|
26
|
-
.uint32("blue_offset")
|
|
27
|
-
.uint32("blue_length")
|
|
28
|
-
.uint32("green_offset")
|
|
29
|
-
.uint32("green_length")
|
|
30
|
-
.uint32("alpha_offset")
|
|
31
|
-
.uint32("alpha_length")
|
|
32
|
-
.uint8Array("data", { lengthField: "size" });
|
|
33
|
-
export async function framebuffer(adb) {
|
|
34
|
-
const socket = await adb.createSocket("framebuffer:");
|
|
35
|
-
const stream = new BufferedReadableStream(socket.readable);
|
|
36
|
-
const { version } = await Version.deserialize(stream);
|
|
37
|
-
switch (version) {
|
|
38
|
-
case 1:
|
|
39
|
-
// TODO: AdbFrameBuffer: does all v1 responses uses the same color space? Add it so the command returns same format for all versions.
|
|
40
|
-
return AdbFrameBufferV1.deserialize(stream);
|
|
41
|
-
case 2:
|
|
42
|
-
return AdbFrameBufferV2.deserialize(stream);
|
|
43
|
-
default:
|
|
44
|
-
throw new Error("
|
|
45
|
-
}
|
|
46
|
-
}
|
|
1
|
+
import { BufferedReadableStream } from "@yume-chan/stream-extra";
|
|
2
|
+
import Struct from "@yume-chan/struct";
|
|
3
|
+
const Version = new Struct({ littleEndian: true }).uint32("version");
|
|
4
|
+
export const AdbFrameBufferV1 = new Struct({ littleEndian: true })
|
|
5
|
+
.uint32("bpp")
|
|
6
|
+
.uint32("size")
|
|
7
|
+
.uint32("width")
|
|
8
|
+
.uint32("height")
|
|
9
|
+
.uint32("red_offset")
|
|
10
|
+
.uint32("red_length")
|
|
11
|
+
.uint32("blue_offset")
|
|
12
|
+
.uint32("blue_length")
|
|
13
|
+
.uint32("green_offset")
|
|
14
|
+
.uint32("green_length")
|
|
15
|
+
.uint32("alpha_offset")
|
|
16
|
+
.uint32("alpha_length")
|
|
17
|
+
.uint8Array("data", { lengthField: "size" });
|
|
18
|
+
export const AdbFrameBufferV2 = new Struct({ littleEndian: true })
|
|
19
|
+
.uint32("bpp")
|
|
20
|
+
.uint32("colorSpace")
|
|
21
|
+
.uint32("size")
|
|
22
|
+
.uint32("width")
|
|
23
|
+
.uint32("height")
|
|
24
|
+
.uint32("red_offset")
|
|
25
|
+
.uint32("red_length")
|
|
26
|
+
.uint32("blue_offset")
|
|
27
|
+
.uint32("blue_length")
|
|
28
|
+
.uint32("green_offset")
|
|
29
|
+
.uint32("green_length")
|
|
30
|
+
.uint32("alpha_offset")
|
|
31
|
+
.uint32("alpha_length")
|
|
32
|
+
.uint8Array("data", { lengthField: "size" });
|
|
33
|
+
export async function framebuffer(adb) {
|
|
34
|
+
const socket = await adb.createSocket("framebuffer:");
|
|
35
|
+
const stream = new BufferedReadableStream(socket.readable);
|
|
36
|
+
const { version } = await Version.deserialize(stream);
|
|
37
|
+
switch (version) {
|
|
38
|
+
case 1:
|
|
39
|
+
// TODO: AdbFrameBuffer: does all v1 responses uses the same color space? Add it so the command returns same format for all versions.
|
|
40
|
+
return AdbFrameBufferV1.deserialize(stream);
|
|
41
|
+
case 2:
|
|
42
|
+
return AdbFrameBufferV2.deserialize(stream);
|
|
43
|
+
default:
|
|
44
|
+
throw new Error("Unsupported FrameBuffer version");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
47
|
//# sourceMappingURL=framebuffer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"framebuffer.js","sourceRoot":"","sources":["../../src/commands/framebuffer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAIvC,MAAM,OAAO,GAAG,IAAI,MAAM,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AAErE,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,MAAM,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;KAC7D,MAAM,CAAC,KAAK,CAAC;KACb,MAAM,CAAC,MAAM,CAAC;KACd,MAAM,CAAC,OAAO,CAAC;KACf,MAAM,CAAC,QAAQ,CAAC;KAChB,MAAM,CAAC,YAAY,CAAC;KACpB,MAAM,CAAC,YAAY,CAAC;KACpB,MAAM,CAAC,aAAa,CAAC;KACrB,MAAM,CAAC,aAAa,CAAC;KACrB,MAAM,CAAC,cAAc,CAAC;KACtB,MAAM,CAAC,cAAc,CAAC;KACtB,MAAM,CAAC,cAAc,CAAC;KACtB,MAAM,CAAC,cAAc,CAAC;KACtB,UAAU,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;AAIjD,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,MAAM,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;KAC7D,MAAM,CAAC,KAAK,CAAC;KACb,MAAM,CAAC,YAAY,CAAC;KACpB,MAAM,CAAC,MAAM,CAAC;KACd,MAAM,CAAC,OAAO,CAAC;KACf,MAAM,CAAC,QAAQ,CAAC;KAChB,MAAM,CAAC,YAAY,CAAC;KACpB,MAAM,CAAC,YAAY,CAAC;KACpB,MAAM,CAAC,aAAa,CAAC;KACrB,MAAM,CAAC,aAAa,CAAC;KACrB,MAAM,CAAC,cAAc,CAAC;KACtB,MAAM,CAAC,cAAc,CAAC;KACtB,MAAM,CAAC,cAAc,CAAC;KACtB,MAAM,CAAC,cAAc,CAAC;KACtB,UAAU,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;AAsBjD,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,GAAQ;IACtC,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC;IACtD,MAAM,MAAM,GAAG,IAAI,sBAAsB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC3D,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IACtD,QAAQ,OAAO,EAAE;QACb,KAAK,CAAC;YACF,qIAAqI;YACrI,OAAO,gBAAgB,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAChD,KAAK,CAAC;YACF,OAAO,gBAAgB,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAChD;YACI,MAAM,IAAI,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"framebuffer.js","sourceRoot":"","sources":["../../src/commands/framebuffer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAIvC,MAAM,OAAO,GAAG,IAAI,MAAM,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AAErE,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,MAAM,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;KAC7D,MAAM,CAAC,KAAK,CAAC;KACb,MAAM,CAAC,MAAM,CAAC;KACd,MAAM,CAAC,OAAO,CAAC;KACf,MAAM,CAAC,QAAQ,CAAC;KAChB,MAAM,CAAC,YAAY,CAAC;KACpB,MAAM,CAAC,YAAY,CAAC;KACpB,MAAM,CAAC,aAAa,CAAC;KACrB,MAAM,CAAC,aAAa,CAAC;KACrB,MAAM,CAAC,cAAc,CAAC;KACtB,MAAM,CAAC,cAAc,CAAC;KACtB,MAAM,CAAC,cAAc,CAAC;KACtB,MAAM,CAAC,cAAc,CAAC;KACtB,UAAU,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;AAIjD,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,MAAM,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;KAC7D,MAAM,CAAC,KAAK,CAAC;KACb,MAAM,CAAC,YAAY,CAAC;KACpB,MAAM,CAAC,MAAM,CAAC;KACd,MAAM,CAAC,OAAO,CAAC;KACf,MAAM,CAAC,QAAQ,CAAC;KAChB,MAAM,CAAC,YAAY,CAAC;KACpB,MAAM,CAAC,YAAY,CAAC;KACpB,MAAM,CAAC,aAAa,CAAC;KACrB,MAAM,CAAC,aAAa,CAAC;KACrB,MAAM,CAAC,cAAc,CAAC;KACtB,MAAM,CAAC,cAAc,CAAC;KACtB,MAAM,CAAC,cAAc,CAAC;KACtB,MAAM,CAAC,cAAc,CAAC;KACtB,UAAU,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;AAsBjD,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,GAAQ;IACtC,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC;IACtD,MAAM,MAAM,GAAG,IAAI,sBAAsB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC3D,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IACtD,QAAQ,OAAO,EAAE;QACb,KAAK,CAAC;YACF,qIAAqI;YACrI,OAAO,gBAAgB,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAChD,KAAK,CAAC;YACF,OAAO,gBAAgB,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAChD;YACI,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;KAC1D;AACL,CAAC"}
|
package/esm/commands/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from './tcpip.js';
|
|
1
|
+
export * from "./base.js";
|
|
2
|
+
export * from "./framebuffer.js";
|
|
3
|
+
export * from "./power.js";
|
|
4
|
+
export * from "./reverse.js";
|
|
5
|
+
export * from "./subprocess/index.js";
|
|
6
|
+
export * from "./sync/index.js";
|
|
7
|
+
export * from "./tcpip.js";
|
|
9
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC"}
|
package/esm/commands/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from './tcpip.js';
|
|
1
|
+
export * from "./base.js";
|
|
2
|
+
export * from "./framebuffer.js";
|
|
3
|
+
export * from "./power.js";
|
|
4
|
+
export * from "./reverse.js";
|
|
5
|
+
export * from "./subprocess/index.js";
|
|
6
|
+
export * from "./sync/index.js";
|
|
7
|
+
export * from "./tcpip.js";
|
|
9
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC"}
|
package/esm/commands/power.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { AdbCommandBase } from "./base.js";
|
|
2
|
-
export declare class AdbPower extends AdbCommandBase {
|
|
3
|
-
reboot(
|
|
4
|
-
bootloader(): Promise<string>;
|
|
5
|
-
fastboot(): Promise<string>;
|
|
6
|
-
recovery(): Promise<string>;
|
|
7
|
-
sideload(): Promise<string>;
|
|
8
|
-
/**
|
|
9
|
-
* Reboot to Qualcomm Emergency Download (EDL) Mode.
|
|
10
|
-
*
|
|
11
|
-
* Only works on some Qualcomm devices.
|
|
12
|
-
*/
|
|
13
|
-
qualcommEdlMode(): Promise<string>;
|
|
14
|
-
powerOff(): Promise<string>;
|
|
15
|
-
powerButton(longPress?: boolean): Promise<string>;
|
|
16
|
-
/**
|
|
17
|
-
* Reboot to Samsung Odin download mode.
|
|
18
|
-
*
|
|
19
|
-
* Only works on Samsung devices.
|
|
20
|
-
*/
|
|
21
|
-
samsungOdin(): Promise<string>;
|
|
22
|
-
}
|
|
1
|
+
import { AdbCommandBase } from "./base.js";
|
|
2
|
+
export declare class AdbPower extends AdbCommandBase {
|
|
3
|
+
reboot(mode?: string): Promise<string>;
|
|
4
|
+
bootloader(): Promise<string>;
|
|
5
|
+
fastboot(): Promise<string>;
|
|
6
|
+
recovery(): Promise<string>;
|
|
7
|
+
sideload(): Promise<string>;
|
|
8
|
+
/**
|
|
9
|
+
* Reboot to Qualcomm Emergency Download (EDL) Mode.
|
|
10
|
+
*
|
|
11
|
+
* Only works on some Qualcomm devices.
|
|
12
|
+
*/
|
|
13
|
+
qualcommEdlMode(): Promise<string>;
|
|
14
|
+
powerOff(): Promise<string>;
|
|
15
|
+
powerButton(longPress?: boolean): Promise<string>;
|
|
16
|
+
/**
|
|
17
|
+
* Reboot to Samsung Odin download mode.
|
|
18
|
+
*
|
|
19
|
+
* Only works on Samsung devices.
|
|
20
|
+
*/
|
|
21
|
+
samsungOdin(): Promise<string>;
|
|
22
|
+
}
|
|
23
23
|
//# sourceMappingURL=power.d.ts.map
|
package/esm/commands/power.js
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
// cspell: ignore bootloader
|
|
2
|
-
// cspell: ignore fastboot
|
|
3
|
-
// cspell: ignore keyevent
|
|
4
|
-
// cspell: ignore longpress
|
|
5
|
-
import { AdbCommandBase } from "./base.js";
|
|
6
|
-
export class AdbPower extends AdbCommandBase {
|
|
7
|
-
reboot(
|
|
8
|
-
return this.adb.createSocketAndWait(`reboot:${
|
|
9
|
-
}
|
|
10
|
-
bootloader() {
|
|
11
|
-
return this.reboot("bootloader");
|
|
12
|
-
}
|
|
13
|
-
fastboot() {
|
|
14
|
-
return this.reboot("fastboot");
|
|
15
|
-
}
|
|
16
|
-
recovery() {
|
|
17
|
-
return this.reboot("recovery");
|
|
18
|
-
}
|
|
19
|
-
sideload() {
|
|
20
|
-
return this.reboot("sideload");
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Reboot to Qualcomm Emergency Download (EDL) Mode.
|
|
24
|
-
*
|
|
25
|
-
* Only works on some Qualcomm devices.
|
|
26
|
-
*/
|
|
27
|
-
qualcommEdlMode() {
|
|
28
|
-
return this.reboot("edl");
|
|
29
|
-
}
|
|
30
|
-
powerOff() {
|
|
31
|
-
return this.adb.subprocess.spawnAndWaitLegacy(["reboot", "-p"]);
|
|
32
|
-
}
|
|
33
|
-
powerButton(longPress = false) {
|
|
34
|
-
return this.adb.subprocess.spawnAndWaitLegacy([
|
|
35
|
-
"input",
|
|
36
|
-
"keyevent",
|
|
37
|
-
longPress ? "--longpress POWER" : "POWER",
|
|
38
|
-
]);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Reboot to Samsung Odin download mode.
|
|
42
|
-
*
|
|
43
|
-
* Only works on Samsung devices.
|
|
44
|
-
*/
|
|
45
|
-
samsungOdin() {
|
|
46
|
-
return this.reboot("download");
|
|
47
|
-
}
|
|
48
|
-
}
|
|
1
|
+
// cspell: ignore bootloader
|
|
2
|
+
// cspell: ignore fastboot
|
|
3
|
+
// cspell: ignore keyevent
|
|
4
|
+
// cspell: ignore longpress
|
|
5
|
+
import { AdbCommandBase } from "./base.js";
|
|
6
|
+
export class AdbPower extends AdbCommandBase {
|
|
7
|
+
reboot(mode = "") {
|
|
8
|
+
return this.adb.createSocketAndWait(`reboot:${mode}`);
|
|
9
|
+
}
|
|
10
|
+
bootloader() {
|
|
11
|
+
return this.reboot("bootloader");
|
|
12
|
+
}
|
|
13
|
+
fastboot() {
|
|
14
|
+
return this.reboot("fastboot");
|
|
15
|
+
}
|
|
16
|
+
recovery() {
|
|
17
|
+
return this.reboot("recovery");
|
|
18
|
+
}
|
|
19
|
+
sideload() {
|
|
20
|
+
return this.reboot("sideload");
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Reboot to Qualcomm Emergency Download (EDL) Mode.
|
|
24
|
+
*
|
|
25
|
+
* Only works on some Qualcomm devices.
|
|
26
|
+
*/
|
|
27
|
+
qualcommEdlMode() {
|
|
28
|
+
return this.reboot("edl");
|
|
29
|
+
}
|
|
30
|
+
powerOff() {
|
|
31
|
+
return this.adb.subprocess.spawnAndWaitLegacy(["reboot", "-p"]);
|
|
32
|
+
}
|
|
33
|
+
powerButton(longPress = false) {
|
|
34
|
+
return this.adb.subprocess.spawnAndWaitLegacy([
|
|
35
|
+
"input",
|
|
36
|
+
"keyevent",
|
|
37
|
+
longPress ? "--longpress POWER" : "POWER",
|
|
38
|
+
]);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Reboot to Samsung Odin download mode.
|
|
42
|
+
*
|
|
43
|
+
* Only works on Samsung devices.
|
|
44
|
+
*/
|
|
45
|
+
samsungOdin() {
|
|
46
|
+
return this.reboot("download");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
49
|
//# sourceMappingURL=power.js.map
|
|
@@ -1,29 +1,41 @@
|
|
|
1
|
-
import { AutoDisposable } from "@yume-chan/event";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export interface AdbForwardListener {
|
|
5
|
-
deviceSerial: string;
|
|
6
|
-
localName: string;
|
|
7
|
-
remoteName: string;
|
|
8
|
-
}
|
|
9
|
-
export declare class
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
private
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
*
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
import { AutoDisposable } from "@yume-chan/event";
|
|
2
|
+
import { BufferedReadableStream } from "@yume-chan/stream-extra";
|
|
3
|
+
import type { Adb, AdbIncomingSocketHandler } from "../adb.js";
|
|
4
|
+
export interface AdbForwardListener {
|
|
5
|
+
deviceSerial: string;
|
|
6
|
+
localName: string;
|
|
7
|
+
remoteName: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class AdbReverseError extends Error {
|
|
10
|
+
constructor(message: string);
|
|
11
|
+
}
|
|
12
|
+
export declare class AdbReverseNotSupportedError extends AdbReverseError {
|
|
13
|
+
constructor();
|
|
14
|
+
}
|
|
15
|
+
export declare class AdbReverseCommand extends AutoDisposable {
|
|
16
|
+
#private;
|
|
17
|
+
protected adb: Adb;
|
|
18
|
+
constructor(adb: Adb);
|
|
19
|
+
protected createBufferedStream(service: string): Promise<BufferedReadableStream>;
|
|
20
|
+
protected sendRequest(service: string): Promise<BufferedReadableStream>;
|
|
21
|
+
list(): Promise<AdbForwardListener[]>;
|
|
22
|
+
/**
|
|
23
|
+
* Add an already existing reverse tunnel. Depends on the transport type, this may not do anything.
|
|
24
|
+
* @param deviceAddress The address to be listened on device by ADB daemon. Or `tcp:0` to choose an available TCP port.
|
|
25
|
+
* @param localAddress The address that listens on the local machine.
|
|
26
|
+
* @returns `tcp:{ACTUAL_LISTENING_PORT}`, If `deviceAddress` is `tcp:0`; otherwise, `deviceAddress`.
|
|
27
|
+
*/
|
|
28
|
+
addExternal(deviceAddress: string, localAddress: string): Promise<string>;
|
|
29
|
+
/**
|
|
30
|
+
* @param deviceAddress The address to be listened on device by ADB daemon. Or `tcp:0` to choose an available TCP port.
|
|
31
|
+
* @param handler A callback to handle incoming connections.
|
|
32
|
+
* @param localAddressThe The address that listens on the local machine. May be `undefined` to let the transport choose an appropriate one.
|
|
33
|
+
* @returns `tcp:{ACTUAL_LISTENING_PORT}`, If `deviceAddress` is `tcp:0`; otherwise, `deviceAddress`.
|
|
34
|
+
* @throws {AdbReverseNotSupportedError} If ADB reverse tunnel is not supported on this device when connected wirelessly.
|
|
35
|
+
* @throws {AdbReverseError} If ADB daemon returns an error.
|
|
36
|
+
*/
|
|
37
|
+
add(deviceAddress: string, handler: AdbIncomingSocketHandler, localAddress?: string): Promise<string>;
|
|
38
|
+
remove(deviceAddress: string): Promise<void>;
|
|
39
|
+
removeAll(): Promise<void>;
|
|
40
|
+
}
|
|
29
41
|
//# sourceMappingURL=reverse.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reverse.d.ts","sourceRoot":"","sources":["../../src/commands/reverse.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"reverse.d.ts","sourceRoot":"","sources":["../../src/commands/reverse.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAGjE,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAG/D,MAAM,WAAW,kBAAkB;IAC/B,YAAY,EAAE,MAAM,CAAC;IAErB,SAAS,EAAE,MAAM,CAAC;IAElB,UAAU,EAAE,MAAM,CAAC;CACtB;AAMD,qBAAa,eAAgB,SAAQ,KAAK;gBACnB,OAAO,EAAE,MAAM;CAIrC;AAED,qBAAa,2BAA4B,SAAQ,eAAe;;CAM/D;AAoBD,qBAAa,iBAAkB,SAAQ,cAAc;;IACjD,SAAS,CAAC,GAAG,EAAE,GAAG,CAAC;gBAIA,GAAG,EAAE,GAAG;cAMX,oBAAoB,CAAC,OAAO,EAAE,MAAM;cAKpC,WAAW,CAAC,OAAO,EAAE,MAAM;IAS9B,IAAI,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAgBlD;;;;;OAKG;IACU,WAAW,CAAC,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;IA8BpE;;;;;;;OAOG;IACU,GAAG,CACZ,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,wBAAwB,EACjC,YAAY,CAAC,EAAE,MAAM,GACtB,OAAO,CAAC,MAAM,CAAC;IAgBL,MAAM,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAY5C,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;CAQ1C"}
|
package/esm/commands/reverse.js
CHANGED
|
@@ -1,101 +1,131 @@
|
|
|
1
|
-
// cspell: ignore killforward
|
|
2
|
-
import { AutoDisposable } from "@yume-chan/event";
|
|
3
|
-
import { BufferedReadableStream
|
|
4
|
-
import Struct from "@yume-chan/struct";
|
|
5
|
-
import { decodeUtf8 } from "../utils/index.js";
|
|
6
|
-
const AdbReverseStringResponse = new Struct()
|
|
7
|
-
.string("length", { length: 4 })
|
|
8
|
-
.string("content", { lengthField: "length", lengthFieldRadix: 16 });
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
1
|
+
// cspell: ignore killforward
|
|
2
|
+
import { AutoDisposable } from "@yume-chan/event";
|
|
3
|
+
import { BufferedReadableStream } from "@yume-chan/stream-extra";
|
|
4
|
+
import Struct, { ExactReadableEndedError } from "@yume-chan/struct";
|
|
5
|
+
import { decodeUtf8, hexToNumber } from "../utils/index.js";
|
|
6
|
+
const AdbReverseStringResponse = new Struct()
|
|
7
|
+
.string("length", { length: 4 })
|
|
8
|
+
.string("content", { lengthField: "length", lengthFieldRadix: 16 });
|
|
9
|
+
export class AdbReverseError extends Error {
|
|
10
|
+
constructor(message) {
|
|
11
|
+
super(message);
|
|
12
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export class AdbReverseNotSupportedError extends AdbReverseError {
|
|
16
|
+
constructor() {
|
|
17
|
+
super("ADB reverse tunnel is not supported on this device when connected wirelessly.");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const AdbReverseErrorResponse = new Struct()
|
|
21
|
+
.concat(AdbReverseStringResponse)
|
|
22
|
+
.postDeserialize((value) => {
|
|
23
|
+
// https://issuetracker.google.com/issues/37066218
|
|
24
|
+
// ADB on Android <9 can't create reverse tunnels when connected wirelessly (ADB over WiFi),
|
|
25
|
+
// and returns this confusing "more than one device/emulator" error.
|
|
26
|
+
if (value.content === "more than one device/emulator") {
|
|
27
|
+
throw new AdbReverseNotSupportedError();
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
throw new AdbReverseError(value.content);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
async function readString(stream, length) {
|
|
34
|
+
const buffer = await stream.readExactly(length);
|
|
35
|
+
return decodeUtf8(buffer);
|
|
36
|
+
}
|
|
37
|
+
export class AdbReverseCommand extends AutoDisposable {
|
|
38
|
+
adb;
|
|
39
|
+
#deviceAddressToLocalAddress = new Map();
|
|
40
|
+
constructor(adb) {
|
|
41
|
+
super();
|
|
42
|
+
this.adb = adb;
|
|
43
|
+
}
|
|
44
|
+
async createBufferedStream(service) {
|
|
45
|
+
const socket = await this.adb.createSocket(service);
|
|
46
|
+
return new BufferedReadableStream(socket.readable);
|
|
47
|
+
}
|
|
48
|
+
async sendRequest(service) {
|
|
49
|
+
const stream = await this.createBufferedStream(service);
|
|
50
|
+
const success = (await readString(stream, 4)) === "OKAY";
|
|
51
|
+
if (!success) {
|
|
52
|
+
await AdbReverseErrorResponse.deserialize(stream);
|
|
53
|
+
}
|
|
54
|
+
return stream;
|
|
55
|
+
}
|
|
56
|
+
async list() {
|
|
57
|
+
const stream = await this.createBufferedStream("reverse:list-forward");
|
|
58
|
+
const response = await AdbReverseStringResponse.deserialize(stream);
|
|
59
|
+
return response.content.split("\n").map((line) => {
|
|
60
|
+
const [deviceSerial, localName, remoteName] = line.split(" ");
|
|
61
|
+
return { deviceSerial, localName, remoteName };
|
|
62
|
+
});
|
|
63
|
+
// No need to close the stream, device will close it
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Add an already existing reverse tunnel. Depends on the transport type, this may not do anything.
|
|
67
|
+
* @param deviceAddress The address to be listened on device by ADB daemon. Or `tcp:0` to choose an available TCP port.
|
|
68
|
+
* @param localAddress The address that listens on the local machine.
|
|
69
|
+
* @returns `tcp:{ACTUAL_LISTENING_PORT}`, If `deviceAddress` is `tcp:0`; otherwise, `deviceAddress`.
|
|
70
|
+
*/
|
|
71
|
+
async addExternal(deviceAddress, localAddress) {
|
|
72
|
+
const stream = await this.sendRequest(`reverse:forward:${deviceAddress};${localAddress}`);
|
|
73
|
+
// `tcp:0` tells the device to pick an available port.
|
|
74
|
+
// On Android >=8, device will respond with the selected port for all `tcp:` requests.
|
|
75
|
+
if (deviceAddress.startsWith("tcp:")) {
|
|
76
|
+
const position = stream.position;
|
|
77
|
+
try {
|
|
78
|
+
const length = hexToNumber(await stream.readExactly(4));
|
|
79
|
+
const port = await readString(stream, length);
|
|
80
|
+
deviceAddress = `tcp:${Number.parseInt(port, 10)}`;
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
if (e instanceof ExactReadableEndedError &&
|
|
84
|
+
stream.position === position) {
|
|
85
|
+
// Android <8 doesn't have this response.
|
|
86
|
+
// (the stream is closed now)
|
|
87
|
+
// Can be safely ignored.
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
throw e;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return deviceAddress;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* @param deviceAddress The address to be listened on device by ADB daemon. Or `tcp:0` to choose an available TCP port.
|
|
98
|
+
* @param handler A callback to handle incoming connections.
|
|
99
|
+
* @param localAddressThe The address that listens on the local machine. May be `undefined` to let the transport choose an appropriate one.
|
|
100
|
+
* @returns `tcp:{ACTUAL_LISTENING_PORT}`, If `deviceAddress` is `tcp:0`; otherwise, `deviceAddress`.
|
|
101
|
+
* @throws {AdbReverseNotSupportedError} If ADB reverse tunnel is not supported on this device when connected wirelessly.
|
|
102
|
+
* @throws {AdbReverseError} If ADB daemon returns an error.
|
|
103
|
+
*/
|
|
104
|
+
async add(deviceAddress, handler, localAddress) {
|
|
105
|
+
localAddress = await this.adb.transport.addReverseTunnel(handler, localAddress);
|
|
106
|
+
try {
|
|
107
|
+
deviceAddress = await this.addExternal(deviceAddress, localAddress);
|
|
108
|
+
this.#deviceAddressToLocalAddress.set(deviceAddress, localAddress);
|
|
109
|
+
return deviceAddress;
|
|
110
|
+
}
|
|
111
|
+
catch (e) {
|
|
112
|
+
await this.adb.transport.removeReverseTunnel(localAddress);
|
|
113
|
+
throw e;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async remove(deviceAddress) {
|
|
117
|
+
const localAddress = this.#deviceAddressToLocalAddress.get(deviceAddress);
|
|
118
|
+
if (localAddress) {
|
|
119
|
+
await this.adb.transport.removeReverseTunnel(localAddress);
|
|
120
|
+
}
|
|
121
|
+
await this.sendRequest(`reverse:killforward:${deviceAddress}`);
|
|
122
|
+
// No need to close the stream, device will close it
|
|
123
|
+
}
|
|
124
|
+
async removeAll() {
|
|
125
|
+
await this.adb.transport.clearReverseTunnels();
|
|
126
|
+
this.#deviceAddressToLocalAddress.clear();
|
|
127
|
+
await this.sendRequest(`reverse:killforward-all`);
|
|
128
|
+
// No need to close the stream, device will close it
|
|
129
|
+
}
|
|
130
|
+
}
|
|
101
131
|
//# sourceMappingURL=reverse.js.map
|