fix(scrcpy): fix UHID output stream from server version 2.6

This commit also replaced `ScrcpyOptions`'s `parseDeviceMessage`/`endDeviceMessageStream` methods with `deviceMessageParsers`. If you are using that two methods directly, you need to move to the new API
This commit is contained in:
Simon Chan 2025-06-21 18:28:33 +08:00
parent eff718ce36
commit 7edd616b43
No known key found for this signature in database
GPG key ID: A8B69F750B9BCEDD
28 changed files with 341 additions and 555 deletions

View file

@ -1,6 +1,5 @@
import type { MaybePromiseLike } from "@yume-chan/async";
import type { ReadableStream, TransformStream } from "@yume-chan/stream-extra";
import type { AsyncExactReadable, ExactReadable } from "@yume-chan/struct";
import type {
ScrcpyControlMessageType,
@ -12,6 +11,7 @@ import type {
ScrcpyScrollController,
ScrcpyVideoStream,
} from "../base/index.js";
import { ScrcpyDeviceMessageParsers } from "../base/index.js";
import type {
ScrcpyBackOrScreenOnControlMessage,
ScrcpyInjectTouchControlMessage,
@ -55,12 +55,22 @@ export class ScrcpyOptions1_22
#ackClipboardHandler: AckClipboardHandler | undefined;
#deviceMessageParsers = new ScrcpyDeviceMessageParsers();
get deviceMessageParsers() {
return this.#deviceMessageParsers;
}
constructor(init: Init) {
this.value = { ...Defaults, ...init };
if (this.value.control && this.value.clipboardAutosync) {
this.#clipboard = new ClipboardStream();
this.#ackClipboardHandler = new AckClipboardHandler();
this.#clipboard = this.#deviceMessageParsers.add(
new ClipboardStream(),
);
this.#ackClipboardHandler = this.#deviceMessageParsers.add(
new AckClipboardHandler(),
);
}
}
@ -90,31 +100,6 @@ export class ScrcpyOptions1_22
return parseVideoStreamMetadata(this.value, stream);
}
async parseDeviceMessage(
id: number,
stream: ExactReadable | AsyncExactReadable,
): Promise<void> {
if (await this.#clipboard?.parse(id, stream)) {
return;
}
if (await this.#ackClipboardHandler?.parse(id, stream)) {
return;
}
throw new Error("Unknown device message");
}
endDeviceMessageStream(e?: unknown): void {
if (e) {
this.#clipboard?.error(e);
this.#ackClipboardHandler?.error(e);
} else {
this.#clipboard?.close();
this.#ackClipboardHandler?.close();
}
}
createMediaStreamTransformer(): TransformStream<
Uint8Array,
ScrcpyMediaStreamPacket