-
-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(adb-scrcpy): add aliases for all AdbScrcpyOptions versions
- Loading branch information
Showing
80 changed files
with
1,181 additions
and
331 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@yume-chan/adb-scrcpy": minor | ||
"@yume-chan/scrcpy": minor | ||
--- | ||
|
||
Add alias for all AdbScrcpyOptions versions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type { Adb } from "@yume-chan/adb"; | ||
import type { ScrcpyOptions1_15 } from "@yume-chan/scrcpy"; | ||
|
||
import type { | ||
AdbScrcpyConnection, | ||
AdbScrcpyConnectionOptions, | ||
} from "../../connection.js"; | ||
import { | ||
AdbScrcpyForwardConnection, | ||
AdbScrcpyReverseConnection, | ||
} from "../../connection.js"; | ||
|
||
export function createConnection( | ||
adb: Adb, | ||
options: Pick<ScrcpyOptions1_15.Init, "tunnelForward">, | ||
): AdbScrcpyConnection { | ||
const connectionOptions: AdbScrcpyConnectionOptions = { | ||
scid: undefined, // Not Supported | ||
video: true, // Always enabled | ||
audio: false, // Not Supported | ||
control: true, // Always enabled even when `--no-control` is specified | ||
sendDummyByte: true, // Always enabled | ||
}; | ||
if (options.tunnelForward) { | ||
return new AdbScrcpyForwardConnection(adb, connectionOptions); | ||
} else { | ||
return new AdbScrcpyReverseConnection(adb, connectionOptions); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { Adb } from "@yume-chan/adb"; | ||
import type { ScrcpyDisplay, ScrcpyOptions1_15 } from "@yume-chan/scrcpy"; | ||
|
||
import { AdbScrcpyClient, AdbScrcpyExitedError } from "../../client.js"; | ||
import type { AdbScrcpyOptions } from "../../types.js"; | ||
|
||
export async function getDisplays( | ||
adb: Adb, | ||
path: string, | ||
options: AdbScrcpyOptions<Pick<ScrcpyOptions1_15.Init, "tunnelForward">>, | ||
): Promise<ScrcpyDisplay[]> { | ||
try { | ||
// Server will exit before opening connections when an invalid display id was given | ||
// so `start` will throw an `AdbScrcpyExitedError` | ||
const client = await AdbScrcpyClient.start(adb, path, options); | ||
|
||
// If the server didn't exit, manually stop it and throw an error | ||
await client.close(); | ||
throw new Error("Unexpected server output"); | ||
} catch (e) { | ||
if (e instanceof AdbScrcpyExitedError) { | ||
if (e.output[0]?.startsWith("[server] ERROR:")) { | ||
throw e; | ||
} | ||
|
||
const displays: ScrcpyDisplay[] = []; | ||
for (const line of e.output) { | ||
const display = options.parseDisplay(line); | ||
if (display) { | ||
displays.push(display); | ||
} | ||
} | ||
return displays; | ||
} | ||
|
||
throw e; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { Adb } from "@yume-chan/adb"; | ||
import type { ScrcpyEncoder, ScrcpyOptions1_15 } from "@yume-chan/scrcpy"; | ||
|
||
import { AdbScrcpyClient } from "../../client.js"; | ||
import type { AdbScrcpyOptions } from "../../types.js"; | ||
|
||
export async function getEncoders( | ||
adb: Adb, | ||
path: string, | ||
options: AdbScrcpyOptions<Pick<ScrcpyOptions1_15.Init, "tunnelForward">>, | ||
): Promise<ScrcpyEncoder[]> { | ||
const client = await AdbScrcpyClient.start(adb, path, options); | ||
|
||
const encoders: ScrcpyEncoder[] = []; | ||
|
||
for await (const line of client.stdout) { | ||
const encoder = options.parseEncoder(line); | ||
if (encoder) { | ||
encoders.push(encoder); | ||
} | ||
} | ||
|
||
return encoders; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from "./create-connection.js"; | ||
export * from "./get-displays.js"; | ||
export * from "./get-encoders.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./options.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { Adb } from "@yume-chan/adb"; | ||
import type { ScrcpyDisplay, ScrcpyEncoder } from "@yume-chan/scrcpy"; | ||
import { ScrcpyOptions1_15 } from "@yume-chan/scrcpy"; | ||
|
||
import type { AdbScrcpyConnection } from "../connection.js"; | ||
import { AdbScrcpyOptions } from "../types.js"; | ||
|
||
import { createConnection, getDisplays, getEncoders } from "./impl/index.js"; | ||
|
||
export class AdbScrcpyOptions1_15 extends AdbScrcpyOptions<ScrcpyOptions1_15.Init> { | ||
constructor(init: ScrcpyOptions1_15.Init, version?: string) { | ||
super(new ScrcpyOptions1_15(init, version)); | ||
} | ||
|
||
override getEncoders(adb: Adb, path: string): Promise<ScrcpyEncoder[]> { | ||
return getEncoders(adb, path, this); | ||
} | ||
|
||
override getDisplays(adb: Adb, path: string): Promise<ScrcpyDisplay[]> { | ||
return getDisplays(adb, path, this); | ||
} | ||
|
||
override createConnection(adb: Adb): AdbScrcpyConnection { | ||
return createConnection(adb, this.value); | ||
} | ||
} | ||
|
||
export namespace AdbScrcpyOptions1_15 { | ||
export type Init = ScrcpyOptions1_15.Init; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { Adb } from "@yume-chan/adb"; | ||
import type { ScrcpyDisplay, ScrcpyEncoder } from "@yume-chan/scrcpy"; | ||
import { ScrcpyOptions1_15_1 } from "@yume-chan/scrcpy"; | ||
|
||
import { | ||
createConnection, | ||
getDisplays, | ||
getEncoders, | ||
} from "./1_15/impl/index.js"; | ||
import type { AdbScrcpyConnection } from "./connection.js"; | ||
import { AdbScrcpyOptions } from "./types.js"; | ||
|
||
export class AdbScrcpyOptions1_15_1 extends AdbScrcpyOptions<ScrcpyOptions1_15_1.Init> { | ||
constructor(init: ScrcpyOptions1_15_1.Init, version?: string) { | ||
super(new ScrcpyOptions1_15_1(init, version)); | ||
} | ||
|
||
override getEncoders(adb: Adb, path: string): Promise<ScrcpyEncoder[]> { | ||
return getEncoders(adb, path, this); | ||
} | ||
|
||
override getDisplays(adb: Adb, path: string): Promise<ScrcpyDisplay[]> { | ||
return getDisplays(adb, path, this); | ||
} | ||
|
||
override createConnection(adb: Adb): AdbScrcpyConnection { | ||
return createConnection(adb, this.value); | ||
} | ||
} | ||
|
||
export namespace AdbScrcpyOptions1_15_1 { | ||
export type Init = ScrcpyOptions1_15_1.Init; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { Adb } from "@yume-chan/adb"; | ||
import type { ScrcpyDisplay, ScrcpyEncoder } from "@yume-chan/scrcpy"; | ||
import { ScrcpyOptions1_16 } from "@yume-chan/scrcpy"; | ||
|
||
import { | ||
createConnection, | ||
getDisplays, | ||
getEncoders, | ||
} from "./1_15/impl/index.js"; | ||
import type { AdbScrcpyConnection } from "./connection.js"; | ||
import { AdbScrcpyOptions } from "./types.js"; | ||
|
||
export class AdbScrcpyOptions1_16 extends AdbScrcpyOptions<ScrcpyOptions1_16.Init> { | ||
constructor(init: ScrcpyOptions1_16.Init, version?: string) { | ||
super(new ScrcpyOptions1_16(init, version)); | ||
} | ||
|
||
override getEncoders(adb: Adb, path: string): Promise<ScrcpyEncoder[]> { | ||
return getEncoders(adb, path, this); | ||
} | ||
|
||
override getDisplays(adb: Adb, path: string): Promise<ScrcpyDisplay[]> { | ||
return getDisplays(adb, path, this); | ||
} | ||
|
||
override createConnection(adb: Adb): AdbScrcpyConnection { | ||
return createConnection(adb, this.value); | ||
} | ||
} | ||
|
||
export namespace AdbScrcpyOptions1_16 { | ||
export type Init = ScrcpyOptions1_16.Init; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { Adb } from "@yume-chan/adb"; | ||
import type { ScrcpyDisplay, ScrcpyEncoder } from "@yume-chan/scrcpy"; | ||
import { ScrcpyOptions1_17 } from "@yume-chan/scrcpy"; | ||
|
||
import { | ||
createConnection, | ||
getDisplays, | ||
getEncoders, | ||
} from "./1_15/impl/index.js"; | ||
import type { AdbScrcpyConnection } from "./connection.js"; | ||
import { AdbScrcpyOptions } from "./types.js"; | ||
|
||
export class AdbScrcpyOptions1_17 extends AdbScrcpyOptions<ScrcpyOptions1_17.Init> { | ||
constructor(init: ScrcpyOptions1_17.Init, version?: string) { | ||
super(new ScrcpyOptions1_17(init, version)); | ||
} | ||
|
||
override getEncoders(adb: Adb, path: string): Promise<ScrcpyEncoder[]> { | ||
return getEncoders(adb, path, this); | ||
} | ||
|
||
override getDisplays(adb: Adb, path: string): Promise<ScrcpyDisplay[]> { | ||
return getDisplays(adb, path, this); | ||
} | ||
|
||
override createConnection(adb: Adb): AdbScrcpyConnection { | ||
return createConnection(adb, this.value); | ||
} | ||
} | ||
|
||
export namespace AdbScrcpyOptions1_17 { | ||
export type Init = ScrcpyOptions1_17.Init; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { Adb } from "@yume-chan/adb"; | ||
import type { ScrcpyDisplay, ScrcpyEncoder } from "@yume-chan/scrcpy"; | ||
import { ScrcpyOptions1_18 } from "@yume-chan/scrcpy"; | ||
|
||
import { | ||
createConnection, | ||
getDisplays, | ||
getEncoders, | ||
} from "./1_15/impl/index.js"; | ||
import type { AdbScrcpyConnection } from "./connection.js"; | ||
import { AdbScrcpyOptions } from "./types.js"; | ||
|
||
export class AdbScrcpyOptions1_18 extends AdbScrcpyOptions<ScrcpyOptions1_18.Init> { | ||
constructor(init: ScrcpyOptions1_18.Init, version?: string) { | ||
super(new ScrcpyOptions1_18(init, version)); | ||
} | ||
|
||
override getEncoders(adb: Adb, path: string): Promise<ScrcpyEncoder[]> { | ||
return getEncoders(adb, path, this); | ||
} | ||
|
||
override getDisplays(adb: Adb, path: string): Promise<ScrcpyDisplay[]> { | ||
return getDisplays(adb, path, this); | ||
} | ||
|
||
override createConnection(adb: Adb): AdbScrcpyConnection { | ||
return createConnection(adb, this.value); | ||
} | ||
} | ||
|
||
export namespace AdbScrcpyOptions1_18 { | ||
export type Init = ScrcpyOptions1_18.Init; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { Adb } from "@yume-chan/adb"; | ||
import type { ScrcpyDisplay, ScrcpyEncoder } from "@yume-chan/scrcpy"; | ||
import { ScrcpyOptions1_19 } from "@yume-chan/scrcpy"; | ||
|
||
import { | ||
createConnection, | ||
getDisplays, | ||
getEncoders, | ||
} from "./1_15/impl/index.js"; | ||
import type { AdbScrcpyConnection } from "./connection.js"; | ||
import { AdbScrcpyOptions } from "./types.js"; | ||
|
||
export class AdbScrcpyOptions1_19 extends AdbScrcpyOptions<ScrcpyOptions1_19.Init> { | ||
constructor(init: ScrcpyOptions1_19.Init, version?: string) { | ||
super(new ScrcpyOptions1_19(init, version)); | ||
} | ||
|
||
override getEncoders(adb: Adb, path: string): Promise<ScrcpyEncoder[]> { | ||
return getEncoders(adb, path, this); | ||
} | ||
|
||
override getDisplays(adb: Adb, path: string): Promise<ScrcpyDisplay[]> { | ||
return getDisplays(adb, path, this); | ||
} | ||
|
||
override createConnection(adb: Adb): AdbScrcpyConnection { | ||
return createConnection(adb, this.value); | ||
} | ||
} | ||
|
||
export namespace AdbScrcpyOptions1_19 { | ||
export type Init = ScrcpyOptions1_19.Init; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { Adb } from "@yume-chan/adb"; | ||
import type { ScrcpyDisplay, ScrcpyEncoder } from "@yume-chan/scrcpy"; | ||
import { ScrcpyOptions1_20 } from "@yume-chan/scrcpy"; | ||
|
||
import { | ||
createConnection, | ||
getDisplays, | ||
getEncoders, | ||
} from "./1_15/impl/index.js"; | ||
import type { AdbScrcpyConnection } from "./connection.js"; | ||
import { AdbScrcpyOptions } from "./types.js"; | ||
|
||
export class AdbScrcpyOptions1_20 extends AdbScrcpyOptions<ScrcpyOptions1_20.Init> { | ||
constructor(init: ScrcpyOptions1_20.Init, version?: string) { | ||
super(new ScrcpyOptions1_20(init, version)); | ||
} | ||
|
||
override getEncoders(adb: Adb, path: string): Promise<ScrcpyEncoder[]> { | ||
return getEncoders(adb, path, this); | ||
} | ||
|
||
override getDisplays(adb: Adb, path: string): Promise<ScrcpyDisplay[]> { | ||
return getDisplays(adb, path, this); | ||
} | ||
|
||
override createConnection(adb: Adb): AdbScrcpyConnection { | ||
return createConnection(adb, this.value); | ||
} | ||
} | ||
|
||
export namespace AdbScrcpyOptions1_20 { | ||
export type Init = ScrcpyOptions1_20.Init; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { Adb } from "@yume-chan/adb"; | ||
import type { ScrcpyDisplay, ScrcpyEncoder } from "@yume-chan/scrcpy"; | ||
import { ScrcpyOptions1_21 } from "@yume-chan/scrcpy"; | ||
|
||
import { | ||
createConnection, | ||
getDisplays, | ||
getEncoders, | ||
} from "./1_15/impl/index.js"; | ||
import type { AdbScrcpyConnection } from "./connection.js"; | ||
import { AdbScrcpyOptions } from "./types.js"; | ||
|
||
export class AdbScrcpyOptions1_21 extends AdbScrcpyOptions<ScrcpyOptions1_21.Init> { | ||
constructor(init: ScrcpyOptions1_21.Init, version?: string) { | ||
super(new ScrcpyOptions1_21(init, version)); | ||
} | ||
|
||
override getEncoders(adb: Adb, path: string): Promise<ScrcpyEncoder[]> { | ||
return getEncoders(adb, path, this); | ||
} | ||
|
||
override getDisplays(adb: Adb, path: string): Promise<ScrcpyDisplay[]> { | ||
return getDisplays(adb, path, this); | ||
} | ||
|
||
override createConnection(adb: Adb): AdbScrcpyConnection { | ||
return createConnection(adb, this.value); | ||
} | ||
} | ||
|
||
export namespace AdbScrcpyOptions1_21 { | ||
export type Init = ScrcpyOptions1_21.Init; | ||
} |
Oops, something went wrong.