mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-08-07 05:38:27 +02:00
Rename States to STATES
This commit is contained in:
@@ -2,7 +2,7 @@ import { getLocale } from "../modules/translation";
|
||||
|
||||
export const AppInterface = window.AppInterface;
|
||||
export const NATIVE_FETCH = window.fetch;
|
||||
export const States: BxStates = {
|
||||
export const STATES: BxStates = {
|
||||
isPlaying: false,
|
||||
appContext: {},
|
||||
serverRegions: {},
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { BxEvent } from "../modules/bx-event";
|
||||
import { getPref, PrefKey } from "../modules/preferences";
|
||||
import { States } from "./global";
|
||||
import { STATES } from "./global";
|
||||
import { UserAgent } from "./user-agent";
|
||||
|
||||
export function patchVideoApi() {
|
||||
@@ -100,11 +100,11 @@ export function patchRtcPeerConnection() {
|
||||
// @ts-ignore
|
||||
window.RTCPeerConnection = function() {
|
||||
const conn = new OrgRTCPeerConnection();
|
||||
States.currentStream.peerConnection = conn;
|
||||
STATES.currentStream.peerConnection = conn;
|
||||
|
||||
conn.addEventListener('connectionstatechange', e => {
|
||||
if (conn.connectionState === 'connecting') {
|
||||
States.currentStream.audioGainNode = null;
|
||||
STATES.currentStream.audioGainNode = null;
|
||||
}
|
||||
console.log('connectionState', conn.connectionState);
|
||||
});
|
||||
@@ -118,7 +118,7 @@ export function patchAudioContext() {
|
||||
window.AudioContext.prototype.createGain = function() {
|
||||
const gainNode = nativeCreateGain.apply(this);
|
||||
gainNode.gain.value = getPref(PrefKey.AUDIO_VOLUME) / 100;
|
||||
States.currentStream.audioGainNode = gainNode;
|
||||
STATES.currentStream.audioGainNode = gainNode;
|
||||
return gainNode;
|
||||
}
|
||||
}
|
||||
@@ -127,8 +127,8 @@ export function patchAudioContext() {
|
||||
// @ts-ignore
|
||||
window.AudioContext = function() {
|
||||
const ctx = new OrgAudioContext();
|
||||
States.currentStream.audioContext = ctx;
|
||||
States.currentStream.audioGainNode = null;
|
||||
STATES.currentStream.audioContext = ctx;
|
||||
STATES.currentStream.audioGainNode = null;
|
||||
return ctx;
|
||||
}
|
||||
|
||||
@@ -137,13 +137,13 @@ export function patchAudioContext() {
|
||||
this.muted = true;
|
||||
|
||||
const promise = nativePlay.apply(this);
|
||||
if (States.currentStream.audioGainNode) {
|
||||
if (STATES.currentStream.audioGainNode) {
|
||||
return promise;
|
||||
}
|
||||
|
||||
this.addEventListener('playing', e => (e.target as HTMLAudioElement).pause());
|
||||
|
||||
const audioCtx = States.currentStream.audioContext!;
|
||||
const audioCtx = STATES.currentStream.audioContext!;
|
||||
// TOOD: check srcObject
|
||||
const audioStream = audioCtx.createMediaStreamSource(this.srcObject as any);
|
||||
const gainNode = audioCtx.createGain();
|
||||
@@ -151,7 +151,7 @@ export function patchAudioContext() {
|
||||
audioStream.connect(gainNode);
|
||||
gainNode.connect(audioCtx.destination);
|
||||
gainNode.gain.value = getPref(PrefKey.AUDIO_VOLUME) / 100;
|
||||
States.currentStream.audioGainNode = gainNode;
|
||||
STATES.currentStream.audioGainNode = gainNode;
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@ import { PrefKey, getPref } from "../modules/preferences";
|
||||
import { RemotePlay } from "../modules/remote-play";
|
||||
import { StreamBadges } from "../modules/stream/stream-badges";
|
||||
import { TouchController } from "../modules/touch-controller";
|
||||
import { NATIVE_FETCH, States } from "./global";
|
||||
import { NATIVE_FETCH, STATES } from "./global";
|
||||
import { getPreferredServerRegion } from "./region";
|
||||
import { TitlesInfo } from "./titles-info";
|
||||
|
||||
@@ -189,7 +189,7 @@ class XhomeInterceptor {
|
||||
const obj = await response.clone().json() as any;
|
||||
|
||||
const xboxTitleId = JSON.parse(opts.body).titleIds[0];
|
||||
States.currentStream.xboxTitleId = xboxTitleId;
|
||||
STATES.currentStream.xboxTitleId = xboxTitleId;
|
||||
|
||||
const inputConfigs = obj[0];
|
||||
|
||||
@@ -265,7 +265,7 @@ class XhomeInterceptor {
|
||||
}
|
||||
|
||||
const index = request.url.indexOf('.xboxlive.com');
|
||||
let newUrl = States.remotePlay.server + request.url.substring(index + 13);
|
||||
let newUrl = STATES.remotePlay.server + request.url.substring(index + 13);
|
||||
|
||||
request = new Request(newUrl, opts);
|
||||
let url = (typeof request === 'string') ? request : request.url;
|
||||
@@ -330,14 +330,14 @@ class XcloudInterceptor {
|
||||
}
|
||||
|
||||
region.shortName = shortName.toUpperCase();
|
||||
States.serverRegions[region.name] = Object.assign({}, region);
|
||||
STATES.serverRegions[region.name] = Object.assign({}, region);
|
||||
}
|
||||
|
||||
BxEvent.dispatch(window, BxEvent.XCLOUD_SERVERS_READY);
|
||||
|
||||
const preferredRegion = getPreferredServerRegion();
|
||||
if (preferredRegion in States.serverRegions) {
|
||||
const tmp = Object.assign({}, States.serverRegions[preferredRegion]);
|
||||
if (preferredRegion in STATES.serverRegions) {
|
||||
const tmp = Object.assign({}, STATES.serverRegions[preferredRegion]);
|
||||
tmp.isDefault = true;
|
||||
|
||||
obj.offeringSettings.regions = [tmp];
|
||||
@@ -355,8 +355,8 @@ class XcloudInterceptor {
|
||||
const parsedUrl = new URL(url);
|
||||
|
||||
StreamBadges.region = parsedUrl.host.split('.', 1)[0];
|
||||
for (let regionName in States.appContext) {
|
||||
const region = States.appContext[regionName];
|
||||
for (let regionName in STATES.appContext) {
|
||||
const region = STATES.appContext[regionName];
|
||||
if (parsedUrl.origin == region.baseUri) {
|
||||
StreamBadges.region = regionName;
|
||||
break;
|
||||
@@ -573,7 +573,7 @@ export function interceptHttpRequests() {
|
||||
}
|
||||
|
||||
let requestType: RequestType;
|
||||
if (States.remotePlay.isPlaying || url.includes('/sessions/home')) {
|
||||
if (STATES.remotePlay.isPlaying || url.includes('/sessions/home')) {
|
||||
requestType = RequestType.XHOME;
|
||||
} else {
|
||||
requestType = RequestType.XCLOUD;
|
||||
|
@@ -1,19 +1,19 @@
|
||||
import { getPref, PrefKey } from "../modules/preferences";
|
||||
import { States } from "./global";
|
||||
import { STATES } from "./global";
|
||||
|
||||
|
||||
export function getPreferredServerRegion(shortName = false) {
|
||||
let preferredRegion = getPref(PrefKey.SERVER_REGION);
|
||||
if (preferredRegion in States.serverRegions) {
|
||||
if (shortName && States.serverRegions[preferredRegion].shortName) {
|
||||
return States.serverRegions[preferredRegion].shortName;
|
||||
if (preferredRegion in STATES.serverRegions) {
|
||||
if (shortName && STATES.serverRegions[preferredRegion].shortName) {
|
||||
return STATES.serverRegions[preferredRegion].shortName;
|
||||
} else {
|
||||
return preferredRegion;
|
||||
}
|
||||
}
|
||||
|
||||
for (let regionName in States.serverRegions) {
|
||||
const region = States.serverRegions[regionName];
|
||||
for (let regionName in STATES.serverRegions) {
|
||||
const region = STATES.serverRegions[regionName];
|
||||
if (!region.isDefault) {
|
||||
continue;
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { PrefKey } from "../modules/preferences";
|
||||
import { getPref } from "../modules/preferences";
|
||||
import { States } from "./global";
|
||||
import { STATES } from "./global";
|
||||
import { UserAgent } from "./user-agent";
|
||||
|
||||
export class TitlesInfo {
|
||||
@@ -39,14 +39,14 @@ export class TitlesInfo {
|
||||
}
|
||||
|
||||
static requestCatalogInfo(titleId: string, callback: any) {
|
||||
const url = `https://catalog.gamepass.com/v3/products?market=${States.appContext.marketInfo.market}&language=${States.appContext.marketInfo.locale}&hydration=RemoteHighSapphire0`;
|
||||
const url = `https://catalog.gamepass.com/v3/products?market=${STATES.appContext.marketInfo.market}&language=${STATES.appContext.marketInfo.locale}&hydration=RemoteHighSapphire0`;
|
||||
const appVersion = document.querySelector('meta[name=gamepass-app-version]')!.getAttribute('content');
|
||||
|
||||
fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Ms-Cv': States.appContext.telemetryInfo.initialCv,
|
||||
'Ms-Cv': STATES.appContext.telemetryInfo.initialCv,
|
||||
'Calling-App-Name': 'Xbox Cloud Gaming Web',
|
||||
'Calling-App-Version': appVersion,
|
||||
} as any,
|
||||
@@ -75,7 +75,7 @@ export class PreloadedState {
|
||||
},
|
||||
set: state => {
|
||||
(this as any)._state = state;
|
||||
States.appContext = structuredClone(state.appContext);
|
||||
STATES.appContext = structuredClone(state.appContext);
|
||||
|
||||
// Get a list of touch-supported games
|
||||
if (getPref(PrefKey.STREAM_TOUCH_CONTROLLER) === 'all') {
|
||||
|
Reference in New Issue
Block a user