From 41fe12afc6f335d4459702cbb3673e10e277c7de Mon Sep 17 00:00:00 2001 From: redphx <96280+redphx@users.noreply.github.com> Date: Tue, 30 Jul 2024 18:23:17 +0700 Subject: [PATCH] Try to fix Remote Play issue --- src/types/network.ts | 3 +++ src/utils/network.ts | 11 ++++++----- src/utils/xhome-interceptor.ts | 13 +++++++++---- 3 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 src/types/network.ts diff --git a/src/types/network.ts b/src/types/network.ts new file mode 100644 index 0000000..85681f1 --- /dev/null +++ b/src/types/network.ts @@ -0,0 +1,3 @@ +export type RemotePlayConsoleAddresses = { + [key: string]: number[], +} diff --git a/src/utils/network.ts b/src/utils/network.ts index e4bf256..13037ea 100644 --- a/src/utils/network.ts +++ b/src/utils/network.ts @@ -9,6 +9,7 @@ import { XhomeInterceptor } from "./xhome-interceptor"; import { XcloudInterceptor } from "./xcloud-interceptor"; import { PrefKey } from "@/enums/pref-keys"; import { getPref } from "./settings-storages/global-settings-storage"; +import type { RemotePlayConsoleAddresses } from "@/types/network"; type RequestType = 'xcloud' | 'xhome'; @@ -39,7 +40,7 @@ function clearAllLogs() { clearDbLogs('XCloudAppLogs', 'logs'); } -function updateIceCandidates(candidates: any, options: any) { +function updateIceCandidates(candidates: any, options: {preferIpv6Server: boolean, consoleAddrs?: RemotePlayConsoleAddresses}) { const pattern = new RegExp(/a=candidate:(?\d+) (?\d+) UDP (?\d+) (?[^\s]+) (?\d+) (?.*)/); const lst = []; @@ -83,9 +84,9 @@ function updateIceCandidates(candidates: any, options: any) { if (options.consoleAddrs) { for (const ip in options.consoleAddrs) { - const port = options.consoleAddrs[ip]; - - newCandidates.push(newCandidate(`a=candidate:${newCandidates.length + 1} 1 UDP 1 ${ip} ${port} typ host`)); + for (const port of options.consoleAddrs[ip]) { + newCandidates.push(newCandidate(`a=candidate:${newCandidates.length + 1} 1 UDP 1 ${ip} ${port} typ host`)); + } } } @@ -96,7 +97,7 @@ function updateIceCandidates(candidates: any, options: any) { } -export async function patchIceCandidates(request: Request, consoleAddrs?: {[index: string]: number}) { +export async function patchIceCandidates(request: Request, consoleAddrs?: RemotePlayConsoleAddresses) { const response = await NATIVE_FETCH(request); const text = await response.clone().text(); diff --git a/src/utils/xhome-interceptor.ts b/src/utils/xhome-interceptor.ts index 77af302..b906576 100644 --- a/src/utils/xhome-interceptor.ts +++ b/src/utils/xhome-interceptor.ts @@ -7,9 +7,10 @@ import { STATES } from "./global"; import { patchIceCandidates } from "./network"; import { PrefKey } from "@/enums/pref-keys"; import { getPref } from "./settings-storages/global-settings-storage"; +import type { RemotePlayConsoleAddresses } from "@/types/network"; export class XhomeInterceptor { - static #consoleAddrs: {[index: string]: number} = {}; + static #consoleAddrs: RemotePlayConsoleAddresses = {}; static async #handleLogin(request: Request) { try { @@ -41,15 +42,19 @@ export class XhomeInterceptor { const serverDetails = obj.serverDetails; if (serverDetails.ipAddress) { - XhomeInterceptor.#consoleAddrs[serverDetails.ipAddress] = serverDetails.port; + XhomeInterceptor.#consoleAddrs[serverDetails.ipAddress] = [serverDetails.port]; } if (serverDetails.ipV4Address) { - XhomeInterceptor.#consoleAddrs[serverDetails.ipV4Address] = serverDetails.ipV4Port; + const ports = new Set(); + ports.add(serverDetails.ipV4Port); + ports.add(9002); + + XhomeInterceptor.#consoleAddrs[serverDetails.ipV4Address] = Array.from(ports); } if (serverDetails.ipV6Address) { - XhomeInterceptor.#consoleAddrs[serverDetails.ipV6Address] = serverDetails.ipV6Port; + XhomeInterceptor.#consoleAddrs[serverDetails.ipV6Address] = [serverDetails.ipV6Port]; } response.json = () => Promise.resolve(obj);