@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
  ScrcpyControlMessageType,
@@ -12,6 +11,7 @@ import type {
12
11
  ScrcpyScrollController,
13
12
  ScrcpyVideoStream,
14
13
  } from "../base/index.js";
14
+ import { ScrcpyDeviceMessageParsers } from "../base/index.js";
15
15
  import type {
16
16
  ScrcpyBackOrScreenOnControlMessage,
17
17
  ScrcpyInjectTouchControlMessage,
@@ -55,12 +55,22 @@ export class ScrcpyOptions1_21
55
55
 
56
56
  #ackClipboardHandler: AckClipboardHandler | undefined;
57
57
 
58
+ #deviceMessageParsers = new ScrcpyDeviceMessageParsers();
59
+ get deviceMessageParsers() {
60
+ return this.#deviceMessageParsers;
61
+ }
62
+
58
63
  constructor(init: Init) {
59
64
  this.value = { ...Defaults, ...init };
60
65
 
61
66
  if (this.value.control && this.value.clipboardAutosync) {
62
- this.#clipboard = new ClipboardStream();
63
- this.#ackClipboardHandler = new AckClipboardHandler();
67
+ this.#clipboard = this.#deviceMessageParsers.add(
68
+ new ClipboardStream(),
69
+ );
70
+
71
+ this.#ackClipboardHandler = this.#deviceMessageParsers.add(
72
+ new AckClipboardHandler(),
73
+ );
64
74
  }
65
75
  }
66
76
 
@@ -90,31 +100,6 @@ export class ScrcpyOptions1_21
90
100
  return parseVideoStreamMetadata(stream);
91
101
  }
92
102
 
93
- async parseDeviceMessage(
94
- id: number,
95
- stream: ExactReadable | AsyncExactReadable,
96
- ): Promise<void> {
97
- if (await this.#clipboard?.parse(id, stream)) {
98
- return;
99
- }
100
-
101
- if (await this.#ackClipboardHandler?.parse(id, stream)) {
102
- return;
103
- }
104
-
105
- throw new Error("Unknown device message");
106
- }
107
-
108
- endDeviceMessageStream(e?: unknown): void {
109
- if (e) {
110
- this.#clipboard?.error(e);
111
- this.#ackClipboardHandler?.error(e);
112
- } else {
113
- this.#clipboard?.close();
114
- this.#ackClipboardHandler?.close();
115
- }
116
- }
117
-
118
103
  createMediaStreamTransformer(): TransformStream<
119
104
  Uint8Array,
120
105
  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
  ScrcpyControlMessageType,
@@ -12,6 +11,7 @@ import type {
12
11
  ScrcpyScrollController,
13
12
  ScrcpyVideoStream,
14
13
  } from "../base/index.js";
14
+ import { ScrcpyDeviceMessageParsers } from "../base/index.js";
15
15
  import type {
16
16
  ScrcpyBackOrScreenOnControlMessage,
17
17
  ScrcpyInjectTouchControlMessage,
@@ -55,12 +55,22 @@ export class ScrcpyOptions1_22
55
55
 
56
56
  #ackClipboardHandler: AckClipboardHandler | undefined;
57
57
 
58
+ #deviceMessageParsers = new ScrcpyDeviceMessageParsers();
59
+ get deviceMessageParsers() {
60
+ return this.#deviceMessageParsers;
61
+ }
62
+
58
63
  constructor(init: Init) {
59
64
  this.value = { ...Defaults, ...init };
60
65
 
61
66
  if (this.value.control && this.value.clipboardAutosync) {
62
- this.#clipboard = new ClipboardStream();
63
- this.#ackClipboardHandler = new AckClipboardHandler();
67
+ this.#clipboard = this.#deviceMessageParsers.add(
68
+ new ClipboardStream(),
69
+ );
70
+
71
+ this.#ackClipboardHandler = this.#deviceMessageParsers.add(
72
+ new AckClipboardHandler(),
73
+ );
64
74
  }
65
75
  }
66
76
 
@@ -90,31 +100,6 @@ export class ScrcpyOptions1_22
90
100
  return parseVideoStreamMetadata(this.value, stream);
91
101
  }
92
102
 
93
- async parseDeviceMessage(
94
- id: number,
95
- stream: ExactReadable | AsyncExactReadable,
96
- ): Promise<void> {
97
- if (await this.#clipboard?.parse(id, stream)) {
98
- return;
99
- }
100
-
101
- if (await this.#ackClipboardHandler?.parse(id, stream)) {
102
- return;
103
- }
104
-
105
- throw new Error("Unknown device message");
106
- }
107
-
108
- endDeviceMessageStream(e?: unknown): void {
109
- if (e) {
110
- this.#clipboard?.error(e);
111
- this.#ackClipboardHandler?.error(e);
112
- } else {
113
- this.#clipboard?.close();
114
- this.#ackClipboardHandler?.close();
115
- }
116
- }
117
-
118
103
  createMediaStreamTransformer(): TransformStream<
119
104
  Uint8Array,
120
105
  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
  ScrcpyControlMessageType,
@@ -12,6 +11,7 @@ import type {
12
11
  ScrcpyScrollController,
13
12
  ScrcpyVideoStream,
14
13
  } from "../base/index.js";
14
+ import { ScrcpyDeviceMessageParsers } from "../base/index.js";
15
15
  import type {
16
16
  ScrcpyBackOrScreenOnControlMessage,
17
17
  ScrcpyInjectTouchControlMessage,
@@ -55,12 +55,22 @@ export class ScrcpyOptions1_23
55
55
 
56
56
  #ackClipboardHandler: AckClipboardHandler | undefined;
57
57
 
58
+ #deviceMessageParsers = new ScrcpyDeviceMessageParsers();
59
+ get deviceMessageParsers() {
60
+ return this.#deviceMessageParsers;
61
+ }
62
+
58
63
  constructor(init: Init) {
59
64
  this.value = { ...Defaults, ...init };
60
65
 
61
66
  if (this.value.control && this.value.clipboardAutosync) {
62
- this.#clipboard = new ClipboardStream();
63
- this.#ackClipboardHandler = new AckClipboardHandler();
67
+ this.#clipboard = this.#deviceMessageParsers.add(
68
+ new ClipboardStream(),
69
+ );
70
+
71
+ this.#ackClipboardHandler = this.#deviceMessageParsers.add(
72
+ new AckClipboardHandler(),
73
+ );
64
74
  }
65
75
  }
66
76
 
@@ -90,31 +100,6 @@ export class ScrcpyOptions1_23
90
100
  return parseVideoStreamMetadata(this.value, stream);
91
101
  }
92
102
 
93
- async parseDeviceMessage(
94
- id: number,
95
- stream: ExactReadable | AsyncExactReadable,
96
- ): Promise<void> {
97
- if (await this.#clipboard?.parse(id, stream)) {
98
- return;
99
- }
100
-
101
- if (await this.#ackClipboardHandler?.parse(id, stream)) {
102
- return;
103
- }
104
-
105
- throw new Error("Unknown device message");
106
- }
107
-
108
- endDeviceMessageStream(e?: unknown): void {
109
- if (e) {
110
- this.#clipboard?.error(e);
111
- this.#ackClipboardHandler?.error(e);
112
- } else {
113
- this.#clipboard?.close();
114
- this.#ackClipboardHandler?.close();
115
- }
116
- }
117
-
118
103
  createMediaStreamTransformer(): TransformStream<
119
104
  Uint8Array,
120
105
  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
  ScrcpyControlMessageType,
@@ -12,6 +11,7 @@ import type {
12
11
  ScrcpyScrollController,
13
12
  ScrcpyVideoStream,
14
13
  } from "../base/index.js";
14
+ import { ScrcpyDeviceMessageParsers } from "../base/index.js";
15
15
  import type {
16
16
  ScrcpyBackOrScreenOnControlMessage,
17
17
  ScrcpyInjectTouchControlMessage,
@@ -55,12 +55,22 @@ export class ScrcpyOptions1_24
55
55
 
56
56
  #ackClipboardHandler: AckClipboardHandler | undefined;
57
57
 
58
+ #deviceMessageParsers = new ScrcpyDeviceMessageParsers();
59
+ get deviceMessageParsers() {
60
+ return this.#deviceMessageParsers;
61
+ }
62
+
58
63
  constructor(init: Init) {
59
64
  this.value = { ...Defaults, ...init };
60
65
 
61
66
  if (this.value.control && this.value.clipboardAutosync) {
62
- this.#clipboard = new ClipboardStream();
63
- this.#ackClipboardHandler = new AckClipboardHandler();
67
+ this.#clipboard = this.#deviceMessageParsers.add(
68
+ new ClipboardStream(),
69
+ );
70
+
71
+ this.#ackClipboardHandler = this.#deviceMessageParsers.add(
72
+ new AckClipboardHandler(),
73
+ );
64
74
  }
65
75
  }
66
76
 
@@ -90,31 +100,6 @@ export class ScrcpyOptions1_24
90
100
  return parseVideoStreamMetadata(this.value, stream);
91
101
  }
92
102
 
93
- async parseDeviceMessage(
94
- id: number,
95
- stream: ExactReadable | AsyncExactReadable,
96
- ): Promise<void> {
97
- if (await this.#clipboard?.parse(id, stream)) {
98
- return;
99
- }
100
-
101
- if (await this.#ackClipboardHandler?.parse(id, stream)) {
102
- return;
103
- }
104
-
105
- throw new Error("Unknown device message");
106
- }
107
-
108
- endDeviceMessageStream(e?: unknown): void {
109
- if (e) {
110
- this.#clipboard?.error(e);
111
- this.#ackClipboardHandler?.error(e);
112
- } else {
113
- this.#clipboard?.close();
114
- this.#ackClipboardHandler?.close();
115
- }
116
- }
117
-
118
103
  createMediaStreamTransformer(): TransformStream<
119
104
  Uint8Array,
120
105
  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
  ScrcpyControlMessageType,
@@ -12,6 +11,7 @@ import type {
12
11
  ScrcpyScrollController,
13
12
  ScrcpyVideoStream,
14
13
  } from "../base/index.js";
14
+ import { ScrcpyDeviceMessageParsers } from "../base/index.js";
15
15
  import type {
16
16
  ScrcpyBackOrScreenOnControlMessage,
17
17
  ScrcpyInjectTouchControlMessage,
@@ -55,12 +55,22 @@ export class ScrcpyOptions1_25
55
55
 
56
56
  #ackClipboardHandler: AckClipboardHandler | undefined;
57
57
 
58
+ #deviceMessageParsers = new ScrcpyDeviceMessageParsers();
59
+ get deviceMessageParsers() {
60
+ return this.#deviceMessageParsers;
61
+ }
62
+
58
63
  constructor(init: Init) {
59
64
  this.value = { ...Defaults, ...init };
60
65
 
61
66
  if (this.value.control && this.value.clipboardAutosync) {
62
- this.#clipboard = new ClipboardStream();
63
- this.#ackClipboardHandler = new AckClipboardHandler();
67
+ this.#clipboard = this.#deviceMessageParsers.add(
68
+ new ClipboardStream(),
69
+ );
70
+
71
+ this.#ackClipboardHandler = this.#deviceMessageParsers.add(
72
+ new AckClipboardHandler(),
73
+ );
64
74
  }
65
75
  }
66
76
 
@@ -90,31 +100,6 @@ export class ScrcpyOptions1_25
90
100
  return parseVideoStreamMetadata(this.value, stream);
91
101
  }
92
102
 
93
- async parseDeviceMessage(
94
- id: number,
95
- stream: ExactReadable | AsyncExactReadable,
96
- ): Promise<void> {
97
- if (await this.#clipboard?.parse(id, stream)) {
98
- return;
99
- }
100
-
101
- if (await this.#ackClipboardHandler?.parse(id, stream)) {
102
- return;
103
- }
104
-
105
- throw new Error("Unknown device message");
106
- }
107
-
108
- endDeviceMessageStream(e?: unknown): void {
109
- if (e) {
110
- this.#clipboard?.error(e);
111
- this.#ackClipboardHandler?.error(e);
112
- } else {
113
- this.#clipboard?.close();
114
- this.#ackClipboardHandler?.close();
115
- }
116
- }
117
-
118
103
  createMediaStreamTransformer(): TransformStream<
119
104
  Uint8Array,
120
105
  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,
@@ -56,12 +56,22 @@ export class ScrcpyOptions2_0
56
56
 
57
57
  #ackClipboardHandler: AckClipboardHandler | undefined;
58
58
 
59
+ #deviceMessageParsers = new ScrcpyDeviceMessageParsers();
60
+ get deviceMessageParsers() {
61
+ return this.#deviceMessageParsers;
62
+ }
63
+
59
64
  constructor(init: Init) {
60
65
  this.value = { ...Defaults, ...init };
61
66
 
62
67
  if (this.value.control && this.value.clipboardAutosync) {
63
- this.#clipboard = new ClipboardStream();
64
- this.#ackClipboardHandler = new AckClipboardHandler();
68
+ this.#clipboard = this.#deviceMessageParsers.add(
69
+ new ClipboardStream(),
70
+ );
71
+
72
+ this.#ackClipboardHandler = this.#deviceMessageParsers.add(
73
+ new AckClipboardHandler(),
74
+ );
65
75
  }
66
76
  }
67
77
 
@@ -97,31 +107,6 @@ export class ScrcpyOptions2_0
97
107
  return parseAudioStreamMetadata(stream, this.value);
98
108
  }
99
109
 
100
- async parseDeviceMessage(
101
- id: number,
102
- stream: ExactReadable | AsyncExactReadable,
103
- ): Promise<void> {
104
- if (await this.#clipboard?.parse(id, stream)) {
105
- return;
106
- }
107
-
108
- if (await this.#ackClipboardHandler?.parse(id, stream)) {
109
- return;
110
- }
111
-
112
- throw new Error("Unknown device message");
113
- }
114
-
115
- endDeviceMessageStream(e?: unknown): void {
116
- if (e) {
117
- this.#clipboard?.error(e);
118
- this.#ackClipboardHandler?.error(e);
119
- } else {
120
- this.#clipboard?.close();
121
- this.#ackClipboardHandler?.close();
122
- }
123
- }
124
-
125
110
  createMediaStreamTransformer(): TransformStream<
126
111
  Uint8Array,
127
112
  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,
@@ -56,12 +56,22 @@ export class ScrcpyOptions2_1<TVideo extends boolean>
56
56
 
57
57
  #ackClipboardHandler: AckClipboardHandler | undefined;
58
58
 
59
+ #deviceMessageParsers = new ScrcpyDeviceMessageParsers();
60
+ get deviceMessageParsers() {
61
+ return this.#deviceMessageParsers;
62
+ }
63
+
59
64
  constructor(init: Init<TVideo>) {
60
65
  this.value = { ...Defaults, ...init } as never;
61
66
 
62
67
  if (this.value.control && this.value.clipboardAutosync) {
63
- this.#clipboard = new ClipboardStream();
64
- this.#ackClipboardHandler = new AckClipboardHandler();
68
+ this.#clipboard = this.#deviceMessageParsers.add(
69
+ new ClipboardStream(),
70
+ );
71
+
72
+ this.#ackClipboardHandler = this.#deviceMessageParsers.add(
73
+ new AckClipboardHandler(),
74
+ );
65
75
  }
66
76
  }
67
77
 
@@ -97,31 +107,6 @@ export class ScrcpyOptions2_1<TVideo extends boolean>
97
107
  return parseAudioStreamMetadata(stream, this.value);
98
108
  }
99
109
 
100
- async parseDeviceMessage(
101
- id: number,
102
- stream: ExactReadable | AsyncExactReadable,
103
- ): Promise<void> {
104
- if (await this.#clipboard?.parse(id, stream)) {
105
- return;
106
- }
107
-
108
- if (await this.#ackClipboardHandler?.parse(id, stream)) {
109
- return;
110
- }
111
-
112
- throw new Error("Unknown device message");
113
- }
114
-
115
- endDeviceMessageStream(e?: unknown): void {
116
- if (e) {
117
- this.#clipboard?.error(e);
118
- this.#ackClipboardHandler?.error(e);
119
- } else {
120
- this.#clipboard?.close();
121
- this.#ackClipboardHandler?.close();
122
- }
123
- }
124
-
125
110
  createMediaStreamTransformer(): TransformStream<
126
111
  Uint8Array,
127
112
  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,
@@ -56,6 +56,11 @@ export class ScrcpyOptions2_2<TVideo extends boolean>
56
56
 
57
57
  #ackClipboardHandler: AckClipboardHandler | undefined;
58
58
 
59
+ #deviceMessageParsers = new ScrcpyDeviceMessageParsers();
60
+ get deviceMessageParsers() {
61
+ return this.#deviceMessageParsers;
62
+ }
63
+
59
64
  constructor(init: Init<TVideo>) {
60
65
  this.value = { ...Defaults, ...init } as never;
61
66
 
@@ -64,8 +69,13 @@ export class ScrcpyOptions2_2<TVideo extends boolean>
64
69
  }
65
70
 
66
71
  if (this.value.control && this.value.clipboardAutosync) {
67
- this.#clipboard = new ClipboardStream();
68
- this.#ackClipboardHandler = new AckClipboardHandler();
72
+ this.#clipboard = this.#deviceMessageParsers.add(
73
+ new ClipboardStream(),
74
+ );
75
+
76
+ this.#ackClipboardHandler = this.#deviceMessageParsers.add(
77
+ new AckClipboardHandler(),
78
+ );
69
79
  }
70
80
  }
71
81
 
@@ -101,31 +111,6 @@ export class ScrcpyOptions2_2<TVideo extends boolean>
101
111
  return parseAudioStreamMetadata(stream, this.value);
102
112
  }
103
113
 
104
- async parseDeviceMessage(
105
- id: number,
106
- stream: ExactReadable | AsyncExactReadable,
107
- ): Promise<void> {
108
- if (await this.#clipboard?.parse(id, stream)) {
109
- return;
110
- }
111
-
112
- if (await this.#ackClipboardHandler?.parse(id, stream)) {
113
- return;
114
- }
115
-
116
- throw new Error("Unknown device message");
117
- }
118
-
119
- endDeviceMessageStream(e?: unknown): void {
120
- if (e) {
121
- this.#clipboard?.error(e);
122
- this.#ackClipboardHandler?.error(e);
123
- } else {
124
- this.#clipboard?.close();
125
- this.#ackClipboardHandler?.close();
126
- }
127
- }
128
-
129
114
  createMediaStreamTransformer(): TransformStream<
130
115
  Uint8Array,
131
116
  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,
@@ -56,6 +56,11 @@ export class ScrcpyOptions2_3<TVideo extends boolean>
56
56
 
57
57
  #ackClipboardHandler: AckClipboardHandler | undefined;
58
58
 
59
+ #deviceMessageParsers = new ScrcpyDeviceMessageParsers();
60
+ get deviceMessageParsers() {
61
+ return this.#deviceMessageParsers;
62
+ }
63
+
59
64
  constructor(init: Init<TVideo>) {
60
65
  this.value = { ...Defaults, ...init } as never;
61
66
 
@@ -64,8 +69,13 @@ export class ScrcpyOptions2_3<TVideo extends boolean>
64
69
  }
65
70
 
66
71
  if (this.value.control && this.value.clipboardAutosync) {
67
- this.#clipboard = new ClipboardStream();
68
- this.#ackClipboardHandler = new AckClipboardHandler();
72
+ this.#clipboard = this.#deviceMessageParsers.add(
73
+ new ClipboardStream(),
74
+ );
75
+
76
+ this.#ackClipboardHandler = this.#deviceMessageParsers.add(
77
+ new AckClipboardHandler(),
78
+ );
69
79
  }
70
80
  }
71
81
 
@@ -101,31 +111,6 @@ export class ScrcpyOptions2_3<TVideo extends boolean>
101
111
  return parseAudioStreamMetadata(stream, this.value);
102
112
  }
103
113
 
104
- async parseDeviceMessage(
105
- id: number,
106
- stream: ExactReadable | AsyncExactReadable,
107
- ): Promise<void> {
108
- if (await this.#clipboard?.parse(id, stream)) {
109
- return;
110
- }
111
-
112
- if (await this.#ackClipboardHandler?.parse(id, stream)) {
113
- return;
114
- }
115
-
116
- throw new Error("Unknown device message");
117
- }
118
-
119
- endDeviceMessageStream(e?: unknown): void {
120
- if (e) {
121
- this.#clipboard?.error(e);
122
- this.#ackClipboardHandler?.error(e);
123
- } else {
124
- this.#clipboard?.close();
125
- this.#ackClipboardHandler?.close();
126
- }
127
- }
128
-
129
114
  createMediaStreamTransformer(): TransformStream<
130
115
  Uint8Array,
131
116
  ScrcpyMediaStreamPacket
@@ -23,6 +23,8 @@ export class UHidOutputStream
23
23
  {
24
24
  #controller: PushReadableStreamController<UHidOutputDeviceMessage>;
25
25
 
26
+ readonly id = 2;
27
+
26
28
  constructor() {
27
29
  let controller!: PushReadableStreamController<UHidOutputDeviceMessage>;
28
30
  super((controller_) => {
@@ -31,14 +33,9 @@ export class UHidOutputStream
31
33
  this.#controller = controller;
32
34
  }
33
35
 
34
- async parse(id: number, stream: AsyncExactReadable): Promise<boolean> {
35
- if (id !== 2) {
36
- return false;
37
- }
38
-
36
+ async parse(_id: number, stream: AsyncExactReadable): Promise<undefined> {
39
37
  const message = await UHidOutputDeviceMessage.deserialize(stream);
40
38
  await this.#controller.enqueue(message);
41
- return true;
42
39
  }
43
40
 
44
41
  close() {