@yume-chan/scrcpy 0.0.16 → 0.0.18

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 (292) hide show
  1. package/CHANGELOG.json +36 -3
  2. package/CHANGELOG.md +21 -4
  3. package/LICENSE +1 -1
  4. package/README.md +291 -37
  5. package/bin/scrcpy-server +0 -0
  6. package/bin/version.d.ts +1 -1
  7. package/bin/version.js +1 -1
  8. package/esm/adb/client.d.ts +41 -0
  9. package/esm/adb/client.d.ts.map +1 -0
  10. package/esm/adb/client.js +243 -0
  11. package/esm/adb/client.js.map +1 -0
  12. package/esm/adb/connection.d.ts +47 -0
  13. package/esm/adb/connection.d.ts.map +1 -0
  14. package/esm/{connection.js → adb/connection.js} +35 -31
  15. package/esm/adb/connection.js.map +1 -0
  16. package/esm/adb/index.d.ts +4 -0
  17. package/esm/adb/index.d.ts.map +1 -0
  18. package/esm/adb/index.js +4 -0
  19. package/esm/adb/index.js.map +1 -0
  20. package/esm/adb/options/1_16.d.ts +8 -0
  21. package/esm/adb/options/1_16.d.ts.map +1 -0
  22. package/esm/adb/options/1_16.js +20 -0
  23. package/esm/adb/options/1_16.js.map +1 -0
  24. package/esm/adb/options/1_22.d.ts +8 -0
  25. package/esm/adb/options/1_22.d.ts.map +1 -0
  26. package/esm/adb/options/1_22.js +17 -0
  27. package/esm/adb/options/1_22.js.map +1 -0
  28. package/esm/adb/options/index.d.ts +4 -0
  29. package/esm/adb/options/index.d.ts.map +1 -0
  30. package/esm/adb/options/index.js +4 -0
  31. package/esm/adb/options/index.js.map +1 -0
  32. package/esm/adb/options/types.d.ts +24 -0
  33. package/esm/adb/options/types.d.ts.map +1 -0
  34. package/esm/adb/options/types.js +37 -0
  35. package/esm/adb/options/types.js.map +1 -0
  36. package/esm/codec.js +2 -2
  37. package/esm/codec.js.map +1 -1
  38. package/esm/control/back-or-screen-on.d.ts +3 -0
  39. package/esm/control/back-or-screen-on.d.ts.map +1 -0
  40. package/esm/control/back-or-screen-on.js +2 -0
  41. package/esm/control/back-or-screen-on.js.map +1 -0
  42. package/esm/control/hover-helper.d.ts +18 -0
  43. package/esm/control/hover-helper.d.ts.map +1 -0
  44. package/esm/control/hover-helper.js +44 -0
  45. package/esm/control/hover-helper.js.map +1 -0
  46. package/esm/control/index.d.ts +12 -0
  47. package/esm/control/index.d.ts.map +1 -0
  48. package/esm/control/index.js +12 -0
  49. package/esm/control/index.js.map +1 -0
  50. package/esm/control/inject-keycode.d.ts +61 -0
  51. package/esm/control/inject-keycode.d.ts.map +1 -0
  52. package/esm/control/inject-keycode.js +62 -0
  53. package/esm/control/inject-keycode.js.map +1 -0
  54. package/esm/control/inject-scroll.d.ts +3 -0
  55. package/esm/control/inject-scroll.d.ts.map +1 -0
  56. package/esm/control/inject-scroll.js +2 -0
  57. package/esm/control/inject-scroll.js.map +1 -0
  58. package/esm/control/inject-text.d.ts +9 -0
  59. package/esm/control/inject-text.d.ts.map +1 -0
  60. package/esm/control/inject-text.js +7 -0
  61. package/esm/control/inject-text.js.map +1 -0
  62. package/esm/control/inject-touch.d.ts +38 -0
  63. package/esm/control/inject-touch.d.ts.map +1 -0
  64. package/esm/control/inject-touch.js +63 -0
  65. package/esm/control/inject-touch.js.map +1 -0
  66. package/esm/control/rotate-device.d.ts +7 -0
  67. package/esm/control/rotate-device.d.ts.map +1 -0
  68. package/esm/control/rotate-device.js +5 -0
  69. package/esm/control/rotate-device.js.map +1 -0
  70. package/esm/control/serializer.d.ts +34 -0
  71. package/esm/control/serializer.d.ts.map +1 -0
  72. package/esm/control/serializer.js +79 -0
  73. package/esm/control/serializer.js.map +1 -0
  74. package/esm/control/set-clipboard.d.ts +3 -0
  75. package/esm/control/set-clipboard.d.ts.map +1 -0
  76. package/esm/control/set-clipboard.js +2 -0
  77. package/esm/control/set-clipboard.js.map +1 -0
  78. package/esm/control/set-screen-power-mode.d.ts +12 -0
  79. package/esm/control/set-screen-power-mode.d.ts.map +1 -0
  80. package/esm/control/set-screen-power-mode.js +12 -0
  81. package/esm/control/set-screen-power-mode.js.map +1 -0
  82. package/esm/control/type.d.ts +15 -0
  83. package/esm/control/type.d.ts.map +1 -0
  84. package/esm/control/type.js +19 -0
  85. package/esm/control/type.js.map +1 -0
  86. package/esm/device-message/ack-clipboard.d.ts +9 -0
  87. package/esm/device-message/ack-clipboard.d.ts.map +1 -0
  88. package/esm/device-message/ack-clipboard.js +6 -0
  89. package/esm/device-message/ack-clipboard.js.map +1 -0
  90. package/esm/device-message/clipboard.d.ts +10 -0
  91. package/esm/device-message/clipboard.d.ts.map +1 -0
  92. package/esm/device-message/clipboard.js +7 -0
  93. package/esm/device-message/clipboard.js.map +1 -0
  94. package/esm/device-message/index.d.ts +5 -0
  95. package/esm/device-message/index.d.ts.map +1 -0
  96. package/esm/device-message/index.js +5 -0
  97. package/esm/device-message/index.js.map +1 -0
  98. package/esm/device-message/stream.d.ts +8 -0
  99. package/esm/device-message/stream.d.ts.map +1 -0
  100. package/esm/device-message/stream.js +20 -0
  101. package/esm/device-message/stream.js.map +1 -0
  102. package/esm/device-message/type.d.ts +5 -0
  103. package/esm/device-message/type.d.ts.map +1 -0
  104. package/esm/device-message/type.js +7 -0
  105. package/esm/device-message/type.js.map +1 -0
  106. package/esm/index.d.ts +3 -6
  107. package/esm/index.d.ts.map +1 -1
  108. package/esm/index.js +3 -6
  109. package/esm/index.js.map +1 -1
  110. package/esm/options/1_16/codec-options.d.ts +20 -0
  111. package/esm/options/1_16/codec-options.d.ts.map +1 -0
  112. package/esm/options/1_16/codec-options.js +26 -0
  113. package/esm/options/1_16/codec-options.js.map +1 -0
  114. package/esm/options/1_16/h264-configuration.d.ts +49 -0
  115. package/esm/options/1_16/h264-configuration.d.ts.map +1 -0
  116. package/esm/options/1_16/h264-configuration.js +414 -0
  117. package/esm/options/1_16/h264-configuration.js.map +1 -0
  118. package/esm/options/1_16/index.d.ts +4 -110
  119. package/esm/options/1_16/index.d.ts.map +1 -1
  120. package/esm/options/1_16/index.js +4 -226
  121. package/esm/options/1_16/index.js.map +1 -1
  122. package/esm/options/1_16/options.d.ts +94 -0
  123. package/esm/options/1_16/options.d.ts.map +1 -0
  124. package/esm/options/1_16/options.js +190 -0
  125. package/esm/options/1_16/options.js.map +1 -0
  126. package/esm/options/1_16/scroll.d.ts +27 -0
  127. package/esm/options/1_16/scroll.d.ts.map +1 -0
  128. package/esm/options/1_16/scroll.js +56 -0
  129. package/esm/options/1_16/scroll.js.map +1 -0
  130. package/esm/options/1_16/sps.d.ts +1 -1
  131. package/esm/options/1_16/sps.d.ts.map +1 -1
  132. package/esm/options/1_16/sps.js +25 -17
  133. package/esm/options/1_16/sps.js.map +1 -1
  134. package/esm/options/1_18.d.ts +8 -8
  135. package/esm/options/1_18.d.ts.map +1 -1
  136. package/esm/options/1_18.js +7 -7
  137. package/esm/options/1_18.js.map +1 -1
  138. package/esm/options/1_21.d.ts +13 -2
  139. package/esm/options/1_21.d.ts.map +1 -1
  140. package/esm/options/1_21.js +14 -3
  141. package/esm/options/1_21.js.map +1 -1
  142. package/esm/options/1_22/index.d.ts +3 -0
  143. package/esm/options/1_22/index.d.ts.map +1 -0
  144. package/esm/options/1_22/index.js +3 -0
  145. package/esm/options/1_22/index.js.map +1 -0
  146. package/esm/options/1_22/options.d.ts +29 -0
  147. package/esm/options/1_22/options.d.ts.map +1 -0
  148. package/esm/options/1_22/options.js +26 -0
  149. package/esm/options/1_22/options.js.map +1 -0
  150. package/esm/options/1_22/scroll.d.ts +17 -0
  151. package/esm/options/1_22/scroll.d.ts.map +1 -0
  152. package/esm/options/1_22/scroll.js +15 -0
  153. package/esm/options/1_22/scroll.js.map +1 -0
  154. package/esm/options/1_23.d.ts +5 -5
  155. package/esm/options/1_23.d.ts.map +1 -1
  156. package/esm/options/1_23.js +7 -6
  157. package/esm/options/1_23.js.map +1 -1
  158. package/esm/options/1_24.d.ts +1 -1
  159. package/esm/options/1_24.d.ts.map +1 -1
  160. package/esm/options/1_24.js.map +1 -1
  161. package/esm/options/1_25/index.d.ts +3 -0
  162. package/esm/options/1_25/index.d.ts.map +1 -0
  163. package/esm/options/1_25/index.js +3 -0
  164. package/esm/options/1_25/index.js.map +1 -0
  165. package/esm/options/1_25/options.d.ts +6 -0
  166. package/esm/options/1_25/options.d.ts.map +1 -0
  167. package/esm/options/1_25/options.js +8 -0
  168. package/esm/options/1_25/options.js.map +1 -0
  169. package/esm/options/1_25/scroll.d.ts +19 -0
  170. package/esm/options/1_25/scroll.d.ts.map +1 -0
  171. package/esm/options/1_25/scroll.js +33 -0
  172. package/esm/options/1_25/scroll.js.map +1 -0
  173. package/esm/options/index.d.ts +5 -4
  174. package/esm/options/index.d.ts.map +1 -1
  175. package/esm/options/index.js +5 -4
  176. package/esm/options/index.js.map +1 -1
  177. package/esm/options/types.d.ts +47 -0
  178. package/esm/options/types.d.ts.map +1 -0
  179. package/esm/options/types.js +18 -0
  180. package/esm/options/types.js.map +1 -0
  181. package/package.json +32 -25
  182. package/scripts/fetch-server.cjs +19 -9
  183. package/src/adb/client.ts +345 -0
  184. package/src/adb/connection.ts +192 -0
  185. package/src/adb/index.ts +3 -0
  186. package/src/adb/options/1_16.ts +30 -0
  187. package/src/adb/options/1_22.ts +26 -0
  188. package/src/adb/options/index.ts +3 -0
  189. package/src/adb/options/types.ts +75 -0
  190. package/src/control/back-or-screen-on.ts +4 -0
  191. package/src/control/hover-helper.ts +56 -0
  192. package/src/control/index.ts +11 -0
  193. package/src/control/inject-keycode.ts +72 -0
  194. package/src/control/inject-scroll.ts +4 -0
  195. package/src/control/inject-text.ts +12 -0
  196. package/src/control/inject-touch.ts +78 -0
  197. package/src/control/rotate-device.ts +10 -0
  198. package/src/control/serializer.ts +151 -0
  199. package/src/control/set-clipboard.ts +4 -0
  200. package/src/control/set-screen-power-mode.ts +17 -0
  201. package/src/control/type.ts +17 -0
  202. package/src/device-message/ack-clipboard.ts +10 -0
  203. package/src/device-message/clipboard.ts +11 -0
  204. package/src/device-message/index.ts +4 -0
  205. package/src/device-message/stream.ts +29 -0
  206. package/src/device-message/type.ts +5 -0
  207. package/src/index.ts +3 -6
  208. package/src/options/1_16/codec-options.ts +55 -0
  209. package/src/options/1_16/h264-configuration.ts +485 -0
  210. package/src/options/1_16/index.ts +4 -345
  211. package/src/options/1_16/options.ts +339 -0
  212. package/src/options/1_16/scroll.ts +76 -0
  213. package/src/options/1_18.ts +24 -12
  214. package/src/options/1_21.ts +34 -6
  215. package/src/options/1_22/index.ts +2 -0
  216. package/src/options/1_22/options.ts +58 -0
  217. package/src/options/1_22/scroll.ts +26 -0
  218. package/src/options/1_23.ts +33 -19
  219. package/src/options/1_24.ts +3 -2
  220. package/src/options/1_25/index.ts +2 -0
  221. package/src/options/1_25/options.ts +12 -0
  222. package/src/options/1_25/scroll.ts +52 -0
  223. package/src/options/index.ts +5 -4
  224. package/src/options/types.ts +102 -0
  225. package/tsconfig.build.json +3 -0
  226. package/tsconfig.build.tsbuildinfo +1 -0
  227. package/esm/client.d.ts +0 -48
  228. package/esm/client.d.ts.map +0 -1
  229. package/esm/client.js +0 -341
  230. package/esm/client.js.map +0 -1
  231. package/esm/connection.d.ts +0 -37
  232. package/esm/connection.d.ts.map +0 -1
  233. package/esm/connection.js.map +0 -1
  234. package/esm/decoder/index.d.ts +0 -4
  235. package/esm/decoder/index.d.ts.map +0 -1
  236. package/esm/decoder/index.js +0 -4
  237. package/esm/decoder/index.js.map +0 -1
  238. package/esm/decoder/tinyh264/index.d.ts +0 -20
  239. package/esm/decoder/tinyh264/index.d.ts.map +0 -1
  240. package/esm/decoder/tinyh264/index.js +0 -86
  241. package/esm/decoder/tinyh264/index.js.map +0 -1
  242. package/esm/decoder/tinyh264/worker.d.ts +0 -2
  243. package/esm/decoder/tinyh264/worker.d.ts.map +0 -1
  244. package/esm/decoder/tinyh264/worker.js +0 -3
  245. package/esm/decoder/tinyh264/worker.js.map +0 -1
  246. package/esm/decoder/tinyh264/wrapper.d.ts +0 -21
  247. package/esm/decoder/tinyh264/wrapper.d.ts.map +0 -1
  248. package/esm/decoder/tinyh264/wrapper.js +0 -68
  249. package/esm/decoder/tinyh264/wrapper.js.map +0 -1
  250. package/esm/decoder/types.d.ts +0 -28
  251. package/esm/decoder/types.d.ts.map +0 -1
  252. package/esm/decoder/types.js +0 -2
  253. package/esm/decoder/types.js.map +0 -1
  254. package/esm/decoder/web-codecs/index.d.ts +0 -22
  255. package/esm/decoder/web-codecs/index.d.ts.map +0 -1
  256. package/esm/decoder/web-codecs/index.js +0 -81
  257. package/esm/decoder/web-codecs/index.js.map +0 -1
  258. package/esm/message.d.ts +0 -98
  259. package/esm/message.d.ts.map +0 -1
  260. package/esm/message.js +0 -98
  261. package/esm/message.js.map +0 -1
  262. package/esm/options/1_22.d.ts +0 -43
  263. package/esm/options/1_22.d.ts.map +0 -1
  264. package/esm/options/1_22.js +0 -43
  265. package/esm/options/1_22.js.map +0 -1
  266. package/esm/options/common.d.ts +0 -34
  267. package/esm/options/common.d.ts.map +0 -1
  268. package/esm/options/common.js +0 -16
  269. package/esm/options/common.js.map +0 -1
  270. package/esm/push-server.d.ts +0 -6
  271. package/esm/push-server.d.ts.map +0 -1
  272. package/esm/push-server.js +0 -16
  273. package/esm/push-server.js.map +0 -1
  274. package/esm/utils.d.ts +0 -2
  275. package/esm/utils.d.ts.map +0 -1
  276. package/esm/utils.js +0 -6
  277. package/esm/utils.js.map +0 -1
  278. package/src/client.ts +0 -435
  279. package/src/connection.ts +0 -148
  280. package/src/decoder/index.ts +0 -3
  281. package/src/decoder/tinyh264/index.ts +0 -112
  282. package/src/decoder/tinyh264/types.d.ts +0 -137
  283. package/src/decoder/tinyh264/worker.ts +0 -2
  284. package/src/decoder/tinyh264/wrapper.ts +0 -89
  285. package/src/decoder/types.ts +0 -35
  286. package/src/decoder/web-codecs/index.ts +0 -99
  287. package/src/message.ts +0 -113
  288. package/src/options/1_16/sps.ts +0 -300
  289. package/src/options/1_22.ts +0 -78
  290. package/src/options/common.ts +0 -66
  291. package/src/push-server.ts +0 -24
  292. package/src/utils.ts +0 -5
package/CHANGELOG.json CHANGED
@@ -1,6 +1,39 @@
1
1
  {
2
2
  "name": "@yume-chan/scrcpy",
3
3
  "entries": [
4
+ {
5
+ "version": "0.0.18",
6
+ "tag": "@yume-chan/scrcpy_v0.0.18",
7
+ "date": "Wed, 25 Jan 2023 21:33:49 GMT",
8
+ "comments": {
9
+ "none": [
10
+ {
11
+ "comment": "Move `@yume-chan/adb` to `peerDependencies`"
12
+ },
13
+ {
14
+ "comment": "Add support for Scrcpy server version 1.25"
15
+ },
16
+ {
17
+ "comment": "Add support for `SetClipboard` control message and `AckClipboard` device message"
18
+ }
19
+ ]
20
+ }
21
+ },
22
+ {
23
+ "version": "0.0.17",
24
+ "tag": "@yume-chan/scrcpy_v0.0.17",
25
+ "date": "Tue, 18 Oct 2022 09:32:30 GMT",
26
+ "comments": {
27
+ "none": [
28
+ {
29
+ "comment": "Add standalone types for serializing/deserializing Scrcpy packets"
30
+ },
31
+ {
32
+ "comment": "Separate decoders to own packages so they don't need optional peer dependencies."
33
+ }
34
+ ]
35
+ }
36
+ },
4
37
  {
5
38
  "version": "0.0.16",
6
39
  "tag": "@yume-chan/scrcpy_v0.0.16",
@@ -41,7 +74,7 @@
41
74
  "comments": {
42
75
  "none": [
43
76
  {
44
- "comment": "Add support for new option of 1.24"
77
+ "comment": "Add support for Scrcpy server version 1.24"
45
78
  }
46
79
  ]
47
80
  }
@@ -53,7 +86,7 @@
53
86
  "comments": {
54
87
  "none": [
55
88
  {
56
- "comment": "Add support for 1.23"
89
+ "comment": "Add support for Scrcpy server version 1.23"
57
90
  }
58
91
  ]
59
92
  }
@@ -71,7 +104,7 @@
71
104
  "comments": {
72
105
  "none": [
73
106
  {
74
- "comment": "Add support for 1.22 new server options"
107
+ "comment": "Add support for Scrcpy server version 1.22"
75
108
  },
76
109
  {
77
110
  "comment": "Update to use Web Streams API"
package/CHANGELOG.md CHANGED
@@ -1,6 +1,23 @@
1
1
  # Change Log - @yume-chan/scrcpy
2
2
 
3
- This log was last generated on Sat, 28 May 2022 03:56:37 GMT and should not be manually modified.
3
+ This log was last generated on Wed, 25 Jan 2023 21:33:49 GMT and should not be manually modified.
4
+
5
+ ## 0.0.18
6
+ Wed, 25 Jan 2023 21:33:49 GMT
7
+
8
+ ### Updates
9
+
10
+ - Move `@yume-chan/adb` to `peerDependencies`
11
+ - Add support for Scrcpy server version 1.25
12
+ - Add support for `SetClipboard` control message and `AckClipboard` device message
13
+
14
+ ## 0.0.17
15
+ Tue, 18 Oct 2022 09:32:30 GMT
16
+
17
+ ### Updates
18
+
19
+ - Add standalone types for serializing/deserializing Scrcpy packets
20
+ - Separate decoders to own packages so they don't need optional peer dependencies.
4
21
 
5
22
  ## 0.0.16
6
23
  Sat, 28 May 2022 03:56:37 GMT
@@ -24,14 +41,14 @@ Sat, 30 Apr 2022 14:05:48 GMT
24
41
 
25
42
  ### Updates
26
43
 
27
- - Add support for new option of 1.24
44
+ - Add support for Scrcpy server version 1.24
28
45
 
29
46
  ## 0.0.13
30
47
  Thu, 28 Apr 2022 01:23:53 GMT
31
48
 
32
49
  ### Updates
33
50
 
34
- - Add support for 1.23
51
+ - Add support for Scrcpy server version 1.23
35
52
 
36
53
  ## 0.0.12
37
54
  Sun, 03 Apr 2022 11:18:47 GMT
@@ -43,7 +60,7 @@ Sun, 03 Apr 2022 10:54:15 GMT
43
60
 
44
61
  ### Updates
45
62
 
46
- - Add support for 1.22 new server options
63
+ - Add support for Scrcpy server version 1.22
47
64
  - Update to use Web Streams API
48
65
  - Improve compatibility with Node.js 12 ESM format
49
66
  - Workaround a issue with server crash on Samsung ROM (https://github.com/Genymobile/scrcpy/issues/2841)
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020-2022 Simon Chan
3
+ Copyright (c) 2020-2023 Simon Chan
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -2,16 +2,57 @@
2
2
 
3
3
  TypeScript implementation of [Scrcpy](https://github.com/Genymobile/scrcpy) client.
4
4
 
5
- It uses the official Scrcpy server releases.
5
+ It's compatible with the official Scrcpy server binaries.
6
6
 
7
7
  **WARNING:** The public API is UNSTABLE. If you have any questions, please open an issue.
8
8
 
9
- ## Download Server Binary
9
+ - [Basic information](#basic-information)
10
+ - [Prepare server binary](#prepare-server-binary)
11
+ - [`fetch-scrcpy-server`](#fetch-scrcpy-server)
12
+ - [Use the server binary](#use-the-server-binary)
13
+ - [Node.js CommonJS](#nodejs-commonjs)
14
+ - [Node.js ES module](#nodejs-es-module)
15
+ - [Webpack 4](#webpack-4)
16
+ - [Webpack 5](#webpack-5)
17
+ - [Read the server version](#read-the-server-version)
18
+ - [Server versions](#server-versions)
19
+ - [Use with `@yume-chan/adb`](#use-with-yume-chanadb)
20
+ - [Push server binary](#push-server-binary)
21
+ - [Start server on device](#start-server-on-device)
22
+ - [Using other transportation](#using-other-transportation)
23
+ - [Parsing video packets](#parsing-video-packets)
24
+ - [Sending control messages](#sending-control-messages)
25
+ - [Reading device messages](#reading-device-messages)
26
+ - [Always read the streams](#always-read-the-streams)
27
+ - [Video stream](#video-stream)
28
+ - [Decode video stream](#decode-video-stream)
10
29
 
11
- This package has a script `fetch-scrcpy-server` to help you download the official server binary.
30
+ ## Basic information
31
+
32
+ Although Scrcpy doesn't install any App on the device, it does have a server binary executable to be run on the device.
33
+
34
+ With the official Scrcpy client and server, the client uses ADB to transfer the server binary file to the device, run it, and communicate with it via ADB tunnel (the bootstrap process).
35
+
36
+ This package provides types that can serialize and deserialize Scrcpy protocol messages, but it generally requires you to do the bootstrapping and provide the data stream to the server.
37
+
38
+ If you are also using `@yume-chan/adb`, this package has a helper class that can complete the bootstrap process using it, doing what the official client does.
39
+
40
+ **NOTE:** `@yume-chan/adb` is a peer dependency, you need to install it yourself. Only those types whose names begin with `Adb` requires `@yume-chan/adb`.
41
+
42
+ ## Prepare server binary
43
+
44
+ This package doesn't include the server binary. It's compatible with many versions of the official server binary, but may not work with future versions due to protocol changes.
45
+
46
+ You can download the server binary from official releases (https://github.com/Genymobile/scrcpy/releases), or use the built-in `fetch-scrcpy-server` script to automate the process.
12
47
 
13
48
  The server binary is subject to [Apache License 2.0](https://github.com/Genymobile/scrcpy/blob/master/LICENSE).
14
49
 
50
+ ### `fetch-scrcpy-server`
51
+
52
+ This package includes a script that downloads the server binary from official releases for you.
53
+
54
+ The `gh-release-fetch@3` package is a peer dependency for this script, thus requires separated installation.
55
+
15
56
  Usage:
16
57
 
17
58
  ```
@@ -21,30 +62,86 @@ $ npx fetch-scrcpy-server <version>
21
62
  For example:
22
63
 
23
64
  ```
24
- $ npx fetch-scrcpy-server 1.21
65
+ $ npx fetch-scrcpy-server 1.25
25
66
  ```
26
67
 
27
- You can also add it to the `postinstall` script of your `package.json` so it will run automatically when you do `npm install`:
68
+ It can also be added to the `postinstall` script in `package.json`, so running `npm install` will automatically invoke the script:
28
69
 
29
70
  ```json
30
71
  "scripts": {
31
- "postinstall": "fetch-scrcpy-server 1.21",
72
+ "postinstall": "fetch-scrcpy-server 1.25",
32
73
  },
33
74
  ```
34
75
 
35
- It will download the binary to `bin/scrcpy` and write the version string to `bin/version.js`. You can import the version string with
76
+ The server binary will be named `bin/scrcpy-server` in this package's installation directory (usually in `node_modules`).
77
+
78
+ ### Use the server binary
79
+
80
+ The server binary file needs to be embedded into your application, the exact method depends on the bundler and runtime.
81
+
82
+ To name a few:
83
+
84
+ #### Node.js CommonJS
85
+
86
+ ```ts
87
+ const fs = require('fs');
88
+ const path: string = require.resolve('@yume-chan/scrcpy/bin/scrcpy-server'); // Or your own server binary path
89
+ const buffer: Buffer = fs.readFileSync(path);
90
+ ```
91
+
92
+ #### Node.js ES module
93
+
94
+ ```ts
95
+ import fs from 'node:fs/promises';
96
+ import { createRequire } from 'node:module';
97
+
98
+ const path: string = createRequire(import.meta.url).resolve('@yume-chan/scrcpy/bin/scrcpy-server'); // Or your own server binary path
99
+ const buffer: Buffer = await fs.readFile(path);
100
+ ```
101
+
102
+ Currently, ES Module doesn't have a `resolve` function like `require.resolve` in CommonJS, so `createRequire` is used to create a CommonJS resolver.
103
+
104
+ `import.meta.resolve` (https://github.com/whatwg/html/pull/5572) is a proposal that fills this gap. Node.js already has experimental support for it behind a flag. See https://nodejs.org/api/esm.html#importmetaresolvespecifier-parent for more information.
105
+
106
+ ```ts
107
+ const path: string = import.meta.resolve('@yume-chan/scrcpy/bin/scrcpy-server');
108
+ ```
109
+
110
+ #### Webpack 4
111
+
112
+ Requires installing and configuring file-loader (https://v4.webpack.js.org/loaders/file-loader/)
113
+
114
+ ```ts
115
+ import SCRCPY_SERVER_URL from '@yume-chan/scrcpy/bin/scrcpy-server'; // Or your own server binary path
116
+ const buffer: ArrayBuffer = await fetch(SCRCPY_SERVER_URL).then(res => res.arrayBuffer());
117
+ ```
118
+
119
+ #### Webpack 5
120
+
121
+ Requires configuring Asset Modules (https://webpack.js.org/guides/asset-modules/)
122
+
123
+ ```ts
124
+ const SCRCPY_SERVER_URL = new URL('@yume-chan/scrcpy/bin/scrcpy-server', import.meta.url); // Or your own server binary path
125
+ const buffer: ArrayBuffer = await fetch(SCRCPY_SERVER_URL).then(res => res.arrayBuffer());
126
+ ```
127
+
128
+ ### Read the server version
129
+
130
+ The correct version number is required to launch the server, so `fetch-scrcpy-server` also writes the version number to `bin/version.js`.
36
131
 
37
132
  ```js
38
- import SCRCPY_SERVER_VERSION from '@yume-chan/scrcpy/bin/version';
133
+ import SCRCPY_SERVER_VERSION from '@yume-chan/scrcpy/bin/version.js';
134
+
135
+ console.log(SCRCPY_SERVER_VERSION); // "1.25"
39
136
  ```
40
137
 
41
- And import the server binary with [file-loader](https://v4.webpack.js.org/loaders/file-loader/) (Webpack 4) or [Asset Modules](https://webpack.js.org/guides/asset-modules/) (Webpack 5).
138
+ ## Server versions
42
139
 
43
- ## Option versions
140
+ Scrcpy protocol change over time, and are usually not backwards compatible. This package supports multiple server versions (or ranges), and uses different option types to choose different behaviors. Using incorrect option version usually results in errors.
44
141
 
45
- Scrcpy server has no backward compatibility on options input format. Currently the following versions are supported:
142
+ The latest one may continue to work for future server versions, but there is no guarantee.
46
143
 
47
- | versions | type |
144
+ | Version | Type |
48
145
  | --------- | ------------------- |
49
146
  | 1.16~1.17 | `ScrcpyOptions1_16` |
50
147
  | 1.18~1.20 | `ScrcpyOptions1_18` |
@@ -52,39 +149,196 @@ Scrcpy server has no backward compatibility on options input format. Currently t
52
149
  | 1.22 | `ScrcpyOptions1_22` |
53
150
  | 1.23 | `ScrcpyOptions1_23` |
54
151
  | 1.24 | `ScrcpyOptions1_24` |
152
+ | 1.25 | `ScrcpyOptions1_25` |
55
153
 
56
- You must use the correct type according to the server version.
154
+ When using `AdbScrcpyClient`, there are `AdbScrcpyOptions` containing `@yume-chan/adb` specific options:
57
155
 
58
- ## Video stream
156
+ | Version | Type |
157
+ | --------- | ---------------------- |
158
+ | 1.16~1.21 | `AdbScrcpyOptions1_16` |
159
+ | 1.22~1.25 | `AdbScrcpyOptions1_22` |
160
+
161
+ ## Use with `@yume-chan/adb`
162
+
163
+ `@yume-chan/adb` is a TypeScript ADB implementation that can run on Web browser. It can be used to bootstrap the server on a device.
164
+
165
+ ### Push server binary
166
+
167
+ The `Adb#sync()#write()` method can be used to push files to the device. Read more at `@yume-chan/adb`'s documentation (https://github.com/yume-chan/ya-webadb/tree/main/libraries/adb#readme).
168
+
169
+ This package also provides the `AdbScrcpyClient.pushServer()` static method as a shortcut, plus it will automatically close the `AdbSync` object on completion.
170
+
171
+ Example using `write()`:
172
+
173
+ ```ts
174
+ import { AdbScrcpyClient } from '@yume-chan/scrcpy';
175
+
176
+ const stream: WritableStream<Uint8Array> = AdbScrcpyClient.pushServer(adb);
177
+ const writer = stream.getWriter();
178
+ await writer.write(new Uint8Array(buffer));
179
+ await writer.close();
180
+ ```
59
181
 
60
- The data from `onVideoData` event is a raw H.264 stream. You can process it as you want, or use the following built-in decoders to render it in browsers:
182
+ Example using `pipeTo()`:
61
183
 
62
- * WebCodecs decoder: Uses the [WebCodecs API](https://developer.mozilla.org/en-US/docs/Web/API/WebCodecs_API). The video stream will be decoded into `VideoFrame`s and drawn on a 2D canvas.
63
- * TinyH264 decoder: TinyH264 compiles the old Android H.264 software decoder (now deprecated and removed) into WebAssembly, and wrap it in Web Worker to prevent blocking the main thread. The video stream will be decoded into YUV frames, then converted to RGB using a WebGL shader.
184
+ ```ts
185
+ import { WrapReadableStream } from '@yume-chan/adb';
186
+ import { AdbScrcpyClient } from '@yume-chan/scrcpy';
187
+
188
+ await fetch(SCRCPY_SERVER_URL)
189
+ // `WrapReadableStream` is required because native `ReadableStream` (from `fetch`)
190
+ // doesn't support `pipeTo()` non-native `WritableStream`s
191
+ // (`@yume-chan/adb` is using `web-streams-polyfill`)
192
+ .then(response => new WrapReadableStream(response.body))
193
+ .then(stream => stream.pipeTo(AdbScrcpyClient.pushServer(adb)));
194
+ ```
195
+
196
+ ### Start server on device
197
+
198
+ To start the server, use the `AdbScrcpyClient.start()` method. It automatically sets up port forwarding, launches the server, and connects to it.
199
+
200
+ ```js
201
+ import { AdbScrcpyClient, AdbScrcpyOptions1_22, DEFAULT_SERVER_PATH, ScrcpyOptions1_24 } from '@yume-chan/scrcpy';
202
+ import SCRCPY_SERVER_VERSION from '@yume-chan/scrcpy/bin/version.js';
203
+
204
+ const client: AdbScrcpyClient = await AdbScrcpyClient.start(
205
+ adb,
206
+ DEFAULT_SERVER_PATH,
207
+ SCRCPY_SERVER_VERSION, // If server binary was downloaded manually, must provide the correct version
208
+ new AdbScrcpyOptions1_22(ScrcpyOptions1_24({
209
+ // options
210
+ }))
211
+ );
212
+
213
+ const stdout: ReadableStream<string> = client.stdout;
214
+ const videoPacketStream: ReadableStream<ScrcpyVideoStreamPacket> = client.videoStream;
215
+ const controlMessageSerializer: ScrcpyControlMessageSerializer | undefined = client.controlMessageSerializer;
216
+ const deviceMessageStream: ReadableStream<ScrcpyDeviceMessage> | undefined = client.deviceMessageStream;
217
+
218
+ // to stop the server
219
+ client.close();
220
+ ```
221
+
222
+ ## Using other transportation
223
+
224
+ If you push, start and connect to the server yourself, you can still use this package to serialize/deserialize packets.
225
+
226
+ ### Parsing video packets
227
+
228
+ Requires a `ReadableStream<Uint8Array>` that reads from the video socket, preserving packet boundaries.
229
+
230
+ **NOTE:** Because this package uses `web-streams-polyfill` NPM package's Web Streams API implementation, the provided `ReadableStream` must also be from `web-streams-polyfill` (or another polyfill that doesn't check object prototype when piping).
231
+
232
+ ```ts
233
+ import { ScrcpyOptions1_24, ScrcpyVideoStreamPacket } from '@yume-chan/scrcpy';
234
+
235
+ const videoStream: ReadableStream<Uint8Array>; // get the stream yourself
236
+
237
+ const options = new ScrcpyOptions1_24({
238
+ // use the same version and options
239
+ });
240
+
241
+ const videoPacketStream: ReadableStream<ScrcpyVideoStreamPacket> = videoStream.pipeThrough(options.createVideoStreamTransformer());
242
+ // Read from `videoPacketStream`
243
+ ```
244
+
245
+ ### Sending control messages
246
+
247
+ Requires a `WritableStream<Uint8Array>` that writes to the control socket.
248
+
249
+ Control socket is optional if control is not enabled. Video socket and control socket can run completely separately.
250
+
251
+ ```ts
252
+ import { ScrcpyControlMessageSerializer, ScrcpyOptions1_24 } from '@yume-chan/scrcpy';
253
+
254
+ const controlStream: ReadableWritablePair<Uint8Array, Uint8Array> | undefined // get the stream yourself
255
+
256
+ const options = new ScrcpyOptions1_24({
257
+ // use the same version and options
258
+ });
259
+
260
+ const controlMessageSerializer = new ScrcpyControlMessageSerializer(controlStream.writable, options);
261
+ // Call methods on `controlMessageSerializer`
262
+ controlMessageSerializer.injectText("Hello World!");
263
+ ```
264
+
265
+ ### Reading device messages
266
+
267
+ Requires a `ReadableStream<Uint8Array>` that reads from the control socket.
268
+
269
+ **NOTE:** Because this package uses `web-streams-polyfill` NPM package's Web Streams API implementation, the provided `ReadableStream` must also be from `web-streams-polyfill` (or another polyfill that doesn't check object prototype when piping).
270
+
271
+ ```ts
272
+ import { ScrcpyDeviceMessageDeserializeStream, ScrcpyOptions1_24 } from '@yume-chan/scrcpy';
273
+
274
+ const controlStream: ReadableWritablePair<Uint8Array, Uint8Array> | undefined // get the stream yourself
275
+
276
+ const deviceMessageStream: ReadableStream<ScrcpyDeviceMessage> = controlStream.readable.pipeThrough(new ScrcpyDeviceMessageDeserializeStream());
277
+ ```
64
278
 
65
- | Name | Chrome | Firefox | Safari | Performance | Supported H.264 profile/level |
66
- | ----------------- | ------ | ------- | ------ | ------------------------------- | ----------------------------- |
67
- | WebCodecs decoder | 94 | No | No | High with Hardware acceleration | High level 5 |
68
- | TinyH264 decoder | 57 | 52 | 11 | Poor | Baseline level 4 |
279
+ ## Always read the streams
69
280
 
70
- TinyH264 decoder needs some extra setup:
281
+ In Web Streams API, `ReadableStream` will block its upstream when too many chunks are kept not read. If multiple streams are from the same upstream source, block one stream means blocking all of them.
71
282
 
72
- 1. `tinyh264`, `yuv-buffer` and `yuv-canvas` packages are peer dependencies. You must install them separately.
73
- 2. The bundler you use must support the `new Worker(new URL('./worker.js', import.meta.url))` syntax. It's known to work with Webpack 5.
283
+ For Scrcpy, usually all streams are originated from the same ADB connection (either USB or TCP), so it's important to always read from all streams, even if you don't care about their data.
74
284
 
75
- Example usage:
285
+ ```ts
286
+ // when using `AdbScrcpyClient`
287
+ stdout
288
+ .pipeTo(
289
+ new WritableStream<string>({
290
+ write: (line) => {
291
+ // Handle or ignore the stdout line
292
+ },
293
+ }),
294
+ )
295
+ .catch(() => {})
296
+ .then(() => {
297
+ // Handle server exit
298
+ });
299
+
300
+ videoPacketStream
301
+ .pipeTo(new WritableStream<ScrcpyVideoStreamPacket>({
302
+ write: (packet) => {
303
+ // Handle or ignore the video packet
304
+ },
305
+ }))
306
+ .catch(() => {});
307
+
308
+ deviceMessageStream
309
+ .pipeTo(new WritableStream<ScrcpyDeviceMessage>({
310
+ write: (message) => {
311
+ // Handle or ignore the device message
312
+ },
313
+ }))
314
+ .catch(() => {});
315
+ ```
316
+
317
+ ## Video stream
318
+
319
+ The data from `videoPacketStream` has two types: `configuration` and `frame`. Some fields may not be populated depending on the server version and options.
76
320
 
77
321
  ```ts
78
- const client = new ScrcpyClient(adb);
79
- const decoder = new WebCodecsDecoder(); // Or `new TinyH264Decoder()`
80
- client.onSizeChanged(size => decoder.setSize(size));
81
- client.onVideoData(data => decoder.feed(data));
82
- client.start(serverPath, serverVersion, new ScrcpyOptionsX_XX({
83
- ...options,
84
- codecOptions: new CodecOptions({
85
- profile: decoder.maxProfile,
86
- level: decoder.maxLevel,
87
- }),
88
- }));
89
- document.body.appendChild(decoder.element);
322
+ export interface ScrcpyVideoStreamConfigurationPacket {
323
+ type: 'configuration';
324
+ data: H264Configuration;
325
+ }
326
+
327
+ export interface ScrcpyVideoStreamFramePacket {
328
+ type: 'frame';
329
+ keyframe?: boolean | undefined;
330
+ pts?: bigint | undefined;
331
+ data: Uint8Array;
332
+ }
90
333
  ```
334
+
335
+ When `sendFrameMeta: false` is set, `videoPacketStream` only contains `frame` packets, and only the `data` field in it is available. It's commonly used when feeding into decoders like FFmpeg that can parse the H.264 stream itself, or saving to disk directly.
336
+
337
+ Otherwise, both `configuration` and `frame` packets are available.
338
+
339
+ * `configuration` packets contain the parsed SPS data, and can be used to initialize a video decoder.
340
+ * `pts` (and `keyframe` field from server version 1.23) fields in `frame` packets are available to help decode the video.
341
+
342
+ ## Decode video stream
343
+
344
+ `@yume-chan/scrcpy-decoder-tinyh264` and `@yume-chan/scrcpy-decoder-webcodecs` can be used to decode and render the video stream in Browser environments. Refer to their README files for compatibility and usage information.
package/bin/scrcpy-server CHANGED
Binary file
package/bin/version.d.ts CHANGED
@@ -1 +1 @@
1
- export default '1.24';
1
+ export default '1.25';
package/bin/version.js CHANGED
@@ -1 +1 @@
1
- export default '1.24';
1
+ export default '1.25';
@@ -0,0 +1,41 @@
1
+ import { type Adb, type AdbSubprocessProtocol } from "@yume-chan/adb";
2
+ import { ReadableStream, WrapWritableStream, type ReadableWritablePair } from "@yume-chan/stream-extra";
3
+ import { ScrcpyControlMessageSerializer } from "../control/index.js";
4
+ import { type ScrcpyDeviceMessage } from "../device-message/index.js";
5
+ import { type ScrcpyVideoStreamPacket } from "../options/index.js";
6
+ import { type AdbScrcpyOptions } from "./options/index.js";
7
+ export declare class ScrcpyExitedError extends Error {
8
+ output: string[];
9
+ constructor(output: string[]);
10
+ }
11
+ export declare class AdbScrcpyClient {
12
+ static pushServer(adb: Adb, path?: string): WrapWritableStream<Uint8Array>;
13
+ static start(adb: Adb, path: string, version: string, options: AdbScrcpyOptions<object>): Promise<AdbScrcpyClient>;
14
+ /**
15
+ * This method will modify the given `options`,
16
+ * so don't reuse it elsewhere.
17
+ */
18
+ static getEncoders(adb: Adb, path: string, version: string, options: AdbScrcpyOptions<object>): Promise<string[]>;
19
+ /**
20
+ * This method will modify the given `options`,
21
+ * so don't reuse it elsewhere.
22
+ */
23
+ static getDisplays(adb: Adb, path: string, version: string, options: AdbScrcpyOptions<object>): Promise<number[]>;
24
+ private process;
25
+ private _stdout;
26
+ get stdout(): ReadableStream<string>;
27
+ get exit(): Promise<number>;
28
+ private _screenWidth;
29
+ get screenWidth(): number | undefined;
30
+ private _screenHeight;
31
+ get screenHeight(): number | undefined;
32
+ private _videoStream;
33
+ get videoStream(): ReadableStream<ScrcpyVideoStreamPacket>;
34
+ private _controlMessageSerializer;
35
+ get controlMessageSerializer(): ScrcpyControlMessageSerializer | undefined;
36
+ private _deviceMessageStream;
37
+ get deviceMessageStream(): ReadableStream<ScrcpyDeviceMessage> | undefined;
38
+ constructor(options: AdbScrcpyOptions<object>, process: AdbSubprocessProtocol, stdout: ReadableStream<string>, videoStream: ReadableStream<Uint8Array>, controlStream: ReadableWritablePair<Uint8Array, Uint8Array> | undefined);
39
+ close(): Promise<void>;
40
+ }
41
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/adb/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,KAAK,GAAG,EACR,KAAK,qBAAqB,EAE7B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAIH,cAAc,EAEd,kBAAkB,EAIlB,KAAK,oBAAoB,EAC5B,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAEH,KAAK,mBAAmB,EAC3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAEH,KAAK,uBAAuB,EAC/B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AA0D3D,qBAAa,iBAAkB,SAAQ,KAAK;IACjC,MAAM,EAAE,MAAM,EAAE,CAAC;gBAEL,MAAM,EAAE,MAAM,EAAE;CAItC;AAED,qBAAa,eAAe;WACV,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,SAAsB;WAazC,KAAK,CACrB,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,gBAAgB,CAAC,MAAM,CAAC;IA4ErC;;;OAGG;WACiB,WAAW,CAC3B,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,gBAAgB,CAAC,MAAM,CAAC,GAClC,OAAO,CAAC,MAAM,EAAE,CAAC;IA+BpB;;;OAGG;WACiB,WAAW,CAC3B,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,gBAAgB,CAAC,MAAM,CAAC,GAClC,OAAO,CAAC,MAAM,EAAE,CAAC;IA8BpB,OAAO,CAAC,OAAO,CAAwB;IAEvC,OAAO,CAAC,OAAO,CAAyB;IACxC,IAAW,MAAM,2BAEhB;IAED,IAAW,IAAI,oBAEd;IAED,OAAO,CAAC,YAAY,CAAqB;IACzC,IAAW,WAAW,uBAErB;IAED,OAAO,CAAC,aAAa,CAAqB;IAC1C,IAAW,YAAY,uBAEtB;IAED,OAAO,CAAC,YAAY,CAA0C;IAC9D,IAAW,WAAW,4CAErB;IAED,OAAO,CAAC,yBAAyB,CAEjB;IAChB,IAAW,wBAAwB,+CAElC;IAED,OAAO,CAAC,oBAAoB,CAEZ;IAChB,IAAW,mBAAmB,oDAE7B;gBAGG,OAAO,EAAE,gBAAgB,CAAC,MAAM,CAAC,EACjC,OAAO,EAAE,qBAAqB,EAC9B,MAAM,EAAE,cAAc,CAAC,MAAM,CAAC,EAC9B,WAAW,EAAE,cAAc,CAAC,UAAU,CAAC,EACvC,aAAa,EAAE,oBAAoB,CAAC,UAAU,EAAE,UAAU,CAAC,GAAG,SAAS;IA2B9D,KAAK;CAGrB"}