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"
},
"devDependencies": {
"@types/node": "^22.7.7",
"@types/node": "^22.9.0",
"@yume-chan/eslint-config": "workspace:^",
"@yume-chan/tsconfig": "workspace:^",
"prettier": "^3.3.3",

View file

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

View file

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

View file

@ -39,7 +39,7 @@ export class AdbScrcpyOptions1_16 extends AdbScrcpyOptions<
adb: Adb,
path: string,
version: string,
options: AdbScrcpyOptions<object>,
options: AdbScrcpyOptions<Pick<ScrcpyOptionsInit1_16, "tunnelForward">>,
): Promise<ScrcpyEncoder[]> {
const client = await AdbScrcpyClient.start(adb, path, version, options);
@ -62,7 +62,7 @@ export class AdbScrcpyOptions1_16 extends AdbScrcpyOptions<
adb: Adb,
path: string,
version: string,
options: AdbScrcpyOptions<object>,
options: AdbScrcpyOptions<Pick<ScrcpyOptionsInit1_16, "tunnelForward">>,
): Promise<ScrcpyDisplay[]> {
try {
// 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
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,
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 {
ScrcpyDisplay,
ScrcpyEncoder,
ScrcpyOptionsInit1_16,
ScrcpyOptionsInit2_0,
} from "@yume-chan/scrcpy";
@ -23,7 +24,7 @@ export class AdbScrcpyOptions2_0 extends AdbScrcpyOptions<
adb: Adb,
path: string,
version: string,
options: AdbScrcpyOptions<object>,
options: AdbScrcpyOptions<Pick<ScrcpyOptionsInit1_16, "tunnelForward">>,
): Promise<ScrcpyEncoder[]> {
try {
// Similar to `AdbScrcpyOptions1_16.getDisplays`,
@ -80,7 +81,7 @@ export class AdbScrcpyOptions2_0 extends AdbScrcpyOptions<
control: this.value.control,
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,
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;
}
/**
* Allows the client to forcefully enable forward tunnel mode
* when reverse tunnel fails.
*/
tunnelForwardOverride = false;
constructor(base: ScrcpyOptions<T>) {
super(
// HACK: `ScrcpyOptions`'s constructor requires a constructor for the base class,

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -37,7 +37,7 @@
"@yume-chan/no-data-view": "workspace:^"
},
"devDependencies": {
"@types/node": "^22.7.7",
"@types/node": "^22.9.0",
"@yume-chan/eslint-config": "workspace:^",
"@yume-chan/test-runner": "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"
},
"dependencies": {
"@eslint/js": "^9.13.0",
"@types/node": "^22.7.7",
"eslint": "^9.13.0",
"eslint-plugin-import-x": "^4.3.1",
"@eslint/js": "^9.15.0",
"@types/node": "^22.9.0",
"eslint": "^9.15.0",
"eslint-plugin-import-x": "^4.4.2",
"typescript": "^5.6.3",
"typescript-eslint": "^8.11.0"
"typescript-eslint": "^8.15.0"
},
"devDependencies": {
"prettier": "^3.3.3"

View file

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

View file

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