mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-06 07:37: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 { PreloadedState } from "./utils/titles-info";
|
||||||
import { patchAudioContext, patchRtcCodecs, patchRtcPeerConnection, patchVideoApi } from "./utils/monkey-patches";
|
import { patchAudioContext, patchRtcCodecs, patchRtcPeerConnection, patchVideoApi } from "./utils/monkey-patches";
|
||||||
import { interceptHttpRequests } from "./utils/network";
|
import { interceptHttpRequests } from "./utils/network";
|
||||||
import { States } from "./utils/global";
|
import { STATES } from "./utils/global";
|
||||||
import { injectStreamMenuButtons } from "./modules/stream/stream-ui";
|
import { injectStreamMenuButtons } from "./modules/stream/stream-ui";
|
||||||
|
|
||||||
/* ADDITIONAL CODE */
|
/* ADDITIONAL CODE */
|
||||||
@ -118,12 +118,12 @@ window.addEventListener(BxEvent.STREAM_LOADING, e => {
|
|||||||
if (window.location.pathname.includes('/launch/')) {
|
if (window.location.pathname.includes('/launch/')) {
|
||||||
const matches = /\/launch\/(?<title_id>[^\/]+)\/(?<product_id>\w+)/.exec(window.location.pathname);
|
const matches = /\/launch\/(?<title_id>[^\/]+)\/(?<product_id>\w+)/.exec(window.location.pathname);
|
||||||
if (matches?.groups) {
|
if (matches?.groups) {
|
||||||
States.currentStream.titleId = matches.groups.title_id;
|
STATES.currentStream.titleId = matches.groups.title_id;
|
||||||
States.currentStream.productId = matches.groups.product_id;
|
STATES.currentStream.productId = matches.groups.product_id;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
States.currentStream.titleId = 'remote-play';
|
STATES.currentStream.titleId = 'remote-play';
|
||||||
States.currentStream.productId = '';
|
STATES.currentStream.productId = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup UI
|
// Setup UI
|
||||||
@ -147,9 +147,9 @@ window.addEventListener(BxEvent.STREAM_STARTING, e => {
|
|||||||
|
|
||||||
window.addEventListener(BxEvent.STREAM_PLAYING, e => {
|
window.addEventListener(BxEvent.STREAM_PLAYING, e => {
|
||||||
const $video = (e as any).$video;
|
const $video = (e as any).$video;
|
||||||
States.currentStream.$video = $video;
|
STATES.currentStream.$video = $video;
|
||||||
|
|
||||||
States.isPlaying = true;
|
STATES.isPlaying = true;
|
||||||
injectStreamMenuButtons();
|
injectStreamMenuButtons();
|
||||||
/*
|
/*
|
||||||
if (getPref(Preferences.CONTROLLER_ENABLE_SHORTCUTS)) {
|
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);
|
const PREF_SCREENSHOT_BUTTON_POSITION = getPref(PrefKey.SCREENSHOT_BUTTON_POSITION);
|
||||||
States.currentStream.$screenshotCanvas!.width = $video.videoWidth;
|
STATES.currentStream.$screenshotCanvas!.width = $video.videoWidth;
|
||||||
States.currentStream.$screenshotCanvas!.height = $video.videoHeight;
|
STATES.currentStream.$screenshotCanvas!.height = $video.videoHeight;
|
||||||
updateVideoPlayerCss();
|
updateVideoPlayerCss();
|
||||||
|
|
||||||
// Setup screenshot button
|
// Setup screenshot button
|
||||||
@ -180,11 +180,11 @@ window.addEventListener(BxEvent.STREAM_ERROR_PAGE, e => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener(BxEvent.STREAM_STOPPED, e => {
|
window.addEventListener(BxEvent.STREAM_STOPPED, e => {
|
||||||
if (!States.isPlaying) {
|
if (!STATES.isPlaying) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
States.isPlaying = false;
|
STATES.isPlaying = false;
|
||||||
|
|
||||||
// Stop MKB listeners
|
// Stop MKB listeners
|
||||||
getPref(PrefKey.MKB_ENABLED) && MkbHandler.INSTANCE.destroy();
|
getPref(PrefKey.MKB_ENABLED) && MkbHandler.INSTANCE.destroy();
|
||||||
@ -194,8 +194,8 @@ window.addEventListener(BxEvent.STREAM_STOPPED, e => {
|
|||||||
$quickBar.classList.add('bx-gone');
|
$quickBar.classList.add('bx-gone');
|
||||||
}
|
}
|
||||||
|
|
||||||
States.currentStream.audioGainNode = null;
|
STATES.currentStream.audioGainNode = null;
|
||||||
States.currentStream.$video = null;
|
STATES.currentStream.$video = null;
|
||||||
StreamStats.onStoppedPlaying();
|
StreamStats.onStoppedPlaying();
|
||||||
|
|
||||||
const $screenshotBtn = document.querySelector('.bx-screenshot-button');
|
const $screenshotBtn = document.querySelector('.bx-screenshot-button');
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { States } from "../utils/global";
|
import { STATES } from "../utils/global";
|
||||||
|
|
||||||
export const BxExposed = {
|
export const BxExposed = {
|
||||||
onPollingModeChanged: (mode: 'All' | 'None') => {
|
onPollingModeChanged: (mode: 'All' | 'None') => {
|
||||||
if (!States.isPlaying) {
|
if (!STATES.isPlaying) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { States } from "../utils/global";
|
import { STATES } from "../utils/global";
|
||||||
import { BX_FLAGS } from "./bx-flags";
|
import { BX_FLAGS } from "./bx-flags";
|
||||||
import { getPref, PrefKey } from "./preferences";
|
import { getPref, PrefKey } from "./preferences";
|
||||||
import { VibrationManager } from "./vibration-manager";
|
import { VibrationManager } from "./vibration-manager";
|
||||||
@ -424,7 +424,7 @@ let PATCH_ORDERS = [
|
|||||||
'overrideSettings',
|
'overrideSettings',
|
||||||
],
|
],
|
||||||
|
|
||||||
getPref(PrefKey.REMOTE_PLAY_ENABLED) && States.hasTouchSupport && ['patchUpdateInputConfigurationAsync'],
|
getPref(PrefKey.REMOTE_PLAY_ENABLED) && STATES.hasTouchSupport && ['patchUpdateInputConfigurationAsync'],
|
||||||
|
|
||||||
getPref(PrefKey.GAME_FORTNITE_FORCE_CONSOLE) && ['forceFortniteConsole'],
|
getPref(PrefKey.GAME_FORTNITE_FORCE_CONSOLE) && ['forceFortniteConsole'],
|
||||||
];
|
];
|
||||||
@ -438,8 +438,8 @@ const PLAYING_PATCH_ORDERS = [
|
|||||||
['patchStreamHud'],
|
['patchStreamHud'],
|
||||||
|
|
||||||
['playVibration'],
|
['playVibration'],
|
||||||
States.hasTouchSupport && getPref(PrefKey.STREAM_TOUCH_CONTROLLER) === 'all' && ['exposeTouchLayoutManager'],
|
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) === 'off' || getPref(PrefKey.STREAM_TOUCH_CONTROLLER_AUTO_OFF)) && ['disableTakRenderer'],
|
||||||
|
|
||||||
BX_FLAGS.EnableXcloudLogging && ['enableConsoleLogging'],
|
BX_FLAGS.EnableXcloudLogging && ['enableConsoleLogging'],
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import { SettingElement, SettingElementType } from "./settings";
|
|||||||
import { UserAgentProfile } from "../utils/user-agent";
|
import { UserAgentProfile } from "../utils/user-agent";
|
||||||
import { StreamStat } from "./stream/stream-stats";
|
import { StreamStat } from "./stream/stream-stats";
|
||||||
import type { PreferenceSettings } from "../types/preferences";
|
import type { PreferenceSettings } from "../types/preferences";
|
||||||
import { States } from "../utils/global";
|
import { STATES } from "../utils/global";
|
||||||
|
|
||||||
export enum PrefKey {
|
export enum PrefKey {
|
||||||
LAST_UPDATE_CHECK = 'version_last_check',
|
LAST_UPDATE_CHECK = 'version_last_check',
|
||||||
@ -280,7 +280,7 @@ export class Preferences {
|
|||||||
all: t('tc-all-games'),
|
all: t('tc-all-games'),
|
||||||
off: t('off'),
|
off: t('off'),
|
||||||
},
|
},
|
||||||
unsupported: !States.hasTouchSupport,
|
unsupported: !STATES.hasTouchSupport,
|
||||||
ready: () => {
|
ready: () => {
|
||||||
const setting = Preferences.SETTINGS[PrefKey.STREAM_TOUCH_CONTROLLER];
|
const setting = Preferences.SETTINGS[PrefKey.STREAM_TOUCH_CONTROLLER];
|
||||||
if (setting.unsupported) {
|
if (setting.unsupported) {
|
||||||
@ -291,7 +291,7 @@ export class Preferences {
|
|||||||
[PrefKey.STREAM_TOUCH_CONTROLLER_AUTO_OFF]: {
|
[PrefKey.STREAM_TOUCH_CONTROLLER_AUTO_OFF]: {
|
||||||
label: t('tc-auto-off'),
|
label: t('tc-auto-off'),
|
||||||
default: false,
|
default: false,
|
||||||
unsupported: !States.hasTouchSupport,
|
unsupported: !STATES.hasTouchSupport,
|
||||||
},
|
},
|
||||||
[PrefKey.STREAM_TOUCH_CONTROLLER_STYLE_STANDARD]: {
|
[PrefKey.STREAM_TOUCH_CONTROLLER_STYLE_STANDARD]: {
|
||||||
label: t('tc-standard-layout-style'),
|
label: t('tc-standard-layout-style'),
|
||||||
@ -301,7 +301,7 @@ export class Preferences {
|
|||||||
white: t('tc-all-white'),
|
white: t('tc-all-white'),
|
||||||
muted: t('tc-muted-colors'),
|
muted: t('tc-muted-colors'),
|
||||||
},
|
},
|
||||||
unsupported: !States.hasTouchSupport,
|
unsupported: !STATES.hasTouchSupport,
|
||||||
},
|
},
|
||||||
[PrefKey.STREAM_TOUCH_CONTROLLER_STYLE_CUSTOM]: {
|
[PrefKey.STREAM_TOUCH_CONTROLLER_STYLE_CUSTOM]: {
|
||||||
label: t('tc-custom-layout-style'),
|
label: t('tc-custom-layout-style'),
|
||||||
@ -310,7 +310,7 @@ export class Preferences {
|
|||||||
default: t('default'),
|
default: t('default'),
|
||||||
muted: t('tc-muted-colors'),
|
muted: t('tc-muted-colors'),
|
||||||
},
|
},
|
||||||
unsupported: !States.hasTouchSupport,
|
unsupported: !STATES.hasTouchSupport,
|
||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.STREAM_SIMPLIFY_MENU]: {
|
[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 { CE, createButton, ButtonStyle, Icon } from "../utils/html";
|
||||||
import { Toast } from "../utils/toast";
|
import { Toast } from "../utils/toast";
|
||||||
import { BxEvent } from "./bx-event";
|
import { BxEvent } from "./bx-event";
|
||||||
@ -259,7 +259,7 @@ export class RemotePlay {
|
|||||||
RemotePlay.#CONSOLES = json.results;
|
RemotePlay.#CONSOLES = json.results;
|
||||||
|
|
||||||
// Store working server
|
// Store working server
|
||||||
States.remotePlay.server = region.baseUri;
|
STATES.remotePlay.server = region.baseUri;
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
@ -270,7 +270,7 @@ export class RemotePlay {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// None of the servers worked
|
// None of the servers worked
|
||||||
if (!States.remotePlay.server) {
|
if (!STATES.remotePlay.server) {
|
||||||
RemotePlay.#CONSOLES = [];
|
RemotePlay.#CONSOLES = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -280,10 +280,10 @@ export class RemotePlay {
|
|||||||
setPref(PrefKey.REMOTE_PLAY_RESOLUTION, resolution);
|
setPref(PrefKey.REMOTE_PLAY_RESOLUTION, resolution);
|
||||||
}
|
}
|
||||||
|
|
||||||
States.remotePlay.config = {
|
STATES.remotePlay.config = {
|
||||||
serverId: serverId,
|
serverId: serverId,
|
||||||
};
|
};
|
||||||
window.BX_REMOTE_PLAY_CONFIG = States.remotePlay.config;
|
window.BX_REMOTE_PLAY_CONFIG = STATES.remotePlay.config;
|
||||||
|
|
||||||
localRedirect('/launch/fortnite/BT5P2X999VH2#remote-play');
|
localRedirect('/launch/fortnite/BT5P2X999VH2#remote-play');
|
||||||
RemotePlay.detachPopup();
|
RemotePlay.detachPopup();
|
||||||
@ -337,9 +337,9 @@ export class RemotePlay {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
States.remotePlay.isPlaying = window.location.pathname.includes('/launch/') && window.location.hash.startsWith('#remote-play');
|
STATES.remotePlay.isPlaying = window.location.pathname.includes('/launch/') && window.location.hash.startsWith('#remote-play');
|
||||||
if (States.remotePlay?.isPlaying) {
|
if (STATES.remotePlay?.isPlaying) {
|
||||||
window.BX_REMOTE_PLAY_CONFIG = States.remotePlay.config;
|
window.BX_REMOTE_PLAY_CONFIG = STATES.remotePlay.config;
|
||||||
// Remove /launch/... from URL
|
// Remove /launch/... from URL
|
||||||
window.history.replaceState({origin: 'better-xcloud'}, '', 'https://www.xbox.com/' + location.pathname.substring(1, 6) + '/play');
|
window.history.replaceState({origin: 'better-xcloud'}, '', 'https://www.xbox.com/' + location.pathname.substring(1, 6) + '/play');
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { States, AppInterface } from "../utils/global";
|
import { STATES, AppInterface } from "../utils/global";
|
||||||
import { CE } from "../utils/html";
|
import { CE } from "../utils/html";
|
||||||
|
|
||||||
export function takeScreenshot(callback: any) {
|
export function takeScreenshot(callback: any) {
|
||||||
const currentStream = States.currentStream!;
|
const currentStream = STATES.currentStream!;
|
||||||
const $video = currentStream.$video;
|
const $video = currentStream.$video;
|
||||||
const $canvas = currentStream.$screenshotCanvas;
|
const $canvas = currentStream.$screenshotCanvas;
|
||||||
if (!$video || !$canvas) {
|
if (!$video || !$canvas) {
|
||||||
@ -44,7 +44,7 @@ export function takeScreenshot(callback: any) {
|
|||||||
|
|
||||||
|
|
||||||
export function setupScreenshotButton() {
|
export function setupScreenshotButton() {
|
||||||
const currentStream = States.currentStream!
|
const currentStream = STATES.currentStream!
|
||||||
currentStream.$screenshotCanvas = CE('canvas', {'class': 'bx-screenshot-canvas'});
|
currentStream.$screenshotCanvas = CE('canvas', {'class': 'bx-screenshot-canvas'});
|
||||||
document.documentElement.appendChild(currentStream.$screenshotCanvas!);
|
document.documentElement.appendChild(currentStream.$screenshotCanvas!);
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { t } from "../translation";
|
import { t } from "../translation";
|
||||||
import { BxEvent } from "../bx-event";
|
import { BxEvent } from "../bx-event";
|
||||||
import { CE } from "../../utils/html";
|
import { CE } from "../../utils/html";
|
||||||
import { States } from "../../utils/global";
|
import { STATES } from "../../utils/global";
|
||||||
|
|
||||||
enum StreamBadge {
|
enum StreamBadge {
|
||||||
PLAYTIME = 'playtime',
|
PLAYTIME = 'playtime',
|
||||||
@ -86,7 +86,7 @@ export class StreamBadges {
|
|||||||
} catch(e) {}
|
} catch(e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
const stats = await States.currentStream.peerConnection?.getStats()!;
|
const stats = await STATES.currentStream.peerConnection?.getStats()!;
|
||||||
let totalIn = 0;
|
let totalIn = 0;
|
||||||
let totalOut = 0;
|
let totalOut = 0;
|
||||||
stats.forEach(stat => {
|
stats.forEach(stat => {
|
||||||
|
@ -4,7 +4,7 @@ import { getPref } from "../preferences"
|
|||||||
import { StreamBadges } from "./stream-badges"
|
import { StreamBadges } from "./stream-badges"
|
||||||
import { CE } from "../../utils/html"
|
import { CE } from "../../utils/html"
|
||||||
import { t } from "../translation"
|
import { t } from "../translation"
|
||||||
import { States } from "../../utils/global"
|
import { STATES } from "../../utils/global"
|
||||||
|
|
||||||
export enum StreamStat {
|
export enum StreamStat {
|
||||||
PING = 'ping',
|
PING = 'ping',
|
||||||
@ -106,13 +106,13 @@ export class StreamStats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static update() {
|
static update() {
|
||||||
if (StreamStats.isHidden() || !States.currentStream.peerConnection) {
|
if (StreamStats.isHidden() || !STATES.currentStream.peerConnection) {
|
||||||
StreamStats.onStoppedPlaying();
|
StreamStats.onStoppedPlaying();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PREF_STATS_CONDITIONAL_FORMATTING = getPref(PrefKey.STATS_CONDITIONAL_FORMATTING);
|
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 => {
|
stats.forEach(stat => {
|
||||||
let grade = '';
|
let grade = '';
|
||||||
if (stat.type === 'inbound-rtp' && stat.kind === 'video') {
|
if (stat.type === 'inbound-rtp' && stat.kind === 'video') {
|
||||||
@ -214,7 +214,7 @@ export class StreamStats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static getServerStats() {
|
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} = {};
|
const allVideoCodecs: {[index: string]: RTCBasicStat} = {};
|
||||||
let videoCodecId;
|
let videoCodecId;
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { States } from "../../utils/global";
|
import { STATES } from "../../utils/global";
|
||||||
import { Icon } from "../../utils/html";
|
import { Icon } from "../../utils/html";
|
||||||
import { BxEvent } from "../bx-event";
|
import { BxEvent } from "../bx-event";
|
||||||
import { PrefKey, getPref } from "../preferences";
|
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('transitionstart', onTransitionStart);
|
||||||
$container.addEventListener('transitionend', onTransitionEnd);
|
$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 { CE } from "../utils/html";
|
||||||
import { Toast } from "../utils/toast";
|
import { Toast } from "../utils/toast";
|
||||||
import { BxEvent } from "./bx-event";
|
import { BxEvent } from "./bx-event";
|
||||||
@ -189,7 +189,7 @@ export class TouchController {
|
|||||||
|
|
||||||
touch_layout_manager && touch_layout_manager.changeLayoutForScope({
|
touch_layout_manager && touch_layout_manager.changeLayoutForScope({
|
||||||
type: 'showLayout',
|
type: 'showLayout',
|
||||||
scope: '' + States.currentStream?.xboxTitleId,
|
scope: '' + STATES.currentStream?.xboxTitleId,
|
||||||
subscope: 'base',
|
subscope: 'base',
|
||||||
layout: {
|
layout: {
|
||||||
id: 'System.Standard',
|
id: 'System.Standard',
|
||||||
@ -273,7 +273,7 @@ export class TouchController {
|
|||||||
if (msg.data.includes('touchcontrols/showtitledefault')) {
|
if (msg.data.includes('touchcontrols/showtitledefault')) {
|
||||||
if (TouchController.#enable) {
|
if (TouchController.#enable) {
|
||||||
if (focused) {
|
if (focused) {
|
||||||
TouchController.getCustomLayouts(States.currentStream?.xboxTitleId!);
|
TouchController.getCustomLayouts(STATES.currentStream?.xboxTitleId!);
|
||||||
} else {
|
} else {
|
||||||
TouchController.#showDefault();
|
TouchController.#showDefault();
|
||||||
}
|
}
|
||||||
@ -292,7 +292,7 @@ export class TouchController {
|
|||||||
TouchController.#show();
|
TouchController.#show();
|
||||||
}
|
}
|
||||||
|
|
||||||
States.currentStream.xboxTitleId = parseInt(json.titleid, 16).toString();
|
STATES.currentStream.xboxTitleId = parseInt(json.titleid, 16).toString();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(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 { CE, createButton, Icon, ButtonStyle } from "../../utils/html";
|
||||||
import { getPreferredServerRegion } from "../../utils/region";
|
import { getPreferredServerRegion } from "../../utils/region";
|
||||||
import { UserAgent, UserAgentProfile } from "../../utils/user-agent";
|
import { UserAgent, UserAgentProfile } from "../../utils/user-agent";
|
||||||
@ -51,8 +51,8 @@ const SETTINGS_UI = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
[t('touch-controller')]: {
|
[t('touch-controller')]: {
|
||||||
note: !States.hasTouchSupport ? '⚠️ ' + t('device-unsupported-touch') : null,
|
note: !STATES.hasTouchSupport ? '⚠️ ' + t('device-unsupported-touch') : null,
|
||||||
unsupported: !States.hasTouchSupport,
|
unsupported: !STATES.hasTouchSupport,
|
||||||
items: [
|
items: [
|
||||||
PrefKey.STREAM_TOUCH_CONTROLLER,
|
PrefKey.STREAM_TOUCH_CONTROLLER,
|
||||||
PrefKey.STREAM_TOUCH_CONTROLLER_AUTO_OFF,
|
PrefKey.STREAM_TOUCH_CONTROLLER_AUTO_OFF,
|
||||||
@ -251,8 +251,8 @@ export function setupSettingsUi() {
|
|||||||
selectedValue = PREF_PREFERRED_REGION;
|
selectedValue = PREF_PREFERRED_REGION;
|
||||||
|
|
||||||
setting.options = {};
|
setting.options = {};
|
||||||
for (let regionName in States.serverRegions) {
|
for (let regionName in STATES.serverRegions) {
|
||||||
const region = States.serverRegions[regionName];
|
const region = STATES.serverRegions[regionName];
|
||||||
let value = regionName;
|
let value = regionName;
|
||||||
|
|
||||||
let label = `${region.shortName} - ${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 { Icon, CE, createButton, ButtonStyle } from "../../utils/html";
|
||||||
import { UserAgent } from "../../utils/user-agent";
|
import { UserAgent } from "../../utils/user-agent";
|
||||||
import { BxEvent } from "../bx-event";
|
import { BxEvent } from "../bx-event";
|
||||||
@ -95,7 +95,7 @@ function setupQuickSettingsBar() {
|
|||||||
pref: PrefKey.AUDIO_VOLUME,
|
pref: PrefKey.AUDIO_VOLUME,
|
||||||
label: t('volume'),
|
label: t('volume'),
|
||||||
onChange: (e: any, value: number) => {
|
onChange: (e: any, value: number) => {
|
||||||
States.currentStream && (States.currentStream.audioGainNode!.gain.value = value / 100)
|
STATES.currentStream && (STATES.currentStream.audioGainNode!.gain.value = value / 100)
|
||||||
},
|
},
|
||||||
params: {
|
params: {
|
||||||
disabled: !getPref(PrefKey.AUDIO_ENABLE_VOLUME_CONTROL),
|
disabled: !getPref(PrefKey.AUDIO_ENABLE_VOLUME_CONTROL),
|
||||||
@ -176,7 +176,7 @@ function setupQuickSettingsBar() {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
States.hasTouchSupport && {
|
STATES.hasTouchSupport && {
|
||||||
group: 'touch-controller',
|
group: 'touch-controller',
|
||||||
label: t('touch-controller'),
|
label: t('touch-controller'),
|
||||||
items: [
|
items: [
|
||||||
@ -185,18 +185,18 @@ function setupQuickSettingsBar() {
|
|||||||
content: CE('select', {disabled: true}, CE('option', {}, t('default'))),
|
content: CE('select', {disabled: true}, CE('option', {}, t('default'))),
|
||||||
onMounted: ($elm: HTMLSelectElement) => {
|
onMounted: ($elm: HTMLSelectElement) => {
|
||||||
$elm.addEventListener('change', e => {
|
$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 => {
|
window.addEventListener(BxEvent.CUSTOM_TOUCH_LAYOUTS_LOADED, e => {
|
||||||
const data = (e as any).data;
|
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'));
|
$elm.dispatchEvent(new Event('change'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
($elm as any).xboxTitleId = States.currentStream?.xboxTitleId;
|
($elm as any).xboxTitleId = STATES.currentStream?.xboxTitleId;
|
||||||
|
|
||||||
// Clear options
|
// Clear options
|
||||||
while ($elm.firstChild) {
|
while ($elm.firstChild) {
|
||||||
@ -431,7 +431,7 @@ export function updateVideoPlayerCss() {
|
|||||||
|
|
||||||
// Apply video filters to screenshots
|
// Apply video filters to screenshots
|
||||||
if (getPref(PrefKey.SCREENSHOT_APPLY_FILTERS)) {
|
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);
|
const PREF_RATIO = getPref(PrefKey.VIDEO_RATIO);
|
||||||
|
@ -2,7 +2,7 @@ import { getLocale } from "../modules/translation";
|
|||||||
|
|
||||||
export const AppInterface = window.AppInterface;
|
export const AppInterface = window.AppInterface;
|
||||||
export const NATIVE_FETCH = window.fetch;
|
export const NATIVE_FETCH = window.fetch;
|
||||||
export const States: BxStates = {
|
export const STATES: BxStates = {
|
||||||
isPlaying: false,
|
isPlaying: false,
|
||||||
appContext: {},
|
appContext: {},
|
||||||
serverRegions: {},
|
serverRegions: {},
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { BxEvent } from "../modules/bx-event";
|
import { BxEvent } from "../modules/bx-event";
|
||||||
import { getPref, PrefKey } from "../modules/preferences";
|
import { getPref, PrefKey } from "../modules/preferences";
|
||||||
import { States } from "./global";
|
import { STATES } from "./global";
|
||||||
import { UserAgent } from "./user-agent";
|
import { UserAgent } from "./user-agent";
|
||||||
|
|
||||||
export function patchVideoApi() {
|
export function patchVideoApi() {
|
||||||
@ -100,11 +100,11 @@ export function patchRtcPeerConnection() {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
window.RTCPeerConnection = function() {
|
window.RTCPeerConnection = function() {
|
||||||
const conn = new OrgRTCPeerConnection();
|
const conn = new OrgRTCPeerConnection();
|
||||||
States.currentStream.peerConnection = conn;
|
STATES.currentStream.peerConnection = conn;
|
||||||
|
|
||||||
conn.addEventListener('connectionstatechange', e => {
|
conn.addEventListener('connectionstatechange', e => {
|
||||||
if (conn.connectionState === 'connecting') {
|
if (conn.connectionState === 'connecting') {
|
||||||
States.currentStream.audioGainNode = null;
|
STATES.currentStream.audioGainNode = null;
|
||||||
}
|
}
|
||||||
console.log('connectionState', conn.connectionState);
|
console.log('connectionState', conn.connectionState);
|
||||||
});
|
});
|
||||||
@ -118,7 +118,7 @@ export function patchAudioContext() {
|
|||||||
window.AudioContext.prototype.createGain = function() {
|
window.AudioContext.prototype.createGain = function() {
|
||||||
const gainNode = nativeCreateGain.apply(this);
|
const gainNode = nativeCreateGain.apply(this);
|
||||||
gainNode.gain.value = getPref(PrefKey.AUDIO_VOLUME) / 100;
|
gainNode.gain.value = getPref(PrefKey.AUDIO_VOLUME) / 100;
|
||||||
States.currentStream.audioGainNode = gainNode;
|
STATES.currentStream.audioGainNode = gainNode;
|
||||||
return gainNode;
|
return gainNode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -127,8 +127,8 @@ export function patchAudioContext() {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
window.AudioContext = function() {
|
window.AudioContext = function() {
|
||||||
const ctx = new OrgAudioContext();
|
const ctx = new OrgAudioContext();
|
||||||
States.currentStream.audioContext = ctx;
|
STATES.currentStream.audioContext = ctx;
|
||||||
States.currentStream.audioGainNode = null;
|
STATES.currentStream.audioGainNode = null;
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,13 +137,13 @@ export function patchAudioContext() {
|
|||||||
this.muted = true;
|
this.muted = true;
|
||||||
|
|
||||||
const promise = nativePlay.apply(this);
|
const promise = nativePlay.apply(this);
|
||||||
if (States.currentStream.audioGainNode) {
|
if (STATES.currentStream.audioGainNode) {
|
||||||
return promise;
|
return promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.addEventListener('playing', e => (e.target as HTMLAudioElement).pause());
|
this.addEventListener('playing', e => (e.target as HTMLAudioElement).pause());
|
||||||
|
|
||||||
const audioCtx = States.currentStream.audioContext!;
|
const audioCtx = STATES.currentStream.audioContext!;
|
||||||
// TOOD: check srcObject
|
// TOOD: check srcObject
|
||||||
const audioStream = audioCtx.createMediaStreamSource(this.srcObject as any);
|
const audioStream = audioCtx.createMediaStreamSource(this.srcObject as any);
|
||||||
const gainNode = audioCtx.createGain();
|
const gainNode = audioCtx.createGain();
|
||||||
@ -151,7 +151,7 @@ export function patchAudioContext() {
|
|||||||
audioStream.connect(gainNode);
|
audioStream.connect(gainNode);
|
||||||
gainNode.connect(audioCtx.destination);
|
gainNode.connect(audioCtx.destination);
|
||||||
gainNode.gain.value = getPref(PrefKey.AUDIO_VOLUME) / 100;
|
gainNode.gain.value = getPref(PrefKey.AUDIO_VOLUME) / 100;
|
||||||
States.currentStream.audioGainNode = gainNode;
|
STATES.currentStream.audioGainNode = gainNode;
|
||||||
|
|
||||||
return promise;
|
return promise;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import { PrefKey, getPref } from "../modules/preferences";
|
|||||||
import { RemotePlay } from "../modules/remote-play";
|
import { RemotePlay } from "../modules/remote-play";
|
||||||
import { StreamBadges } from "../modules/stream/stream-badges";
|
import { StreamBadges } from "../modules/stream/stream-badges";
|
||||||
import { TouchController } from "../modules/touch-controller";
|
import { TouchController } from "../modules/touch-controller";
|
||||||
import { NATIVE_FETCH, States } from "./global";
|
import { NATIVE_FETCH, STATES } from "./global";
|
||||||
import { getPreferredServerRegion } from "./region";
|
import { getPreferredServerRegion } from "./region";
|
||||||
import { TitlesInfo } from "./titles-info";
|
import { TitlesInfo } from "./titles-info";
|
||||||
|
|
||||||
@ -189,7 +189,7 @@ class XhomeInterceptor {
|
|||||||
const obj = await response.clone().json() as any;
|
const obj = await response.clone().json() as any;
|
||||||
|
|
||||||
const xboxTitleId = JSON.parse(opts.body).titleIds[0];
|
const xboxTitleId = JSON.parse(opts.body).titleIds[0];
|
||||||
States.currentStream.xboxTitleId = xboxTitleId;
|
STATES.currentStream.xboxTitleId = xboxTitleId;
|
||||||
|
|
||||||
const inputConfigs = obj[0];
|
const inputConfigs = obj[0];
|
||||||
|
|
||||||
@ -265,7 +265,7 @@ class XhomeInterceptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const index = request.url.indexOf('.xboxlive.com');
|
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);
|
request = new Request(newUrl, opts);
|
||||||
let url = (typeof request === 'string') ? request : request.url;
|
let url = (typeof request === 'string') ? request : request.url;
|
||||||
@ -330,14 +330,14 @@ class XcloudInterceptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
region.shortName = shortName.toUpperCase();
|
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);
|
BxEvent.dispatch(window, BxEvent.XCLOUD_SERVERS_READY);
|
||||||
|
|
||||||
const preferredRegion = getPreferredServerRegion();
|
const preferredRegion = getPreferredServerRegion();
|
||||||
if (preferredRegion in States.serverRegions) {
|
if (preferredRegion in STATES.serverRegions) {
|
||||||
const tmp = Object.assign({}, States.serverRegions[preferredRegion]);
|
const tmp = Object.assign({}, STATES.serverRegions[preferredRegion]);
|
||||||
tmp.isDefault = true;
|
tmp.isDefault = true;
|
||||||
|
|
||||||
obj.offeringSettings.regions = [tmp];
|
obj.offeringSettings.regions = [tmp];
|
||||||
@ -355,8 +355,8 @@ class XcloudInterceptor {
|
|||||||
const parsedUrl = new URL(url);
|
const parsedUrl = new URL(url);
|
||||||
|
|
||||||
StreamBadges.region = parsedUrl.host.split('.', 1)[0];
|
StreamBadges.region = parsedUrl.host.split('.', 1)[0];
|
||||||
for (let regionName in States.appContext) {
|
for (let regionName in STATES.appContext) {
|
||||||
const region = States.appContext[regionName];
|
const region = STATES.appContext[regionName];
|
||||||
if (parsedUrl.origin == region.baseUri) {
|
if (parsedUrl.origin == region.baseUri) {
|
||||||
StreamBadges.region = regionName;
|
StreamBadges.region = regionName;
|
||||||
break;
|
break;
|
||||||
@ -573,7 +573,7 @@ export function interceptHttpRequests() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let requestType: RequestType;
|
let requestType: RequestType;
|
||||||
if (States.remotePlay.isPlaying || url.includes('/sessions/home')) {
|
if (STATES.remotePlay.isPlaying || url.includes('/sessions/home')) {
|
||||||
requestType = RequestType.XHOME;
|
requestType = RequestType.XHOME;
|
||||||
} else {
|
} else {
|
||||||
requestType = RequestType.XCLOUD;
|
requestType = RequestType.XCLOUD;
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
import { getPref, PrefKey } from "../modules/preferences";
|
import { getPref, PrefKey } from "../modules/preferences";
|
||||||
import { States } from "./global";
|
import { STATES } from "./global";
|
||||||
|
|
||||||
|
|
||||||
export function getPreferredServerRegion(shortName = false) {
|
export function getPreferredServerRegion(shortName = false) {
|
||||||
let preferredRegion = getPref(PrefKey.SERVER_REGION);
|
let preferredRegion = getPref(PrefKey.SERVER_REGION);
|
||||||
if (preferredRegion in States.serverRegions) {
|
if (preferredRegion in STATES.serverRegions) {
|
||||||
if (shortName && States.serverRegions[preferredRegion].shortName) {
|
if (shortName && STATES.serverRegions[preferredRegion].shortName) {
|
||||||
return States.serverRegions[preferredRegion].shortName;
|
return STATES.serverRegions[preferredRegion].shortName;
|
||||||
} else {
|
} else {
|
||||||
return preferredRegion;
|
return preferredRegion;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let regionName in States.serverRegions) {
|
for (let regionName in STATES.serverRegions) {
|
||||||
const region = States.serverRegions[regionName];
|
const region = STATES.serverRegions[regionName];
|
||||||
if (!region.isDefault) {
|
if (!region.isDefault) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { PrefKey } from "../modules/preferences";
|
import { PrefKey } from "../modules/preferences";
|
||||||
import { getPref } from "../modules/preferences";
|
import { getPref } from "../modules/preferences";
|
||||||
import { States } from "./global";
|
import { STATES } from "./global";
|
||||||
import { UserAgent } from "./user-agent";
|
import { UserAgent } from "./user-agent";
|
||||||
|
|
||||||
export class TitlesInfo {
|
export class TitlesInfo {
|
||||||
@ -39,14 +39,14 @@ export class TitlesInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static requestCatalogInfo(titleId: string, callback: any) {
|
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');
|
const appVersion = document.querySelector('meta[name=gamepass-app-version]')!.getAttribute('content');
|
||||||
|
|
||||||
fetch(url, {
|
fetch(url, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'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-Name': 'Xbox Cloud Gaming Web',
|
||||||
'Calling-App-Version': appVersion,
|
'Calling-App-Version': appVersion,
|
||||||
} as any,
|
} as any,
|
||||||
@ -75,7 +75,7 @@ export class PreloadedState {
|
|||||||
},
|
},
|
||||||
set: state => {
|
set: state => {
|
||||||
(this as any)._state = state;
|
(this as any)._state = state;
|
||||||
States.appContext = structuredClone(state.appContext);
|
STATES.appContext = structuredClone(state.appContext);
|
||||||
|
|
||||||
// Get a list of touch-supported games
|
// Get a list of touch-supported games
|
||||||
if (getPref(PrefKey.STREAM_TOUCH_CONTROLLER) === 'all') {
|
if (getPref(PrefKey.STREAM_TOUCH_CONTROLLER) === 'all') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user