From e5bd7e64a75f98d3a9cb4547e73dc0e28fb8f4bd Mon Sep 17 00:00:00 2001 From: redphx <96280+redphx@users.noreply.github.com> Date: Mon, 14 Oct 2024 20:08:47 +0700 Subject: [PATCH] Refactor xCloud & xHome interceptors --- src/utils/xcloud-interceptor.ts | 54 ++++++++++++++++----------------- src/utils/xhome-interceptor.ts | 30 +++++++++--------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/utils/xcloud-interceptor.ts b/src/utils/xcloud-interceptor.ts index d1869a8..552de7c 100644 --- a/src/utils/xcloud-interceptor.ts +++ b/src/utils/xcloud-interceptor.ts @@ -13,9 +13,25 @@ import { BypassServerIps } from "@/enums/bypass-servers"; import { PrefKey } from "@/enums/pref-keys"; import { getPref, StreamResolution, StreamTouchController } from "./settings-storages/global-settings-storage"; -export -class XcloudInterceptor { - static async #handleLogin(request: RequestInfo | URL, init?: RequestInit) { +export class XcloudInterceptor { + private static readonly SERVER_EMOJIS = { + AustraliaEast: 'πŸ‡¦πŸ‡Ί', + AustraliaSouthEast: 'πŸ‡¦πŸ‡Ί', + BrazilSouth: 'πŸ‡§πŸ‡·', + EastUS: 'πŸ‡ΊπŸ‡Έ', + EastUS2: 'πŸ‡ΊπŸ‡Έ', + JapanEast: 'πŸ‡―πŸ‡΅', + KoreaCentral: 'πŸ‡°πŸ‡·', + MexicoCentral: 'πŸ‡²πŸ‡½', + NorthCentralUs: 'πŸ‡ΊπŸ‡Έ', + SouthCentralUS: 'πŸ‡ΊπŸ‡Έ', + UKSouth: 'πŸ‡¬πŸ‡§', + WestEurope: 'πŸ‡ͺπŸ‡Ί', + WestUS: 'πŸ‡ΊπŸ‡Έ', + WestUS2: 'πŸ‡ΊπŸ‡Έ', + }; + + private static async handleLogin(request: RequestInfo | URL, init?: RequestInit) { const bypassServer = getPref(PrefKey.SERVER_BYPASS_RESTRICTION); if (bypassServer !== 'off') { const ip = BypassServerIps[bypassServer as keyof typeof BypassServerIps]; @@ -35,24 +51,8 @@ class XcloudInterceptor { RemotePlayManager.getInstance().xcloudToken = obj.gsToken; // Get server list - const serverEmojis = { - AustraliaEast: 'πŸ‡¦πŸ‡Ί', - AustraliaSouthEast: 'πŸ‡¦πŸ‡Ί', - BrazilSouth: 'πŸ‡§πŸ‡·', - EastUS: 'πŸ‡ΊπŸ‡Έ', - EastUS2: 'πŸ‡ΊπŸ‡Έ', - JapanEast: 'πŸ‡―πŸ‡΅', - KoreaCentral: 'πŸ‡°πŸ‡·', - MexicoCentral: 'πŸ‡²πŸ‡½', - NorthCentralUs: 'πŸ‡ΊπŸ‡Έ', - SouthCentralUS: 'πŸ‡ΊπŸ‡Έ', - UKSouth: 'πŸ‡¬πŸ‡§', - WestEurope: 'πŸ‡ͺπŸ‡Ί', - WestUS: 'πŸ‡ΊπŸ‡Έ', - WestUS2: 'πŸ‡ΊπŸ‡Έ', - }; - const serverRegex = /\/\/(\w+)\./; + const serverEmojis = XcloudInterceptor.SERVER_EMOJIS; for (let region of obj.offeringSettings.regions) { const regionName = region.name as keyof typeof serverEmojis; @@ -91,7 +91,7 @@ class XcloudInterceptor { return response; } - static async #handlePlay(request: RequestInfo | URL, init?: RequestInit) { + private static async handlePlay(request: RequestInfo | URL, init?: RequestInit) { const PREF_STREAM_TARGET_RESOLUTION = getPref(PrefKey.STREAM_TARGET_RESOLUTION); const PREF_STREAM_PREFERRED_LOCALE = getPref(PrefKey.STREAM_PREFERRED_LOCALE); @@ -129,7 +129,7 @@ class XcloudInterceptor { return NATIVE_FETCH(newRequest); } - static async #handleWaitTime(request: RequestInfo | URL, init?: RequestInit) { + private static async handleWaitTime(request: RequestInfo | URL, init?: RequestInit) { const response = await NATIVE_FETCH(request, init); if (getPref(PrefKey.UI_LOADING_SCREEN_WAIT_TIME)) { @@ -143,7 +143,7 @@ class XcloudInterceptor { return response; } - static async #handleConfiguration(request: RequestInfo | URL, init?: RequestInit) { + private static async handleConfiguration(request: RequestInfo | URL, init?: RequestInit) { if ((request as Request).method !== 'GET') { return NATIVE_FETCH(request, init); } @@ -213,13 +213,13 @@ class XcloudInterceptor { // Server list if (url.endsWith('/v2/login/user')) { - return XcloudInterceptor.#handleLogin(request, init); + return XcloudInterceptor.handleLogin(request, init); } else if (url.endsWith('/sessions/cloud/play')) { // Get session - return XcloudInterceptor.#handlePlay(request, init); + return XcloudInterceptor.handlePlay(request, init); } else if (url.includes('xboxlive.com') && url.includes('/waittime/')) { - return XcloudInterceptor.#handleWaitTime(request, init); + return XcloudInterceptor.handleWaitTime(request, init); } else if (url.endsWith('/configuration')) { - return XcloudInterceptor.#handleConfiguration(request, init); + return XcloudInterceptor.handleConfiguration(request, init); } else if (url && url.endsWith('/ice') && url.includes('/sessions/') && (request as Request).method === 'GET') { return patchIceCandidates(request as Request); } diff --git a/src/utils/xhome-interceptor.ts b/src/utils/xhome-interceptor.ts index c39073a..8a9ed3b 100644 --- a/src/utils/xhome-interceptor.ts +++ b/src/utils/xhome-interceptor.ts @@ -10,7 +10,7 @@ import type { RemotePlayConsoleAddresses } from "@/types/network"; import { RemotePlayManager } from "@/modules/remote-play-manager"; export class XhomeInterceptor { - static #consoleAddrs: RemotePlayConsoleAddresses = {}; + private static consoleAddrs: RemotePlayConsoleAddresses = {}; private static readonly BASE_DEVICE_INFO = { appInfo: { @@ -52,7 +52,7 @@ export class XhomeInterceptor { }, }; - static async #handleLogin(request: Request) { + private static async handleLogin(request: Request) { try { const clone = (request as Request).clone(); @@ -74,7 +74,7 @@ export class XhomeInterceptor { return NATIVE_FETCH(request); } - static async #handleConfiguration(request: Request | URL) { + private static async handleConfiguration(request: Request | URL) { const response = await NATIVE_FETCH(request); const obj = await response.clone().json() @@ -90,15 +90,15 @@ export class XhomeInterceptor { const serverDetails = obj.serverDetails; if (serverDetails.ipAddress) { - XhomeInterceptor.#consoleAddrs[serverDetails.ipAddress] = processPorts(serverDetails.port); + XhomeInterceptor.consoleAddrs[serverDetails.ipAddress] = processPorts(serverDetails.port); } if (serverDetails.ipV4Address) { - XhomeInterceptor.#consoleAddrs[serverDetails.ipV4Address] = processPorts(serverDetails.ipV4Port); + XhomeInterceptor.consoleAddrs[serverDetails.ipV4Address] = processPorts(serverDetails.ipV4Port); } if (serverDetails.ipV6Address) { - XhomeInterceptor.#consoleAddrs[serverDetails.ipV6Address] = processPorts(serverDetails.ipV6Port); + XhomeInterceptor.consoleAddrs[serverDetails.ipV6Address] = processPorts(serverDetails.ipV6Port); } response.json = () => Promise.resolve(obj); @@ -107,7 +107,7 @@ export class XhomeInterceptor { return response; } - static async #handleInputConfigs(request: Request | URL, opts: {[index: string]: any}) { + private static async handleInputConfigs(request: Request | URL, opts: {[index: string]: any}) { const response = await NATIVE_FETCH(request); if (getPref(PrefKey.STREAM_TOUCH_CONTROLLER) !== StreamTouchController.ALL) { @@ -144,7 +144,7 @@ export class XhomeInterceptor { return response; } - static async #handleTitles(request: Request) { + private static async handleTitles(request: Request) { const clone = request.clone(); const headers: {[index: string]: any} = {}; @@ -163,7 +163,7 @@ export class XhomeInterceptor { return NATIVE_FETCH(request); } - static async #handlePlay(request: RequestInfo | URL) { + private static async handlePlay(request: RequestInfo | URL) { const clone = (request as Request).clone(); const body = await clone.json(); @@ -216,17 +216,17 @@ export class XhomeInterceptor { // Get console IP if (url.includes('/configuration')) { - return XhomeInterceptor.#handleConfiguration(request); + return XhomeInterceptor.handleConfiguration(request); } else if (url.endsWith('/sessions/home/play')) { - return XhomeInterceptor.#handlePlay(request); + return XhomeInterceptor.handlePlay(request); } else if (url.includes('inputconfigs')) { - return XhomeInterceptor.#handleInputConfigs(request, opts); + return XhomeInterceptor.handleInputConfigs(request, opts); } else if (url.includes('/login/user')) { - return XhomeInterceptor.#handleLogin(request); + return XhomeInterceptor.handleLogin(request); } else if (url.endsWith('/titles')) { - return XhomeInterceptor.#handleTitles(request); + return XhomeInterceptor.handleTitles(request); } else if (url && url.endsWith('/ice') && url.includes('/sessions/') && (request as Request).method === 'GET') { - return patchIceCandidates(request, XhomeInterceptor.#consoleAddrs); + return patchIceCandidates(request, XhomeInterceptor.consoleAddrs); } return await NATIVE_FETCH(request);