fix(adb-scrcpy): fallback to forward tunnel when reverse tunnel not supported

This commit is contained in:
Simon Chan 2024-11-19 11:35:44 +08:00
parent b3a142cbf0
commit 6cb0a589fa
No known key found for this signature in database
GPG key ID: A8B69F750B9BCEDD
23 changed files with 261 additions and 322 deletions

View file

@ -41,7 +41,7 @@
"source-map-support": "^0.5.21" "source-map-support": "^0.5.21"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^22.7.7", "@types/node": "^22.9.0",
"@yume-chan/eslint-config": "workspace:^", "@yume-chan/eslint-config": "workspace:^",
"@yume-chan/tsconfig": "workspace:^", "@yume-chan/tsconfig": "workspace:^",
"prettier": "^3.3.3", "prettier": "^3.3.3",

View file

@ -39,7 +39,7 @@
"@yume-chan/struct": "workspace:^" "@yume-chan/struct": "workspace:^"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^22.7.7", "@types/node": "^22.9.0",
"@yume-chan/eslint-config": "workspace:^", "@yume-chan/eslint-config": "workspace:^",
"@yume-chan/test-runner": "workspace:^", "@yume-chan/test-runner": "workspace:^",
"@yume-chan/tsconfig": "workspace:^", "@yume-chan/tsconfig": "workspace:^",

View file

@ -10,6 +10,7 @@ import type {
ScrcpyDisplay, ScrcpyDisplay,
ScrcpyEncoder, ScrcpyEncoder,
ScrcpyMediaStreamPacket, ScrcpyMediaStreamPacket,
ScrcpyOptionsInit1_16,
ScrcpyVideoStreamMetadata, ScrcpyVideoStreamMetadata,
} from "@yume-chan/scrcpy"; } from "@yume-chan/scrcpy";
import { import {
@ -120,7 +121,7 @@ export class AdbScrcpyClient {
adb: Adb, adb: Adb,
path: string, path: string,
version: string, version: string,
options: AdbScrcpyOptions<object>, options: AdbScrcpyOptions<Pick<ScrcpyOptionsInit1_16, "tunnelForward">>,
) { ) {
let connection: AdbScrcpyConnection | undefined; let connection: AdbScrcpyConnection | undefined;
let process: AdbSubprocessProtocol | undefined; let process: AdbSubprocessProtocol | undefined;
@ -132,7 +133,7 @@ export class AdbScrcpyClient {
} catch (e) { } catch (e) {
if (e instanceof AdbReverseNotSupportedError) { if (e instanceof AdbReverseNotSupportedError) {
// When reverse tunnel is not supported, try forward tunnel. // When reverse tunnel is not supported, try forward tunnel.
options.tunnelForwardOverride = true; options.value.tunnelForward = true;
connection = options.createConnection(adb); connection = options.createConnection(adb);
await connection.initialize(); await connection.initialize();
} else { } else {

View file

@ -39,7 +39,7 @@ export class AdbScrcpyOptions1_16 extends AdbScrcpyOptions<
adb: Adb, adb: Adb,
path: string, path: string,
version: string, version: string,
options: AdbScrcpyOptions<object>, options: AdbScrcpyOptions<Pick<ScrcpyOptionsInit1_16, "tunnelForward">>,
): Promise<ScrcpyEncoder[]> { ): Promise<ScrcpyEncoder[]> {
const client = await AdbScrcpyClient.start(adb, path, version, options); const client = await AdbScrcpyClient.start(adb, path, version, options);
@ -62,7 +62,7 @@ export class AdbScrcpyOptions1_16 extends AdbScrcpyOptions<
adb: Adb, adb: Adb,
path: string, path: string,
version: string, version: string,
options: AdbScrcpyOptions<object>, options: AdbScrcpyOptions<Pick<ScrcpyOptionsInit1_16, "tunnelForward">>,
): Promise<ScrcpyDisplay[]> { ): Promise<ScrcpyDisplay[]> {
try { try {
// Server will exit before opening connections when an invalid display id was given // Server will exit before opening connections when an invalid display id was given
@ -119,7 +119,7 @@ export class AdbScrcpyOptions1_16 extends AdbScrcpyOptions<
control: true, // Always enabled even when `--no-control` is specified control: true, // Always enabled even when `--no-control` is specified
sendDummyByte: true, // Always enabled sendDummyByte: true, // Always enabled
}, },
this.tunnelForwardOverride || this.value.tunnelForward, this.value.tunnelForward,
); );
} }
} }

View file

@ -41,7 +41,7 @@ export class AdbScrcpyOptions1_22 extends AdbScrcpyOptions<
control: this.value.control, control: this.value.control,
sendDummyByte: this.value.sendDummyByte, sendDummyByte: this.value.sendDummyByte,
}, },
this.tunnelForwardOverride || this.value.tunnelForward, this.value.tunnelForward,
); );
} }
} }

View file

@ -2,6 +2,7 @@ import type { Adb } from "@yume-chan/adb";
import type { import type {
ScrcpyDisplay, ScrcpyDisplay,
ScrcpyEncoder, ScrcpyEncoder,
ScrcpyOptionsInit1_16,
ScrcpyOptionsInit2_0, ScrcpyOptionsInit2_0,
} from "@yume-chan/scrcpy"; } from "@yume-chan/scrcpy";
@ -23,7 +24,7 @@ export class AdbScrcpyOptions2_0 extends AdbScrcpyOptions<
adb: Adb, adb: Adb,
path: string, path: string,
version: string, version: string,
options: AdbScrcpyOptions<object>, options: AdbScrcpyOptions<Pick<ScrcpyOptionsInit1_16, "tunnelForward">>,
): Promise<ScrcpyEncoder[]> { ): Promise<ScrcpyEncoder[]> {
try { try {
// Similar to `AdbScrcpyOptions1_16.getDisplays`, // Similar to `AdbScrcpyOptions1_16.getDisplays`,
@ -80,7 +81,7 @@ export class AdbScrcpyOptions2_0 extends AdbScrcpyOptions<
control: this.value.control, control: this.value.control,
sendDummyByte: this.value.sendDummyByte, sendDummyByte: this.value.sendDummyByte,
}, },
this.tunnelForwardOverride || this.value.tunnelForward, this.value.tunnelForward,
); );
} }
} }

View file

@ -50,7 +50,7 @@ export class AdbScrcpyOptions2_1 extends AdbScrcpyOptions<
control: this.value.control, control: this.value.control,
sendDummyByte: this.value.sendDummyByte, sendDummyByte: this.value.sendDummyByte,
}, },
this.tunnelForwardOverride || this.value.tunnelForward, this.value.tunnelForward,
); );
} }
} }

View file

@ -13,12 +13,6 @@ export abstract class AdbScrcpyOptions<
return this.#base.defaults; return this.#base.defaults;
} }
/**
* Allows the client to forcefully enable forward tunnel mode
* when reverse tunnel fails.
*/
tunnelForwardOverride = false;
constructor(base: ScrcpyOptions<T>) { constructor(base: ScrcpyOptions<T>) {
super( super(
// HACK: `ScrcpyOptions`'s constructor requires a constructor for the base class, // HACK: `ScrcpyOptions`'s constructor requires a constructor for the base class,

View file

@ -37,7 +37,7 @@
"@yume-chan/struct": "workspace:^" "@yume-chan/struct": "workspace:^"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^22.7.7", "@types/node": "^22.9.0",
"@yume-chan/eslint-config": "workspace:^", "@yume-chan/eslint-config": "workspace:^",
"@yume-chan/tsconfig": "workspace:^", "@yume-chan/tsconfig": "workspace:^",
"prettier": "^3.3.3", "prettier": "^3.3.3",

View file

@ -39,7 +39,7 @@
"@yume-chan/struct": "workspace:^" "@yume-chan/struct": "workspace:^"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^22.7.7", "@types/node": "^22.9.0",
"@yume-chan/eslint-config": "workspace:^", "@yume-chan/eslint-config": "workspace:^",
"@yume-chan/test-runner": "workspace:^", "@yume-chan/test-runner": "workspace:^",
"@yume-chan/tsconfig": "workspace:^", "@yume-chan/tsconfig": "workspace:^",

View file

@ -37,7 +37,7 @@
"@yume-chan/struct": "workspace:^" "@yume-chan/struct": "workspace:^"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^22.7.7", "@types/node": "^22.9.0",
"@yume-chan/eslint-config": "workspace:^", "@yume-chan/eslint-config": "workspace:^",
"@yume-chan/test-runner": "workspace:^", "@yume-chan/test-runner": "workspace:^",
"@yume-chan/tsconfig": "workspace:^", "@yume-chan/tsconfig": "workspace:^",

View file

@ -36,7 +36,7 @@
"@yume-chan/async": "^4.0.0" "@yume-chan/async": "^4.0.0"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^22.7.7", "@types/node": "^22.9.0",
"@yume-chan/eslint-config": "workspace:^", "@yume-chan/eslint-config": "workspace:^",
"@yume-chan/test-runner": "workspace:^", "@yume-chan/test-runner": "workspace:^",
"@yume-chan/tsconfig": "workspace:^", "@yume-chan/tsconfig": "workspace:^",

View file

@ -31,6 +31,6 @@
"gh-release-fetch": "^4.0.3" "gh-release-fetch": "^4.0.3"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^22.7.7" "@types/node": "^22.9.0"
} }
} }

View file

@ -30,12 +30,12 @@
"test": "run-test" "test": "run-test"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^22.7.7", "@types/node": "^22.9.0",
"@yume-chan/eslint-config": "workspace:^", "@yume-chan/eslint-config": "workspace:^",
"@yume-chan/test-runner": "workspace:^", "@yume-chan/test-runner": "workspace:^",
"@yume-chan/tsconfig": "workspace:^", "@yume-chan/tsconfig": "workspace:^",
"prettier": "^3.3.3", "prettier": "^3.3.3",
"tinybench": "^2.9.0", "tinybench": "^3.0.6",
"typescript": "^5.6.3" "typescript": "^5.6.3"
} }
} }

View file

@ -30,7 +30,7 @@
"prepublishOnly": "npm run build" "prepublishOnly": "npm run build"
}, },
"devDependencies": { "devDependencies": {
"@types/audioworklet": "^0.0.62", "@types/audioworklet": "^0.0.64",
"@yume-chan/eslint-config": "workspace:^", "@yume-chan/eslint-config": "workspace:^",
"@yume-chan/tsconfig": "workspace:^", "@yume-chan/tsconfig": "workspace:^",
"prettier": "^3.3.3", "prettier": "^3.3.3",

View file

@ -39,7 +39,7 @@
"@yume-chan/struct": "workspace:^" "@yume-chan/struct": "workspace:^"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^22.7.7", "@types/node": "^22.9.0",
"@yume-chan/eslint-config": "workspace:^", "@yume-chan/eslint-config": "workspace:^",
"@yume-chan/test-runner": "workspace:^", "@yume-chan/test-runner": "workspace:^",
"@yume-chan/tsconfig": "workspace:^", "@yume-chan/tsconfig": "workspace:^",

View file

@ -218,7 +218,7 @@ export type AndroidKeyCode =
export const AndroidKeyNames = /* #__PURE__ */ (() => export const AndroidKeyNames = /* #__PURE__ */ (() =>
Object.fromEntries( Object.fromEntries(
Object.entries(AndroidKeyCode).map(([k, v]) => [v, k]), Object.entries(AndroidKeyCode).map(([k, v]) => [v, k]),
) as { [k in AndroidKeyCode]: string })(); ) as Record<AndroidKeyCode, string>)();
export const ScrcpyInjectKeyCodeControlMessage = struct( export const ScrcpyInjectKeyCodeControlMessage = struct(
{ {

View file

@ -36,7 +36,7 @@
"@yume-chan/struct": "workspace:^" "@yume-chan/struct": "workspace:^"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^22.7.7", "@types/node": "^22.9.0",
"@yume-chan/eslint-config": "workspace:^", "@yume-chan/eslint-config": "workspace:^",
"@yume-chan/test-runner": "workspace:^", "@yume-chan/test-runner": "workspace:^",
"@yume-chan/tsconfig": "workspace:^", "@yume-chan/tsconfig": "workspace:^",

View file

@ -37,7 +37,7 @@
"@yume-chan/no-data-view": "workspace:^" "@yume-chan/no-data-view": "workspace:^"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^22.7.7", "@types/node": "^22.9.0",
"@yume-chan/eslint-config": "workspace:^", "@yume-chan/eslint-config": "workspace:^",
"@yume-chan/test-runner": "workspace:^", "@yume-chan/test-runner": "workspace:^",
"@yume-chan/tsconfig": "workspace:^", "@yume-chan/tsconfig": "workspace:^",

515
pnpm-lock.yaml generated

File diff suppressed because it is too large Load diff

View file

@ -8,12 +8,12 @@
"run-eslint": "run-eslint.js" "run-eslint": "run-eslint.js"
}, },
"dependencies": { "dependencies": {
"@eslint/js": "^9.13.0", "@eslint/js": "^9.15.0",
"@types/node": "^22.7.7", "@types/node": "^22.9.0",
"eslint": "^9.13.0", "eslint": "^9.15.0",
"eslint-plugin-import-x": "^4.3.1", "eslint-plugin-import-x": "^4.4.2",
"typescript": "^5.6.3", "typescript": "^5.6.3",
"typescript-eslint": "^8.11.0" "typescript-eslint": "^8.15.0"
}, },
"devDependencies": { "devDependencies": {
"prettier": "^3.3.3" "prettier": "^3.3.3"

View file

@ -7,7 +7,7 @@
"scripts": {}, "scripts": {},
"keywords": [], "keywords": [],
"dependencies": { "dependencies": {
"@types/node": "^22.7.7", "@types/node": "^22.9.0",
"json5": "^2.2.3" "json5": "^2.2.3"
}, },
"author": "", "author": "",

View file

@ -6,7 +6,7 @@
"run-test": "wrapper.js" "run-test": "wrapper.js"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^22.7.7", "@types/node": "^22.9.0",
"typescript": "^5.6.3" "typescript": "^5.6.3"
} }
} }