@yume-chan/scrcpy 0.0.16 → 0.0.17

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 (209) hide show
  1. package/CHANGELOG.json +15 -0
  2. package/CHANGELOG.md +9 -1
  3. package/README.md +275 -38
  4. package/esm/adb/client.d.ts +40 -0
  5. package/esm/adb/client.d.ts.map +1 -0
  6. package/esm/adb/client.js +218 -0
  7. package/esm/adb/client.js.map +1 -0
  8. package/esm/adb/connection.d.ts +38 -0
  9. package/esm/adb/connection.d.ts.map +1 -0
  10. package/esm/{connection.js → adb/connection.js} +20 -24
  11. package/esm/adb/connection.js.map +1 -0
  12. package/esm/adb/index.d.ts +4 -0
  13. package/esm/adb/index.d.ts.map +1 -0
  14. package/esm/adb/index.js +4 -0
  15. package/esm/adb/index.js.map +1 -0
  16. package/esm/adb/options/1_16.d.ts +8 -0
  17. package/esm/adb/options/1_16.d.ts.map +1 -0
  18. package/esm/adb/options/1_16.js +20 -0
  19. package/esm/adb/options/1_16.js.map +1 -0
  20. package/esm/adb/options/1_22.d.ts +8 -0
  21. package/esm/adb/options/1_22.d.ts.map +1 -0
  22. package/esm/adb/options/1_22.js +17 -0
  23. package/esm/adb/options/1_22.js.map +1 -0
  24. package/esm/adb/options/index.d.ts +4 -0
  25. package/esm/adb/options/index.d.ts.map +1 -0
  26. package/esm/adb/options/index.js +4 -0
  27. package/esm/adb/options/index.js.map +1 -0
  28. package/esm/adb/options/types.d.ts +23 -0
  29. package/esm/adb/options/types.d.ts.map +1 -0
  30. package/esm/adb/options/types.js +30 -0
  31. package/esm/adb/options/types.js.map +1 -0
  32. package/esm/codec.js +2 -2
  33. package/esm/codec.js.map +1 -1
  34. package/esm/control/index.d.ts +8 -0
  35. package/esm/control/index.d.ts.map +1 -0
  36. package/esm/control/index.js +8 -0
  37. package/esm/control/index.js.map +1 -0
  38. package/esm/control/inject-keycode.d.ts +53 -0
  39. package/esm/control/inject-keycode.d.ts.map +1 -0
  40. package/esm/control/inject-keycode.js +54 -0
  41. package/esm/control/inject-keycode.js.map +1 -0
  42. package/esm/control/inject-text.d.ts +9 -0
  43. package/esm/control/inject-text.d.ts.map +1 -0
  44. package/esm/control/inject-text.js +7 -0
  45. package/esm/control/inject-text.js.map +1 -0
  46. package/esm/control/inject-touch.d.ts +30 -0
  47. package/esm/control/inject-touch.d.ts.map +1 -0
  48. package/esm/control/inject-touch.js +30 -0
  49. package/esm/control/inject-touch.js.map +1 -0
  50. package/esm/control/rotate-device.d.ts +7 -0
  51. package/esm/control/rotate-device.d.ts.map +1 -0
  52. package/esm/control/rotate-device.js +5 -0
  53. package/esm/control/rotate-device.js.map +1 -0
  54. package/esm/control/serializer.d.ts +23 -0
  55. package/esm/control/serializer.d.ts.map +1 -0
  56. package/esm/control/serializer.js +73 -0
  57. package/esm/control/serializer.js.map +1 -0
  58. package/esm/control/set-screen-power-mode.d.ts +12 -0
  59. package/esm/control/set-screen-power-mode.d.ts.map +1 -0
  60. package/esm/control/set-screen-power-mode.js +12 -0
  61. package/esm/control/set-screen-power-mode.js.map +1 -0
  62. package/esm/control/type.d.ts +15 -0
  63. package/esm/control/type.d.ts.map +1 -0
  64. package/esm/control/type.js +19 -0
  65. package/esm/control/type.js.map +1 -0
  66. package/esm/decoder/index.d.ts +27 -3
  67. package/esm/decoder/index.d.ts.map +1 -1
  68. package/esm/decoder/index.js +1 -3
  69. package/esm/decoder/index.js.map +1 -1
  70. package/esm/decoder/tinyh264/index.d.ts +5 -5
  71. package/esm/decoder/tinyh264/index.d.ts.map +1 -1
  72. package/esm/decoder/tinyh264/index.js +4 -4
  73. package/esm/decoder/tinyh264/index.js.map +1 -1
  74. package/esm/decoder/tinyh264/worker.js.map +1 -1
  75. package/esm/decoder/tinyh264/wrapper.d.ts.map +1 -1
  76. package/esm/decoder/tinyh264/wrapper.js +14 -8
  77. package/esm/decoder/tinyh264/wrapper.js.map +1 -1
  78. package/esm/decoder/types.d.ts +1 -27
  79. package/esm/decoder/types.d.ts.map +1 -1
  80. package/esm/decoder/web-codecs/index.d.ts +4 -4
  81. package/esm/decoder/web-codecs/index.d.ts.map +1 -1
  82. package/esm/decoder/web-codecs/index.js +1 -1
  83. package/esm/decoder/web-codecs/index.js.map +1 -1
  84. package/esm/device-message/clipboard.d.ts +10 -0
  85. package/esm/device-message/clipboard.d.ts.map +1 -0
  86. package/esm/device-message/clipboard.js +7 -0
  87. package/esm/device-message/clipboard.js.map +1 -0
  88. package/esm/device-message/index.d.ts +4 -0
  89. package/esm/device-message/index.d.ts.map +1 -0
  90. package/esm/device-message/index.js +4 -0
  91. package/esm/device-message/index.js.map +1 -0
  92. package/esm/device-message/stream.d.ts +7 -0
  93. package/esm/device-message/stream.d.ts.map +1 -0
  94. package/esm/device-message/stream.js +16 -0
  95. package/esm/device-message/stream.js.map +1 -0
  96. package/esm/device-message/type.d.ts +5 -0
  97. package/esm/device-message/type.d.ts.map +1 -0
  98. package/esm/device-message/type.js +7 -0
  99. package/esm/device-message/type.js.map +1 -0
  100. package/esm/index.d.ts +3 -6
  101. package/esm/index.d.ts.map +1 -1
  102. package/esm/index.js +3 -6
  103. package/esm/index.js.map +1 -1
  104. package/esm/options/1_16/codec-options.d.ts +19 -0
  105. package/esm/options/1_16/codec-options.d.ts.map +1 -0
  106. package/esm/options/1_16/codec-options.js +27 -0
  107. package/esm/options/1_16/codec-options.js.map +1 -0
  108. package/esm/options/1_16/index.d.ts +3 -110
  109. package/esm/options/1_16/index.d.ts.map +1 -1
  110. package/esm/options/1_16/index.js +3 -226
  111. package/esm/options/1_16/index.js.map +1 -1
  112. package/esm/options/1_16/options.d.ts +97 -0
  113. package/esm/options/1_16/options.d.ts.map +1 -0
  114. package/esm/options/1_16/options.js +188 -0
  115. package/esm/options/1_16/options.js.map +1 -0
  116. package/esm/options/1_18.d.ts +8 -8
  117. package/esm/options/1_18.d.ts.map +1 -1
  118. package/esm/options/1_18.js +6 -6
  119. package/esm/options/1_18.js.map +1 -1
  120. package/esm/options/1_21.d.ts +1 -1
  121. package/esm/options/1_21.d.ts.map +1 -1
  122. package/esm/options/1_21.js +1 -1
  123. package/esm/options/1_21.js.map +1 -1
  124. package/esm/options/1_22.d.ts +5 -8
  125. package/esm/options/1_22.d.ts.map +1 -1
  126. package/esm/options/1_22.js +4 -17
  127. package/esm/options/1_22.js.map +1 -1
  128. package/esm/options/1_23.d.ts +4 -4
  129. package/esm/options/1_23.d.ts.map +1 -1
  130. package/esm/options/1_23.js +1 -1
  131. package/esm/options/1_23.js.map +1 -1
  132. package/esm/options/1_24.d.ts +1 -1
  133. package/esm/options/1_24.d.ts.map +1 -1
  134. package/esm/options/1_24.js.map +1 -1
  135. package/esm/options/index.d.ts +1 -1
  136. package/esm/options/index.d.ts.map +1 -1
  137. package/esm/options/index.js +1 -1
  138. package/esm/options/index.js.map +1 -1
  139. package/esm/options/types.d.ts +45 -0
  140. package/esm/options/types.d.ts.map +1 -0
  141. package/esm/options/{common.js → types.js} +1 -1
  142. package/esm/options/types.js.map +1 -0
  143. package/package.json +24 -24
  144. package/src/adb/client.ts +292 -0
  145. package/src/{connection.ts → adb/connection.ts} +35 -38
  146. package/src/adb/index.ts +3 -0
  147. package/src/adb/options/1_16.ts +23 -0
  148. package/src/adb/options/1_22.ts +20 -0
  149. package/src/adb/options/index.ts +3 -0
  150. package/src/adb/options/types.ts +55 -0
  151. package/src/control/index.ts +7 -0
  152. package/src/control/inject-keycode.ts +59 -0
  153. package/src/control/inject-text.ts +12 -0
  154. package/src/control/inject-touch.ts +34 -0
  155. package/src/control/rotate-device.ts +10 -0
  156. package/src/control/serializer.ts +86 -0
  157. package/src/control/set-screen-power-mode.ts +17 -0
  158. package/src/control/type.ts +17 -0
  159. package/src/device-message/clipboard.ts +11 -0
  160. package/src/device-message/index.ts +3 -0
  161. package/src/device-message/stream.ts +19 -0
  162. package/src/device-message/type.ts +5 -0
  163. package/src/index.ts +3 -6
  164. package/src/options/1_16/codec-options.ts +48 -0
  165. package/src/options/1_16/index.ts +3 -345
  166. package/src/options/1_16/options.ts +294 -0
  167. package/src/options/1_18.ts +12 -10
  168. package/src/options/1_21.ts +16 -6
  169. package/src/options/1_22.ts +10 -21
  170. package/src/options/1_23.ts +7 -5
  171. package/src/options/1_24.ts +3 -2
  172. package/src/options/index.ts +1 -1
  173. package/src/options/{common.ts → types.ts} +32 -13
  174. package/tsconfig.build.json +3 -0
  175. package/tsconfig.build.tsbuildinfo +1 -0
  176. package/tsconfig.test.tsbuildinfo +1 -0
  177. package/esm/client.d.ts +0 -48
  178. package/esm/client.d.ts.map +0 -1
  179. package/esm/client.js +0 -341
  180. package/esm/client.js.map +0 -1
  181. package/esm/connection.d.ts +0 -37
  182. package/esm/connection.d.ts.map +0 -1
  183. package/esm/connection.js.map +0 -1
  184. package/esm/message.d.ts +0 -98
  185. package/esm/message.d.ts.map +0 -1
  186. package/esm/message.js +0 -98
  187. package/esm/message.js.map +0 -1
  188. package/esm/options/common.d.ts +0 -34
  189. package/esm/options/common.d.ts.map +0 -1
  190. package/esm/options/common.js.map +0 -1
  191. package/esm/push-server.d.ts +0 -6
  192. package/esm/push-server.d.ts.map +0 -1
  193. package/esm/push-server.js +0 -16
  194. package/esm/push-server.js.map +0 -1
  195. package/esm/utils.d.ts +0 -2
  196. package/esm/utils.d.ts.map +0 -1
  197. package/esm/utils.js +0 -6
  198. package/esm/utils.js.map +0 -1
  199. package/src/client.ts +0 -435
  200. package/src/decoder/index.ts +0 -3
  201. package/src/decoder/tinyh264/index.ts +0 -112
  202. package/src/decoder/tinyh264/types.d.ts +0 -137
  203. package/src/decoder/tinyh264/worker.ts +0 -2
  204. package/src/decoder/tinyh264/wrapper.ts +0 -89
  205. package/src/decoder/types.ts +0 -35
  206. package/src/decoder/web-codecs/index.ts +0 -99
  207. package/src/message.ts +0 -113
  208. package/src/push-server.ts +0 -24
  209. package/src/utils.ts +0 -5
@@ -0,0 +1,294 @@
1
+ import { StructDeserializeStream, TransformStream } from '@yume-chan/stream-extra';
2
+ import Struct from '@yume-chan/struct';
3
+
4
+ import { AndroidKeyEventAction, ScrcpyControlMessageType } from '../../control/index.js';
5
+ import type { ScrcpyBackOrScreenOnControlMessage1_18 } from '../1_18.js';
6
+ import type { ScrcpyInjectScrollControlMessage1_22 } from '../1_22.js';
7
+ import { toScrcpyOptionValue, type ScrcpyOptions, type ScrcpyVideoStreamPacket } from '../types.js';
8
+ import { CodecOptions } from './codec-options.js';
9
+ import { parse_sequence_parameter_set } from './sps.js';
10
+
11
+ export enum ScrcpyLogLevel {
12
+ Verbose = 'verbose',
13
+ Debug = 'debug',
14
+ Info = 'info',
15
+ Warn = 'warn',
16
+ Error = 'error',
17
+ }
18
+
19
+ export enum ScrcpyVideoOrientation {
20
+ Initial = -2,
21
+ Unlocked = -1,
22
+ Portrait = 0,
23
+ Landscape = 1,
24
+ PortraitFlipped = 2,
25
+ LandscapeFlipped = 3,
26
+ }
27
+
28
+ export interface ScrcpyOptionsInit1_16 {
29
+ logLevel: ScrcpyLogLevel;
30
+
31
+ /**
32
+ * The maximum value of both width and height.
33
+ */
34
+ maxSize: number;
35
+
36
+ bitRate: number;
37
+
38
+ /**
39
+ * 0 for unlimited.
40
+ *
41
+ * @default 0
42
+ */
43
+ maxFps: number;
44
+
45
+ /**
46
+ * The orientation of the video stream.
47
+ *
48
+ * It will not keep the device screen in specific orientation,
49
+ * only the captured video will in this orientation.
50
+ */
51
+ lockVideoOrientation: ScrcpyVideoOrientation;
52
+
53
+ tunnelForward: boolean;
54
+
55
+ crop: string;
56
+
57
+ /**
58
+ * Send PTS so that the client may record properly
59
+ *
60
+ * Note: When `sendFrameMeta: false` is specified,
61
+ * `onChangeEncoding` event won't fire and `onVideoData` event doesn't
62
+ * merge sps/pps frame and first video frame. Which means you can't use
63
+ * the shipped decoders to render the video
64
+ * (You can still record the stream into a file).
65
+ *
66
+ * @default true
67
+ */
68
+ sendFrameMeta: boolean;
69
+
70
+ /**
71
+ * @default true
72
+ */
73
+ control: boolean;
74
+
75
+ displayId: number;
76
+
77
+ showTouches: boolean;
78
+
79
+ stayAwake: boolean;
80
+
81
+ codecOptions: CodecOptions;
82
+
83
+ encoderName: string;
84
+ }
85
+
86
+ export const VideoPacket =
87
+ new Struct()
88
+ .uint64('pts')
89
+ .uint32('size')
90
+ .uint8Array('data', { lengthField: 'size' });
91
+
92
+ export const NO_PTS = BigInt(1) << BigInt(63);
93
+
94
+ export const ScrcpyBackOrScreenOnControlMessage1_16 =
95
+ new Struct()
96
+ .uint8('type', ScrcpyControlMessageType.BackOrScreenOn as const);
97
+
98
+ export const ScrcpyInjectScrollControlMessage1_16 =
99
+ new Struct()
100
+ .uint8('type', ScrcpyControlMessageType.InjectScroll as const)
101
+ .uint32('pointerX')
102
+ .uint32('pointerY')
103
+ .uint16('screenWidth')
104
+ .uint16('screenHeight')
105
+ .int32('scrollX')
106
+ .int32('scrollY');
107
+
108
+ export class ScrcpyOptions1_16<T extends ScrcpyOptionsInit1_16 = ScrcpyOptionsInit1_16>
109
+ implements ScrcpyOptions<T> {
110
+ public value: Partial<T>;
111
+
112
+ public constructor(value: Partial<ScrcpyOptionsInit1_16>) {
113
+ if (new.target === ScrcpyOptions1_16 &&
114
+ value.logLevel === ScrcpyLogLevel.Verbose) {
115
+ value.logLevel = ScrcpyLogLevel.Debug;
116
+ }
117
+
118
+ if (new.target === ScrcpyOptions1_16 &&
119
+ value.lockVideoOrientation === ScrcpyVideoOrientation.Initial) {
120
+ value.lockVideoOrientation = ScrcpyVideoOrientation.Unlocked;
121
+ }
122
+
123
+ this.value = value as Partial<T>;
124
+ }
125
+
126
+ protected getArgumentOrder(): (keyof T)[] {
127
+ return [
128
+ 'logLevel',
129
+ 'maxSize',
130
+ 'bitRate',
131
+ 'maxFps',
132
+ 'lockVideoOrientation',
133
+ 'tunnelForward',
134
+ 'crop',
135
+ 'sendFrameMeta',
136
+ 'control',
137
+ 'displayId',
138
+ 'showTouches',
139
+ 'stayAwake',
140
+ 'codecOptions',
141
+ 'encoderName',
142
+ ];
143
+ }
144
+
145
+ public getDefaultValue(): T {
146
+ return {
147
+ logLevel: ScrcpyLogLevel.Debug,
148
+ maxSize: 0,
149
+ bitRate: 8_000_000,
150
+ maxFps: 0,
151
+ lockVideoOrientation: ScrcpyVideoOrientation.Unlocked,
152
+ tunnelForward: false,
153
+ crop: '-',
154
+ sendFrameMeta: true,
155
+ control: true,
156
+ displayId: 0,
157
+ showTouches: false,
158
+ stayAwake: false,
159
+ codecOptions: new CodecOptions({}),
160
+ encoderName: '-',
161
+ } as T;
162
+ }
163
+
164
+ public formatServerArguments(): string[] {
165
+ const defaults = this.getDefaultValue();
166
+ return this.getArgumentOrder()
167
+ .map(
168
+ key =>
169
+ toScrcpyOptionValue(this.value[key] || defaults[key], '-')
170
+ );
171
+ }
172
+
173
+ public getOutputEncoderNameRegex(): RegExp {
174
+ return /\s+scrcpy --encoder-name '(.*?)'/;
175
+ }
176
+
177
+ public createVideoStreamTransformer(): TransformStream<Uint8Array, ScrcpyVideoStreamPacket> {
178
+ // Optimized path for video frames only
179
+ if (this.value.sendFrameMeta === false) {
180
+ return new TransformStream({
181
+ transform(chunk, controller) {
182
+ controller.enqueue({
183
+ type: 'frame',
184
+ data: chunk,
185
+ });
186
+ },
187
+ });
188
+ }
189
+
190
+ let header: Uint8Array | undefined;
191
+
192
+ let deserializeStream = new StructDeserializeStream(VideoPacket);
193
+ return {
194
+ writable: deserializeStream.writable,
195
+ readable: deserializeStream.readable.pipeThrough(new TransformStream({
196
+ transform(packet, controller) {
197
+ if (packet.pts === NO_PTS) {
198
+ const sequenceParameterSet = parse_sequence_parameter_set(packet.data.slice().buffer);
199
+
200
+ const {
201
+ profile_idc: profileIndex,
202
+ constraint_set: constraintSet,
203
+ level_idc: levelIndex,
204
+ pic_width_in_mbs_minus1,
205
+ pic_height_in_map_units_minus1,
206
+ frame_mbs_only_flag,
207
+ frame_crop_left_offset,
208
+ frame_crop_right_offset,
209
+ frame_crop_top_offset,
210
+ frame_crop_bottom_offset,
211
+ } = sequenceParameterSet;
212
+
213
+ const encodedWidth = (pic_width_in_mbs_minus1 + 1) * 16;
214
+ const encodedHeight = (pic_height_in_map_units_minus1 + 1) * (2 - frame_mbs_only_flag) * 16;
215
+ const cropLeft = frame_crop_left_offset * 2;
216
+ const cropRight = frame_crop_right_offset * 2;
217
+ const cropTop = frame_crop_top_offset * 2;
218
+ const cropBottom = frame_crop_bottom_offset * 2;
219
+
220
+ const croppedWidth = encodedWidth - cropLeft - cropRight;
221
+ const croppedHeight = encodedHeight - cropTop - cropBottom;
222
+
223
+ header = packet.data;
224
+ controller.enqueue({
225
+ type: 'configuration',
226
+ data: {
227
+ profileIndex,
228
+ constraintSet,
229
+ levelIndex,
230
+ encodedWidth,
231
+ encodedHeight,
232
+ cropLeft,
233
+ cropRight,
234
+ cropTop,
235
+ cropBottom,
236
+ croppedWidth,
237
+ croppedHeight,
238
+ }
239
+ });
240
+ return;
241
+ }
242
+
243
+ let frameData: Uint8Array;
244
+ if (header) {
245
+ frameData = new Uint8Array(header.byteLength + packet.data.byteLength);
246
+ frameData.set(header);
247
+ frameData.set(packet.data, header.byteLength);
248
+ header = undefined;
249
+ } else {
250
+ frameData = packet.data;
251
+ }
252
+
253
+ controller.enqueue({
254
+ type: 'frame',
255
+ pts: packet.pts,
256
+ data: frameData,
257
+ });
258
+ }
259
+ }))
260
+ };
261
+ }
262
+
263
+ public getControlMessageTypes(): ScrcpyControlMessageType[] {
264
+ return [
265
+ /* 0 */ ScrcpyControlMessageType.InjectKeyCode,
266
+ /* 1 */ ScrcpyControlMessageType.InjectText,
267
+ /* 2 */ ScrcpyControlMessageType.InjectTouch,
268
+ /* 3 */ ScrcpyControlMessageType.InjectScroll,
269
+ /* 4 */ ScrcpyControlMessageType.BackOrScreenOn,
270
+ /* 5 */ ScrcpyControlMessageType.ExpandNotificationPanel,
271
+ /* 6 */ ScrcpyControlMessageType.CollapseNotificationPanel,
272
+ /* 7 */ ScrcpyControlMessageType.GetClipboard,
273
+ /* 8 */ ScrcpyControlMessageType.SetClipboard,
274
+ /* 9 */ ScrcpyControlMessageType.SetScreenPowerMode,
275
+ /* 10 */ ScrcpyControlMessageType.RotateDevice,
276
+ ];
277
+ }
278
+
279
+ public serializeBackOrScreenOnControlMessage(
280
+ message: ScrcpyBackOrScreenOnControlMessage1_18,
281
+ ) {
282
+ if (message.action === AndroidKeyEventAction.Down) {
283
+ return ScrcpyBackOrScreenOnControlMessage1_16.serialize(message);
284
+ }
285
+
286
+ return undefined;
287
+ }
288
+
289
+ public serializeInjectScrollControlMessage(
290
+ message: ScrcpyInjectScrollControlMessage1_22,
291
+ ): Uint8Array {
292
+ return ScrcpyInjectScrollControlMessage1_16.serialize(message);
293
+ }
294
+ }
@@ -1,19 +1,21 @@
1
- import Struct, { placeholder } from "@yume-chan/struct";
2
- import { AndroidKeyEventAction, ScrcpyControlMessageType } from "../message.js";
3
- import { ScrcpyBackOrScreenOnEvent1_16, ScrcpyOptions1_16, type ScrcpyOptionsInit1_16 } from "./1_16/index.js";
1
+ import Struct, { placeholder } from '@yume-chan/struct';
2
+
3
+ import { AndroidKeyEventAction, ScrcpyControlMessageType } from '../control/index.js';
4
+ import { ScrcpyBackOrScreenOnControlMessage1_16, ScrcpyOptions1_16, type ScrcpyOptionsInit1_16 } from './1_16/options.js';
4
5
 
5
6
  export interface ScrcpyOptionsInit1_18 extends ScrcpyOptionsInit1_16 {
6
7
  powerOffOnClose: boolean;
7
8
  }
8
9
 
9
- export const ScrcpyBackOrScreenOnEvent1_18 =
10
+ export const ScrcpyBackOrScreenOnControlMessage1_18 =
10
11
  new Struct()
11
- .fields(ScrcpyBackOrScreenOnEvent1_16)
12
+ .fields(ScrcpyBackOrScreenOnControlMessage1_16)
12
13
  .uint8('action', placeholder<AndroidKeyEventAction>());
13
14
 
14
- export type ScrcpyBackOrScreenOnEvent1_18 = typeof ScrcpyBackOrScreenOnEvent1_18["TInit"];
15
+ export type ScrcpyBackOrScreenOnControlMessage1_18 = typeof ScrcpyBackOrScreenOnControlMessage1_18['TInit'];
15
16
 
16
- export class ScrcpyOptions1_18<T extends ScrcpyOptionsInit1_18 = ScrcpyOptionsInit1_18> extends ScrcpyOptions1_16<T> {
17
+ export class ScrcpyOptions1_18<T extends ScrcpyOptionsInit1_18 = ScrcpyOptionsInit1_18>
18
+ extends ScrcpyOptions1_16<T> {
17
19
  constructor(value: Partial<ScrcpyOptionsInit1_18>) {
18
20
  super(value);
19
21
  }
@@ -22,7 +24,7 @@ export class ScrcpyOptions1_18<T extends ScrcpyOptionsInit1_18 = ScrcpyOptionsIn
22
24
  return super.getArgumentOrder().concat(['powerOffOnClose']);
23
25
  }
24
26
 
25
- protected override getDefaultValue(): T {
27
+ public override getDefaultValue(): T {
26
28
  return {
27
29
  ...super.getDefaultValue(),
28
30
  powerOffOnClose: false,
@@ -54,8 +56,8 @@ export class ScrcpyOptions1_18<T extends ScrcpyOptionsInit1_18 = ScrcpyOptionsIn
54
56
  }
55
57
 
56
58
  public override serializeBackOrScreenOnControlMessage(
57
- message: ScrcpyBackOrScreenOnEvent1_18,
59
+ message: ScrcpyBackOrScreenOnControlMessage1_18,
58
60
  ) {
59
- return ScrcpyBackOrScreenOnEvent1_18.serialize(message);
61
+ return ScrcpyBackOrScreenOnControlMessage1_18.serialize(message);
60
62
  }
61
63
  }
@@ -1,7 +1,7 @@
1
1
  // cspell: ignore autosync
2
2
 
3
3
  import { ScrcpyOptions1_18, type ScrcpyOptionsInit1_18 } from './1_18.js';
4
- import { toScrcpyOptionValue } from "./common.js";
4
+ import { toScrcpyOptionValue } from './types.js';
5
5
 
6
6
  export interface ScrcpyOptionsInit1_21 extends ScrcpyOptionsInit1_18 {
7
7
  clipboardAutosync?: boolean;
@@ -11,12 +11,13 @@ function toSnakeCase(input: string): string {
11
11
  return input.replace(/([A-Z])/g, '_$1').toLowerCase();
12
12
  }
13
13
 
14
- export class ScrcpyOptions1_21<T extends ScrcpyOptionsInit1_21 = ScrcpyOptionsInit1_21> extends ScrcpyOptions1_18<T> {
14
+ export class ScrcpyOptions1_21<T extends ScrcpyOptionsInit1_21 = ScrcpyOptionsInit1_21>
15
+ extends ScrcpyOptions1_18<T> {
15
16
  public constructor(init: Partial<ScrcpyOptionsInit1_21>) {
16
17
  super(init);
17
18
  }
18
19
 
19
- protected override getDefaultValue(): T {
20
+ public override getDefaultValue(): T {
20
21
  return {
21
22
  ...super.getDefaultValue(),
22
23
  clipboardAutosync: true,
@@ -27,8 +28,17 @@ export class ScrcpyOptions1_21<T extends ScrcpyOptionsInit1_21 = ScrcpyOptionsIn
27
28
  // 1.21 changed the format of arguments
28
29
  // So `getArgumentOrder()` is no longer needed
29
30
  return Object.entries(this.value)
30
- .map(([key, value]) => [key, toScrcpyOptionValue(value, undefined)] as const)
31
- .filter((pair): pair is [string, string] => pair[1] !== undefined)
32
- .map(([key, value]) => `${toSnakeCase(key)}=${value}`);
31
+ .map(
32
+ ([key, value]) =>
33
+ [key, toScrcpyOptionValue(value, undefined)] as const
34
+ )
35
+ .filter(
36
+ (pair): pair is [string, string] =>
37
+ pair[1] !== undefined
38
+ )
39
+ .map(
40
+ ([key, value]) =>
41
+ `${toSnakeCase(key)}=${value}`
42
+ );
33
43
  }
34
44
  }
@@ -1,8 +1,7 @@
1
- import type { Adb } from "@yume-chan/adb";
2
- import Struct from "@yume-chan/struct";
3
- import { ScrcpyClientForwardConnection, ScrcpyClientReverseConnection, type ScrcpyClientConnection } from "../connection.js";
4
- import { ScrcpyInjectScrollControlMessage1_16 } from "./1_16/index.js";
5
- import { ScrcpyOptions1_21, type ScrcpyOptionsInit1_21 } from "./1_21.js";
1
+ import Struct from '@yume-chan/struct';
2
+
3
+ import { ScrcpyInjectScrollControlMessage1_16 } from './1_16/options.js';
4
+ import { ScrcpyOptions1_21, type ScrcpyOptionsInit1_21 } from './1_21.js';
6
5
 
7
6
  export interface ScrcpyOptionsInit1_22 extends ScrcpyOptionsInit1_21 {
8
7
  downsizeOnError: boolean;
@@ -32,11 +31,13 @@ export interface ScrcpyOptionsInit1_22 extends ScrcpyOptionsInit1_21 {
32
31
  export const ScrcpyInjectScrollControlMessage1_22 =
33
32
  new Struct()
34
33
  .fields(ScrcpyInjectScrollControlMessage1_16)
35
- .int32("buttons");
34
+ .int32('buttons');
36
35
 
37
- export type ScrcpyInjectScrollControlMessage1_22 = typeof ScrcpyInjectScrollControlMessage1_22["TInit"];
36
+ export type ScrcpyInjectScrollControlMessage1_22 =
37
+ typeof ScrcpyInjectScrollControlMessage1_22['TInit'];
38
38
 
39
- export class ScrcpyOptions1_22<T extends ScrcpyOptionsInit1_22 = ScrcpyOptionsInit1_22> extends ScrcpyOptions1_21<T> {
39
+ export class ScrcpyOptions1_22<T extends ScrcpyOptionsInit1_22 = ScrcpyOptionsInit1_22>
40
+ extends ScrcpyOptions1_21<T> {
40
41
  public constructor(init: Partial<ScrcpyOptionsInit1_22>) {
41
42
  if (init.rawVideoStream) {
42
43
  // Set implied options for client-side processing
@@ -48,7 +49,7 @@ export class ScrcpyOptions1_22<T extends ScrcpyOptionsInit1_22 = ScrcpyOptionsIn
48
49
  super(init);
49
50
  }
50
51
 
51
- protected override getDefaultValue(): T {
52
+ public override getDefaultValue(): T {
52
53
  return {
53
54
  ...super.getDefaultValue(),
54
55
  downsizeOnError: true,
@@ -58,18 +59,6 @@ export class ScrcpyOptions1_22<T extends ScrcpyOptionsInit1_22 = ScrcpyOptionsIn
58
59
  };
59
60
  }
60
61
 
61
- public override createConnection(device: Adb): ScrcpyClientConnection {
62
- const options = {
63
- ...this.getDefaultValue(),
64
- ...this.value,
65
- };
66
- if (this.value.tunnelForward) {
67
- return new ScrcpyClientForwardConnection(device, options);
68
- } else {
69
- return new ScrcpyClientReverseConnection(device, options);
70
- }
71
- }
72
-
73
62
  public override serializeInjectScrollControlMessage(
74
63
  message: ScrcpyInjectScrollControlMessage1_22,
75
64
  ): Uint8Array {
@@ -1,6 +1,7 @@
1
- import { TransformStream } from "@yume-chan/adb";
1
+ import { TransformStream } from '@yume-chan/stream-extra';
2
+
2
3
  import { ScrcpyOptions1_22, type ScrcpyOptionsInit1_22 } from './1_22.js';
3
- import type { VideoStreamPacket } from "./common.js";
4
+ import type { ScrcpyVideoStreamPacket } from './types.js';
4
5
 
5
6
  export interface ScrcpyOptionsInit1_23 extends ScrcpyOptionsInit1_22 {
6
7
  cleanup: boolean;
@@ -8,19 +9,20 @@ export interface ScrcpyOptionsInit1_23 extends ScrcpyOptionsInit1_22 {
8
9
 
9
10
  const KEYFRAME_PTS = BigInt(1) << BigInt(62);
10
11
 
11
- export class ScrcpyOptions1_23<T extends ScrcpyOptionsInit1_23 = ScrcpyOptionsInit1_23> extends ScrcpyOptions1_22<T> {
12
+ export class ScrcpyOptions1_23<T extends ScrcpyOptionsInit1_23 = ScrcpyOptionsInit1_23>
13
+ extends ScrcpyOptions1_22<T> {
12
14
  public constructor(init: Partial<ScrcpyOptionsInit1_23>) {
13
15
  super(init);
14
16
  }
15
17
 
16
- protected override getDefaultValue(): T {
18
+ public override getDefaultValue(): T {
17
19
  return {
18
20
  ...super.getDefaultValue(),
19
21
  cleanup: true,
20
22
  };
21
23
  }
22
24
 
23
- public override createVideoStreamTransformer(): TransformStream<Uint8Array, VideoStreamPacket> {
25
+ public override createVideoStreamTransformer(): TransformStream<Uint8Array, ScrcpyVideoStreamPacket> {
24
26
  const superStream = super.createVideoStreamTransformer();
25
27
  return {
26
28
  writable: superStream.writable,
@@ -4,12 +4,13 @@ export interface ScrcpyOptionsInit1_24 extends ScrcpyOptionsInit1_23 {
4
4
  powerOn: boolean;
5
5
  }
6
6
 
7
- export class ScrcpyOptions1_24<T extends ScrcpyOptionsInit1_24 = ScrcpyOptionsInit1_24> extends ScrcpyOptions1_23<T> {
7
+ export class ScrcpyOptions1_24<T extends ScrcpyOptionsInit1_24 = ScrcpyOptionsInit1_24>
8
+ extends ScrcpyOptions1_23<T> {
8
9
  public constructor(init: Partial<ScrcpyOptionsInit1_24>) {
9
10
  super(init);
10
11
  }
11
12
 
12
- protected override getDefaultValue(): T {
13
+ public override getDefaultValue(): T {
13
14
  return {
14
15
  ...super.getDefaultValue(),
15
16
  powerOn: true,
@@ -4,4 +4,4 @@ export * from './1_21.js';
4
4
  export * from './1_22.js';
5
5
  export * from './1_23.js';
6
6
  export * from './1_24.js';
7
- export * from './common.js';
7
+ export * from './types.js';
@@ -1,9 +1,8 @@
1
- import type { Adb, TransformStream } from "@yume-chan/adb";
2
- import type { ScrcpyClientConnection } from "../connection.js";
3
- import type { H264Configuration } from "../decoder/index.js";
4
- import type { ScrcpyControlMessageType } from "../message.js";
5
- import type { ScrcpyBackOrScreenOnEvent1_18 } from "./1_18.js";
6
- import type { ScrcpyInjectScrollControlMessage1_22 } from "./1_22.js";
1
+ import type { TransformStream } from '@yume-chan/stream-extra';
2
+
3
+ import type { ScrcpyControlMessageType } from '../control/index.js';
4
+ import type { ScrcpyBackOrScreenOnControlMessage1_18 } from './1_18.js';
5
+ import type { ScrcpyInjectScrollControlMessage1_22 } from './1_22.js';
7
6
 
8
7
  export const DEFAULT_SERVER_PATH = '/data/local/tmp/scrcpy-server.jar';
9
8
 
@@ -29,35 +28,55 @@ export function toScrcpyOptionValue<T>(value: any, empty: T): string | T {
29
28
  return `${value}`;
30
29
  }
31
30
 
32
- export interface VideoStreamConfigurationPacket {
31
+ export interface H264Configuration {
32
+ profileIndex: number;
33
+ constraintSet: number;
34
+ levelIndex: number;
35
+
36
+ encodedWidth: number;
37
+ encodedHeight: number;
38
+
39
+ cropLeft: number;
40
+ cropRight: number;
41
+
42
+ cropTop: number;
43
+ cropBottom: number;
44
+
45
+ croppedWidth: number;
46
+ croppedHeight: number;
47
+ }
48
+
49
+ export interface ScrcpyVideoStreamConfigurationPacket {
33
50
  type: 'configuration';
34
51
  data: H264Configuration;
35
52
  }
36
53
 
37
- export interface VideoStreamFramePacket {
54
+ export interface ScrcpyVideoStreamFramePacket {
38
55
  type: 'frame';
39
56
  keyframe?: boolean | undefined;
40
57
  pts?: bigint | undefined;
41
58
  data: Uint8Array;
42
59
  }
43
60
 
44
- export type VideoStreamPacket = VideoStreamConfigurationPacket | VideoStreamFramePacket;
61
+ export type ScrcpyVideoStreamPacket =
62
+ | ScrcpyVideoStreamConfigurationPacket
63
+ | ScrcpyVideoStreamFramePacket;
45
64
 
46
65
  export interface ScrcpyOptions<T> {
47
66
  value: Partial<T>;
48
67
 
68
+ getDefaultValue(): T;
69
+
49
70
  formatServerArguments(): string[];
50
71
 
51
72
  getOutputEncoderNameRegex(): RegExp;
52
73
 
53
- createConnection(adb: Adb): ScrcpyClientConnection;
54
-
55
- createVideoStreamTransformer(): TransformStream<Uint8Array, VideoStreamPacket>;
74
+ createVideoStreamTransformer(): TransformStream<Uint8Array, ScrcpyVideoStreamPacket>;
56
75
 
57
76
  getControlMessageTypes(): ScrcpyControlMessageType[];
58
77
 
59
78
  serializeBackOrScreenOnControlMessage(
60
- message: ScrcpyBackOrScreenOnEvent1_18,
79
+ message: ScrcpyBackOrScreenOnControlMessage1_18,
61
80
  ): Uint8Array | undefined;
62
81
 
63
82
  serializeInjectScrollControlMessage(
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "./node_modules/@yume-chan/ts-package-builder/tsconfig.base.json"
3
+ }