From 336e0ffd5d83cffa6a29b314d812e4fd37624041 Mon Sep 17 00:00:00 2001 From: Simon Chan <1330321+yume-chan@users.noreply.github.com> Date: Fri, 3 Nov 2023 11:18:25 +0800 Subject: [PATCH] feat(scrcpy): support v2.2 --- .../fetch-scrcpy-server/bin/fetch-server.js | 11 +-- libraries/scrcpy/src/options/2_2.ts | 68 +++++++++++++++++++ libraries/scrcpy/src/options/index.ts | 1 + libraries/scrcpy/src/options/latest.ts | 8 +-- 4 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 libraries/scrcpy/src/options/2_2.ts diff --git a/libraries/fetch-scrcpy-server/bin/fetch-server.js b/libraries/fetch-scrcpy-server/bin/fetch-server.js index 8d3924f96..a9f339f86 100644 --- a/libraries/fetch-scrcpy-server/bin/fetch-server.js +++ b/libraries/fetch-scrcpy-server/bin/fetch-server.js @@ -7,7 +7,10 @@ import { fileURLToPath } from "node:url"; const __dirname = fileURLToPath(dirname(import.meta.url)); -const serverVersion = process.argv[2]; +let serverVersion = process.argv[2]; +if (!serverVersion.startsWith("v")) { + serverVersion = "v" + serverVersion; +} if (!serverVersion) { console.log("Usage: fetch-scrcpy-server "); process.exit(1); @@ -18,15 +21,15 @@ const binFolder = resolve(__dirname, ".."); await fetchVersion({ repository: "Genymobile/scrcpy", - version: `v${serverVersion}`, - package: `scrcpy-server-v${serverVersion}`, + version: serverVersion, + package: `scrcpy-server-${serverVersion}`, destination: binFolder, extract: false, }); await Promise.all([ fs.rename( - resolve(binFolder, `scrcpy-server-v${serverVersion}`), + resolve(binFolder, `scrcpy-server-${serverVersion}`), resolve(binFolder, "server.bin"), ), fs.writeFile( diff --git a/libraries/scrcpy/src/options/2_2.ts b/libraries/scrcpy/src/options/2_2.ts new file mode 100644 index 000000000..dd0622c29 --- /dev/null +++ b/libraries/scrcpy/src/options/2_2.ts @@ -0,0 +1,68 @@ +import { ScrcpyOptions1_21 } from "./1_21.js"; +import type { ScrcpyOptionsInit2_1 } from "./2_1.js"; +import { ScrcpyOptions2_1 } from "./2_1.js"; +import type { ScrcpyDisplay } from "./types.js"; +import { ScrcpyOptionsBase } from "./types.js"; + +export interface ScrcpyOptionsInit2_2 + extends Omit { + videoSource?: "display" | "camera"; + displayId?: number; + cameraId?: string | undefined; + cameraSize?: string | undefined; + cameraFacing?: "front" | "back" | "external" | undefined; + cameraAr?: string | undefined; + cameraFps?: number | undefined; + cameraHighSpeed?: boolean; + + listCameras?: boolean; + listCameraSizes?: boolean; +} + +export class ScrcpyOptions2_2 extends ScrcpyOptionsBase< + ScrcpyOptionsInit2_2, + ScrcpyOptions2_1 +> { + static readonly DEFAULTS = { + ...ScrcpyOptions2_1.DEFAULTS, + videoSource: "display", + displayId: 0, + cameraId: undefined, + cameraSize: undefined, + cameraFacing: undefined, + cameraAr: undefined, + cameraFps: undefined, + cameraHighSpeed: false, + listCameras: false, + listCameraSizes: false, + } as const satisfies Required; + + override get defaults(): Required { + return ScrcpyOptions2_2.DEFAULTS; + } + + constructor(init: ScrcpyOptionsInit2_2) { + super(new ScrcpyOptions2_1(init), { + ...ScrcpyOptions2_2.DEFAULTS, + ...init, + }); + } + + override parseDisplay(line: string): ScrcpyDisplay | undefined { + const match = line.match(/\s+--display-id=(\d+)\s+\((.*?)\)/); + if (match) { + const display: ScrcpyDisplay = { + id: Number.parseInt(match[1]!, 10), + }; + if (match[2] !== "size unknown") { + display.resolution = match[2]!; + } + return display; + } + return undefined; + } + + override serialize(): string[] { + return ScrcpyOptions1_21.serialize(this.value, this.defaults); + } +} diff --git a/libraries/scrcpy/src/options/index.ts b/libraries/scrcpy/src/options/index.ts index a051ec085..c710cd32e 100644 --- a/libraries/scrcpy/src/options/index.ts +++ b/libraries/scrcpy/src/options/index.ts @@ -8,6 +8,7 @@ export * from "./1_24.js"; export * from "./1_25/index.js"; export * from "./2_0.js"; export * from "./2_1.js"; +export * from "./2_2.js"; export * from "./codec.js"; export * from "./latest.js"; export * from "./types.js"; diff --git a/libraries/scrcpy/src/options/latest.ts b/libraries/scrcpy/src/options/latest.ts index e7f5b27de..c96c2b66f 100644 --- a/libraries/scrcpy/src/options/latest.ts +++ b/libraries/scrcpy/src/options/latest.ts @@ -1,6 +1,6 @@ import { ScrcpyLogLevel1_18, ScrcpyVideoOrientation1_18 } from "./1_18.js"; -import type { ScrcpyOptionsInit2_1 } from "./2_1.js"; -import { ScrcpyOptions2_1 } from "./2_1.js"; +import type { ScrcpyOptionsInit2_2 } from "./2_2.js"; +import { ScrcpyOptions2_2 } from "./2_2.js"; export const ScrcpyLogLevel = ScrcpyLogLevel1_18; export type ScrcpyLogLevel = ScrcpyLogLevel1_18; @@ -8,5 +8,5 @@ export type ScrcpyLogLevel = ScrcpyLogLevel1_18; export const ScrcpyVideoOrientation = ScrcpyVideoOrientation1_18; export type ScrcpyVideoOrientation = ScrcpyVideoOrientation1_18; -export type ScrcpyOptionsInitLatest = ScrcpyOptionsInit2_1; -export class ScrcpyOptionsLatest extends ScrcpyOptions2_1 {} +export type ScrcpyOptionsInitLatest = ScrcpyOptionsInit2_2; +export class ScrcpyOptionsLatest extends ScrcpyOptions2_2 {}