Skip to content

Commit

Permalink
feat(scrcpy): support v2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
yume-chan committed Nov 3, 2023
1 parent d6d0306 commit 336e0ff
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 8 deletions.
11 changes: 7 additions & 4 deletions libraries/fetch-scrcpy-server/bin/fetch-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <version>");
process.exit(1);
Expand All @@ -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(
Expand Down
68 changes: 68 additions & 0 deletions libraries/scrcpy/src/options/2_2.ts
Original file line number Diff line number Diff line change
@@ -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<ScrcpyOptionsInit2_1, "display"> {
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<ScrcpyOptionsInit2_2>;

override get defaults(): Required<ScrcpyOptionsInit2_2> {
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);
}
}
1 change: 1 addition & 0 deletions libraries/scrcpy/src/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
8 changes: 4 additions & 4 deletions libraries/scrcpy/src/options/latest.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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;

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 {}

0 comments on commit 336e0ff

Please sign in to comment.