MCPcopy
hub / github.com/yume-chan/ya-webadb / ScrcpyControlMessageWriter

Class ScrcpyControlMessageWriter

libraries/scrcpy/src/control/writer.ts:20–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18import type { ScrcpyUHidInputControlMessage } from "./uhid.js";
19
20export class ScrcpyControlMessageWriter {
21 #writer: WritableStreamDefaultWriter<Consumable<Uint8Array>>;
22 #serializer: ScrcpyControlMessageSerializer;
23
24 constructor(
25 writer: WritableStreamDefaultWriter<Consumable<Uint8Array>>,
26 options: ScrcpyOptions<object>,
27 ) {
28 this.#writer = writer;
29 this.#serializer = new ScrcpyControlMessageSerializer(options);
30 }
31
32 write(message: Uint8Array) {
33 return Consumable.WritableStream.write(this.#writer, message);
34 }
35
36 injectKeyCode(message: Omit<ScrcpyInjectKeyCodeControlMessage, "type">) {
37 return this.write(this.#serializer.injectKeyCode(message));
38 }
39
40 injectText(text: string) {
41 return this.write(this.#serializer.injectText(text));
42 }
43
44 /**
45 * `pressure` is a float value between 0 and 1.
46 */
47 injectTouch(message: Omit<ScrcpyInjectTouchControlMessage, "type">) {
48 return this.write(this.#serializer.injectTouch(message));
49 }
50
51 /**
52 * `scrollX` and `scrollY` are float values between 0 and 1.
53 */
54 async injectScroll(
55 message: Omit<ScrcpyInjectScrollControlMessage, "type">,
56 ) {
57 const data = this.#serializer.injectScroll(message);
58 if (data) {
59 await this.write(data);
60 }
61 }
62
63 async backOrScreenOn(action: AndroidKeyEventAction) {
64 const data = this.#serializer.backOrScreenOn(action);
65 if (data) {
66 await this.write(data);
67 }
68 }
69
70 setScreenPowerMode(mode: AndroidScreenPowerMode) {
71 return this.write(this.#serializer.setDisplayPower(mode));
72 }
73
74 expandNotificationPanel() {
75 return this.write(this.#serializer.expandNotificationPanel());
76 }
77

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected