@yume-chan/scrcpy 2.1.0 → 2.2.0

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 (180) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +3 -0
  3. package/esm/1_15/impl/clipboard-stream.d.ts +2 -1
  4. package/esm/1_15/impl/clipboard-stream.d.ts.map +1 -1
  5. package/esm/1_15/impl/clipboard-stream.js +4 -7
  6. package/esm/1_15/impl/clipboard-stream.js.map +1 -1
  7. package/esm/1_15/impl/scroll-controller.d.ts.map +1 -1
  8. package/esm/1_15/impl/scroll-controller.js +22 -21
  9. package/esm/1_15/impl/scroll-controller.js.map +1 -1
  10. package/esm/1_15/options.d.ts +2 -3
  11. package/esm/1_15/options.d.ts.map +1 -1
  12. package/esm/1_15/options.js +6 -15
  13. package/esm/1_15/options.js.map +1 -1
  14. package/esm/1_17/options.d.ts +2 -3
  15. package/esm/1_17/options.d.ts.map +1 -1
  16. package/esm/1_17/options.js +6 -15
  17. package/esm/1_17/options.js.map +1 -1
  18. package/esm/1_18/options.d.ts +2 -3
  19. package/esm/1_18/options.d.ts.map +1 -1
  20. package/esm/1_18/options.js +6 -15
  21. package/esm/1_18/options.js.map +1 -1
  22. package/esm/1_21/impl/set-clipboard.d.ts +2 -1
  23. package/esm/1_21/impl/set-clipboard.d.ts.map +1 -1
  24. package/esm/1_21/impl/set-clipboard.js +2 -5
  25. package/esm/1_21/impl/set-clipboard.js.map +1 -1
  26. package/esm/1_21/options.d.ts +2 -3
  27. package/esm/1_21/options.d.ts.map +1 -1
  28. package/esm/1_21/options.js +7 -21
  29. package/esm/1_21/options.js.map +1 -1
  30. package/esm/1_22/options.d.ts +2 -3
  31. package/esm/1_22/options.d.ts.map +1 -1
  32. package/esm/1_22/options.js +7 -21
  33. package/esm/1_22/options.js.map +1 -1
  34. package/esm/1_23/options.d.ts +2 -3
  35. package/esm/1_23/options.d.ts.map +1 -1
  36. package/esm/1_23/options.js +7 -21
  37. package/esm/1_23/options.js.map +1 -1
  38. package/esm/1_24/options.d.ts +2 -3
  39. package/esm/1_24/options.d.ts.map +1 -1
  40. package/esm/1_24/options.js +7 -21
  41. package/esm/1_24/options.js.map +1 -1
  42. package/esm/1_25/options.d.ts +2 -3
  43. package/esm/1_25/options.d.ts.map +1 -1
  44. package/esm/1_25/options.js +7 -21
  45. package/esm/1_25/options.js.map +1 -1
  46. package/esm/2_0/options.d.ts +2 -3
  47. package/esm/2_0/options.d.ts.map +1 -1
  48. package/esm/2_0/options.js +7 -21
  49. package/esm/2_0/options.js.map +1 -1
  50. package/esm/2_1/options.d.ts +2 -3
  51. package/esm/2_1/options.d.ts.map +1 -1
  52. package/esm/2_1/options.js +7 -21
  53. package/esm/2_1/options.js.map +1 -1
  54. package/esm/2_2/options.d.ts +2 -3
  55. package/esm/2_2/options.d.ts.map +1 -1
  56. package/esm/2_2/options.js +7 -21
  57. package/esm/2_2/options.js.map +1 -1
  58. package/esm/2_3/options.d.ts +2 -3
  59. package/esm/2_3/options.d.ts.map +1 -1
  60. package/esm/2_3/options.js +7 -21
  61. package/esm/2_3/options.js.map +1 -1
  62. package/esm/2_4/impl/uhid-output-stream.d.ts +2 -1
  63. package/esm/2_4/impl/uhid-output-stream.d.ts.map +1 -1
  64. package/esm/2_4/impl/uhid-output-stream.js +2 -5
  65. package/esm/2_4/impl/uhid-output-stream.js.map +1 -1
  66. package/esm/2_4/options.d.ts +2 -3
  67. package/esm/2_4/options.d.ts.map +1 -1
  68. package/esm/2_4/options.js +8 -27
  69. package/esm/2_4/options.js.map +1 -1
  70. package/esm/2_6/options.d.ts +2 -3
  71. package/esm/2_6/options.d.ts.map +1 -1
  72. package/esm/2_6/options.js +8 -22
  73. package/esm/2_6/options.js.map +1 -1
  74. package/esm/2_7/impl/serialize-uhid-create.d.ts +2 -2
  75. package/esm/2_7/impl/serialize-uhid-create.d.ts.map +1 -1
  76. package/esm/2_7/impl/serialize-uhid-create.js +3 -4
  77. package/esm/2_7/impl/serialize-uhid-create.js.map +1 -1
  78. package/esm/2_7/options.d.ts +2 -3
  79. package/esm/2_7/options.d.ts.map +1 -1
  80. package/esm/2_7/options.js +8 -22
  81. package/esm/2_7/options.js.map +1 -1
  82. package/esm/3_0/options.d.ts +2 -3
  83. package/esm/3_0/options.d.ts.map +1 -1
  84. package/esm/3_0/options.js +8 -22
  85. package/esm/3_0/options.js.map +1 -1
  86. package/esm/3_1/impl/serialize-uhid-create.d.ts +2 -2
  87. package/esm/3_1/impl/serialize-uhid-create.d.ts.map +1 -1
  88. package/esm/3_1/impl/serialize-uhid-create.js +3 -4
  89. package/esm/3_1/impl/serialize-uhid-create.js.map +1 -1
  90. package/esm/3_1/options.d.ts +2 -3
  91. package/esm/3_1/options.d.ts.map +1 -1
  92. package/esm/3_1/options.js +8 -22
  93. package/esm/3_1/options.js.map +1 -1
  94. package/esm/3_2/options.d.ts +2 -3
  95. package/esm/3_2/options.d.ts.map +1 -1
  96. package/esm/3_2/options.js +8 -22
  97. package/esm/3_2/options.js.map +1 -1
  98. package/esm/3_3.d.ts +8 -0
  99. package/esm/3_3.d.ts.map +1 -0
  100. package/esm/3_3.js +7 -0
  101. package/esm/3_3.js.map +1 -0
  102. package/esm/3_3_1/impl/index.d.ts +3 -0
  103. package/esm/3_3_1/impl/index.d.ts.map +1 -0
  104. package/esm/3_3_1/impl/index.js +3 -0
  105. package/esm/3_3_1/impl/index.js.map +1 -0
  106. package/esm/3_3_1/impl/prev.d.ts +2 -0
  107. package/esm/3_3_1/impl/prev.d.ts.map +1 -0
  108. package/esm/3_3_1/impl/prev.js +2 -0
  109. package/esm/3_3_1/impl/prev.js.map +1 -0
  110. package/esm/3_3_1/impl/scroll-controller.d.ts +7 -0
  111. package/esm/3_3_1/impl/scroll-controller.d.ts.map +1 -0
  112. package/esm/3_3_1/impl/scroll-controller.js +15 -0
  113. package/esm/3_3_1/impl/scroll-controller.js.map +1 -0
  114. package/esm/3_3_1/index.d.ts +2 -0
  115. package/esm/3_3_1/index.d.ts.map +1 -0
  116. package/esm/3_3_1/index.js +2 -0
  117. package/esm/3_3_1/index.js.map +1 -0
  118. package/esm/3_3_1/options.d.ts +90 -0
  119. package/esm/3_3_1/options.d.ts.map +1 -0
  120. package/esm/3_3_1/options.js +78 -0
  121. package/esm/3_3_1/options.js.map +1 -0
  122. package/esm/3_3_2.d.ts +8 -0
  123. package/esm/3_3_2.d.ts.map +1 -0
  124. package/esm/3_3_2.js +7 -0
  125. package/esm/3_3_2.js.map +1 -0
  126. package/esm/base/device-message.d.ts +10 -1
  127. package/esm/base/device-message.d.ts.map +1 -1
  128. package/esm/base/device-message.js +40 -1
  129. package/esm/base/device-message.js.map +1 -1
  130. package/esm/base/options.d.ts +2 -3
  131. package/esm/base/options.d.ts.map +1 -1
  132. package/esm/control/message-type-map.d.ts +2 -2
  133. package/esm/control/message-type-map.d.ts.map +1 -1
  134. package/esm/control/message-type-map.js.map +1 -1
  135. package/esm/index.d.ts +3 -0
  136. package/esm/index.d.ts.map +1 -1
  137. package/esm/index.js +3 -0
  138. package/esm/index.js.map +1 -1
  139. package/esm/latest.d.ts +5 -5
  140. package/esm/latest.d.ts.map +1 -1
  141. package/esm/latest.js +3 -3
  142. package/esm/latest.js.map +1 -1
  143. package/package.json +4 -4
  144. package/src/1_15/impl/clipboard-stream.ts +5 -7
  145. package/src/1_15/impl/scroll-controller.ts +22 -19
  146. package/src/1_15/options.ts +9 -21
  147. package/src/1_17/options.ts +9 -21
  148. package/src/1_18/options.ts +9 -21
  149. package/src/1_21/impl/set-clipboard.ts +2 -5
  150. package/src/1_21/options.ts +13 -28
  151. package/src/1_22/options.ts +13 -28
  152. package/src/1_23/options.ts +13 -28
  153. package/src/1_24/options.ts +13 -28
  154. package/src/1_25/options.ts +13 -28
  155. package/src/2_0/options.ts +13 -28
  156. package/src/2_1/options.ts +13 -28
  157. package/src/2_2/options.ts +13 -28
  158. package/src/2_3/options.ts +13 -28
  159. package/src/2_4/impl/uhid-output-stream.ts +3 -6
  160. package/src/2_4/options.ts +16 -35
  161. package/src/2_6/options.ts +16 -29
  162. package/src/2_7/impl/serialize-uhid-create.ts +9 -11
  163. package/src/2_7/options.ts +16 -29
  164. package/src/3_0/options.ts +16 -29
  165. package/src/3_1/impl/serialize-uhid-create.ts +11 -13
  166. package/src/3_1/options.ts +16 -29
  167. package/src/3_2/options.ts +16 -29
  168. package/src/3_3.ts +14 -0
  169. package/src/3_3_1/impl/index.ts +6 -0
  170. package/src/3_3_1/impl/prev.ts +1 -0
  171. package/src/3_3_1/impl/scroll-controller.ts +21 -0
  172. package/src/3_3_1/index.ts +1 -0
  173. package/src/3_3_1/options.ts +177 -0
  174. package/src/3_3_2.ts +14 -0
  175. package/src/base/device-message.ts +50 -1
  176. package/src/base/options.ts +3 -8
  177. package/src/control/message-type-map.ts +3 -3
  178. package/src/index.ts +3 -0
  179. package/src/latest.ts +5 -5
  180. package/tsconfig.build.tsbuildinfo +1 -1
@@ -1,6 +1,5 @@
1
1
  import type { MaybePromiseLike } from "@yume-chan/async";
2
2
  import type { ReadableStream, TransformStream } from "@yume-chan/stream-extra";
3
- import type { AsyncExactReadable, ExactReadable } from "@yume-chan/struct";
4
3
 
5
4
  import type {
6
5
  ScrcpyAudioStreamMetadata,
@@ -13,6 +12,7 @@ import type {
13
12
  ScrcpyScrollController,
14
13
  ScrcpyVideoStream,
15
14
  } from "../base/index.js";
15
+ import { ScrcpyDeviceMessageParsers } from "../base/index.js";
16
16
  import type {
17
17
  ScrcpyBackOrScreenOnControlMessage,
18
18
  ScrcpyInjectTouchControlMessage,
@@ -67,6 +67,11 @@ export class ScrcpyOptions2_4<TVideo extends boolean>
67
67
  return this.#uHidOutput;
68
68
  }
69
69
 
70
+ #deviceMessageParsers = new ScrcpyDeviceMessageParsers();
71
+ get deviceMessageParsers() {
72
+ return this.#deviceMessageParsers;
73
+ }
74
+
70
75
  constructor(init: Init<TVideo>) {
71
76
  this.value = { ...Defaults, ...init } as never;
72
77
 
@@ -76,11 +81,18 @@ export class ScrcpyOptions2_4<TVideo extends boolean>
76
81
 
77
82
  if (this.value.control) {
78
83
  if (this.value.clipboardAutosync) {
79
- this.#clipboard = new ClipboardStream();
80
- this.#ackClipboardHandler = new AckClipboardHandler();
84
+ this.#clipboard = this.#deviceMessageParsers.add(
85
+ new ClipboardStream(),
86
+ );
87
+
88
+ this.#ackClipboardHandler = this.#deviceMessageParsers.add(
89
+ new AckClipboardHandler(),
90
+ );
81
91
  }
82
92
 
83
- this.#uHidOutput = new UHidOutputStream();
93
+ this.#uHidOutput = this.#deviceMessageParsers.add(
94
+ new UHidOutputStream(),
95
+ );
84
96
  }
85
97
  }
86
98
 
@@ -116,37 +128,6 @@ export class ScrcpyOptions2_4<TVideo extends boolean>
116
128
  return parseAudioStreamMetadata(stream, this.value);
117
129
  }
118
130
 
119
- async parseDeviceMessage(
120
- id: number,
121
- stream: ExactReadable | AsyncExactReadable,
122
- ): Promise<void> {
123
- if (await this.#clipboard?.parse(id, stream)) {
124
- return;
125
- }
126
-
127
- if (await this.#ackClipboardHandler?.parse(id, stream)) {
128
- return;
129
- }
130
-
131
- if (await this.#uHidOutput?.parse(id, stream)) {
132
- return;
133
- }
134
-
135
- throw new Error("Unknown device message");
136
- }
137
-
138
- endDeviceMessageStream(e?: unknown): void {
139
- if (e) {
140
- this.#clipboard?.error(e);
141
- this.#ackClipboardHandler?.error(e);
142
- this.#uHidOutput?.error(e);
143
- } else {
144
- this.#clipboard?.close();
145
- this.#ackClipboardHandler?.close();
146
- this.#uHidOutput?.close();
147
- }
148
- }
149
-
150
131
  createMediaStreamTransformer(): TransformStream<
151
132
  Uint8Array,
152
133
  ScrcpyMediaStreamPacket
@@ -1,6 +1,5 @@
1
1
  import type { MaybePromiseLike } from "@yume-chan/async";
2
2
  import type { ReadableStream, TransformStream } from "@yume-chan/stream-extra";
3
- import type { AsyncExactReadable, ExactReadable } from "@yume-chan/struct";
4
3
 
5
4
  import type {
6
5
  ScrcpyAudioStreamMetadata,
@@ -13,6 +12,7 @@ import type {
13
12
  ScrcpyScrollController,
14
13
  ScrcpyVideoStream,
15
14
  } from "../base/index.js";
15
+ import { ScrcpyDeviceMessageParsers } from "../base/index.js";
16
16
  import type {
17
17
  ScrcpyBackOrScreenOnControlMessage,
18
18
  ScrcpyInjectTouchControlMessage,
@@ -67,6 +67,11 @@ export class ScrcpyOptions2_6<TVideo extends boolean>
67
67
  return this.#uHidOutput;
68
68
  }
69
69
 
70
+ #deviceMessageParsers = new ScrcpyDeviceMessageParsers();
71
+ get deviceMessageParsers() {
72
+ return this.#deviceMessageParsers;
73
+ }
74
+
70
75
  constructor(init: Init<TVideo>) {
71
76
  this.value = { ...Defaults, ...init } as never;
72
77
 
@@ -80,11 +85,18 @@ export class ScrcpyOptions2_6<TVideo extends boolean>
80
85
 
81
86
  if (this.value.control) {
82
87
  if (this.value.clipboardAutosync) {
83
- this.#clipboard = new ClipboardStream();
84
- this.#ackClipboardHandler = new AckClipboardHandler();
88
+ this.#clipboard = this.#deviceMessageParsers.add(
89
+ new ClipboardStream(),
90
+ );
91
+
92
+ this.#ackClipboardHandler = this.#deviceMessageParsers.add(
93
+ new AckClipboardHandler(),
94
+ );
85
95
  }
86
96
 
87
- this.#uHidOutput = new UHidOutputStream();
97
+ this.#uHidOutput = this.#deviceMessageParsers.add(
98
+ new UHidOutputStream(),
99
+ );
88
100
  }
89
101
  }
90
102
 
@@ -120,31 +132,6 @@ export class ScrcpyOptions2_6<TVideo extends boolean>
120
132
  return parseAudioStreamMetadata(stream, this.value);
121
133
  }
122
134
 
123
- async parseDeviceMessage(
124
- id: number,
125
- stream: ExactReadable | AsyncExactReadable,
126
- ): Promise<void> {
127
- if (await this.#clipboard?.parse(id, stream)) {
128
- return;
129
- }
130
-
131
- if (await this.#ackClipboardHandler?.parse(id, stream)) {
132
- return;
133
- }
134
-
135
- throw new Error("Unknown device message");
136
- }
137
-
138
- endDeviceMessageStream(e?: unknown): void {
139
- if (e) {
140
- this.#clipboard?.error(e);
141
- this.#ackClipboardHandler?.error(e);
142
- } else {
143
- this.#clipboard?.close();
144
- this.#ackClipboardHandler?.close();
145
- }
146
- }
147
-
148
135
  createMediaStreamTransformer(): TransformStream<
149
136
  Uint8Array,
150
137
  ScrcpyMediaStreamPacket
@@ -1,19 +1,17 @@
1
1
  import type { StructInit } from "@yume-chan/struct";
2
2
  import { buffer, string, struct, u16, u8 } from "@yume-chan/struct";
3
3
 
4
- import { ScrcpyControlMessageType } from "../../base/control-message-type.js";
5
4
  import type { ScrcpyUHidCreateControlMessage } from "../../latest.js";
6
5
 
7
- export const UHidCreateControlMessage = /* #__PURE__ */ (() =>
8
- struct(
9
- {
10
- type: u8(ScrcpyControlMessageType.UHidCreate),
11
- id: u16,
12
- name: string(u8),
13
- data: buffer(u16),
14
- },
15
- { littleEndian: false },
16
- ))();
6
+ export const UHidCreateControlMessage = struct(
7
+ {
8
+ type: u8,
9
+ id: u16,
10
+ name: string(u8),
11
+ data: buffer(u16),
12
+ },
13
+ { littleEndian: false },
14
+ );
17
15
 
18
16
  export type UHidCreateControlMessage = StructInit<
19
17
  typeof UHidCreateControlMessage
@@ -1,6 +1,5 @@
1
1
  import type { MaybePromiseLike } from "@yume-chan/async";
2
2
  import type { ReadableStream, TransformStream } from "@yume-chan/stream-extra";
3
- import type { AsyncExactReadable, ExactReadable } from "@yume-chan/struct";
4
3
 
5
4
  import type {
6
5
  ScrcpyAudioStreamMetadata,
@@ -13,6 +12,7 @@ import type {
13
12
  ScrcpyScrollController,
14
13
  ScrcpyVideoStream,
15
14
  } from "../base/index.js";
15
+ import { ScrcpyDeviceMessageParsers } from "../base/index.js";
16
16
  import type {
17
17
  ScrcpyBackOrScreenOnControlMessage,
18
18
  ScrcpyInjectTouchControlMessage,
@@ -67,6 +67,11 @@ export class ScrcpyOptions2_7<TVideo extends boolean>
67
67
  return this.#uHidOutput;
68
68
  }
69
69
 
70
+ #deviceMessageParsers = new ScrcpyDeviceMessageParsers();
71
+ get deviceMessageParsers() {
72
+ return this.#deviceMessageParsers;
73
+ }
74
+
70
75
  constructor(init: Init<TVideo>) {
71
76
  this.value = { ...Defaults, ...init } as never;
72
77
 
@@ -80,11 +85,18 @@ export class ScrcpyOptions2_7<TVideo extends boolean>
80
85
 
81
86
  if (this.value.control) {
82
87
  if (this.value.clipboardAutosync) {
83
- this.#clipboard = new ClipboardStream();
84
- this.#ackClipboardHandler = new AckClipboardHandler();
88
+ this.#clipboard = this.#deviceMessageParsers.add(
89
+ new ClipboardStream(),
90
+ );
91
+
92
+ this.#ackClipboardHandler = this.#deviceMessageParsers.add(
93
+ new AckClipboardHandler(),
94
+ );
85
95
  }
86
96
 
87
- this.#uHidOutput = new UHidOutputStream();
97
+ this.#uHidOutput = this.#deviceMessageParsers.add(
98
+ new UHidOutputStream(),
99
+ );
88
100
  }
89
101
  }
90
102
 
@@ -120,31 +132,6 @@ export class ScrcpyOptions2_7<TVideo extends boolean>
120
132
  return parseAudioStreamMetadata(stream, this.value);
121
133
  }
122
134
 
123
- async parseDeviceMessage(
124
- id: number,
125
- stream: ExactReadable | AsyncExactReadable,
126
- ): Promise<void> {
127
- if (await this.#clipboard?.parse(id, stream)) {
128
- return;
129
- }
130
-
131
- if (await this.#ackClipboardHandler?.parse(id, stream)) {
132
- return;
133
- }
134
-
135
- throw new Error("Unknown device message");
136
- }
137
-
138
- endDeviceMessageStream(e?: unknown): void {
139
- if (e) {
140
- this.#clipboard?.error(e);
141
- this.#ackClipboardHandler?.error(e);
142
- } else {
143
- this.#clipboard?.close();
144
- this.#ackClipboardHandler?.close();
145
- }
146
- }
147
-
148
135
  createMediaStreamTransformer(): TransformStream<
149
136
  Uint8Array,
150
137
  ScrcpyMediaStreamPacket
@@ -1,6 +1,5 @@
1
1
  import type { MaybePromiseLike } from "@yume-chan/async";
2
2
  import type { ReadableStream, TransformStream } from "@yume-chan/stream-extra";
3
- import type { AsyncExactReadable, ExactReadable } from "@yume-chan/struct";
4
3
 
5
4
  import type {
6
5
  ScrcpyAudioStreamMetadata,
@@ -13,6 +12,7 @@ import type {
13
12
  ScrcpyScrollController,
14
13
  ScrcpyVideoStream,
15
14
  } from "../base/index.js";
15
+ import { ScrcpyDeviceMessageParsers } from "../base/index.js";
16
16
  import type {
17
17
  ScrcpyBackOrScreenOnControlMessage,
18
18
  ScrcpyInjectTouchControlMessage,
@@ -67,6 +67,11 @@ export class ScrcpyOptions3_0<TVideo extends boolean>
67
67
  return this.#uHidOutput;
68
68
  }
69
69
 
70
+ #deviceMessageParsers = new ScrcpyDeviceMessageParsers();
71
+ get deviceMessageParsers() {
72
+ return this.#deviceMessageParsers;
73
+ }
74
+
70
75
  constructor(init: Init<TVideo>) {
71
76
  this.value = { ...Defaults, ...init } as never;
72
77
 
@@ -80,11 +85,18 @@ export class ScrcpyOptions3_0<TVideo extends boolean>
80
85
 
81
86
  if (this.value.control) {
82
87
  if (this.value.clipboardAutosync) {
83
- this.#clipboard = new ClipboardStream();
84
- this.#ackClipboardHandler = new AckClipboardHandler();
88
+ this.#clipboard = this.#deviceMessageParsers.add(
89
+ new ClipboardStream(),
90
+ );
91
+
92
+ this.#ackClipboardHandler = this.#deviceMessageParsers.add(
93
+ new AckClipboardHandler(),
94
+ );
85
95
  }
86
96
 
87
- this.#uHidOutput = new UHidOutputStream();
97
+ this.#uHidOutput = this.#deviceMessageParsers.add(
98
+ new UHidOutputStream(),
99
+ );
88
100
  }
89
101
  }
90
102
 
@@ -120,31 +132,6 @@ export class ScrcpyOptions3_0<TVideo extends boolean>
120
132
  return parseAudioStreamMetadata(stream, this.value);
121
133
  }
122
134
 
123
- async parseDeviceMessage(
124
- id: number,
125
- stream: ExactReadable | AsyncExactReadable,
126
- ): Promise<void> {
127
- if (await this.#clipboard?.parse(id, stream)) {
128
- return;
129
- }
130
-
131
- if (await this.#ackClipboardHandler?.parse(id, stream)) {
132
- return;
133
- }
134
-
135
- throw new Error("Unknown device message");
136
- }
137
-
138
- endDeviceMessageStream(e?: unknown): void {
139
- if (e) {
140
- this.#clipboard?.error(e);
141
- this.#ackClipboardHandler?.error(e);
142
- } else {
143
- this.#clipboard?.close();
144
- this.#ackClipboardHandler?.close();
145
- }
146
- }
147
-
148
135
  createMediaStreamTransformer(): TransformStream<
149
136
  Uint8Array,
150
137
  ScrcpyMediaStreamPacket
@@ -1,21 +1,19 @@
1
1
  import type { StructInit } from "@yume-chan/struct";
2
2
  import { buffer, string, struct, u16, u8 } from "@yume-chan/struct";
3
3
 
4
- import { ScrcpyControlMessageType } from "../../base/control-message-type.js";
5
4
  import type { ScrcpyUHidCreateControlMessage } from "../../latest.js";
6
5
 
7
- export const UHidCreateControlMessage = /* #__PURE__ */ (() =>
8
- struct(
9
- {
10
- type: u8(ScrcpyControlMessageType.UHidCreate),
11
- id: u16,
12
- vendorId: u16,
13
- productId: u16,
14
- name: string(u8),
15
- data: buffer(u16),
16
- },
17
- { littleEndian: false },
18
- ))();
6
+ export const UHidCreateControlMessage = struct(
7
+ {
8
+ type: u8,
9
+ id: u16,
10
+ vendorId: u16,
11
+ productId: u16,
12
+ name: string(u8),
13
+ data: buffer(u16),
14
+ },
15
+ { littleEndian: false },
16
+ );
19
17
 
20
18
  export type UHidCreateControlMessage = StructInit<
21
19
  typeof UHidCreateControlMessage
@@ -1,6 +1,5 @@
1
1
  import type { MaybePromiseLike } from "@yume-chan/async";
2
2
  import type { ReadableStream, TransformStream } from "@yume-chan/stream-extra";
3
- import type { AsyncExactReadable, ExactReadable } from "@yume-chan/struct";
4
3
 
5
4
  import type {
6
5
  ScrcpyAudioStreamMetadata,
@@ -13,6 +12,7 @@ import type {
13
12
  ScrcpyScrollController,
14
13
  ScrcpyVideoStream,
15
14
  } from "../base/index.js";
15
+ import { ScrcpyDeviceMessageParsers } from "../base/index.js";
16
16
  import type {
17
17
  ScrcpyBackOrScreenOnControlMessage,
18
18
  ScrcpyInjectTouchControlMessage,
@@ -67,6 +67,11 @@ export class ScrcpyOptions3_1<TVideo extends boolean>
67
67
  return this.#uHidOutput;
68
68
  }
69
69
 
70
+ #deviceMessageParsers = new ScrcpyDeviceMessageParsers();
71
+ get deviceMessageParsers() {
72
+ return this.#deviceMessageParsers;
73
+ }
74
+
70
75
  constructor(init: Init<TVideo>) {
71
76
  this.value = { ...Defaults, ...init } as never;
72
77
 
@@ -80,11 +85,18 @@ export class ScrcpyOptions3_1<TVideo extends boolean>
80
85
 
81
86
  if (this.value.control) {
82
87
  if (this.value.clipboardAutosync) {
83
- this.#clipboard = new ClipboardStream();
84
- this.#ackClipboardHandler = new AckClipboardHandler();
88
+ this.#clipboard = this.#deviceMessageParsers.add(
89
+ new ClipboardStream(),
90
+ );
91
+
92
+ this.#ackClipboardHandler = this.#deviceMessageParsers.add(
93
+ new AckClipboardHandler(),
94
+ );
85
95
  }
86
96
 
87
- this.#uHidOutput = new UHidOutputStream();
97
+ this.#uHidOutput = this.#deviceMessageParsers.add(
98
+ new UHidOutputStream(),
99
+ );
88
100
  }
89
101
  }
90
102
 
@@ -120,31 +132,6 @@ export class ScrcpyOptions3_1<TVideo extends boolean>
120
132
  return parseAudioStreamMetadata(stream, this.value);
121
133
  }
122
134
 
123
- async parseDeviceMessage(
124
- id: number,
125
- stream: ExactReadable | AsyncExactReadable,
126
- ): Promise<void> {
127
- if (await this.#clipboard?.parse(id, stream)) {
128
- return;
129
- }
130
-
131
- if (await this.#ackClipboardHandler?.parse(id, stream)) {
132
- return;
133
- }
134
-
135
- throw new Error("Unknown device message");
136
- }
137
-
138
- endDeviceMessageStream(e?: unknown): void {
139
- if (e) {
140
- this.#clipboard?.error(e);
141
- this.#ackClipboardHandler?.error(e);
142
- } else {
143
- this.#clipboard?.close();
144
- this.#ackClipboardHandler?.close();
145
- }
146
- }
147
-
148
135
  createMediaStreamTransformer(): TransformStream<
149
136
  Uint8Array,
150
137
  ScrcpyMediaStreamPacket
@@ -1,6 +1,5 @@
1
1
  import type { MaybePromiseLike } from "@yume-chan/async";
2
2
  import type { ReadableStream, TransformStream } from "@yume-chan/stream-extra";
3
- import type { AsyncExactReadable, ExactReadable } from "@yume-chan/struct";
4
3
 
5
4
  import type {
6
5
  ScrcpyAudioStreamMetadata,
@@ -13,6 +12,7 @@ import type {
13
12
  ScrcpyScrollController,
14
13
  ScrcpyVideoStream,
15
14
  } from "../base/index.js";
15
+ import { ScrcpyDeviceMessageParsers } from "../base/index.js";
16
16
  import type {
17
17
  ScrcpyBackOrScreenOnControlMessage,
18
18
  ScrcpyInjectTouchControlMessage,
@@ -67,6 +67,11 @@ export class ScrcpyOptions3_2<TVideo extends boolean>
67
67
  return this.#uHidOutput;
68
68
  }
69
69
 
70
+ #deviceMessageParsers = new ScrcpyDeviceMessageParsers();
71
+ get deviceMessageParsers() {
72
+ return this.#deviceMessageParsers;
73
+ }
74
+
70
75
  constructor(init: Init<TVideo>) {
71
76
  this.value = { ...Defaults, ...init } as never;
72
77
 
@@ -80,11 +85,18 @@ export class ScrcpyOptions3_2<TVideo extends boolean>
80
85
 
81
86
  if (this.value.control) {
82
87
  if (this.value.clipboardAutosync) {
83
- this.#clipboard = new ClipboardStream();
84
- this.#ackClipboardHandler = new AckClipboardHandler();
88
+ this.#clipboard = this.#deviceMessageParsers.add(
89
+ new ClipboardStream(),
90
+ );
91
+
92
+ this.#ackClipboardHandler = this.#deviceMessageParsers.add(
93
+ new AckClipboardHandler(),
94
+ );
85
95
  }
86
96
 
87
- this.#uHidOutput = new UHidOutputStream();
97
+ this.#uHidOutput = this.#deviceMessageParsers.add(
98
+ new UHidOutputStream(),
99
+ );
88
100
  }
89
101
  }
90
102
 
@@ -120,31 +132,6 @@ export class ScrcpyOptions3_2<TVideo extends boolean>
120
132
  return parseAudioStreamMetadata(stream, this.value);
121
133
  }
122
134
 
123
- async parseDeviceMessage(
124
- id: number,
125
- stream: ExactReadable | AsyncExactReadable,
126
- ): Promise<void> {
127
- if (await this.#clipboard?.parse(id, stream)) {
128
- return;
129
- }
130
-
131
- if (await this.#ackClipboardHandler?.parse(id, stream)) {
132
- return;
133
- }
134
-
135
- throw new Error("Unknown device message");
136
- }
137
-
138
- endDeviceMessageStream(e?: unknown): void {
139
- if (e) {
140
- this.#clipboard?.error(e);
141
- this.#ackClipboardHandler?.error(e);
142
- } else {
143
- this.#clipboard?.close();
144
- this.#ackClipboardHandler?.close();
145
- }
146
- }
147
-
148
135
  createMediaStreamTransformer(): TransformStream<
149
136
  Uint8Array,
150
137
  ScrcpyMediaStreamPacket
package/src/3_3.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { ScrcpyOptions3_2 } from "./3_2/index.js";
2
+
3
+ export class ScrcpyOptions3_3<
4
+ TVideo extends boolean,
5
+ > extends ScrcpyOptions3_2<TVideo> {
6
+ constructor(init: ScrcpyOptions3_2.Init<TVideo>) {
7
+ super(init);
8
+ }
9
+ }
10
+
11
+ export namespace ScrcpyOptions3_3 {
12
+ export type Init<TVideo extends boolean = boolean> =
13
+ ScrcpyOptions3_2.Init<TVideo>;
14
+ }
@@ -0,0 +1,6 @@
1
+ export * from "../../3_2/impl/index.js";
2
+
3
+ export {
4
+ createScrollController,
5
+ ScrollController,
6
+ } from "./scroll-controller.js";
@@ -0,0 +1 @@
1
+ export * as PrevImpl from "../../3_2/impl/index.js";
@@ -0,0 +1,21 @@
1
+ import type { ScrcpyScrollController } from "../../base/index.js";
2
+ import type { ScrcpyInjectScrollControlMessage } from "../../latest.js";
3
+
4
+ import { PrevImpl } from "./prev.js";
5
+
6
+ export class ScrollController implements ScrcpyScrollController {
7
+ serializeScrollMessage(
8
+ message: ScrcpyInjectScrollControlMessage,
9
+ ): Uint8Array | undefined {
10
+ message = {
11
+ ...message,
12
+ scrollX: message.scrollX / 16,
13
+ scrollY: message.scrollY / 16,
14
+ };
15
+ return PrevImpl.InjectScrollControlMessage.serialize(message);
16
+ }
17
+ }
18
+
19
+ export function createScrollController(): ScrcpyScrollController {
20
+ return new ScrollController();
21
+ }
@@ -0,0 +1 @@
1
+ export * from "./options.js";