Try to fix Remote Play issue

This commit is contained in:
redphx 2024-07-30 18:23:17 +07:00
parent 361ce057b7
commit 41fe12afc6
3 changed files with 18 additions and 9 deletions

3
src/types/network.ts Normal file
View File

@ -0,0 +1,3 @@
export type RemotePlayConsoleAddresses = {
[key: string]: number[],
}

View File

@ -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:(?<foundation>\d+) (?<component>\d+) UDP (?<priority>\d+) (?<ip>[^\s]+) (?<port>\d+) (?<the_rest>.*)/);
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();

View File

@ -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<number>();
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);