Skip to content

Commit

Permalink
feat: add display orientation options for Scrcpy version 2.3
Browse files Browse the repository at this point in the history
Introduce new classes and enums to handle Scrcpy version 2.3 options.
This update includes new display orientation options and modifies the
existing interfaces to accommodate additional settings.

See Genymobile/scrcpy#4441
  • Loading branch information
Gasol committed Nov 6, 2024
1 parent 0345719 commit 6e70cb5
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
57 changes: 57 additions & 0 deletions libraries/adb-scrcpy/src/options/2_3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import type { Adb } from "@gasol/adb";
import type {
ScrcpyDisplay,
ScrcpyEncoder,
ScrcpyOptionsInit2_3,
} from "@gasol/scrcpy";

import type { AdbScrcpyConnection } from "../connection.js";

import { AdbScrcpyOptions1_16 } from "./1_16.js";
import { AdbScrcpyOptions2_0 } from "./2_0.js";
import { AdbScrcpyOptions } from "./types.js";

export class AdbScrcpyOptions2_3 extends AdbScrcpyOptions<
// Only pick options that are used in this class,
// so changes in `ScrcpyOptionsInitX_XX` won't affect type assignability with this class
Pick<
ScrcpyOptionsInit2_3,
| "displayOrientation"
| "tunnelForward"
| "control"
| "sendDummyByte"
| "scid"
| "audio"
| "video"
>
> {
override async getEncoders(
adb: Adb,
path: string,
version: string,
): Promise<ScrcpyEncoder[]> {
return AdbScrcpyOptions2_0.getEncoders(adb, path, version, this);
}

override getDisplays(
adb: Adb,
path: string,
version: string,
): Promise<ScrcpyDisplay[]> {
return AdbScrcpyOptions1_16.getDisplays(adb, path, version, this);
}

override createConnection(adb: Adb): AdbScrcpyConnection {
return AdbScrcpyOptions1_16.createConnection(
adb,
{
scid: this.value.scid.value,
video: this.value.video,
audio: this.value.audio,
control: this.value.control,
sendDummyByte: this.value.sendDummyByte,
},
this.tunnelForwardOverride || this.value.tunnelForward,
);
}
}
15 changes: 15 additions & 0 deletions libraries/scrcpy/src/options/2_3.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as assert from "node:assert";
import { describe, it } from "node:test";

import { ScrcpyDisplayOrientation2_3, ScrcpyOptions2_3 } from "./2_3.js";

describe("ScrcpyOptions2_3", () => {
describe("displayOrientation", () => {
it("should set `displayOrientation` to `flip180`", () => {
const options = new ScrcpyOptions2_3({
displayOrientation: ScrcpyDisplayOrientation2_3.Flip180,
});
assert.strictEqual(options.value.displayOrientation, "flip180");
});
});
});
14 changes: 14 additions & 0 deletions libraries/scrcpy/src/options/2_3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,28 @@ import type { ScrcpyAudioStreamMetadata } from "./codec.js";
import { ScrcpyAudioCodec } from "./codec.js";
import { ScrcpyOptions } from "./types.js";

// https://github.com/Genymobile/scrcpy/pull/4441
export enum ScrcpyDisplayOrientation2_3 {
Zero = "0",
Ninety = "90",
OneEighty = "180",
TwoSeventy = "270",
Flip0 = "flip0",
Flip90 = "flip90",
Flip180 = "flip180",
Flip270 = "flip270",
}

export interface ScrcpyOptionsInit2_3
extends Omit<ScrcpyOptionsInit2_2, "audioCodec"> {
audioCodec?: "raw" | "opus" | "aac" | "flac";
displayOrientation?: ScrcpyDisplayOrientation2_3 | undefined;
}

export class ScrcpyOptions2_3 extends ScrcpyOptions<ScrcpyOptionsInit2_3> {
static readonly DEFAULTS = {
...ScrcpyOptions2_2.DEFAULTS,
displayOrientation: undefined,
} as const satisfies Required<ScrcpyOptionsInit2_3>;

override get defaults(): Required<ScrcpyOptionsInit2_3> {
Expand Down

0 comments on commit 6e70cb5

Please sign in to comment.