mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-03 06:07:19 +02:00
Rename States to STATES
This commit is contained in:
parent
fd0f0799ee
commit
06ffcf20f7
26
src/index.ts
26
src/index.ts
@ -24,7 +24,7 @@ import { VibrationManager } from "./modules/vibration-manager";
|
||||
import { PreloadedState } from "./utils/titles-info";
|
||||
import { patchAudioContext, patchRtcCodecs, patchRtcPeerConnection, patchVideoApi } from "./utils/monkey-patches";
|
||||
import { interceptHttpRequests } from "./utils/network";
|
||||
import { States } from "./utils/global";
|
||||
import { STATES } from "./utils/global";
|
||||
import { injectStreamMenuButtons } from "./modules/stream/stream-ui";
|
||||
|
||||
/* ADDITIONAL CODE */
|
||||
@ -118,12 +118,12 @@ window.addEventListener(BxEvent.STREAM_LOADING, e => {
|
||||
if (window.location.pathname.includes('/launch/')) {
|
||||
const matches = /\/launch\/(?<title_id>[^\/]+)\/(?<product_id>\w+)/.exec(window.location.pathname);
|
||||
if (matches?.groups) {
|
||||
States.currentStream.titleId = matches.groups.title_id;
|
||||
States.currentStream.productId = matches.groups.product_id;
|
||||
STATES.currentStream.titleId = matches.groups.title_id;
|
||||
STATES.currentStream.productId = matches.groups.product_id;
|
||||
}
|
||||
} else {
|
||||
States.currentStream.titleId = 'remote-play';
|
||||
States.currentStream.productId = '';
|
||||
STATES.currentStream.titleId = 'remote-play';
|
||||
STATES.currentStream.productId = '';
|
||||
}
|
||||
|
||||
// Setup UI
|
||||
@ -147,9 +147,9 @@ window.addEventListener(BxEvent.STREAM_STARTING, e => {
|
||||
|
||||
window.addEventListener(BxEvent.STREAM_PLAYING, e => {
|
||||
const $video = (e as any).$video;
|
||||
States.currentStream.$video = $video;
|
||||
STATES.currentStream.$video = $video;
|
||||
|
||||
States.isPlaying = true;
|
||||
STATES.isPlaying = true;
|
||||
injectStreamMenuButtons();
|
||||
/*
|
||||
if (getPref(Preferences.CONTROLLER_ENABLE_SHORTCUTS)) {
|
||||
@ -158,8 +158,8 @@ window.addEventListener(BxEvent.STREAM_PLAYING, e => {
|
||||
*/
|
||||
|
||||
const PREF_SCREENSHOT_BUTTON_POSITION = getPref(PrefKey.SCREENSHOT_BUTTON_POSITION);
|
||||
States.currentStream.$screenshotCanvas!.width = $video.videoWidth;
|
||||
States.currentStream.$screenshotCanvas!.height = $video.videoHeight;
|
||||
STATES.currentStream.$screenshotCanvas!.width = $video.videoWidth;
|
||||
STATES.currentStream.$screenshotCanvas!.height = $video.videoHeight;
|
||||
updateVideoPlayerCss();
|
||||
|
||||
// Setup screenshot button
|
||||
@ -180,11 +180,11 @@ window.addEventListener(BxEvent.STREAM_ERROR_PAGE, e => {
|
||||
});
|
||||
|
||||
window.addEventListener(BxEvent.STREAM_STOPPED, e => {
|
||||
if (!States.isPlaying) {
|
||||
if (!STATES.isPlaying) {
|
||||
return;
|
||||
}
|
||||
|
||||
States.isPlaying = false;
|
||||
STATES.isPlaying = false;
|
||||
|
||||
// Stop MKB listeners
|
||||
getPref(PrefKey.MKB_ENABLED) && MkbHandler.INSTANCE.destroy();
|
||||
@ -194,8 +194,8 @@ window.addEventListener(BxEvent.STREAM_STOPPED, e => {
|
||||
$quickBar.classList.add('bx-gone');
|
||||
}
|
||||
|
||||
States.currentStream.audioGainNode = null;
|
||||
States.currentStream.$video = null;
|
||||
STATES.currentStream.audioGainNode = null;
|
||||
STATES.currentStream.$video = null;
|
||||
StreamStats.onStoppedPlaying();
|
||||
|
||||
const $screenshotBtn = document.querySelector('.bx-screenshot-button');
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { States } from "../utils/global";
|
||||
import { STATES } from "../utils/global";
|
||||
|
||||
export const BxExposed = {
|
||||
onPollingModeChanged: (mode: 'All' | 'None') => {
|
||||
if (!States.isPlaying) {
|
||||
if (!STATES.isPlaying) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { States } from "../utils/global";
|
||||
import { STATES } from "../utils/global";
|
||||
import { BX_FLAGS } from "./bx-flags";
|
||||
import { getPref, PrefKey } from "./preferences";
|
||||
import { VibrationManager } from "./vibration-manager";
|
||||
@ -424,7 +424,7 @@ let PATCH_ORDERS = [
|
||||
'overrideSettings',
|
||||
],
|
||||
|
||||
getPref(PrefKey.REMOTE_PLAY_ENABLED) && States.hasTouchSupport && ['patchUpdateInputConfigurationAsync'],
|
||||
getPref(PrefKey.REMOTE_PLAY_ENABLED) && STATES.hasTouchSupport && ['patchUpdateInputConfigurationAsync'],
|
||||
|
||||
getPref(PrefKey.GAME_FORTNITE_FORCE_CONSOLE) && ['forceFortniteConsole'],
|
||||
];
|
||||
@ -438,8 +438,8 @@ const PLAYING_PATCH_ORDERS = [
|
||||
['patchStreamHud'],
|
||||
|
||||
['playVibration'],
|
||||
States.hasTouchSupport && getPref(PrefKey.STREAM_TOUCH_CONTROLLER) === 'all' && ['exposeTouchLayoutManager'],
|
||||
States.hasTouchSupport && (getPref(PrefKey.STREAM_TOUCH_CONTROLLER) === 'off' || getPref(PrefKey.STREAM_TOUCH_CONTROLLER_AUTO_OFF)) && ['disableTakRenderer'],
|
||||
STATES.hasTouchSupport && getPref(PrefKey.STREAM_TOUCH_CONTROLLER) === 'all' && ['exposeTouchLayoutManager'],
|
||||
STATES.hasTouchSupport && (getPref(PrefKey.STREAM_TOUCH_CONTROLLER) === 'off' || getPref(PrefKey.STREAM_TOUCH_CONTROLLER_AUTO_OFF)) && ['disableTakRenderer'],
|
||||
|
||||
BX_FLAGS.EnableXcloudLogging && ['enableConsoleLogging'],
|
||||
|
||||
|
@ -4,7 +4,7 @@ import { SettingElement, SettingElementType } from "./settings";
|
||||
import { UserAgentProfile } from "../utils/user-agent";
|
||||
import { StreamStat } from "./stream/stream-stats";
|
||||
import type { PreferenceSettings } from "../types/preferences";
|
||||
import { States } from "../utils/global";
|
||||
import { STATES } from "../utils/global";
|
||||
|
||||
export enum PrefKey {
|
||||
LAST_UPDATE_CHECK = 'version_last_check',
|
||||
@ -280,7 +280,7 @@ export class Preferences {
|
||||
all: t('tc-all-games'),
|
||||
off: t('off'),
|
||||
},
|
||||
unsupported: !States.hasTouchSupport,
|
||||
unsupported: !STATES.hasTouchSupport,
|
||||
ready: () => {
|
||||
const setting = Preferences.SETTINGS[PrefKey.STREAM_TOUCH_CONTROLLER];
|
||||
if (setting.unsupported) {
|
||||
@ -291,7 +291,7 @@ export class Preferences {
|
||||
[PrefKey.STREAM_TOUCH_CONTROLLER_AUTO_OFF]: {
|
||||
label: t('tc-auto-off'),
|
||||
default: false,
|
||||
unsupported: !States.hasTouchSupport,
|
||||
unsupported: !STATES.hasTouchSupport,
|
||||
},
|
||||
[PrefKey.STREAM_TOUCH_CONTROLLER_STYLE_STANDARD]: {
|
||||
label: t('tc-standard-layout-style'),
|
||||
@ -301,7 +301,7 @@ export class Preferences {
|
||||
white: t('tc-all-white'),
|
||||
muted: t('tc-muted-colors'),
|
||||
},
|
||||
unsupported: !States.hasTouchSupport,
|
||||
unsupported: !STATES.hasTouchSupport,
|
||||
},
|
||||
[PrefKey.STREAM_TOUCH_CONTROLLER_STYLE_CUSTOM]: {
|
||||
label: t('tc-custom-layout-style'),
|
||||
@ -310,7 +310,7 @@ export class Preferences {
|
||||
default: t('default'),
|
||||
muted: t('tc-muted-colors'),
|
||||
},
|
||||
unsupported: !States.hasTouchSupport,
|
||||
unsupported: !STATES.hasTouchSupport,
|
||||
},
|
||||
|
||||
[PrefKey.STREAM_SIMPLIFY_MENU]: {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { States, AppInterface } from "../utils/global";
|
||||
import { STATES, AppInterface } from "../utils/global";
|
||||
import { CE, createButton, ButtonStyle, Icon } from "../utils/html";
|
||||
import { Toast } from "../utils/toast";
|
||||
import { BxEvent } from "./bx-event";
|
||||
@ -259,7 +259,7 @@ export class RemotePlay {
|
||||
RemotePlay.#CONSOLES = json.results;
|
||||
|
||||
// Store working server
|
||||
States.remotePlay.server = region.baseUri;
|
||||
STATES.remotePlay.server = region.baseUri;
|
||||
|
||||
callback();
|
||||
} catch (e) {}
|
||||
@ -270,7 +270,7 @@ export class RemotePlay {
|
||||
}
|
||||
|
||||
// None of the servers worked
|
||||
if (!States.remotePlay.server) {
|
||||
if (!STATES.remotePlay.server) {
|
||||
RemotePlay.#CONSOLES = [];
|
||||
}
|
||||
}
|
||||
@ -280,10 +280,10 @@ export class RemotePlay {
|
||||
setPref(PrefKey.REMOTE_PLAY_RESOLUTION, resolution);
|
||||
}
|
||||
|
||||
States.remotePlay.config = {
|
||||
STATES.remotePlay.config = {
|
||||
serverId: serverId,
|
||||
};
|
||||
window.BX_REMOTE_PLAY_CONFIG = States.remotePlay.config;
|
||||
window.BX_REMOTE_PLAY_CONFIG = STATES.remotePlay.config;
|
||||
|
||||
localRedirect('/launch/fortnite/BT5P2X999VH2#remote-play');
|
||||
RemotePlay.detachPopup();
|
||||
@ -337,9 +337,9 @@ export class RemotePlay {
|
||||
return;
|
||||
}
|
||||
|
||||
States.remotePlay.isPlaying = window.location.pathname.includes('/launch/') && window.location.hash.startsWith('#remote-play');
|
||||
if (States.remotePlay?.isPlaying) {
|
||||
window.BX_REMOTE_PLAY_CONFIG = States.remotePlay.config;
|
||||
STATES.remotePlay.isPlaying = window.location.pathname.includes('/launch/') && window.location.hash.startsWith('#remote-play');
|
||||
if (STATES.remotePlay?.isPlaying) {
|
||||
window.BX_REMOTE_PLAY_CONFIG = STATES.remotePlay.config;
|
||||
// Remove /launch/... from URL
|
||||
window.history.replaceState({origin: 'better-xcloud'}, '', 'https://www.xbox.com/' + location.pathname.substring(1, 6) + '/play');
|
||||
} else {
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { States, AppInterface } from "../utils/global";
|
||||
import { STATES, AppInterface } from "../utils/global";
|
||||
import { CE } from "../utils/html";
|
||||
|
||||
export function takeScreenshot(callback: any) {
|
||||
const currentStream = States.currentStream!;
|
||||
const currentStream = STATES.currentStream!;
|
||||
const $video = currentStream.$video;
|
||||
const $canvas = currentStream.$screenshotCanvas;
|
||||
if (!$video || !$canvas) {
|
||||
@ -44,7 +44,7 @@ export function takeScreenshot(callback: any) {
|
||||
|
||||
|
||||
export function setupScreenshotButton() {
|
||||
const currentStream = States.currentStream!
|
||||
const currentStream = STATES.currentStream!
|
||||
currentStream.$screenshotCanvas = CE('canvas', {'class': 'bx-screenshot-canvas'});
|
||||
document.documentElement.appendChild(currentStream.$screenshotCanvas!);
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { t } from "../translation";
|
||||
import { BxEvent } from "../bx-event";
|
||||
import { CE } from "../../utils/html";
|
||||
import { States } from "../../utils/global";
|
||||
import { STATES } from "../../utils/global";
|
||||
|
||||
enum StreamBadge {
|
||||
PLAYTIME = 'playtime',
|
||||
@ -86,7 +86,7 @@ export class StreamBadges {
|
||||
} catch(e) {}
|
||||
}
|
||||
|
||||
const stats = await States.currentStream.peerConnection?.getStats()!;
|
||||
const stats = await STATES.currentStream.peerConnection?.getStats()!;
|
||||
let totalIn = 0;
|
||||
let totalOut = 0;
|
||||
stats.forEach(stat => {
|
||||
|
@ -4,7 +4,7 @@ import { getPref } from "../preferences"
|
||||
import { StreamBadges } from "./stream-badges"
|
||||
import { CE } from "../../utils/html"
|
||||
import { t } from "../translation"
|
||||
import { States } from "../../utils/global"
|
||||
import { STATES } from "../../utils/global"
|
||||
|
||||
export enum StreamStat {
|
||||
PING = 'ping',
|
||||
@ -106,13 +106,13 @@ export class StreamStats {
|
||||
}
|
||||
|
||||
static update() {
|
||||
if (StreamStats.isHidden() || !States.currentStream.peerConnection) {
|
||||
if (StreamStats.isHidden() || !STATES.currentStream.peerConnection) {
|
||||
StreamStats.onStoppedPlaying();
|
||||
return;
|
||||
}
|
||||
|
||||
const PREF_STATS_CONDITIONAL_FORMATTING = getPref(PrefKey.STATS_CONDITIONAL_FORMATTING);
|
||||
States.currentStream.peerConnection.getStats().then(stats => {
|
||||
STATES.currentStream.peerConnection.getStats().then(stats => {
|
||||
stats.forEach(stat => {
|
||||
let grade = '';
|
||||
if (stat.type === 'inbound-rtp' && stat.kind === 'video') {
|
||||
@ -214,7 +214,7 @@ export class StreamStats {
|
||||
}
|
||||
|
||||
static getServerStats() {
|
||||
States.currentStream.peerConnection && States.currentStream.peerConnection.getStats().then(stats => {
|
||||
STATES.currentStream.peerConnection && STATES.currentStream.peerConnection.getStats().then(stats => {
|
||||
const allVideoCodecs: {[index: string]: RTCBasicStat} = {};
|
||||
let videoCodecId;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { States } from "../../utils/global";
|
||||
import { STATES } from "../../utils/global";
|
||||
import { Icon } from "../../utils/html";
|
||||
import { BxEvent } from "../bx-event";
|
||||
import { PrefKey, getPref } from "../preferences";
|
||||
@ -93,7 +93,7 @@ function cloneStreamHudButton($orgButton: HTMLElement, label: string, svgIcon: I
|
||||
}
|
||||
};
|
||||
|
||||
if (States.hasTouchSupport) {
|
||||
if (STATES.hasTouchSupport) {
|
||||
$container.addEventListener('transitionstart', onTransitionStart);
|
||||
$container.addEventListener('transitionend', onTransitionEnd);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { NATIVE_FETCH, States } from "../utils/global";
|
||||
import { NATIVE_FETCH, STATES } from "../utils/global";
|
||||
import { CE } from "../utils/html";
|
||||
import { Toast } from "../utils/toast";
|
||||
import { BxEvent } from "./bx-event";
|
||||
@ -189,7 +189,7 @@ export class TouchController {
|
||||
|
||||
touch_layout_manager && touch_layout_manager.changeLayoutForScope({
|
||||
type: 'showLayout',
|
||||
scope: '' + States.currentStream?.xboxTitleId,
|
||||
scope: '' + STATES.currentStream?.xboxTitleId,
|
||||
subscope: 'base',
|
||||
layout: {
|
||||
id: 'System.Standard',
|
||||
@ -273,7 +273,7 @@ export class TouchController {
|
||||
if (msg.data.includes('touchcontrols/showtitledefault')) {
|
||||
if (TouchController.#enable) {
|
||||
if (focused) {
|
||||
TouchController.getCustomLayouts(States.currentStream?.xboxTitleId!);
|
||||
TouchController.getCustomLayouts(STATES.currentStream?.xboxTitleId!);
|
||||
} else {
|
||||
TouchController.#showDefault();
|
||||
}
|
||||
@ -292,7 +292,7 @@ export class TouchController {
|
||||
TouchController.#show();
|
||||
}
|
||||
|
||||
States.currentStream.xboxTitleId = parseInt(json.titleid, 16).toString();
|
||||
STATES.currentStream.xboxTitleId = parseInt(json.titleid, 16).toString();
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { States, AppInterface, SCRIPT_HOME, SCRIPT_VERSION } from "../../utils/global";
|
||||
import { STATES, AppInterface, SCRIPT_HOME, SCRIPT_VERSION } from "../../utils/global";
|
||||
import { CE, createButton, Icon, ButtonStyle } from "../../utils/html";
|
||||
import { getPreferredServerRegion } from "../../utils/region";
|
||||
import { UserAgent, UserAgentProfile } from "../../utils/user-agent";
|
||||
@ -51,8 +51,8 @@ const SETTINGS_UI = {
|
||||
},
|
||||
|
||||
[t('touch-controller')]: {
|
||||
note: !States.hasTouchSupport ? '⚠️ ' + t('device-unsupported-touch') : null,
|
||||
unsupported: !States.hasTouchSupport,
|
||||
note: !STATES.hasTouchSupport ? '⚠️ ' + t('device-unsupported-touch') : null,
|
||||
unsupported: !STATES.hasTouchSupport,
|
||||
items: [
|
||||
PrefKey.STREAM_TOUCH_CONTROLLER,
|
||||
PrefKey.STREAM_TOUCH_CONTROLLER_AUTO_OFF,
|
||||
@ -251,8 +251,8 @@ export function setupSettingsUi() {
|
||||
selectedValue = PREF_PREFERRED_REGION;
|
||||
|
||||
setting.options = {};
|
||||
for (let regionName in States.serverRegions) {
|
||||
const region = States.serverRegions[regionName];
|
||||
for (let regionName in STATES.serverRegions) {
|
||||
const region = STATES.serverRegions[regionName];
|
||||
let value = regionName;
|
||||
|
||||
let label = `${region.shortName} - ${regionName}`;
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { States } from "../../utils/global";
|
||||
import { STATES } from "../../utils/global";
|
||||
import { Icon, CE, createButton, ButtonStyle } from "../../utils/html";
|
||||
import { UserAgent } from "../../utils/user-agent";
|
||||
import { BxEvent } from "../bx-event";
|
||||
@ -95,7 +95,7 @@ function setupQuickSettingsBar() {
|
||||
pref: PrefKey.AUDIO_VOLUME,
|
||||
label: t('volume'),
|
||||
onChange: (e: any, value: number) => {
|
||||
States.currentStream && (States.currentStream.audioGainNode!.gain.value = value / 100)
|
||||
STATES.currentStream && (STATES.currentStream.audioGainNode!.gain.value = value / 100)
|
||||
},
|
||||
params: {
|
||||
disabled: !getPref(PrefKey.AUDIO_ENABLE_VOLUME_CONTROL),
|
||||
@ -176,7 +176,7 @@ function setupQuickSettingsBar() {
|
||||
],
|
||||
},
|
||||
|
||||
States.hasTouchSupport && {
|
||||
STATES.hasTouchSupport && {
|
||||
group: 'touch-controller',
|
||||
label: t('touch-controller'),
|
||||
items: [
|
||||
@ -185,18 +185,18 @@ function setupQuickSettingsBar() {
|
||||
content: CE('select', {disabled: true}, CE('option', {}, t('default'))),
|
||||
onMounted: ($elm: HTMLSelectElement) => {
|
||||
$elm.addEventListener('change', e => {
|
||||
TouchController.loadCustomLayout(States.currentStream?.xboxTitleId!, $elm.value, 1000);
|
||||
TouchController.loadCustomLayout(STATES.currentStream?.xboxTitleId!, $elm.value, 1000);
|
||||
});
|
||||
|
||||
window.addEventListener(BxEvent.CUSTOM_TOUCH_LAYOUTS_LOADED, e => {
|
||||
const data = (e as any).data;
|
||||
|
||||
if (States.currentStream?.xboxTitleId && ($elm as any).xboxTitleId === States.currentStream?.xboxTitleId) {
|
||||
if (STATES.currentStream?.xboxTitleId && ($elm as any).xboxTitleId === STATES.currentStream?.xboxTitleId) {
|
||||
$elm.dispatchEvent(new Event('change'));
|
||||
return;
|
||||
}
|
||||
|
||||
($elm as any).xboxTitleId = States.currentStream?.xboxTitleId;
|
||||
($elm as any).xboxTitleId = STATES.currentStream?.xboxTitleId;
|
||||
|
||||
// Clear options
|
||||
while ($elm.firstChild) {
|
||||
@ -431,7 +431,7 @@ export function updateVideoPlayerCss() {
|
||||
|
||||
// Apply video filters to screenshots
|
||||
if (getPref(PrefKey.SCREENSHOT_APPLY_FILTERS)) {
|
||||
States.currentStream.$screenshotCanvas!.getContext('2d')!.filter = filters;
|
||||
STATES.currentStream.$screenshotCanvas!.getContext('2d')!.filter = filters;
|
||||
}
|
||||
|
||||
const PREF_RATIO = getPref(PrefKey.VIDEO_RATIO);
|
||||
|
@ -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') {
|
||||
|
Loading…
x
Reference in New Issue
Block a user