@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.
Files changed (241) hide show
  1. package/CHANGELOG.json +54 -0
  2. package/CHANGELOG.md +25 -1
  3. package/README.md +220 -103
  4. package/esm/adb.d.ts +43 -60
  5. package/esm/adb.d.ts.map +1 -1
  6. package/esm/adb.js +68 -249
  7. package/esm/adb.js.map +1 -1
  8. package/esm/banner.d.ts +17 -0
  9. package/esm/banner.d.ts.map +1 -0
  10. package/esm/banner.js +67 -0
  11. package/esm/banner.js.map +1 -0
  12. package/esm/commands/base.d.ts +6 -6
  13. package/esm/commands/base.d.ts.map +1 -1
  14. package/esm/commands/base.js +8 -8
  15. package/esm/commands/framebuffer.d.ts +53 -53
  16. package/esm/commands/framebuffer.d.ts.map +1 -1
  17. package/esm/commands/framebuffer.js +46 -46
  18. package/esm/commands/framebuffer.js.map +1 -1
  19. package/esm/commands/index.d.ts +7 -8
  20. package/esm/commands/index.d.ts.map +1 -1
  21. package/esm/commands/index.js +7 -8
  22. package/esm/commands/index.js.map +1 -1
  23. package/esm/commands/power.d.ts +22 -22
  24. package/esm/commands/power.js +48 -48
  25. package/esm/commands/reverse.d.ts +40 -28
  26. package/esm/commands/reverse.d.ts.map +1 -1
  27. package/esm/commands/reverse.js +130 -100
  28. package/esm/commands/reverse.js.map +1 -1
  29. package/esm/commands/subprocess/command.d.ts +57 -51
  30. package/esm/commands/subprocess/command.d.ts.map +1 -1
  31. package/esm/commands/subprocess/command.js +86 -80
  32. package/esm/commands/subprocess/command.js.map +1 -1
  33. package/esm/commands/subprocess/index.d.ts +3 -3
  34. package/esm/commands/subprocess/index.js +3 -3
  35. package/esm/commands/subprocess/protocols/index.d.ts +3 -3
  36. package/esm/commands/subprocess/protocols/index.js +3 -3
  37. package/esm/commands/subprocess/protocols/none.d.ts +30 -35
  38. package/esm/commands/subprocess/protocols/none.d.ts.map +1 -1
  39. package/esm/commands/subprocess/protocols/none.js +65 -55
  40. package/esm/commands/subprocess/protocols/none.js.map +1 -1
  41. package/esm/commands/subprocess/protocols/shell.d.ts +33 -38
  42. package/esm/commands/subprocess/protocols/shell.d.ts.map +1 -1
  43. package/esm/commands/subprocess/protocols/shell.js +172 -162
  44. package/esm/commands/subprocess/protocols/shell.js.map +1 -1
  45. package/esm/commands/subprocess/protocols/types.d.ts +48 -49
  46. package/esm/commands/subprocess/protocols/types.d.ts.map +1 -1
  47. package/esm/commands/subprocess/protocols/types.js +1 -1
  48. package/esm/commands/subprocess/utils.d.ts +1 -1
  49. package/esm/commands/subprocess/utils.js +18 -18
  50. package/esm/commands/sync/index.d.ts +8 -7
  51. package/esm/commands/sync/index.d.ts.map +1 -1
  52. package/esm/commands/sync/index.js +8 -7
  53. package/esm/commands/sync/index.js.map +1 -1
  54. package/esm/commands/sync/list.d.ts +42 -40
  55. package/esm/commands/sync/list.d.ts.map +1 -1
  56. package/esm/commands/sync/list.js +67 -47
  57. package/esm/commands/sync/list.js.map +1 -1
  58. package/esm/commands/sync/pull.d.ts +13 -11
  59. package/esm/commands/sync/pull.d.ts.map +1 -1
  60. package/esm/commands/sync/pull.js +35 -37
  61. package/esm/commands/sync/pull.js.map +1 -1
  62. package/esm/commands/sync/push.d.ts +57 -7
  63. package/esm/commands/sync/push.d.ts.map +1 -1
  64. package/esm/commands/sync/push.js +89 -22
  65. package/esm/commands/sync/push.js.map +1 -1
  66. package/esm/commands/sync/request.d.ts +26 -23
  67. package/esm/commands/sync/request.d.ts.map +1 -1
  68. package/esm/commands/sync/request.js +40 -42
  69. package/esm/commands/sync/request.js.map +1 -1
  70. package/esm/commands/sync/response.d.ts +19 -19
  71. package/esm/commands/sync/response.d.ts.map +1 -1
  72. package/esm/commands/sync/response.js +54 -54
  73. package/esm/commands/sync/response.js.map +1 -1
  74. package/esm/commands/sync/socket.d.ts +22 -0
  75. package/esm/commands/sync/socket.d.ts.map +1 -0
  76. package/esm/commands/sync/socket.js +69 -0
  77. package/esm/commands/sync/socket.js.map +1 -0
  78. package/esm/commands/sync/stat.d.ts +72 -72
  79. package/esm/commands/sync/stat.d.ts.map +1 -1
  80. package/esm/commands/sync/stat.js +116 -104
  81. package/esm/commands/sync/stat.js.map +1 -1
  82. package/esm/commands/sync/sync.d.ts +65 -60
  83. package/esm/commands/sync/sync.d.ts.map +1 -1
  84. package/esm/commands/sync/sync.js +123 -149
  85. package/esm/commands/sync/sync.js.map +1 -1
  86. package/esm/commands/tcpip.d.ts +5 -5
  87. package/esm/commands/tcpip.d.ts.map +1 -1
  88. package/esm/commands/tcpip.js +20 -18
  89. package/esm/commands/tcpip.js.map +1 -1
  90. package/esm/{auth.d.ts → daemon/auth.d.ts} +50 -51
  91. package/esm/daemon/auth.d.ts.map +1 -0
  92. package/esm/{auth.js → daemon/auth.js} +95 -96
  93. package/esm/daemon/auth.js.map +1 -0
  94. package/esm/daemon/connection.d.ts +11 -0
  95. package/esm/daemon/connection.d.ts.map +1 -0
  96. package/esm/daemon/connection.js +2 -0
  97. package/esm/daemon/connection.js.map +1 -0
  98. package/esm/{crypto.d.ts → daemon/crypto.d.ts} +36 -36
  99. package/esm/daemon/crypto.d.ts.map +1 -0
  100. package/esm/{crypto.js → daemon/crypto.js} +244 -248
  101. package/esm/daemon/crypto.js.map +1 -0
  102. package/esm/daemon/device.d.ts +9 -0
  103. package/esm/daemon/device.d.ts.map +1 -0
  104. package/esm/daemon/device.js +2 -0
  105. package/esm/daemon/device.js.map +1 -0
  106. package/esm/daemon/dispatcher.d.ts +42 -0
  107. package/esm/daemon/dispatcher.d.ts.map +1 -0
  108. package/esm/{socket → daemon}/dispatcher.js +225 -234
  109. package/esm/daemon/dispatcher.js.map +1 -0
  110. package/esm/daemon/index.d.ts +8 -0
  111. package/esm/daemon/index.d.ts.map +1 -0
  112. package/esm/daemon/index.js +8 -0
  113. package/esm/daemon/index.js.map +1 -0
  114. package/esm/{packet.d.ts → daemon/packet.d.ts} +45 -46
  115. package/esm/daemon/packet.d.ts.map +1 -0
  116. package/esm/{packet.js → daemon/packet.js} +43 -48
  117. package/esm/daemon/packet.js.map +1 -0
  118. package/esm/daemon/socket.d.ts +58 -0
  119. package/esm/daemon/socket.d.ts.map +1 -0
  120. package/esm/{socket → daemon}/socket.js +121 -118
  121. package/esm/daemon/socket.js.map +1 -0
  122. package/esm/daemon/transport.d.ts +45 -0
  123. package/esm/daemon/transport.d.ts.map +1 -0
  124. package/esm/daemon/transport.js +184 -0
  125. package/esm/daemon/transport.js.map +1 -0
  126. package/esm/features.d.ts +10 -7
  127. package/esm/features.d.ts.map +1 -1
  128. package/esm/features.js +13 -10
  129. package/esm/features.js.map +1 -1
  130. package/esm/index.d.ts +7 -9
  131. package/esm/index.d.ts.map +1 -1
  132. package/esm/index.js +7 -9
  133. package/esm/index.js.map +1 -1
  134. package/esm/server/client.d.ts +78 -0
  135. package/esm/server/client.d.ts.map +1 -0
  136. package/esm/server/client.js +329 -0
  137. package/esm/server/client.js.map +1 -0
  138. package/esm/server/index.d.ts +3 -0
  139. package/esm/server/index.d.ts.map +1 -0
  140. package/esm/server/index.js +3 -0
  141. package/esm/server/index.js.map +1 -0
  142. package/esm/server/transport.d.ts +19 -0
  143. package/esm/server/transport.d.ts.map +1 -0
  144. package/esm/server/transport.js +44 -0
  145. package/esm/server/transport.js.map +1 -0
  146. package/esm/utils/auto-reset-event.d.ts +8 -9
  147. package/esm/utils/auto-reset-event.d.ts.map +1 -1
  148. package/esm/utils/auto-reset-event.js +33 -33
  149. package/esm/utils/auto-reset-event.js.map +1 -1
  150. package/esm/utils/base64.d.ts +27 -27
  151. package/esm/utils/base64.js +246 -246
  152. package/esm/utils/base64.js.map +1 -1
  153. package/esm/utils/conditional-variable.d.ts +8 -0
  154. package/esm/utils/conditional-variable.d.ts.map +1 -0
  155. package/esm/utils/conditional-variable.js +34 -0
  156. package/esm/utils/conditional-variable.js.map +1 -0
  157. package/esm/utils/hex.d.ts +3 -0
  158. package/esm/utils/hex.d.ts.map +1 -0
  159. package/esm/utils/hex.js +55 -0
  160. package/esm/utils/hex.js.map +1 -0
  161. package/esm/utils/index.d.ts +6 -3
  162. package/esm/utils/index.d.ts.map +1 -1
  163. package/esm/utils/index.js +6 -3
  164. package/esm/utils/index.js.map +1 -1
  165. package/esm/utils/no-op.d.ts +7 -0
  166. package/esm/utils/no-op.d.ts.map +1 -0
  167. package/esm/utils/no-op.js +12 -0
  168. package/esm/utils/no-op.js.map +1 -0
  169. package/package.json +14 -12
  170. package/src/adb.ts +47 -248
  171. package/src/banner.ts +82 -0
  172. package/src/commands/base.ts +1 -1
  173. package/src/commands/framebuffer.ts +4 -4
  174. package/src/commands/index.ts +7 -8
  175. package/src/commands/power.ts +2 -2
  176. package/src/commands/reverse.ts +90 -70
  177. package/src/commands/subprocess/command.ts +12 -4
  178. package/src/commands/subprocess/index.ts +3 -3
  179. package/src/commands/subprocess/protocols/index.ts +3 -3
  180. package/src/commands/subprocess/protocols/none.ts +36 -23
  181. package/src/commands/subprocess/protocols/shell.ts +94 -74
  182. package/src/commands/subprocess/protocols/types.ts +7 -7
  183. package/src/commands/subprocess/utils.ts +1 -1
  184. package/src/commands/sync/index.ts +8 -7
  185. package/src/commands/sync/list.ts +44 -25
  186. package/src/commands/sync/pull.ts +40 -45
  187. package/src/commands/sync/push.ts +158 -39
  188. package/src/commands/sync/request.ts +21 -16
  189. package/src/commands/sync/response.ts +10 -9
  190. package/src/commands/sync/socket.ts +99 -0
  191. package/src/commands/sync/stat.ts +47 -42
  192. package/src/commands/sync/sync.ts +73 -116
  193. package/src/commands/tcpip.ts +9 -7
  194. package/src/{auth.ts → daemon/auth.ts} +24 -23
  195. package/src/{crypto.ts → daemon/crypto.ts} +25 -33
  196. package/src/daemon/device.ts +14 -0
  197. package/src/{socket → daemon}/dispatcher.ts +95 -117
  198. package/src/daemon/index.ts +7 -0
  199. package/src/daemon/packet.ts +75 -0
  200. package/src/{socket → daemon}/socket.ts +71 -56
  201. package/src/daemon/transport.ts +269 -0
  202. package/src/features.ts +9 -6
  203. package/src/index.ts +3 -5
  204. package/src/server/client.ts +476 -0
  205. package/src/server/index.ts +2 -0
  206. package/src/server/transport.ts +77 -0
  207. package/src/utils/auto-reset-event.ts +14 -15
  208. package/src/utils/conditional-variable.ts +45 -0
  209. package/src/utils/hex.ts +58 -0
  210. package/src/utils/index.ts +6 -3
  211. package/src/utils/no-op.ts +12 -0
  212. package/tsconfig.build.json +12 -1
  213. package/tsconfig.build.tsbuildinfo +1 -1
  214. package/esm/auth.d.ts.map +0 -1
  215. package/esm/auth.js.map +0 -1
  216. package/esm/backend.d.ts +0 -9
  217. package/esm/backend.d.ts.map +0 -1
  218. package/esm/backend.js +0 -2
  219. package/esm/backend.js.map +0 -1
  220. package/esm/commands/install.d.ts +0 -4
  221. package/esm/commands/install.d.ts.map +0 -1
  222. package/esm/commands/install.js +0 -29
  223. package/esm/commands/install.js.map +0 -1
  224. package/esm/crypto.d.ts.map +0 -1
  225. package/esm/crypto.js.map +0 -1
  226. package/esm/packet.d.ts.map +0 -1
  227. package/esm/packet.js.map +0 -1
  228. package/esm/socket/dispatcher.d.ts +0 -60
  229. package/esm/socket/dispatcher.d.ts.map +0 -1
  230. package/esm/socket/dispatcher.js.map +0 -1
  231. package/esm/socket/index.d.ts +0 -3
  232. package/esm/socket/index.d.ts.map +0 -1
  233. package/esm/socket/index.js +0 -3
  234. package/esm/socket/index.js.map +0 -1
  235. package/esm/socket/socket.d.ts +0 -60
  236. package/esm/socket/socket.d.ts.map +0 -1
  237. package/esm/socket/socket.js.map +0 -1
  238. package/src/backend.ts +0 -14
  239. package/src/commands/install.ts +0 -40
  240. package/src/packet.ts +0 -90
  241. 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("Unknown FrameBuffer version");
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,CA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AC;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"}
@@ -1,9 +1,8 @@
1
- export * from './base.js';
2
- export * from './framebuffer.js';
3
- export * from './install.js';
4
- export * from './power.js';
5
- export * from './reverse.js';
6
- export * from './subprocess/index.js';
7
- export * from './sync/index.js';
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,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,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"}
@@ -1,9 +1,8 @@
1
- export * from './base.js';
2
- export * from './framebuffer.js';
3
- export * from './install.js';
4
- export * from './power.js';
5
- export * from './reverse.js';
6
- export * from './subprocess/index.js';
7
- export * from './sync/index.js';
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,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,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"}
@@ -1,23 +1,23 @@
1
- import { AdbCommandBase } from "./base.js";
2
- export declare class AdbPower extends AdbCommandBase {
3
- reboot(name?: 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
- }
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
@@ -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(name = "") {
8
- return this.adb.createSocketAndWait(`reboot:${name}`);
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 { type Adb } from "../adb.js";
3
- import { type AdbIncomingSocketHandler, type AdbSocket } from "../socket/index.js";
4
- export interface AdbForwardListener {
5
- deviceSerial: string;
6
- localName: string;
7
- remoteName: string;
8
- }
9
- export declare class AdbReverseCommand extends AutoDisposable {
10
- protected localAddressToHandler: Map<string, AdbIncomingSocketHandler>;
11
- protected deviceAddressToLocalAddress: Map<string, string>;
12
- protected adb: Adb;
13
- protected listening: boolean;
14
- constructor(adb: Adb);
15
- protected handleIncomingSocket: (socket: AdbSocket) => Promise<boolean>;
16
- private createBufferedStream;
17
- private sendRequest;
18
- list(): Promise<AdbForwardListener[]>;
19
- /**
20
- * @param deviceAddress The address adbd on device is listening on. Can be `tcp:0` to let adbd choose an available TCP port by itself.
21
- * @param localAddress Native ADB client will open a connection to this address when reverse connection received. In WebADB, it's only used to uniquely identify a reverse tunnel registry, `handler` will be called to handle the connection.
22
- * @param handler A callback to handle incoming connections. It must return `true` if it accepts the connection.
23
- * @returns `tcp:{ACTUAL_LISTENING_PORT}`, If `deviceAddress` is `tcp:0`; otherwise, `deviceAddress`.
24
- */
25
- add(deviceAddress: string, localAddress: string, handler: AdbIncomingSocketHandler): Promise<string>;
26
- remove(deviceAddress: string): Promise<void>;
27
- removeAll(): Promise<void>;
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;AAOlD,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EACH,KAAK,wBAAwB,EAC7B,KAAK,SAAS,EACjB,MAAM,oBAAoB,CAAC;AAG5B,MAAM,WAAW,kBAAkB;IAC/B,YAAY,EAAE,MAAM,CAAC;IAErB,SAAS,EAAE,MAAM,CAAC;IAElB,UAAU,EAAE,MAAM,CAAC;CACtB;AAYD,qBAAa,iBAAkB,SAAQ,cA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AAI,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"}
@@ -1,101 +1,131 @@
1
- // cspell: ignore killforward
2
- import { AutoDisposable } from "@yume-chan/event";
3
- import { BufferedReadableStream, BufferedReadableStreamEndedError, } from "@yume-chan/stream-extra";
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
- const AdbReverseErrorResponse = new Struct()
10
- .fields(AdbReverseStringResponse)
11
- .postDeserialize((value) => {
12
- throw new Error(value.content);
13
- });
14
- export class AdbReverseCommand extends AutoDisposable {
15
- localAddressToHandler = new Map();
16
- deviceAddressToLocalAddress = new Map();
17
- adb;
18
- listening = false;
19
- constructor(adb) {
20
- super();
21
- this.adb = adb;
22
- this.addDisposable(this.adb.onIncomingSocket(this.handleIncomingSocket));
23
- }
24
- handleIncomingSocket = async (socket) => {
25
- let address = socket.serviceString;
26
- // ADB daemon appends `\0` to the service string
27
- address = address.replace(/\0/g, "");
28
- return !!(await this.localAddressToHandler.get(address)?.(socket));
29
- };
30
- async createBufferedStream(service) {
31
- const socket = await this.adb.createSocket(service);
32
- return new BufferedReadableStream(socket.readable);
33
- }
34
- async sendRequest(service) {
35
- const stream = await this.createBufferedStream(service);
36
- const success = decodeUtf8(await stream.read(4)) === "OKAY";
37
- if (!success) {
38
- await AdbReverseErrorResponse.deserialize(stream);
39
- }
40
- return stream;
41
- }
42
- async list() {
43
- const stream = await this.createBufferedStream("reverse:list-forward");
44
- const response = await AdbReverseStringResponse.deserialize(stream);
45
- return response.content.split("\n").map((line) => {
46
- const [deviceSerial, localName, remoteName] = line.split(" ");
47
- return { deviceSerial, localName, remoteName };
48
- });
49
- // No need to close the stream, device will close it
50
- }
51
- /**
52
- * @param deviceAddress The address adbd on device is listening on. Can be `tcp:0` to let adbd choose an available TCP port by itself.
53
- * @param localAddress Native ADB client will open a connection to this address when reverse connection received. In WebADB, it's only used to uniquely identify a reverse tunnel registry, `handler` will be called to handle the connection.
54
- * @param handler A callback to handle incoming connections. It must return `true` if it accepts the connection.
55
- * @returns `tcp:{ACTUAL_LISTENING_PORT}`, If `deviceAddress` is `tcp:0`; otherwise, `deviceAddress`.
56
- */
57
- async add(deviceAddress, localAddress, handler) {
58
- // TODO(reverse): handle ADB bug
59
- // https://issuetracker.google.com/issues/37066218
60
- const stream = await this.sendRequest(`reverse:forward:${deviceAddress};${localAddress}`);
61
- // `tcp:0` tells the device to pick an available port.
62
- // On Android >=8, device will respond with the selected port for all `tcp:` requests.
63
- if (deviceAddress.startsWith("tcp:")) {
64
- let length;
65
- try {
66
- length = Number.parseInt(decodeUtf8(await stream.read(4)), 16);
67
- }
68
- catch (e) {
69
- if (!(e instanceof BufferedReadableStreamEndedError)) {
70
- throw e;
71
- }
72
- // Android <8 doesn't have this response.
73
- // (the stream is closed now)
74
- // Can be safely ignored.
75
- }
76
- if (length !== undefined) {
77
- const port = decodeUtf8(await stream.read(length));
78
- deviceAddress = `tcp:${Number.parseInt(port, 10)}`;
79
- }
80
- }
81
- this.localAddressToHandler.set(localAddress, handler);
82
- this.deviceAddressToLocalAddress.set(deviceAddress, localAddress);
83
- return deviceAddress;
84
- // No need to close the stream, device will close it
85
- }
86
- async remove(deviceAddress) {
87
- await this.sendRequest(`reverse:killforward:${deviceAddress}`);
88
- if (this.deviceAddressToLocalAddress.has(deviceAddress)) {
89
- this.localAddressToHandler.delete(this.deviceAddressToLocalAddress.get(deviceAddress));
90
- this.deviceAddressToLocalAddress.delete(deviceAddress);
91
- }
92
- // No need to close the stream, device will close it
93
- }
94
- async removeAll() {
95
- await this.sendRequest(`reverse:killforward-all`);
96
- this.deviceAddressToLocalAddress.clear();
97
- this.localAddressToHandler.clear();
98
- // No need to close the stream, device will close it
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