mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-29 10:51:44 +02:00
Compare commits
45 Commits
Author | SHA1 | Date | |
---|---|---|---|
2eea9ce8f5 | |||
27abab8473 | |||
0c34173815 | |||
0164423e45 | |||
71dcaf4b07 | |||
8f49c48e74 | |||
6fa1f73702 | |||
728abced45 | |||
411e43ceb0 | |||
baa22dbefc | |||
97fb7a114f | |||
39b2f814b6 | |||
3d34bb3edf | |||
ab1c93eb3a | |||
739adfce41 | |||
2e77f19006 | |||
8a40d361d9 | |||
98fa273b48 | |||
1e6527413c | |||
b9134bc141 | |||
336a965653 | |||
3a91210ba7 | |||
14f2d8a741 | |||
c24d1620b6 | |||
63f30111cb | |||
d30a628fb1 | |||
5b80170c8b | |||
203346c0a1 | |||
9719454ea1 | |||
59a178bb16 | |||
fd1494ebfa | |||
8e6dec4b70 | |||
6e905621f6 | |||
76b205a65a | |||
af41dc7c5e | |||
d0f43db1fd | |||
eed0aa9d9e | |||
9007663a3a | |||
8f6bc5cb1b | |||
12d8d766dc | |||
aeffccaf67 | |||
b2736d574d | |||
98cf893956 | |||
086afafedf | |||
bd58355ef5 |
16
build.sh
Executable file
16
build.sh
Executable file
@ -0,0 +1,16 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
build_all () {
|
||||||
|
# Clear screen
|
||||||
|
printf "\033c"
|
||||||
|
|
||||||
|
# Build all variants
|
||||||
|
bun build.ts --version $1 --variant full
|
||||||
|
bun build.ts --version $1 --variant lite
|
||||||
|
|
||||||
|
# Wait for key
|
||||||
|
read -p ">> Press Enter to build again..."
|
||||||
|
build_all $1
|
||||||
|
}
|
||||||
|
|
||||||
|
build_all $1
|
68
build.ts
68
build.ts
@ -5,6 +5,8 @@ import { sys } from "typescript";
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import txtScriptHeader from "./src/assets/header_script.txt" with { type: "text" };
|
import txtScriptHeader from "./src/assets/header_script.txt" with { type: "text" };
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
import txtScriptHeaderLite from "./src/assets/header_script.lite.txt" with { type: "text" };
|
||||||
|
// @ts-ignore
|
||||||
import txtMetaHeader from "./src/assets/header_meta.txt" with { type: "text" };
|
import txtMetaHeader from "./src/assets/header_meta.txt" with { type: "text" };
|
||||||
import { assert } from "node:console";
|
import { assert } from "node:console";
|
||||||
import { ESLint } from "eslint";
|
import { ESLint } from "eslint";
|
||||||
@ -16,6 +18,8 @@ enum BuildTarget {
|
|||||||
WEBOS = 'webos',
|
WEBOS = 'webos',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BuildVariant = 'full' | 'lite';
|
||||||
|
|
||||||
const postProcess = (str: string): string => {
|
const postProcess = (str: string): string => {
|
||||||
// Unescape unicode charaters
|
// Unescape unicode charaters
|
||||||
str = unescape((str.replace(/\\u/g, '%u')));
|
str = unescape((str.replace(/\\u/g, '%u')));
|
||||||
@ -51,7 +55,7 @@ const postProcess = (str: string): string => {
|
|||||||
|
|
||||||
// Minify SVG import code
|
// Minify SVG import code
|
||||||
const svgMap = {}
|
const svgMap = {}
|
||||||
str = str.replaceAll(/var ([\w_]+) = ("<svg.*?");\n\n/g, function(match, p1, p2) {
|
str = str.replaceAll(/var ([\w_]+) = ("<svg.*?");\n\n/g, (match, p1, p2) => {
|
||||||
// Remove new lines in SVG
|
// Remove new lines in SVG
|
||||||
p2 = p2.replaceAll(/\\n*\s*/g, '');
|
p2 = p2.replaceAll(/\\n*\s*/g, '');
|
||||||
|
|
||||||
@ -72,6 +76,17 @@ const postProcess = (str: string): string => {
|
|||||||
// Remove blank lines
|
// Remove blank lines
|
||||||
str = str.replaceAll(/\n([\s]*)\n/g, "\n");
|
str = str.replaceAll(/\n([\s]*)\n/g, "\n");
|
||||||
|
|
||||||
|
// Minify WebGL shaders & JS strings
|
||||||
|
// Replace "\n " with "\n"
|
||||||
|
str = str.replaceAll(/\\n+\s*/g, '\\n');
|
||||||
|
// Remove comment line
|
||||||
|
str = str.replaceAll(/\\n\/\/.*?(?=\\n)/g, '');
|
||||||
|
|
||||||
|
// Replace ${"time".toUpperCase()} with "TIME"
|
||||||
|
str = str.replaceAll(/\$\{"([^"]+)"\.toUpperCase\(\)\}/g, (match, p1) => {
|
||||||
|
return p1.toUpperCase();
|
||||||
|
});
|
||||||
|
|
||||||
assert(str.includes('/* ADDITIONAL CODE */'));
|
assert(str.includes('/* ADDITIONAL CODE */'));
|
||||||
assert(str.includes('window.BX_EXPOSED = BxExposed'));
|
assert(str.includes('window.BX_EXPOSED = BxExposed'));
|
||||||
assert(str.includes('window.BxEvent = BxEvent'));
|
assert(str.includes('window.BxEvent = BxEvent'));
|
||||||
@ -80,7 +95,7 @@ const postProcess = (str: string): string => {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
const build = async (target: BuildTarget, version: string, config: any={}) => {
|
const build = async (target: BuildTarget, version: string, variant: BuildVariant, config: any={}) => {
|
||||||
console.log('-- Target:', target);
|
console.log('-- Target:', target);
|
||||||
const startTime = performance.now();
|
const startTime = performance.now();
|
||||||
|
|
||||||
@ -88,6 +103,11 @@ const build = async (target: BuildTarget, version: string, config: any={}) => {
|
|||||||
if (target !== BuildTarget.ALL) {
|
if (target !== BuildTarget.ALL) {
|
||||||
outputScriptName += `.${target}`;
|
outputScriptName += `.${target}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (variant !== 'full') {
|
||||||
|
outputScriptName += `.${variant}`;
|
||||||
|
}
|
||||||
|
|
||||||
let outputMetaName = outputScriptName;
|
let outputMetaName = outputScriptName;
|
||||||
outputScriptName += '.user.js';
|
outputScriptName += '.user.js';
|
||||||
outputMetaName += '.meta.js';
|
outputMetaName += '.meta.js';
|
||||||
@ -103,6 +123,7 @@ const build = async (target: BuildTarget, version: string, config: any={}) => {
|
|||||||
},
|
},
|
||||||
define: {
|
define: {
|
||||||
'Bun.env.BUILD_TARGET': JSON.stringify(target),
|
'Bun.env.BUILD_TARGET': JSON.stringify(target),
|
||||||
|
'Bun.env.BUILD_VARIANT': JSON.stringify(variant),
|
||||||
'Bun.env.SCRIPT_VERSION': JSON.stringify(version),
|
'Bun.env.SCRIPT_VERSION': JSON.stringify(version),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -117,13 +138,19 @@ const build = async (target: BuildTarget, version: string, config: any={}) => {
|
|||||||
let result = postProcess(await readFile(path, 'utf-8'));
|
let result = postProcess(await readFile(path, 'utf-8'));
|
||||||
|
|
||||||
// Replace [[VERSION]] with real value
|
// Replace [[VERSION]] with real value
|
||||||
const scriptHeader = txtScriptHeader.replace('[[VERSION]]', version);
|
let scriptHeader: string;
|
||||||
|
if (variant === 'full') {
|
||||||
|
scriptHeader = txtScriptHeader;
|
||||||
|
} else {
|
||||||
|
scriptHeader = txtScriptHeaderLite;
|
||||||
|
}
|
||||||
|
scriptHeader = scriptHeader.replace('[[VERSION]]', version);
|
||||||
|
|
||||||
// Save to script
|
// Save to script
|
||||||
await Bun.write(path, scriptHeader + result);
|
await Bun.write(path, scriptHeader + result);
|
||||||
|
|
||||||
// Create meta file (don't build if it's beta version)
|
// Create meta file (don't build if it's beta version)
|
||||||
if (!version.includes('beta')) {
|
if (!version.includes('beta') && variant === 'full') {
|
||||||
await Bun.write(outDir + '/' + outputMetaName, txtMetaHeader.replace('[[VERSION]]', version));
|
await Bun.write(outDir + '/' + outputMetaName, txtMetaHeader.replace('[[VERSION]]', version));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,28 +175,44 @@ const buildTargets = [
|
|||||||
const { values, positionals } = parseArgs({
|
const { values, positionals } = parseArgs({
|
||||||
args: Bun.argv,
|
args: Bun.argv,
|
||||||
options: {
|
options: {
|
||||||
version: {
|
version: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
},
|
||||||
|
|
||||||
},
|
variant: {
|
||||||
|
type: 'string',
|
||||||
|
default: 'full',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
strict: true,
|
strict: true,
|
||||||
allowPositionals: true,
|
allowPositionals: true,
|
||||||
});
|
}) as {
|
||||||
|
values: {
|
||||||
|
version: string,
|
||||||
|
variant: BuildVariant,
|
||||||
|
},
|
||||||
|
positionals: string[],
|
||||||
|
};
|
||||||
|
|
||||||
if (!values['version']) {
|
if (!values['version']) {
|
||||||
console.log('Missing --version param');
|
console.log('Missing --version param');
|
||||||
sys.exit(-1);
|
sys.exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (values['variant'] !== 'full' && values['variant'] !== 'lite') {
|
||||||
|
console.log('--variant param must be either "full" or "lite"');
|
||||||
|
sys.exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const config = {};
|
const config = {};
|
||||||
console.log('Building: ', values['version']);
|
console.log(`Building: VERSION=${values['version']}, VARIANT=${values['variant']}`);
|
||||||
for (const target of buildTargets) {
|
for (const target of buildTargets) {
|
||||||
await build(target, values['version']!!, config);
|
await build(target, values['version']!!, values['variant'], config);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('\n** Press Enter to build or Esc to exit');
|
console.log('')
|
||||||
|
// console.log('\n** Press Enter to build or Esc to exit');
|
||||||
}
|
}
|
||||||
|
|
||||||
function onKeyPress(data: any) {
|
function onKeyPress(data: any) {
|
||||||
@ -182,6 +225,9 @@ function onKeyPress(data: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
|
||||||
|
/*
|
||||||
process.stdin.setRawMode(true);
|
process.stdin.setRawMode(true);
|
||||||
process.stdin.resume();
|
process.stdin.resume();
|
||||||
process.stdin.on('data', onKeyPress);
|
process.stdin.on('data', onKeyPress);
|
||||||
|
*/
|
||||||
|
5700
dist/better-xcloud.lite.user.js
vendored
Normal file
5700
dist/better-xcloud.lite.user.js
vendored
Normal file
File diff suppressed because one or more lines are too long
2
dist/better-xcloud.meta.js
vendored
2
dist/better-xcloud.meta.js
vendored
@ -1,5 +1,5 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Better xCloud
|
// @name Better xCloud
|
||||||
// @namespace https://github.com/redphx
|
// @namespace https://github.com/redphx
|
||||||
// @version 5.7.7
|
// @version 5.8.3
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
2668
dist/better-xcloud.user.js
vendored
2668
dist/better-xcloud.user.js
vendored
File diff suppressed because one or more lines are too long
@ -2,6 +2,7 @@
|
|||||||
"name": "better-xcloud",
|
"name": "better-xcloud",
|
||||||
"module": "src/index.ts",
|
"module": "src/index.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
"sideEffects": false,
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"Chrome >= 80"
|
"Chrome >= 80"
|
||||||
],
|
],
|
||||||
@ -9,10 +10,10 @@
|
|||||||
"build": "build.ts"
|
"build": "build.ts"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/bun": "^1.1.9",
|
"@types/bun": "^1.1.10",
|
||||||
"@types/node": "^22.5.5",
|
"@types/node": "^22.7.5",
|
||||||
"@types/stylus": "^0.48.43",
|
"@types/stylus": "^0.48.43",
|
||||||
"eslint": "^9.10.0",
|
"eslint": "^9.12.0",
|
||||||
"eslint-plugin-compat": "^6.0.1",
|
"eslint-plugin-compat": "^6.0.1",
|
||||||
"stylus": "^0.63.0"
|
"stylus": "^0.63.0"
|
||||||
},
|
},
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
display: inline-block;
|
display: inline-block;
|
||||||
min-width: 40px;
|
min-width: 40px;
|
||||||
font-family: var(--bx-monospaced-font);
|
font-family: var(--bx-monospaced-font);
|
||||||
font-size: 12px;
|
font-size: 13px;
|
||||||
margin: 0 4px;
|
margin: 0 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,9 @@ div[class^=StreamMenu-module__container] .bx-badges {
|
|||||||
|
|
||||||
/* STATS BAR */
|
/* STATS BAR */
|
||||||
.bx-stats-bar {
|
.bx-stats-bar {
|
||||||
display: block;
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
gap: 8px;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
-webkit-user-select: none;
|
-webkit-user-select: none;
|
||||||
position: fixed;
|
position: fixed;
|
||||||
@ -84,22 +86,34 @@ div[class^=StreamMenu-module__container] .bx-badges {
|
|||||||
z-index: var(--bx-stats-bar-z-index);
|
z-index: var(--bx-stats-bar-z-index);
|
||||||
text-wrap: nowrap;
|
text-wrap: nowrap;
|
||||||
|
|
||||||
|
&[data-stats*="[time]"] > .bx-stat-time,
|
||||||
|
&[data-stats*="[play]"] > .bx-stat-play,
|
||||||
|
&[data-stats*="[batt]"] > .bx-stat-batt,
|
||||||
&[data-stats*="[fps]"] > .bx-stat-fps,
|
&[data-stats*="[fps]"] > .bx-stat-fps,
|
||||||
&[data-stats*="[ping]"] > .bx-stat-ping,
|
&[data-stats*="[ping]"] > .bx-stat-ping,
|
||||||
|
&[data-stats*="[jit]"] > .bx-stat-jit,
|
||||||
&[data-stats*="[btr]"] > .bx-stat-btr,
|
&[data-stats*="[btr]"] > .bx-stat-btr,
|
||||||
&[data-stats*="[dt]"] > .bx-stat-dt,
|
&[data-stats*="[dt]"] > .bx-stat-dt,
|
||||||
&[data-stats*="[pl]"] > .bx-stat-pl,
|
&[data-stats*="[pl]"] > .bx-stat-pl,
|
||||||
&[data-stats*="[fl]"] > .bx-stat-fl {
|
&[data-stats*="[fl]"] > .bx-stat-fl,
|
||||||
display: inline-block;
|
&[data-stats*="[dl]"] > .bx-stat-dl,
|
||||||
|
&[data-stats*="[ul]"] > .bx-stat-ul {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: baseline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&[data-stats$="[time]"] > .bx-stat-time,
|
||||||
|
&[data-stats$="[play]"] > .bx-stat-play,
|
||||||
|
&[data-stats$="[batt]"] > .bx-stat-batt,
|
||||||
&[data-stats$="[fps]"] > .bx-stat-fps,
|
&[data-stats$="[fps]"] > .bx-stat-fps,
|
||||||
&[data-stats$="[ping]"] > .bx-stat-ping,
|
&[data-stats$="[ping]"] > .bx-stat-ping,
|
||||||
|
&[data-stats$="[jit]"] > .bx-stat-jit,
|
||||||
&[data-stats$="[btr]"] > .bx-stat-btr,
|
&[data-stats$="[btr]"] > .bx-stat-btr,
|
||||||
&[data-stats$="[dt]"] > .bx-stat-dt,
|
&[data-stats$="[dt]"] > .bx-stat-dt,
|
||||||
&[data-stats$="[pl]"] > .bx-stat-pl,
|
&[data-stats$="[pl]"] > .bx-stat-pl,
|
||||||
&[data-stats$="[fl]"] > .bx-stat-fl {
|
&[data-stats$="[fl]"] > .bx-stat-fl,
|
||||||
margin-right: 0;
|
&[data-stats$="[dl]"] > .bx-stat-dl,
|
||||||
|
&[data-stats$="[ul]"] > .bx-stat-ul {
|
||||||
border-right: none;
|
border-right: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,7 +151,6 @@ div[class^=StreamMenu-module__container] .bx-badges {
|
|||||||
|
|
||||||
> div {
|
> div {
|
||||||
display: none;
|
display: none;
|
||||||
margin-right: 8px;
|
|
||||||
border-right: 1px solid #fff;
|
border-right: 1px solid #fff;
|
||||||
padding-right: 8px;
|
padding-right: 8px;
|
||||||
}
|
}
|
||||||
@ -145,7 +158,7 @@ div[class^=StreamMenu-module__container] .bx-badges {
|
|||||||
label {
|
label {
|
||||||
margin: 0 8px 0 0;
|
margin: 0 8px 0 0;
|
||||||
font-family: var(--bx-title-font);
|
font-family: var(--bx-title-font);
|
||||||
font-size: inherit;
|
font-size: 70%;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
cursor: help;
|
cursor: help;
|
||||||
|
@ -64,6 +64,7 @@
|
|||||||
input {
|
input {
|
||||||
margin: 0 4px;
|
margin: 0 4px;
|
||||||
accent-color: var(--bx-primary-button-color);
|
accent-color: var(--bx-primary-button-color);
|
||||||
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
&:hover,
|
&:hover,
|
||||||
|
13
src/assets/header_script.lite.txt
Normal file
13
src/assets/header_script.lite.txt
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
// ==UserScript==
|
||||||
|
// @name Better xCloud (Lite)
|
||||||
|
// @namespace https://github.com/redphx
|
||||||
|
// @version [[VERSION]]
|
||||||
|
// @description Improve Xbox Cloud Gaming (xCloud) experience
|
||||||
|
// @author redphx
|
||||||
|
// @license MIT
|
||||||
|
// @match https://www.xbox.com/*/play*
|
||||||
|
// @match https://www.xbox.com/*/auth/msa?*loggedIn*
|
||||||
|
// @run-at document-end
|
||||||
|
// @grant none
|
||||||
|
// ==/UserScript==
|
||||||
|
"use strict";
|
@ -75,6 +75,7 @@ export enum PrefKey {
|
|||||||
VIDEO_PLAYER_TYPE = 'video_player_type',
|
VIDEO_PLAYER_TYPE = 'video_player_type',
|
||||||
VIDEO_PROCESSING = 'video_processing',
|
VIDEO_PROCESSING = 'video_processing',
|
||||||
VIDEO_POWER_PREFERENCE = 'video_power_preference',
|
VIDEO_POWER_PREFERENCE = 'video_power_preference',
|
||||||
|
VIDEO_MAX_FPS = 'video_max_fps',
|
||||||
VIDEO_SHARPNESS = 'video_sharpness',
|
VIDEO_SHARPNESS = 'video_sharpness',
|
||||||
VIDEO_RATIO = 'video_ratio',
|
VIDEO_RATIO = 'video_ratio',
|
||||||
VIDEO_BRIGHTNESS = 'video_brightness',
|
VIDEO_BRIGHTNESS = 'video_brightness',
|
||||||
@ -98,4 +99,5 @@ export enum PrefKey {
|
|||||||
REMOTE_PLAY_RESOLUTION = 'xhome_resolution',
|
REMOTE_PLAY_RESOLUTION = 'xhome_resolution',
|
||||||
|
|
||||||
GAME_FORTNITE_FORCE_CONSOLE = 'game_fortnite_force_console',
|
GAME_FORTNITE_FORCE_CONSOLE = 'game_fortnite_force_console',
|
||||||
|
GAME_MSFS2020_FORCE_NATIVE_MKB = 'game_msfs2020_force_native_mkb',
|
||||||
}
|
}
|
||||||
|
112
src/index.ts
112
src/index.ts
@ -1,3 +1,5 @@
|
|||||||
|
import { compressCss, isFullVersion } from "@macros/build" with {type: "macro"};
|
||||||
|
|
||||||
import "@utils/global";
|
import "@utils/global";
|
||||||
import { BxEvent } from "@utils/bx-event";
|
import { BxEvent } from "@utils/bx-event";
|
||||||
import { BX_FLAGS } from "@utils/bx-flags";
|
import { BX_FLAGS } from "@utils/bx-flags";
|
||||||
@ -35,12 +37,11 @@ import { ProductDetailsPage } from "./modules/ui/product-details";
|
|||||||
import { NavigationDialogManager } from "./modules/ui/dialog/navigation-dialog";
|
import { NavigationDialogManager } from "./modules/ui/dialog/navigation-dialog";
|
||||||
import { PrefKey } from "./enums/pref-keys";
|
import { PrefKey } from "./enums/pref-keys";
|
||||||
import { getPref, StreamTouchController } from "./utils/settings-storages/global-settings-storage";
|
import { getPref, StreamTouchController } from "./utils/settings-storages/global-settings-storage";
|
||||||
import { compressCss } from "@macros/build" with {type: "macro"};
|
|
||||||
import { SettingsNavigationDialog } from "./modules/ui/dialog/settings-dialog";
|
import { SettingsNavigationDialog } from "./modules/ui/dialog/settings-dialog";
|
||||||
import { StreamUiHandler } from "./modules/stream/stream-ui";
|
import { StreamUiHandler } from "./modules/stream/stream-ui";
|
||||||
import { UserAgent } from "./utils/user-agent";
|
import { UserAgent } from "./utils/user-agent";
|
||||||
import { XboxApi } from "./utils/xbox-api";
|
import { XboxApi } from "./utils/xbox-api";
|
||||||
|
import { StreamStatsCollector } from "./utils/stream-stats-collector";
|
||||||
|
|
||||||
// Handle login page
|
// Handle login page
|
||||||
if (window.location.pathname.includes('/auth/msa')) {
|
if (window.location.pathname.includes('/auth/msa')) {
|
||||||
@ -63,7 +64,7 @@ if (window.location.pathname.includes('/auth/msa')) {
|
|||||||
|
|
||||||
BxLogger.info('readyState', document.readyState);
|
BxLogger.info('readyState', document.readyState);
|
||||||
|
|
||||||
if (BX_FLAGS.SafariWorkaround && document.readyState !== 'loading') {
|
if (isFullVersion() && BX_FLAGS.SafariWorkaround && document.readyState !== 'loading') {
|
||||||
// Stop loading
|
// Stop loading
|
||||||
window.stop();
|
window.stop();
|
||||||
|
|
||||||
@ -192,8 +193,11 @@ window.addEventListener(BxEvent.XCLOUD_SERVERS_UNAVAILABLE, e => {
|
|||||||
window.setTimeout(HeaderSection.watchHeader, 2000);
|
window.setTimeout(HeaderSection.watchHeader, 2000);
|
||||||
|
|
||||||
// Open Settings dialog on Unsupported page
|
// Open Settings dialog on Unsupported page
|
||||||
SettingsNavigationDialog.getInstance().show();
|
const $unsupportedPage = document.querySelector('div[class^=UnsupportedMarketPage-module__container]') as HTMLElement;
|
||||||
});
|
if ($unsupportedPage) {
|
||||||
|
SettingsNavigationDialog.getInstance().show();
|
||||||
|
}
|
||||||
|
}, {once: true});
|
||||||
|
|
||||||
window.addEventListener(BxEvent.XCLOUD_SERVERS_READY, e => {
|
window.addEventListener(BxEvent.XCLOUD_SERVERS_READY, e => {
|
||||||
STATES.isSignedIn = true;
|
STATES.isSignedIn = true;
|
||||||
@ -227,15 +231,17 @@ window.addEventListener(BxEvent.STREAM_PLAYING, e => {
|
|||||||
STATES.isPlaying = true;
|
STATES.isPlaying = true;
|
||||||
StreamUiHandler.observe();
|
StreamUiHandler.observe();
|
||||||
|
|
||||||
if (getPref(PrefKey.GAME_BAR_POSITION) !== 'off') {
|
if (isFullVersion() && getPref(PrefKey.GAME_BAR_POSITION) !== 'off') {
|
||||||
const gameBar = GameBar.getInstance();
|
const gameBar = GameBar.getInstance();
|
||||||
gameBar.reset();
|
gameBar.reset();
|
||||||
gameBar.enable();
|
gameBar.enable();
|
||||||
gameBar.showBar();
|
gameBar.showBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
const $video = (e as any).$video as HTMLVideoElement;
|
if (isFullVersion()) {
|
||||||
Screenshot.updateCanvasSize($video.videoWidth, $video.videoHeight);
|
const $video = (e as any).$video as HTMLVideoElement;
|
||||||
|
Screenshot.updateCanvasSize($video.videoWidth, $video.videoHeight);
|
||||||
|
}
|
||||||
|
|
||||||
updateVideoPlayer();
|
updateVideoPlayer();
|
||||||
});
|
});
|
||||||
@ -288,9 +294,11 @@ function unload() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop MKB listeners
|
if (isFullVersion()) {
|
||||||
EmulatedMkbHandler.getInstance().destroy();
|
// Stop MKB listeners
|
||||||
NativeMkbHandler.getInstance().destroy();
|
EmulatedMkbHandler.getInstance().destroy();
|
||||||
|
NativeMkbHandler.getInstance().destroy();
|
||||||
|
}
|
||||||
|
|
||||||
// Destroy StreamPlayer
|
// Destroy StreamPlayer
|
||||||
STATES.currentStream.streamPlayer?.destroy();
|
STATES.currentStream.streamPlayer?.destroy();
|
||||||
@ -303,9 +311,11 @@ function unload() {
|
|||||||
NavigationDialogManager.getInstance().hide();
|
NavigationDialogManager.getInstance().hide();
|
||||||
StreamStats.getInstance().onStoppedPlaying();
|
StreamStats.getInstance().onStoppedPlaying();
|
||||||
|
|
||||||
MouseCursorHider.stop();
|
if (isFullVersion()) {
|
||||||
TouchController.reset();
|
MouseCursorHider.stop();
|
||||||
GameBar.getInstance().disable();
|
TouchController.reset();
|
||||||
|
GameBar.getInstance().disable();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener(BxEvent.STREAM_STOPPED, unload);
|
window.addEventListener(BxEvent.STREAM_STOPPED, unload);
|
||||||
@ -313,7 +323,7 @@ window.addEventListener('pagehide', e => {
|
|||||||
BxEvent.dispatch(window, BxEvent.STREAM_STOPPED);
|
BxEvent.dispatch(window, BxEvent.STREAM_STOPPED);
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener(BxEvent.CAPTURE_SCREENSHOT, e => {
|
isFullVersion() && window.addEventListener(BxEvent.CAPTURE_SCREENSHOT, e => {
|
||||||
Screenshot.takeScreenshot();
|
Screenshot.takeScreenshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -368,7 +378,9 @@ function waitForRootDialog() {
|
|||||||
|
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
waitForRootDialog();
|
if (getPref(PrefKey.GAME_MSFS2020_FORCE_NATIVE_MKB)) {
|
||||||
|
BX_FLAGS.ForceNativeMkbTitles.push('9PMQDM08SNK9');
|
||||||
|
}
|
||||||
|
|
||||||
// Monkey patches
|
// Monkey patches
|
||||||
patchRtcPeerConnection();
|
patchRtcPeerConnection();
|
||||||
@ -376,7 +388,7 @@ function main() {
|
|||||||
interceptHttpRequests();
|
interceptHttpRequests();
|
||||||
patchVideoApi();
|
patchVideoApi();
|
||||||
patchCanvasContext();
|
patchCanvasContext();
|
||||||
AppInterface && patchPointerLockApi();
|
isFullVersion() && AppInterface && patchPointerLockApi();
|
||||||
|
|
||||||
getPref(PrefKey.AUDIO_ENABLE_VOLUME_CONTROL) && patchAudioContext();
|
getPref(PrefKey.AUDIO_ENABLE_VOLUME_CONTROL) && patchAudioContext();
|
||||||
|
|
||||||
@ -385,52 +397,58 @@ function main() {
|
|||||||
disableAdobeAudienceManager();
|
disableAdobeAudienceManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
STATES.userAgent.capabilities.touch && TouchController.updateCustomList();
|
waitForRootDialog();
|
||||||
overridePreloadState();
|
|
||||||
|
|
||||||
VibrationManager.initialSetup();
|
|
||||||
|
|
||||||
// Check for Update
|
|
||||||
BX_FLAGS.CheckForUpdate && checkForUpdate();
|
|
||||||
|
|
||||||
// Setup UI
|
// Setup UI
|
||||||
addCss();
|
addCss();
|
||||||
Toast.setup();
|
Toast.setup();
|
||||||
(getPref(PrefKey.GAME_BAR_POSITION) !== 'off') && GameBar.getInstance();
|
|
||||||
Screenshot.setup();
|
|
||||||
|
|
||||||
GuideMenu.addEventListeners();
|
GuideMenu.addEventListeners();
|
||||||
|
StreamStatsCollector.setupEvents();
|
||||||
StreamBadges.setupEvents();
|
StreamBadges.setupEvents();
|
||||||
StreamStats.setupEvents();
|
StreamStats.setupEvents();
|
||||||
EmulatedMkbHandler.setupEvents();
|
|
||||||
|
|
||||||
Patcher.init();
|
if (isFullVersion()) {
|
||||||
|
(getPref(PrefKey.GAME_BAR_POSITION) !== 'off') && GameBar.getInstance();
|
||||||
|
Screenshot.setup();
|
||||||
|
|
||||||
disablePwa();
|
STATES.userAgent.capabilities.touch && TouchController.updateCustomList();
|
||||||
|
overridePreloadState();
|
||||||
|
|
||||||
|
VibrationManager.initialSetup();
|
||||||
|
|
||||||
|
// Check for Update
|
||||||
|
BX_FLAGS.CheckForUpdate && checkForUpdate();
|
||||||
|
|
||||||
|
Patcher.init();
|
||||||
|
disablePwa();
|
||||||
|
|
||||||
|
// Preload Remote Play
|
||||||
|
if (getPref(PrefKey.REMOTE_PLAY_ENABLED)) {
|
||||||
|
RemotePlayManager.detect();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getPref(PrefKey.STREAM_TOUCH_CONTROLLER) === StreamTouchController.ALL) {
|
||||||
|
TouchController.setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start PointerProviderServer
|
||||||
|
if (getPref(PrefKey.MKB_ENABLED) && AppInterface) {
|
||||||
|
STATES.pointerServerPort = AppInterface.startPointerServer() || 9269;
|
||||||
|
BxLogger.info('startPointerServer', 'Port', STATES.pointerServerPort.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show wait time in game card
|
||||||
|
getPref(PrefKey.UI_GAME_CARD_SHOW_WAIT_TIME) && GameTile.setup();
|
||||||
|
|
||||||
|
EmulatedMkbHandler.setupEvents();
|
||||||
|
}
|
||||||
|
|
||||||
// Show a toast when connecting/disconecting controller
|
// Show a toast when connecting/disconecting controller
|
||||||
if (getPref(PrefKey.CONTROLLER_SHOW_CONNECTION_STATUS)) {
|
if (getPref(PrefKey.CONTROLLER_SHOW_CONNECTION_STATUS)) {
|
||||||
window.addEventListener('gamepadconnected', e => showGamepadToast(e.gamepad));
|
window.addEventListener('gamepadconnected', e => showGamepadToast(e.gamepad));
|
||||||
window.addEventListener('gamepaddisconnected', e => showGamepadToast(e.gamepad));
|
window.addEventListener('gamepaddisconnected', e => showGamepadToast(e.gamepad));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Preload Remote Play
|
|
||||||
if (getPref(PrefKey.REMOTE_PLAY_ENABLED)) {
|
|
||||||
RemotePlayManager.detect();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getPref(PrefKey.STREAM_TOUCH_CONTROLLER) === StreamTouchController.ALL) {
|
|
||||||
TouchController.setup();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start PointerProviderServer
|
|
||||||
if (getPref(PrefKey.MKB_ENABLED) && AppInterface) {
|
|
||||||
STATES.pointerServerPort = AppInterface.startPointerServer() || 9269;
|
|
||||||
BxLogger.info('startPointerServer', 'Port', STATES.pointerServerPort.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show wait time in game card
|
|
||||||
getPref(PrefKey.UI_GAME_CARD_SHOW_WAIT_TIME) && GameTile.setup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
@ -1,5 +1,13 @@
|
|||||||
import stylus from 'stylus';
|
import stylus from 'stylus';
|
||||||
|
|
||||||
|
export const isFullVersion = () => {
|
||||||
|
return Bun.env.BUILD_VARIANT === 'full';
|
||||||
|
};
|
||||||
|
|
||||||
|
export const isLiteVersion = () => {
|
||||||
|
return Bun.env.BUILD_VARIANT === 'lite';
|
||||||
|
};
|
||||||
|
|
||||||
export const renderStylus = async () => {
|
export const renderStylus = async () => {
|
||||||
const file = Bun.file('./src/assets/css/styles.styl');
|
const file = Bun.file('./src/assets/css/styles.styl');
|
||||||
const cssStr = await file.text();
|
const cssStr = await file.text();
|
||||||
|
@ -3,7 +3,6 @@ import { GamepadKey } from "@enums/mkb";
|
|||||||
import { PrompFont } from "@enums/prompt-font";
|
import { PrompFont } from "@enums/prompt-font";
|
||||||
import { CE, removeChildElements } from "@utils/html";
|
import { CE, removeChildElements } from "@utils/html";
|
||||||
import { t } from "@utils/translation";
|
import { t } from "@utils/translation";
|
||||||
import { EmulatedMkbHandler } from "./mkb/mkb-handler";
|
|
||||||
import { StreamStats } from "./stream/stream-stats";
|
import { StreamStats } from "./stream/stream-stats";
|
||||||
import { MicrophoneShortcut } from "./shortcuts/shortcut-microphone";
|
import { MicrophoneShortcut } from "./shortcuts/shortcut-microphone";
|
||||||
import { StreamUiShortcut } from "./shortcuts/shortcut-stream-ui";
|
import { StreamUiShortcut } from "./shortcuts/shortcut-stream-ui";
|
||||||
@ -15,6 +14,7 @@ import { setNearby } from "@/utils/navigation-utils";
|
|||||||
import { PrefKey } from "@/enums/pref-keys";
|
import { PrefKey } from "@/enums/pref-keys";
|
||||||
import { getPref } from "@/utils/settings-storages/global-settings-storage";
|
import { getPref } from "@/utils/settings-storages/global-settings-storage";
|
||||||
import { SettingsNavigationDialog } from "./ui/dialog/settings-dialog";
|
import { SettingsNavigationDialog } from "./ui/dialog/settings-dialog";
|
||||||
|
import { VIRTUAL_GAMEPAD_ID } from "./mkb/mkb-handler";
|
||||||
|
|
||||||
const enum ShortcutAction {
|
const enum ShortcutAction {
|
||||||
BETTER_XCLOUD_SETTINGS_SHOW = 'bx-settings-show',
|
BETTER_XCLOUD_SETTINGS_SHOW = 'bx-settings-show',
|
||||||
@ -185,7 +185,7 @@ export class ControllerShortcut {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ignore emulated gamepad
|
// Ignore emulated gamepad
|
||||||
if (gamepad.id === EmulatedMkbHandler.VIRTUAL_GAMEPAD_ID) {
|
if (gamepad.id === VIRTUAL_GAMEPAD_ID) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { isFullVersion } from "@macros/build" with {type: "macro"};
|
||||||
|
|
||||||
import { MkbPreset } from "./mkb-preset";
|
import { MkbPreset } from "./mkb-preset";
|
||||||
import { GamepadKey, MkbPresetKey, GamepadStick, MouseMapTo, WheelCode } from "@enums/mkb";
|
import { GamepadKey, MkbPresetKey, GamepadStick, MouseMapTo, WheelCode } from "@enums/mkb";
|
||||||
import { createButton, ButtonStyle, CE } from "@utils/html";
|
import { createButton, ButtonStyle, CE } from "@utils/html";
|
||||||
@ -26,6 +28,7 @@ const PointerToMouseButton = {
|
|||||||
4: 1,
|
4: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const VIRTUAL_GAMEPAD_ID = 'Xbox 360 Controller';
|
||||||
|
|
||||||
class WebSocketMouseDataProvider extends MouseDataProvider {
|
class WebSocketMouseDataProvider extends MouseDataProvider {
|
||||||
#pointerClient: PointerClient | undefined
|
#pointerClient: PointerClient | undefined
|
||||||
@ -136,10 +139,8 @@ export class EmulatedMkbHandler extends MkbHandler {
|
|||||||
static readonly DEFAULT_DEADZONE_COUNTERWEIGHT = 0.01;
|
static readonly DEFAULT_DEADZONE_COUNTERWEIGHT = 0.01;
|
||||||
static readonly MAXIMUM_STICK_RANGE = 1.1;
|
static readonly MAXIMUM_STICK_RANGE = 1.1;
|
||||||
|
|
||||||
static VIRTUAL_GAMEPAD_ID = 'Xbox 360 Controller';
|
|
||||||
|
|
||||||
#VIRTUAL_GAMEPAD = {
|
#VIRTUAL_GAMEPAD = {
|
||||||
id: EmulatedMkbHandler.VIRTUAL_GAMEPAD_ID,
|
id: VIRTUAL_GAMEPAD_ID,
|
||||||
index: 3,
|
index: 3,
|
||||||
connected: false,
|
connected: false,
|
||||||
hapticActuators: null,
|
hapticActuators: null,
|
||||||
@ -678,7 +679,7 @@ export class EmulatedMkbHandler extends MkbHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static setupEvents() {
|
static setupEvents() {
|
||||||
window.addEventListener(BxEvent.STREAM_PLAYING, () => {
|
isFullVersion() && window.addEventListener(BxEvent.STREAM_PLAYING, () => {
|
||||||
if (STATES.currentStream.titleInfo?.details.hasMkbSupport) {
|
if (STATES.currentStream.titleInfo?.details.hasMkbSupport) {
|
||||||
// Enable native MKB in Android app
|
// Enable native MKB in Android app
|
||||||
if (AppInterface && getPref(PrefKey.NATIVE_MKB_ENABLED) === 'on') {
|
if (AppInterface && getPref(PrefKey.NATIVE_MKB_ENABLED) === 'on') {
|
||||||
|
@ -211,7 +211,8 @@ const PATCHES = {
|
|||||||
|
|
||||||
// Block gamepad stats collecting
|
// Block gamepad stats collecting
|
||||||
if (getPref(PrefKey.BLOCK_TRACKING)) {
|
if (getPref(PrefKey.BLOCK_TRACKING)) {
|
||||||
codeBlock = codeBlock.replaceAll('this.inputPollingIntervalStats.addValue', '');
|
codeBlock = codeBlock.replace('this.inputPollingIntervalStats.addValue', '');
|
||||||
|
codeBlock = codeBlock.replace('this.inputPollingDurationStats.addValue', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map the Share button on Xbox Series controller with the capturing screenshot feature
|
// Map the Share button on Xbox Series controller with the capturing screenshot feature
|
||||||
@ -219,8 +220,8 @@ const PATCHES = {
|
|||||||
if (match) {
|
if (match) {
|
||||||
const gamepadVar = match[1];
|
const gamepadVar = match[1];
|
||||||
const newCode = renderString(codeControllerShortcuts, {
|
const newCode = renderString(codeControllerShortcuts, {
|
||||||
gamepadVar,
|
gamepadVar,
|
||||||
});
|
});
|
||||||
|
|
||||||
codeBlock = codeBlock.replace('this.gamepadTimestamps.set', newCode + 'this.gamepadTimestamps.set');
|
codeBlock = codeBlock.replace('this.gamepadTimestamps.set', newCode + 'this.gamepadTimestamps.set');
|
||||||
}
|
}
|
||||||
|
@ -1,121 +1,100 @@
|
|||||||
const int FILTER_UNSHARP_MASKING = 1;
|
#version 300 es
|
||||||
const int FILTER_CAS = 2;
|
|
||||||
|
|
||||||
precision highp float;
|
precision mediump float;
|
||||||
uniform sampler2D data;
|
uniform sampler2D data;
|
||||||
uniform vec2 iResolution;
|
uniform vec2 iResolution;
|
||||||
|
|
||||||
|
const int FILTER_UNSHARP_MASKING = 1;
|
||||||
|
// const int FILTER_CAS = 2;
|
||||||
|
|
||||||
|
// constrast = 0.8
|
||||||
|
const float CAS_CONTRAST_PEAK = 0.8 * -3.0 + 8.0;
|
||||||
|
|
||||||
|
// Luminosity factor
|
||||||
|
const vec3 LUMINOSITY_FACTOR = vec3(0.2126, 0.7152, 0.0722);
|
||||||
|
|
||||||
uniform int filterId;
|
uniform int filterId;
|
||||||
uniform float sharpenFactor;
|
uniform float sharpenFactor;
|
||||||
uniform float brightness;
|
uniform float brightness;
|
||||||
uniform float contrast;
|
uniform float contrast;
|
||||||
uniform float saturation;
|
uniform float saturation;
|
||||||
|
|
||||||
vec3 textureAt(sampler2D tex, vec2 coord) {
|
out vec4 fragColor;
|
||||||
return texture2D(tex, coord / iResolution.xy).rgb;
|
|
||||||
}
|
vec3 clarityBoost(sampler2D tex, vec2 coord, vec3 e) {
|
||||||
|
vec2 texelSize = 1.0 / iResolution.xy;
|
||||||
|
|
||||||
vec3 clarityBoost(sampler2D tex, vec2 coord)
|
|
||||||
{
|
|
||||||
// Load a collection of samples in a 3x3 neighorhood, where e is the current pixel.
|
// Load a collection of samples in a 3x3 neighorhood, where e is the current pixel.
|
||||||
// a b c
|
// a b c
|
||||||
// d e f
|
// d e f
|
||||||
// g h i
|
// g h i
|
||||||
vec3 a = textureAt(tex, coord + vec2(-1, 1));
|
vec3 a = texture(tex, coord + texelSize * vec2(-1, 1)).rgb;
|
||||||
vec3 b = textureAt(tex, coord + vec2(0, 1));
|
vec3 b = texture(tex, coord + texelSize * vec2(0, 1)).rgb;
|
||||||
vec3 c = textureAt(tex, coord + vec2(1, 1));
|
vec3 c = texture(tex, coord + texelSize * vec2(1, 1)).rgb;
|
||||||
|
|
||||||
vec3 d = textureAt(tex, coord + vec2(-1, 0));
|
vec3 d = texture(tex, coord + texelSize * vec2(-1, 0)).rgb;
|
||||||
vec3 e = textureAt(tex, coord);
|
vec3 f = texture(tex, coord + texelSize * vec2(1, 0)).rgb;
|
||||||
vec3 f = textureAt(tex, coord + vec2(1, 0));
|
|
||||||
|
|
||||||
vec3 g = textureAt(tex, coord + vec2(-1, -1));
|
vec3 g = texture(tex, coord + texelSize * vec2(-1, -1)).rgb;
|
||||||
vec3 h = textureAt(tex, coord + vec2(0, -1));
|
vec3 h = texture(tex, coord + texelSize * vec2(0, -1)).rgb;
|
||||||
vec3 i = textureAt(tex, coord + vec2(1, -1));
|
vec3 i = texture(tex, coord + texelSize * vec2(1, -1)).rgb;
|
||||||
|
|
||||||
if (filterId == FILTER_CAS) {
|
// USM
|
||||||
// Soft min and max.
|
if (filterId == FILTER_UNSHARP_MASKING) {
|
||||||
// a b c b
|
vec3 gaussianBlur = (a + c + g + i) * 1.0 + (b + d + f + h) * 2.0 + e * 4.0;
|
||||||
// d e f * 0.5 + d e f * 0.5
|
gaussianBlur /= 16.0;
|
||||||
// g h i h
|
|
||||||
// These are 2.0x bigger (factored out the extra multiply).
|
|
||||||
vec3 minRgb = min(min(min(d, e), min(f, b)), h);
|
|
||||||
vec3 minRgb2 = min(min(a, c), min(g, i));
|
|
||||||
minRgb += min(minRgb, minRgb2);
|
|
||||||
|
|
||||||
vec3 maxRgb = max(max(max(d, e), max(f, b)), h);
|
|
||||||
vec3 maxRgb2 = max(max(a, c), max(g, i));
|
|
||||||
maxRgb += max(maxRgb, maxRgb2);
|
|
||||||
|
|
||||||
// Smooth minimum distance to signal limit divided by smooth max.
|
|
||||||
vec3 reciprocalMaxRgb = 1.0 / maxRgb;
|
|
||||||
vec3 amplifyRgb = clamp(min(minRgb, 2.0 - maxRgb) * reciprocalMaxRgb, 0.0, 1.0);
|
|
||||||
|
|
||||||
// Shaping amount of sharpening.
|
|
||||||
amplifyRgb = inversesqrt(amplifyRgb);
|
|
||||||
|
|
||||||
float contrast = 0.8;
|
|
||||||
float peak = -3.0 * contrast + 8.0;
|
|
||||||
vec3 weightRgb = -(1.0 / (amplifyRgb * peak));
|
|
||||||
|
|
||||||
vec3 reciprocalWeightRgb = 1.0 / (4.0 * weightRgb + 1.0);
|
|
||||||
|
|
||||||
// 0 w 0
|
|
||||||
// Filter shape: w 1 w
|
|
||||||
// 0 w 0
|
|
||||||
vec3 window = (b + d) + (f + h);
|
|
||||||
vec3 outColor = clamp((window * weightRgb + e) * reciprocalWeightRgb, 0.0, 1.0);
|
|
||||||
|
|
||||||
outColor = mix(e, outColor, sharpenFactor / 2.0);
|
|
||||||
|
|
||||||
return outColor;
|
|
||||||
} else if (filterId == FILTER_UNSHARP_MASKING) {
|
|
||||||
vec3 gaussianBlur = (a * 1.0 + b * 2.0 + c * 1.0 +
|
|
||||||
d * 2.0 + e * 4.0 + f * 2.0 +
|
|
||||||
g * 1.0 + h * 2.0 + i * 1.0) / 16.0;
|
|
||||||
|
|
||||||
// Return edge detection
|
// Return edge detection
|
||||||
return e + (e - gaussianBlur) * sharpenFactor / 3.0;
|
return e + (e - gaussianBlur) * sharpenFactor / 3.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return e;
|
// CAS
|
||||||
}
|
// Soft min and max.
|
||||||
|
// a b c b
|
||||||
|
// d e f * 0.5 + d e f * 0.5
|
||||||
|
// g h i h
|
||||||
|
// These are 2.0x bigger (factored out the extra multiply).
|
||||||
|
vec3 minRgb = min(min(min(d, e), min(f, b)), h);
|
||||||
|
minRgb += min(min(a, c), min(g, i));
|
||||||
|
|
||||||
vec3 adjustBrightness(vec3 color) {
|
vec3 maxRgb = max(max(max(d, e), max(f, b)), h);
|
||||||
return (1.0 + brightness) * color;
|
maxRgb += max(max(a, c), max(g, i));
|
||||||
}
|
|
||||||
|
|
||||||
vec3 adjustContrast(vec3 color) {
|
// Smooth minimum distance to signal limit divided by smooth max.
|
||||||
return 0.5 + (1.0 + contrast) * (color - 0.5);
|
vec3 reciprocalMaxRgb = 1.0 / maxRgb;
|
||||||
}
|
vec3 amplifyRgb = clamp(min(minRgb, 2.0 - maxRgb) * reciprocalMaxRgb, 0.0, 1.0);
|
||||||
|
|
||||||
vec3 adjustSaturation(vec3 color) {
|
// Shaping amount of sharpening.
|
||||||
const vec3 luminosityFactor = vec3(0.2126, 0.7152, 0.0722);
|
amplifyRgb = inversesqrt(amplifyRgb);
|
||||||
vec3 grayscale = vec3(dot(color, luminosityFactor));
|
|
||||||
|
|
||||||
return mix(grayscale, color, 1.0 + saturation);
|
vec3 weightRgb = -(1.0 / (amplifyRgb * CAS_CONTRAST_PEAK));
|
||||||
|
vec3 reciprocalWeightRgb = 1.0 / (4.0 * weightRgb + 1.0);
|
||||||
|
|
||||||
|
// 0 w 0
|
||||||
|
// Filter shape: w 1 w
|
||||||
|
// 0 w 0
|
||||||
|
vec3 window = b + d + f + h;
|
||||||
|
vec3 outColor = clamp((window * weightRgb + e) * reciprocalWeightRgb, 0.0, 1.0);
|
||||||
|
|
||||||
|
return mix(e, outColor, sharpenFactor / 2.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec3 color;
|
vec2 uv = gl_FragCoord.xy / iResolution.xy;
|
||||||
|
// Get current pixel
|
||||||
|
vec3 color = texture(data, uv).rgb;
|
||||||
|
|
||||||
if (sharpenFactor > 0.0) {
|
// Clarity boost
|
||||||
color = clarityBoost(data, gl_FragCoord.xy);
|
color = sharpenFactor > 0.0 ? clarityBoost(data, uv, color) : color;
|
||||||
} else {
|
|
||||||
color = textureAt(data, gl_FragCoord.xy);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (saturation != 0.0) {
|
// Saturation
|
||||||
color = adjustSaturation(color);
|
color = saturation != 1.0 ? mix(vec3(dot(color, LUMINOSITY_FACTOR)), color, saturation) : color;
|
||||||
}
|
|
||||||
|
|
||||||
if (contrast != 0.0) {
|
// Contrast
|
||||||
color = adjustContrast(color);
|
color = contrast * (color - 0.5) + 0.5;
|
||||||
}
|
|
||||||
|
|
||||||
if (brightness != 0.0) {
|
// Brightness
|
||||||
color = adjustBrightness(color);
|
color = brightness * color;
|
||||||
}
|
|
||||||
|
|
||||||
gl_FragColor = vec4(color, 1.0);
|
fragColor = vec4(color, 1.0);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
attribute vec2 position;
|
#version 300 es
|
||||||
|
|
||||||
|
in vec4 position;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_Position = vec4(position, 0, 1);
|
gl_Position = position;
|
||||||
}
|
}
|
||||||
|
@ -8,16 +8,16 @@ import { getPref } from "@/utils/settings-storages/global-settings-storage";
|
|||||||
const LOG_TAG = 'WebGL2Player';
|
const LOG_TAG = 'WebGL2Player';
|
||||||
|
|
||||||
export class WebGL2Player {
|
export class WebGL2Player {
|
||||||
#$video: HTMLVideoElement;
|
private $video: HTMLVideoElement;
|
||||||
#$canvas: HTMLCanvasElement;
|
private $canvas: HTMLCanvasElement;
|
||||||
|
|
||||||
#gl: WebGL2RenderingContext | null = null;
|
private gl: WebGL2RenderingContext | null = null;
|
||||||
#resources: Array<any> = [];
|
private resources: Array<any> = [];
|
||||||
#program: WebGLProgram | null = null;
|
private program: WebGLProgram | null = null;
|
||||||
|
|
||||||
#stopped: boolean = false;
|
private stopped: boolean = false;
|
||||||
|
|
||||||
#options = {
|
private options = {
|
||||||
filterId: 1,
|
filterId: 1,
|
||||||
sharpenFactor: 0,
|
sharpenFactor: 0,
|
||||||
brightness: 0.0,
|
brightness: 0.0,
|
||||||
@ -25,112 +25,131 @@ export class WebGL2Player {
|
|||||||
saturation: 0.0,
|
saturation: 0.0,
|
||||||
};
|
};
|
||||||
|
|
||||||
#animFrameId: number | null = null;
|
private targetFps = 60;
|
||||||
|
private frameInterval = Math.ceil(1000 / this.targetFps);
|
||||||
|
private lastFrameTime = 0;
|
||||||
|
|
||||||
|
private animFrameId: number | null = null;
|
||||||
|
|
||||||
constructor($video: HTMLVideoElement) {
|
constructor($video: HTMLVideoElement) {
|
||||||
BxLogger.info(LOG_TAG, 'Initialize');
|
BxLogger.info(LOG_TAG, 'Initialize');
|
||||||
this.#$video = $video;
|
this.$video = $video;
|
||||||
|
|
||||||
const $canvas = document.createElement('canvas');
|
const $canvas = document.createElement('canvas');
|
||||||
$canvas.width = $video.videoWidth;
|
$canvas.width = $video.videoWidth;
|
||||||
$canvas.height = $video.videoHeight;
|
$canvas.height = $video.videoHeight;
|
||||||
this.#$canvas = $canvas;
|
this.$canvas = $canvas;
|
||||||
|
|
||||||
this.#setupShaders();
|
this.setupShaders();
|
||||||
this.#setupRendering();
|
this.setupRendering();
|
||||||
|
|
||||||
$video.insertAdjacentElement('afterend', $canvas);
|
$video.insertAdjacentElement('afterend', $canvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
setFilter(filterId: number, update = true) {
|
setFilter(filterId: number, update = true) {
|
||||||
this.#options.filterId = filterId;
|
this.options.filterId = filterId;
|
||||||
update && this.updateCanvas();
|
update && this.updateCanvas();
|
||||||
}
|
}
|
||||||
|
|
||||||
setSharpness(sharpness: number, update = true) {
|
setSharpness(sharpness: number, update = true) {
|
||||||
this.#options.sharpenFactor = sharpness;
|
this.options.sharpenFactor = sharpness;
|
||||||
update && this.updateCanvas();
|
update && this.updateCanvas();
|
||||||
}
|
}
|
||||||
|
|
||||||
setBrightness(brightness: number, update = true) {
|
setBrightness(brightness: number, update = true) {
|
||||||
this.#options.brightness = (brightness - 100) / 100;
|
this.options.brightness = 1 + (brightness - 100) / 100;
|
||||||
update && this.updateCanvas();
|
update && this.updateCanvas();
|
||||||
}
|
}
|
||||||
|
|
||||||
setContrast(contrast: number, update = true) {
|
setContrast(contrast: number, update = true) {
|
||||||
this.#options.contrast = (contrast - 100) / 100;
|
this.options.contrast = 1 + (contrast - 100) / 100;
|
||||||
update && this.updateCanvas();
|
update && this.updateCanvas();
|
||||||
}
|
}
|
||||||
|
|
||||||
setSaturation(saturation: number, update = true) {
|
setSaturation(saturation: number, update = true) {
|
||||||
this.#options.saturation = (saturation - 100) / 100;
|
this.options.saturation = 1 + (saturation - 100) / 100;
|
||||||
update && this.updateCanvas();
|
update && this.updateCanvas();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setTargetFps(target: number) {
|
||||||
|
this.targetFps = target;
|
||||||
|
this.frameInterval = Math.ceil(1000 / target);
|
||||||
|
}
|
||||||
|
|
||||||
getCanvas() {
|
getCanvas() {
|
||||||
return this.#$canvas;
|
return this.$canvas;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateCanvas() {
|
updateCanvas() {
|
||||||
const gl = this.#gl!;
|
const gl = this.gl!;
|
||||||
const program = this.#program!;
|
const program = this.program!;
|
||||||
|
|
||||||
gl.uniform2f(gl.getUniformLocation(program, 'iResolution'), this.#$canvas.width, this.#$canvas.height);
|
gl.uniform2f(gl.getUniformLocation(program, 'iResolution'), this.$canvas.width, this.$canvas.height);
|
||||||
|
|
||||||
gl.uniform1i(gl.getUniformLocation(program, 'filterId'), this.#options.filterId);
|
gl.uniform1i(gl.getUniformLocation(program, 'filterId'), this.options.filterId);
|
||||||
gl.uniform1f(gl.getUniformLocation(program, 'sharpenFactor'), this.#options.sharpenFactor);
|
gl.uniform1f(gl.getUniformLocation(program, 'sharpenFactor'), this.options.sharpenFactor);
|
||||||
gl.uniform1f(gl.getUniformLocation(program, 'brightness'), this.#options.brightness);
|
gl.uniform1f(gl.getUniformLocation(program, 'brightness'), this.options.brightness);
|
||||||
gl.uniform1f(gl.getUniformLocation(program, 'contrast'), this.#options.contrast);
|
gl.uniform1f(gl.getUniformLocation(program, 'contrast'), this.options.contrast);
|
||||||
gl.uniform1f(gl.getUniformLocation(program, 'saturation'), this.#options.saturation);
|
gl.uniform1f(gl.getUniformLocation(program, 'saturation'), this.options.saturation);
|
||||||
}
|
}
|
||||||
|
|
||||||
drawFrame() {
|
drawFrame() {
|
||||||
const gl = this.#gl!;
|
// Limit FPS
|
||||||
const $video = this.#$video;
|
if (this.targetFps < 60) {
|
||||||
|
const currentTime = performance.now();
|
||||||
|
const timeSinceLastFrame = currentTime - this.lastFrameTime;
|
||||||
|
if (timeSinceLastFrame < this.frameInterval) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.lastFrameTime = currentTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
const gl = this.gl!;
|
||||||
|
const $video = this.$video;
|
||||||
|
|
||||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, $video);
|
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, $video);
|
||||||
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
gl.drawArrays(gl.TRIANGLES, 0, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
#setupRendering() {
|
private setupRendering() {
|
||||||
let animate: any;
|
let animate: any;
|
||||||
|
|
||||||
if ('requestVideoFrameCallback' in HTMLVideoElement.prototype) {
|
if ('requestVideoFrameCallback' in HTMLVideoElement.prototype) {
|
||||||
const $video = this.#$video;
|
const $video = this.$video;
|
||||||
animate = () => {
|
animate = () => {
|
||||||
if (this.#stopped) {
|
if (this.stopped) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.drawFrame();
|
this.drawFrame();
|
||||||
this.#animFrameId = $video.requestVideoFrameCallback(animate);
|
this.animFrameId = $video.requestVideoFrameCallback(animate);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#animFrameId = $video.requestVideoFrameCallback(animate);
|
this.animFrameId = $video.requestVideoFrameCallback(animate);
|
||||||
} else {
|
} else {
|
||||||
animate = () => {
|
animate = () => {
|
||||||
if (this.#stopped) {
|
if (this.stopped) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.drawFrame();
|
this.drawFrame();
|
||||||
this.#animFrameId = requestAnimationFrame(animate);
|
this.animFrameId = requestAnimationFrame(animate);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#animFrameId = requestAnimationFrame(animate);
|
this.animFrameId = requestAnimationFrame(animate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#setupShaders() {
|
private setupShaders() {
|
||||||
BxLogger.info(LOG_TAG, 'Setting up', getPref(PrefKey.VIDEO_POWER_PREFERENCE));
|
BxLogger.info(LOG_TAG, 'Setting up', getPref(PrefKey.VIDEO_POWER_PREFERENCE));
|
||||||
|
|
||||||
const gl = this.#$canvas.getContext('webgl', {
|
const gl = this.$canvas.getContext('webgl2', {
|
||||||
isBx: true,
|
isBx: true,
|
||||||
antialias: true,
|
antialias: true,
|
||||||
alpha: false,
|
alpha: false,
|
||||||
powerPreference: getPref(PrefKey.VIDEO_POWER_PREFERENCE),
|
powerPreference: getPref(PrefKey.VIDEO_POWER_PREFERENCE),
|
||||||
}) as WebGL2RenderingContext;
|
}) as WebGL2RenderingContext;
|
||||||
this.#gl = gl;
|
this.gl = gl;
|
||||||
|
|
||||||
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferWidth);
|
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferWidth);
|
||||||
|
|
||||||
@ -145,7 +164,7 @@ export class WebGL2Player {
|
|||||||
|
|
||||||
// Create and link program
|
// Create and link program
|
||||||
const program = gl.createProgram()!;
|
const program = gl.createProgram()!;
|
||||||
this.#program = program;
|
this.program = program;
|
||||||
|
|
||||||
gl.attachShader(program, vShader);
|
gl.attachShader(program, vShader);
|
||||||
gl.attachShader(program, fShader);
|
gl.attachShader(program, fShader);
|
||||||
@ -162,7 +181,7 @@ export class WebGL2Player {
|
|||||||
|
|
||||||
// Vertices: A screen-filling quad made from two triangles
|
// Vertices: A screen-filling quad made from two triangles
|
||||||
const buffer = gl.createBuffer();
|
const buffer = gl.createBuffer();
|
||||||
this.#resources.push(buffer);
|
this.resources.push(buffer);
|
||||||
|
|
||||||
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
||||||
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
|
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
|
||||||
@ -179,7 +198,7 @@ export class WebGL2Player {
|
|||||||
|
|
||||||
// Texture to contain the video data
|
// Texture to contain the video data
|
||||||
const texture = gl.createTexture();
|
const texture = gl.createTexture();
|
||||||
this.#resources.push(texture);
|
this.resources.push(texture);
|
||||||
|
|
||||||
gl.bindTexture(gl.TEXTURE_2D, texture);
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
||||||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
|
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
|
||||||
@ -197,26 +216,26 @@ export class WebGL2Player {
|
|||||||
|
|
||||||
resume() {
|
resume() {
|
||||||
this.stop();
|
this.stop();
|
||||||
this.#stopped = false;
|
this.stopped = false;
|
||||||
BxLogger.info(LOG_TAG, 'Resume');
|
BxLogger.info(LOG_TAG, 'Resume');
|
||||||
|
|
||||||
this.#$canvas.classList.remove('bx-gone');
|
this.$canvas.classList.remove('bx-gone');
|
||||||
this.#setupRendering();
|
this.setupRendering();
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
BxLogger.info(LOG_TAG, 'Stop');
|
BxLogger.info(LOG_TAG, 'Stop');
|
||||||
this.#$canvas.classList.add('bx-gone');
|
this.$canvas.classList.add('bx-gone');
|
||||||
|
|
||||||
this.#stopped = true;
|
this.stopped = true;
|
||||||
if (this.#animFrameId) {
|
if (this.animFrameId) {
|
||||||
if ('requestVideoFrameCallback' in HTMLVideoElement.prototype) {
|
if ('requestVideoFrameCallback' in HTMLVideoElement.prototype) {
|
||||||
this.#$video.cancelVideoFrameCallback(this.#animFrameId);
|
this.$video.cancelVideoFrameCallback(this.animFrameId);
|
||||||
} else {
|
} else {
|
||||||
cancelAnimationFrame(this.#animFrameId);
|
cancelAnimationFrame(this.animFrameId);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#animFrameId = null;
|
this.animFrameId = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,11 +243,11 @@ export class WebGL2Player {
|
|||||||
BxLogger.info(LOG_TAG, 'Destroy');
|
BxLogger.info(LOG_TAG, 'Destroy');
|
||||||
this.stop();
|
this.stop();
|
||||||
|
|
||||||
const gl = this.#gl;
|
const gl = this.gl;
|
||||||
if (gl) {
|
if (gl) {
|
||||||
gl.getExtension('WEBGL_lose_context')?.loseContext();
|
gl.getExtension('WEBGL_lose_context')?.loseContext();
|
||||||
|
|
||||||
for (const resource of this.#resources) {
|
for (const resource of this.resources) {
|
||||||
if (resource instanceof WebGLProgram) {
|
if (resource instanceof WebGLProgram) {
|
||||||
gl.useProgram(null);
|
gl.useProgram(null);
|
||||||
gl.deleteProgram(resource);
|
gl.deleteProgram(resource);
|
||||||
@ -241,14 +260,14 @@ export class WebGL2Player {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#gl = null;
|
this.gl = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.#$canvas.isConnected) {
|
if (this.$canvas.isConnected) {
|
||||||
this.#$canvas.parentElement?.removeChild(this.#$canvas);
|
this.$canvas.parentElement?.removeChild(this.$canvas);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#$canvas.width = 1;
|
this.$canvas.width = 1;
|
||||||
this.#$canvas.height = 1;
|
this.$canvas.height = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { isFullVersion } from "@macros/build" with {type: "macro"};
|
||||||
|
|
||||||
import { CE } from "@/utils/html";
|
import { CE } from "@/utils/html";
|
||||||
import { WebGL2Player } from "./player/webgl2-player";
|
import { WebGL2Player } from "./player/webgl2-player";
|
||||||
import { Screenshot } from "@/utils/screenshot";
|
import { Screenshot } from "@/utils/screenshot";
|
||||||
@ -15,35 +17,35 @@ export type StreamPlayerOptions = Partial<{
|
|||||||
}>;
|
}>;
|
||||||
|
|
||||||
export class StreamPlayer {
|
export class StreamPlayer {
|
||||||
#$video: HTMLVideoElement;
|
private $video: HTMLVideoElement;
|
||||||
#playerType: StreamPlayerType = StreamPlayerType.VIDEO;
|
private playerType: StreamPlayerType = StreamPlayerType.VIDEO;
|
||||||
|
|
||||||
#options: StreamPlayerOptions = {};
|
private options: StreamPlayerOptions = {};
|
||||||
|
|
||||||
#webGL2Player: WebGL2Player | null = null;
|
private webGL2Player: WebGL2Player | null = null;
|
||||||
|
|
||||||
#$videoCss: HTMLStyleElement | null = null;
|
private $videoCss: HTMLStyleElement | null = null;
|
||||||
#$usmMatrix: SVGFEConvolveMatrixElement | null = null;
|
private $usmMatrix: SVGFEConvolveMatrixElement | null = null;
|
||||||
|
|
||||||
constructor($video: HTMLVideoElement, type: StreamPlayerType, options: StreamPlayerOptions) {
|
constructor($video: HTMLVideoElement, type: StreamPlayerType, options: StreamPlayerOptions) {
|
||||||
this.#setupVideoElements();
|
this.setupVideoElements();
|
||||||
|
|
||||||
this.#$video = $video;
|
this.$video = $video;
|
||||||
this.#options = options || {};
|
this.options = options || {};
|
||||||
this.setPlayerType(type);
|
this.setPlayerType(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
#setupVideoElements() {
|
private setupVideoElements() {
|
||||||
this.#$videoCss = document.getElementById('bx-video-css') as HTMLStyleElement;
|
this.$videoCss = document.getElementById('bx-video-css') as HTMLStyleElement;
|
||||||
if (this.#$videoCss) {
|
if (this.$videoCss) {
|
||||||
this.#$usmMatrix = this.#$videoCss.querySelector('#bx-filter-usm-matrix') as any;
|
this.$usmMatrix = this.$videoCss.querySelector('#bx-filter-usm-matrix') as any;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const $fragment = document.createDocumentFragment();
|
const $fragment = document.createDocumentFragment();
|
||||||
|
|
||||||
this.#$videoCss = CE<HTMLStyleElement>('style', {id: 'bx-video-css'});
|
this.$videoCss = CE<HTMLStyleElement>('style', {id: 'bx-video-css'});
|
||||||
$fragment.appendChild(this.#$videoCss);
|
$fragment.appendChild(this.$videoCss);
|
||||||
|
|
||||||
// Setup SVG filters
|
// Setup SVG filters
|
||||||
const $svg = CE('svg', {
|
const $svg = CE('svg', {
|
||||||
@ -54,7 +56,7 @@ export class StreamPlayer {
|
|||||||
CE('filter', {
|
CE('filter', {
|
||||||
id: 'bx-filter-usm',
|
id: 'bx-filter-usm',
|
||||||
xmlns: 'http://www.w3.org/2000/svg',
|
xmlns: 'http://www.w3.org/2000/svg',
|
||||||
}, this.#$usmMatrix = CE('feConvolveMatrix', {
|
}, this.$usmMatrix = CE('feConvolveMatrix', {
|
||||||
id: 'bx-filter-usm-matrix',
|
id: 'bx-filter-usm-matrix',
|
||||||
order: '3',
|
order: '3',
|
||||||
xmlns: 'http://www.w3.org/2000/svg',
|
xmlns: 'http://www.w3.org/2000/svg',
|
||||||
@ -65,29 +67,29 @@ export class StreamPlayer {
|
|||||||
document.documentElement.appendChild($fragment);
|
document.documentElement.appendChild($fragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
#getVideoPlayerFilterStyle() {
|
private getVideoPlayerFilterStyle() {
|
||||||
const filters = [];
|
const filters = [];
|
||||||
|
|
||||||
const sharpness = this.#options.sharpness || 0;
|
const sharpness = this.options.sharpness || 0;
|
||||||
if (this.#options.processing === StreamVideoProcessing.USM && sharpness != 0) {
|
if (this.options.processing === StreamVideoProcessing.USM && sharpness != 0) {
|
||||||
const level = (7 - ((sharpness / 2) - 1) * 0.5).toFixed(1); // 5, 5.5, 6, 6.5, 7
|
const level = (7 - ((sharpness / 2) - 1) * 0.5).toFixed(1); // 5, 5.5, 6, 6.5, 7
|
||||||
const matrix = `0 -1 0 -1 ${level} -1 0 -1 0`;
|
const matrix = `0 -1 0 -1 ${level} -1 0 -1 0`;
|
||||||
this.#$usmMatrix?.setAttributeNS(null, 'kernelMatrix', matrix);
|
this.$usmMatrix?.setAttributeNS(null, 'kernelMatrix', matrix);
|
||||||
|
|
||||||
filters.push(`url(#bx-filter-usm)`);
|
filters.push(`url(#bx-filter-usm)`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const saturation = this.#options.saturation || 100;
|
const saturation = this.options.saturation || 100;
|
||||||
if (saturation != 100) {
|
if (saturation != 100) {
|
||||||
filters.push(`saturate(${saturation}%)`);
|
filters.push(`saturate(${saturation}%)`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const contrast = this.#options.contrast || 100;
|
const contrast = this.options.contrast || 100;
|
||||||
if (contrast != 100) {
|
if (contrast != 100) {
|
||||||
filters.push(`contrast(${contrast}%)`);
|
filters.push(`contrast(${contrast}%)`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const brightness = this.#options.brightness || 100;
|
const brightness = this.options.brightness || 100;
|
||||||
if (brightness != 100) {
|
if (brightness != 100) {
|
||||||
filters.push(`brightness(${brightness}%)`);
|
filters.push(`brightness(${brightness}%)`);
|
||||||
}
|
}
|
||||||
@ -95,14 +97,14 @@ export class StreamPlayer {
|
|||||||
return filters.join(' ');
|
return filters.join(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
#resizePlayer() {
|
private resizePlayer() {
|
||||||
const PREF_RATIO = getPref(PrefKey.VIDEO_RATIO);
|
const PREF_RATIO = getPref(PrefKey.VIDEO_RATIO);
|
||||||
const $video = this.#$video;
|
const $video = this.$video;
|
||||||
const isNativeTouchGame = STATES.currentStream.titleInfo?.details.hasNativeTouchSupport;
|
const isNativeTouchGame = STATES.currentStream.titleInfo?.details.hasNativeTouchSupport;
|
||||||
|
|
||||||
let $webGL2Canvas;
|
let $webGL2Canvas;
|
||||||
if (this.#playerType == StreamPlayerType.WEBGL2) {
|
if (this.playerType == StreamPlayerType.WEBGL2) {
|
||||||
$webGL2Canvas = this.#webGL2Player?.getCanvas()!;
|
$webGL2Canvas = this.webGL2Player?.getCanvas()!;
|
||||||
}
|
}
|
||||||
|
|
||||||
let targetWidth;
|
let targetWidth;
|
||||||
@ -164,67 +166,67 @@ export class StreamPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update video dimensions
|
// Update video dimensions
|
||||||
if (isNativeTouchGame && this.#playerType == StreamPlayerType.WEBGL2) {
|
if (isNativeTouchGame && this.playerType == StreamPlayerType.WEBGL2) {
|
||||||
window.BX_EXPOSED.streamSession.updateDimensions();
|
window.BX_EXPOSED.streamSession.updateDimensions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setPlayerType(type: StreamPlayerType, refreshPlayer: boolean = false) {
|
setPlayerType(type: StreamPlayerType, refreshPlayer: boolean = false) {
|
||||||
if (this.#playerType !== type) {
|
if (this.playerType !== type) {
|
||||||
// Switch from Video -> WebGL2
|
// Switch from Video -> WebGL2
|
||||||
if (type === StreamPlayerType.WEBGL2) {
|
if (type === StreamPlayerType.WEBGL2) {
|
||||||
// Initialize WebGL2 player
|
// Initialize WebGL2 player
|
||||||
if (!this.#webGL2Player) {
|
if (!this.webGL2Player) {
|
||||||
this.#webGL2Player = new WebGL2Player(this.#$video);
|
this.webGL2Player = new WebGL2Player(this.$video);
|
||||||
} else {
|
} else {
|
||||||
this.#webGL2Player.resume();
|
this.webGL2Player.resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#$videoCss!.textContent = '';
|
this.$videoCss!.textContent = '';
|
||||||
|
|
||||||
this.#$video.classList.add('bx-pixel');
|
this.$video.classList.add('bx-pixel');
|
||||||
} else {
|
} else {
|
||||||
// Cleanup WebGL2 Player
|
// Cleanup WebGL2 Player
|
||||||
this.#webGL2Player?.stop();
|
this.webGL2Player?.stop();
|
||||||
|
|
||||||
this.#$video.classList.remove('bx-pixel');
|
this.$video.classList.remove('bx-pixel');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#playerType = type;
|
this.playerType = type;
|
||||||
refreshPlayer && this.refreshPlayer();
|
refreshPlayer && this.refreshPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
setOptions(options: StreamPlayerOptions, refreshPlayer: boolean = false) {
|
setOptions(options: StreamPlayerOptions, refreshPlayer: boolean = false) {
|
||||||
this.#options = options;
|
this.options = options;
|
||||||
refreshPlayer && this.refreshPlayer();
|
refreshPlayer && this.refreshPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateOptions(options: StreamPlayerOptions, refreshPlayer: boolean = false) {
|
updateOptions(options: StreamPlayerOptions, refreshPlayer: boolean = false) {
|
||||||
this.#options = Object.assign(this.#options, options);
|
this.options = Object.assign(this.options, options);
|
||||||
refreshPlayer && this.refreshPlayer();
|
refreshPlayer && this.refreshPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
getPlayerElement(playerType?: StreamPlayerType) {
|
getPlayerElement(playerType?: StreamPlayerType) {
|
||||||
if (typeof playerType === 'undefined') {
|
if (typeof playerType === 'undefined') {
|
||||||
playerType = this.#playerType;
|
playerType = this.playerType;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playerType === StreamPlayerType.WEBGL2) {
|
if (playerType === StreamPlayerType.WEBGL2) {
|
||||||
return this.#webGL2Player?.getCanvas();
|
return this.webGL2Player?.getCanvas();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.#$video;
|
return this.$video;
|
||||||
}
|
}
|
||||||
|
|
||||||
getWebGL2Player() {
|
getWebGL2Player() {
|
||||||
return this.#webGL2Player;
|
return this.webGL2Player;
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshPlayer() {
|
refreshPlayer() {
|
||||||
if (this.#playerType === StreamPlayerType.WEBGL2) {
|
if (this.playerType === StreamPlayerType.WEBGL2) {
|
||||||
const options = this.#options;
|
const options = this.options;
|
||||||
const webGL2Player = this.#webGL2Player!;
|
const webGL2Player = this.webGL2Player!;
|
||||||
|
|
||||||
if (options.processing === StreamVideoProcessing.USM) {
|
if (options.processing === StreamVideoProcessing.USM) {
|
||||||
webGL2Player.setFilter(1);
|
webGL2Player.setFilter(1);
|
||||||
@ -232,21 +234,21 @@ export class StreamPlayer {
|
|||||||
webGL2Player.setFilter(2);
|
webGL2Player.setFilter(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
Screenshot.updateCanvasFilters('none');
|
isFullVersion() && Screenshot.updateCanvasFilters('none');
|
||||||
|
|
||||||
webGL2Player.setSharpness(options.sharpness || 0);
|
webGL2Player.setSharpness(options.sharpness || 0);
|
||||||
webGL2Player.setSaturation(options.saturation || 100);
|
webGL2Player.setSaturation(options.saturation || 100);
|
||||||
webGL2Player.setContrast(options.contrast || 100);
|
webGL2Player.setContrast(options.contrast || 100);
|
||||||
webGL2Player.setBrightness(options.brightness || 100);
|
webGL2Player.setBrightness(options.brightness || 100);
|
||||||
} else {
|
} else {
|
||||||
let filters = this.#getVideoPlayerFilterStyle();
|
let filters = this.getVideoPlayerFilterStyle();
|
||||||
let videoCss = '';
|
let videoCss = '';
|
||||||
if (filters) {
|
if (filters) {
|
||||||
videoCss += `filter: ${filters} !important;`;
|
videoCss += `filter: ${filters} !important;`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply video filters to screenshots
|
// Apply video filters to screenshots
|
||||||
if (getPref(PrefKey.SCREENSHOT_APPLY_FILTERS)) {
|
if (isFullVersion() && getPref(PrefKey.SCREENSHOT_APPLY_FILTERS)) {
|
||||||
Screenshot.updateCanvasFilters(filters);
|
Screenshot.updateCanvasFilters(filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,26 +257,26 @@ export class StreamPlayer {
|
|||||||
css = `#game-stream video { ${videoCss} }`;
|
css = `#game-stream video { ${videoCss} }`;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#$videoCss!.textContent = css;
|
this.$videoCss!.textContent = css;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#resizePlayer();
|
this.resizePlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
reloadPlayer() {
|
reloadPlayer() {
|
||||||
this.#cleanUpWebGL2Player();
|
this.cleanUpWebGL2Player();
|
||||||
|
|
||||||
this.#playerType = StreamPlayerType.VIDEO;
|
this.playerType = StreamPlayerType.VIDEO;
|
||||||
this.setPlayerType(StreamPlayerType.WEBGL2, false);
|
this.setPlayerType(StreamPlayerType.WEBGL2, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
#cleanUpWebGL2Player() {
|
private cleanUpWebGL2Player() {
|
||||||
// Clean up WebGL2 Player
|
// Clean up WebGL2 Player
|
||||||
this.#webGL2Player?.destroy();
|
this.webGL2Player?.destroy();
|
||||||
this.#webGL2Player = null;
|
this.webGL2Player = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
this.#cleanUpWebGL2Player();
|
this.cleanUpWebGL2Player();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,30 +1,52 @@
|
|||||||
|
import { isLiteVersion } from "@macros/build" with {type: "macro"};
|
||||||
|
|
||||||
import { t } from "@utils/translation";
|
import { t } from "@utils/translation";
|
||||||
import { BxEvent } from "@utils/bx-event";
|
import { BxEvent } from "@utils/bx-event";
|
||||||
import { CE, createSvgIcon } from "@utils/html";
|
import { CE, createSvgIcon, humanFileSize } from "@utils/html";
|
||||||
import { STATES } from "@utils/global";
|
import { STATES } from "@utils/global";
|
||||||
import { BxLogger } from "@/utils/bx-logger";
|
import { BxLogger } from "@/utils/bx-logger";
|
||||||
import { BxIcon } from "@/utils/bx-icon";
|
import { BxIcon } from "@/utils/bx-icon";
|
||||||
|
import { GuideMenuTab } from "../ui/guide-menu";
|
||||||
|
import { StreamStat, StreamStatsCollector } from "@/utils/stream-stats-collector";
|
||||||
|
|
||||||
|
|
||||||
|
type StreamBadgeInfo = {
|
||||||
|
name: string,
|
||||||
|
$element?: HTMLElement,
|
||||||
|
icon: typeof BxIcon,
|
||||||
|
color: string,
|
||||||
|
};
|
||||||
|
|
||||||
|
type StreamServerInfo = {
|
||||||
|
server?: {
|
||||||
|
ipv6: boolean,
|
||||||
|
region?: string,
|
||||||
|
},
|
||||||
|
|
||||||
|
video?: {
|
||||||
|
width: number,
|
||||||
|
height: number,
|
||||||
|
codec: string,
|
||||||
|
profile?: string,
|
||||||
|
},
|
||||||
|
|
||||||
|
audio?: {
|
||||||
|
codec: string,
|
||||||
|
bitrate: number,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
enum StreamBadge {
|
enum StreamBadge {
|
||||||
PLAYTIME = 'playtime',
|
PLAYTIME = 'playtime',
|
||||||
BATTERY = 'battery',
|
BATTERY = 'battery',
|
||||||
DOWNLOAD = 'in',
|
DOWNLOAD = 'download',
|
||||||
UPLOAD = 'out',
|
UPLOAD = 'upload',
|
||||||
|
|
||||||
SERVER = 'server',
|
SERVER = 'server',
|
||||||
VIDEO = 'video',
|
VIDEO = 'video',
|
||||||
AUDIO = 'audio',
|
AUDIO = 'audio',
|
||||||
}
|
}
|
||||||
|
|
||||||
const StreamBadgeIcon: Partial<{[key in StreamBadge]: any}> = {
|
|
||||||
[StreamBadge.PLAYTIME]: BxIcon.PLAYTIME,
|
|
||||||
[StreamBadge.VIDEO]: BxIcon.DISPLAY,
|
|
||||||
[StreamBadge.BATTERY]: BxIcon.BATTERY,
|
|
||||||
[StreamBadge.DOWNLOAD]: BxIcon.DOWNLOAD,
|
|
||||||
[StreamBadge.UPLOAD]: BxIcon.UPLOAD,
|
|
||||||
[StreamBadge.SERVER]: BxIcon.SERVER,
|
|
||||||
[StreamBadge.AUDIO]: BxIcon.AUDIO,
|
|
||||||
}
|
|
||||||
|
|
||||||
export class StreamBadges {
|
export class StreamBadges {
|
||||||
private static instance: StreamBadges;
|
private static instance: StreamBadges;
|
||||||
@ -36,91 +58,100 @@ export class StreamBadges {
|
|||||||
return StreamBadges.instance;
|
return StreamBadges.instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ipv6 = false;
|
private serverInfo: StreamServerInfo = {};
|
||||||
#resolution?: {width: number, height: number} | null = null;
|
|
||||||
#video?: {codec: string, profile?: string | null} | null = null;
|
|
||||||
#audio?: {codec: string, bitrate: number} | null = null;
|
|
||||||
#region = '';
|
|
||||||
|
|
||||||
startBatteryLevel = 100;
|
private badges: Record<StreamBadge, StreamBadgeInfo> = {
|
||||||
startTimestamp = 0;
|
[StreamBadge.PLAYTIME]: {
|
||||||
|
name: t('playtime'),
|
||||||
|
icon: BxIcon.PLAYTIME,
|
||||||
|
color: '#ff004d',
|
||||||
|
},
|
||||||
|
[StreamBadge.BATTERY]: {
|
||||||
|
name: t('battery'),
|
||||||
|
icon: BxIcon.BATTERY,
|
||||||
|
color: '#00b543',
|
||||||
|
},
|
||||||
|
[StreamBadge.DOWNLOAD]: {
|
||||||
|
name: t('download'),
|
||||||
|
icon: BxIcon.DOWNLOAD,
|
||||||
|
color: '#29adff',
|
||||||
|
},
|
||||||
|
[StreamBadge.UPLOAD]: {
|
||||||
|
name: t('upload'),
|
||||||
|
icon: BxIcon.UPLOAD,
|
||||||
|
color: '#ff77a8',
|
||||||
|
},
|
||||||
|
[StreamBadge.SERVER]: {
|
||||||
|
name: t('server'),
|
||||||
|
icon: BxIcon.SERVER,
|
||||||
|
color: '#ff6c24',
|
||||||
|
},
|
||||||
|
[StreamBadge.VIDEO]: {
|
||||||
|
name: t('video'),
|
||||||
|
icon: BxIcon.DISPLAY,
|
||||||
|
color: '#742f29',
|
||||||
|
},
|
||||||
|
[StreamBadge.AUDIO]: {
|
||||||
|
name: t('audio'),
|
||||||
|
icon: BxIcon.AUDIO,
|
||||||
|
color: '#5f574f',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
#$container: HTMLElement | undefined;
|
private $container: HTMLElement | undefined;
|
||||||
#cachedDoms: Partial<{[key in StreamBadge]: HTMLElement}> = {};
|
|
||||||
|
|
||||||
#interval?: number | null;
|
private intervalId?: number | null;
|
||||||
readonly #REFRESH_INTERVAL = 3000;
|
private readonly REFRESH_INTERVAL = 3 * 1000;
|
||||||
|
|
||||||
setRegion(region: string) {
|
setRegion(region: string) {
|
||||||
this.#region = region;
|
this.serverInfo.server = {
|
||||||
|
region: region,
|
||||||
|
ipv6: false,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#renderBadge(name: StreamBadge, value: string, color: string) {
|
renderBadge(name: StreamBadge, value: string) {
|
||||||
|
const badgeInfo = this.badges[name];
|
||||||
|
|
||||||
let $badge;
|
let $badge;
|
||||||
if (this.#cachedDoms[name]) {
|
if (badgeInfo.$element) {
|
||||||
$badge = this.#cachedDoms[name]!;
|
$badge = badgeInfo.$element;
|
||||||
$badge.lastElementChild!.textContent = value;
|
$badge.lastElementChild!.textContent = value;
|
||||||
return $badge;
|
return $badge;
|
||||||
}
|
}
|
||||||
|
|
||||||
$badge = CE('div', {'class': 'bx-badge', 'title': t(`badge-${name}`)},
|
$badge = CE('div', {class: 'bx-badge', title: badgeInfo.name},
|
||||||
CE('span', {'class': 'bx-badge-name'}, createSvgIcon(StreamBadgeIcon[name])),
|
CE('span', {class: 'bx-badge-name'}, createSvgIcon(badgeInfo.icon)),
|
||||||
CE('span', {'class': 'bx-badge-value', 'style': `background-color: ${color}`}, value),
|
CE('span', {class: 'bx-badge-value', style: `background-color: ${badgeInfo.color}`}, value),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (name === StreamBadge.BATTERY) {
|
if (name === StreamBadge.BATTERY) {
|
||||||
$badge.classList.add('bx-badge-battery');
|
$badge.classList.add('bx-badge-battery');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#cachedDoms[name] = $badge;
|
this.badges[name].$element = $badge;
|
||||||
return $badge;
|
return $badge;
|
||||||
}
|
}
|
||||||
|
|
||||||
async #updateBadges(forceUpdate = false) {
|
private async updateBadges(forceUpdate = false) {
|
||||||
if (!this.#$container || (!forceUpdate && !this.#$container.isConnected)) {
|
if (!this.$container || (!forceUpdate && !this.$container.isConnected)) {
|
||||||
this.#stop();
|
this.stop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Playtime
|
const statsCollector = StreamStatsCollector.getInstance();
|
||||||
let now = +new Date;
|
await statsCollector.collect();
|
||||||
const diffSeconds = Math.ceil((now - this.startTimestamp) / 1000);
|
|
||||||
const playtime = this.#secondsToHm(diffSeconds);
|
|
||||||
|
|
||||||
// Battery
|
const play = statsCollector.getStat(StreamStat.PLAYTIME);
|
||||||
let batteryLevel = '100%';
|
const batt = statsCollector.getStat(StreamStat.BATTERY);
|
||||||
let batteryLevelInt = 100;
|
const dl = statsCollector.getStat(StreamStat.DOWNLOAD);
|
||||||
let isCharging = false;
|
const ul = statsCollector.getStat(StreamStat.UPLOAD);
|
||||||
if (STATES.browser.capabilities.batteryApi) {
|
|
||||||
try {
|
|
||||||
const bm = await (navigator as NavigatorBattery).getBattery();
|
|
||||||
isCharging = bm.charging;
|
|
||||||
batteryLevelInt = Math.round(bm.level * 100);
|
|
||||||
batteryLevel = `${batteryLevelInt}%`;
|
|
||||||
|
|
||||||
if (batteryLevelInt != this.startBatteryLevel) {
|
|
||||||
const diffLevel = Math.round(batteryLevelInt - this.startBatteryLevel);
|
|
||||||
const sign = diffLevel > 0 ? '+' : '';
|
|
||||||
batteryLevel += ` (${sign}${diffLevel}%)`;
|
|
||||||
}
|
|
||||||
} catch(e) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
const stats = await STATES.currentStream.peerConnection?.getStats()!;
|
|
||||||
let totalIn = 0;
|
|
||||||
let totalOut = 0;
|
|
||||||
stats.forEach(stat => {
|
|
||||||
if (stat.type === 'candidate-pair' && stat.packetsReceived > 0 && stat.state === 'succeeded') {
|
|
||||||
totalIn += stat.bytesReceived;
|
|
||||||
totalOut += stat.bytesSent;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const badges = {
|
const badges = {
|
||||||
[StreamBadge.DOWNLOAD]: totalIn ? this.#humanFileSize(totalIn) : null,
|
[StreamBadge.DOWNLOAD]: dl.toString(),
|
||||||
[StreamBadge.UPLOAD]: totalOut ? this.#humanFileSize(totalOut) : null,
|
[StreamBadge.UPLOAD]: ul.toString(),
|
||||||
[StreamBadge.PLAYTIME]: playtime,
|
[StreamBadge.PLAYTIME]: play.toString(),
|
||||||
[StreamBadge.BATTERY]: batteryLevel,
|
[StreamBadge.BATTERY]: batt.toString(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let name: keyof typeof badges;
|
let name: keyof typeof badges;
|
||||||
@ -130,97 +161,44 @@ export class StreamBadges {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const $elm = this.#cachedDoms[name]!;
|
const $elm = this.badges[name].$element;
|
||||||
$elm && ($elm.lastElementChild!.textContent = value);
|
if (!$elm) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$elm.lastElementChild!.textContent = value;
|
||||||
|
|
||||||
if (name === StreamBadge.BATTERY) {
|
if (name === StreamBadge.BATTERY) {
|
||||||
if (this.startBatteryLevel === 100 && batteryLevelInt === 100) {
|
if (batt.current === 100 && batt.start === 100) {
|
||||||
// Hide battery badge when the battery is 100%
|
// Hide battery badge when the battery is 100%
|
||||||
$elm.classList.add('bx-gone');
|
$elm.classList.add('bx-gone');
|
||||||
} else {
|
} else {
|
||||||
// Show charging status
|
// Show charging status
|
||||||
$elm.dataset.charging = isCharging.toString()
|
$elm.dataset.charging = batt.isCharging.toString();
|
||||||
$elm.classList.remove('bx-gone');
|
$elm.classList.remove('bx-gone');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async #start() {
|
private async start() {
|
||||||
await this.#updateBadges(true);
|
await this.updateBadges(true);
|
||||||
this.#stop();
|
this.stop();
|
||||||
this.#interval = window.setInterval(this.#updateBadges.bind(this), this.#REFRESH_INTERVAL);
|
this.intervalId = window.setInterval(this.updateBadges.bind(this), this.REFRESH_INTERVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#stop() {
|
private stop() {
|
||||||
this.#interval && clearInterval(this.#interval);
|
this.intervalId && clearInterval(this.intervalId);
|
||||||
this.#interval = null;
|
this.intervalId = null;
|
||||||
}
|
|
||||||
|
|
||||||
#secondsToHm(seconds: number) {
|
|
||||||
let h = Math.floor(seconds / 3600);
|
|
||||||
let m = Math.floor(seconds % 3600 / 60) + 1;
|
|
||||||
|
|
||||||
if (m === 60) {
|
|
||||||
h += 1;
|
|
||||||
m = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const output = [];
|
|
||||||
h > 0 && output.push(`${h}h`);
|
|
||||||
m > 0 && output.push(`${m}m`);
|
|
||||||
|
|
||||||
return output.join(' ');
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://stackoverflow.com/a/20732091
|
|
||||||
#humanFileSize(size: number) {
|
|
||||||
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
||||||
|
|
||||||
const i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
|
|
||||||
return (size / Math.pow(1024, i)).toFixed(2) + ' ' + units[i];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async render() {
|
async render() {
|
||||||
if (this.#$container) {
|
if (this.$container) {
|
||||||
this.#start();
|
this.start();
|
||||||
return this.#$container;
|
return this.$container;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.#getServerStats();
|
await this.getServerStats();
|
||||||
|
|
||||||
// Video
|
|
||||||
let video = '';
|
|
||||||
if (this.#resolution) {
|
|
||||||
video = `${this.#resolution.height}p`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.#video) {
|
|
||||||
video && (video += '/');
|
|
||||||
video += this.#video.codec;
|
|
||||||
if (this.#video.profile) {
|
|
||||||
const profile = this.#video.profile;
|
|
||||||
|
|
||||||
let quality = profile;
|
|
||||||
if (profile.startsWith('4d')) {
|
|
||||||
quality = t('visual-quality-high');
|
|
||||||
} else if (profile.startsWith('42e')) {
|
|
||||||
quality = t('visual-quality-normal');
|
|
||||||
} else if (profile.startsWith('420')) {
|
|
||||||
quality = t('visual-quality-low');
|
|
||||||
}
|
|
||||||
|
|
||||||
video += ` (${quality})`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Audio
|
|
||||||
let audio;
|
|
||||||
if (this.#audio) {
|
|
||||||
audio = this.#audio.codec;
|
|
||||||
const bitrate = this.#audio.bitrate / 1000;
|
|
||||||
audio += ` (${bitrate} kHz)`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Battery
|
// Battery
|
||||||
let batteryLevel = '';
|
let batteryLevel = '';
|
||||||
@ -228,46 +206,50 @@ export class StreamBadges {
|
|||||||
batteryLevel = '100%';
|
batteryLevel = '100%';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Server + Region
|
|
||||||
let server = this.#region;
|
|
||||||
server += '@' + (this.#ipv6 ? 'IPv6' : 'IPv4');
|
|
||||||
|
|
||||||
const BADGES = [
|
const BADGES = [
|
||||||
[StreamBadge.PLAYTIME, '1m', '#ff004d'],
|
[StreamBadge.PLAYTIME, '1m'],
|
||||||
[StreamBadge.BATTERY, batteryLevel, '#00b543'],
|
[StreamBadge.BATTERY, batteryLevel],
|
||||||
[StreamBadge.DOWNLOAD, this.#humanFileSize(0), '#29adff'],
|
[StreamBadge.DOWNLOAD, humanFileSize(0)],
|
||||||
[StreamBadge.UPLOAD, this.#humanFileSize(0), '#ff77a8'],
|
[StreamBadge.UPLOAD, humanFileSize(0)],
|
||||||
[StreamBadge.SERVER, server, '#ff6c24'],
|
this.serverInfo.server ? this.badges.server.$element : [StreamBadge.SERVER, '?'],
|
||||||
video ? [StreamBadge.VIDEO, video, '#742f29'] : null,
|
this.serverInfo.video ? this.badges.video.$element : [StreamBadge.VIDEO, '?'],
|
||||||
audio ? [StreamBadge.AUDIO, audio, '#5f574f'] : null,
|
this.serverInfo.audio ? this.badges.audio.$element : [StreamBadge.AUDIO, '?'],
|
||||||
];
|
];
|
||||||
|
|
||||||
const $container = CE('div', {'class': 'bx-badges'});
|
const $container = CE('div', {class: 'bx-badges'});
|
||||||
BADGES.forEach(item => {
|
BADGES.forEach(item => {
|
||||||
if (!item) {
|
if (!item) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const $badge = this.#renderBadge(...(item as [StreamBadge, string, string]));
|
let $badge: HTMLElement;
|
||||||
|
if (!(item instanceof HTMLElement)) {
|
||||||
|
$badge = this.renderBadge(...(item as [StreamBadge, string]));
|
||||||
|
} else {
|
||||||
|
$badge = item;
|
||||||
|
}
|
||||||
|
|
||||||
$container.appendChild($badge);
|
$container.appendChild($badge);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.#$container = $container;
|
this.$container = $container;
|
||||||
await this.#start();
|
await this.start();
|
||||||
|
|
||||||
return $container;
|
return $container;
|
||||||
}
|
}
|
||||||
|
|
||||||
async #getServerStats() {
|
private async getServerStats() {
|
||||||
const stats = await STATES.currentStream.peerConnection!.getStats();
|
const stats = await STATES.currentStream.peerConnection!.getStats();
|
||||||
|
|
||||||
const allVideoCodecs: {[index: string]: RTCBasicStat} = {};
|
const allVideoCodecs: Record<string, RTCBasicStat> = {};
|
||||||
let videoCodecId;
|
let videoCodecId;
|
||||||
|
let videoWidth = 0;
|
||||||
|
let videoHeight = 0;
|
||||||
|
|
||||||
const allAudioCodecs: {[index: string]: RTCBasicStat} = {};
|
const allAudioCodecs: Record<string, RTCBasicStat> = {};
|
||||||
let audioCodecId;
|
let audioCodecId;
|
||||||
|
|
||||||
const allCandidates: {[index: string]: string} = {};
|
const allCandidates: Record<string, string> = {};
|
||||||
let candidateId;
|
let candidateId;
|
||||||
|
|
||||||
stats.forEach((stat: RTCBasicStat) => {
|
stats.forEach((stat: RTCBasicStat) => {
|
||||||
@ -284,6 +266,8 @@ export class StreamBadges {
|
|||||||
// Get the codecId of the video/audio track currently being used
|
// Get the codecId of the video/audio track currently being used
|
||||||
if (stat.kind === 'video') {
|
if (stat.kind === 'video') {
|
||||||
videoCodecId = stat.codecId;
|
videoCodecId = stat.codecId;
|
||||||
|
videoWidth = stat.frameWidth;
|
||||||
|
videoHeight = stat.frameHeight;
|
||||||
} else if (stat.kind === 'audio') {
|
} else if (stat.kind === 'audio') {
|
||||||
audioCodecId = stat.codecId;
|
audioCodecId = stat.codecId;
|
||||||
}
|
}
|
||||||
@ -297,71 +281,91 @@ export class StreamBadges {
|
|||||||
// Get video codec from codecId
|
// Get video codec from codecId
|
||||||
if (videoCodecId) {
|
if (videoCodecId) {
|
||||||
const videoStat = allVideoCodecs[videoCodecId];
|
const videoStat = allVideoCodecs[videoCodecId];
|
||||||
const video: any = {
|
const video: StreamServerInfo['video'] = {
|
||||||
|
width: videoWidth,
|
||||||
|
height: videoHeight,
|
||||||
codec: videoStat.mimeType.substring(6),
|
codec: videoStat.mimeType.substring(6),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (video.codec === 'H264') {
|
if (video.codec === 'H264') {
|
||||||
const match = /profile-level-id=([0-9a-f]{6})/.exec(videoStat.sdpFmtpLine);
|
const match = /profile-level-id=([0-9a-f]{6})/.exec(videoStat.sdpFmtpLine);
|
||||||
video.profile = match ? match[1] : null;
|
match && (video.profile = match[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#video = video;
|
let text = videoHeight + 'p';
|
||||||
|
text && (text += '/');
|
||||||
|
text += video.codec;
|
||||||
|
if (video.profile) {
|
||||||
|
const profile = video.profile;
|
||||||
|
|
||||||
|
let quality = profile;
|
||||||
|
if (profile.startsWith('4d')) {
|
||||||
|
quality = t('visual-quality-high');
|
||||||
|
} else if (profile.startsWith('42e')) {
|
||||||
|
quality = t('visual-quality-normal');
|
||||||
|
} else if (profile.startsWith('420')) {
|
||||||
|
quality = t('visual-quality-low');
|
||||||
|
}
|
||||||
|
|
||||||
|
text += ` (${quality})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render badge
|
||||||
|
this.badges.video.$element = this.renderBadge(StreamBadge.VIDEO, text);
|
||||||
|
|
||||||
|
this.serverInfo.video = video;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get audio codec from codecId
|
// Get audio codec from codecId
|
||||||
if (audioCodecId) {
|
if (audioCodecId) {
|
||||||
const audioStat = allAudioCodecs[audioCodecId];
|
const audioStat = allAudioCodecs[audioCodecId];
|
||||||
this.#audio = {
|
const audio: StreamServerInfo['audio'] = {
|
||||||
codec: audioStat.mimeType.substring(6),
|
codec: audioStat.mimeType.substring(6),
|
||||||
bitrate: audioStat.clockRate,
|
bitrate: audioStat.clockRate,
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const bitrate = audio.bitrate / 1000;
|
||||||
|
const text = `${audio.codec} (${bitrate} kHz)`;
|
||||||
|
this.badges.audio.$element = this.renderBadge(StreamBadge.AUDIO, text);
|
||||||
|
|
||||||
|
this.serverInfo.audio = audio;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get server type
|
// Get server type
|
||||||
if (candidateId) {
|
if (candidateId) {
|
||||||
BxLogger.info('candidate', candidateId, allCandidates);
|
BxLogger.info('candidate', candidateId, allCandidates);
|
||||||
this.#ipv6 = allCandidates[candidateId].includes(':');
|
|
||||||
|
// Server + Region
|
||||||
|
const server = this.serverInfo.server;
|
||||||
|
if (server) {
|
||||||
|
server.ipv6 = allCandidates[candidateId].includes(':');
|
||||||
|
|
||||||
|
let text = '';
|
||||||
|
if (server.region) {
|
||||||
|
text += server.region;
|
||||||
|
}
|
||||||
|
|
||||||
|
text += '@' + (server.ipv6 ? 'IPv6' : 'IPv4');
|
||||||
|
this.badges.server.$element = this.renderBadge(StreamBadge.SERVER, text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static setupEvents() {
|
static setupEvents() {
|
||||||
window.addEventListener(BxEvent.STREAM_PLAYING, e => {
|
// Since the Lite version doesn't have the "..." button on System menu
|
||||||
const $video = (e as any).$video;
|
// we need to display Stream badges in the Guide menu instead
|
||||||
const streamBadges = StreamBadges.getInstance();
|
isLiteVersion() && window.addEventListener(BxEvent.XCLOUD_GUIDE_MENU_SHOWN, async e => {
|
||||||
|
const where = (e as any).where as GuideMenuTab;
|
||||||
|
|
||||||
streamBadges.#resolution = {
|
if (where !== GuideMenuTab.HOME || !STATES.isPlaying) {
|
||||||
width: $video.videoWidth,
|
|
||||||
height: $video.videoHeight,
|
|
||||||
};
|
|
||||||
streamBadges.startTimestamp = +new Date;
|
|
||||||
|
|
||||||
// Get battery level
|
|
||||||
try {
|
|
||||||
STATES.browser.capabilities.batteryApi && (navigator as NavigatorBattery).getBattery().then(bm => {
|
|
||||||
streamBadges.startBatteryLevel = Math.round(bm.level * 100);
|
|
||||||
});
|
|
||||||
} catch(e) {}
|
|
||||||
});
|
|
||||||
|
|
||||||
/*
|
|
||||||
Don't do this until xCloud remove the Stream Menu page
|
|
||||||
|
|
||||||
window.addEventListener(BxEvent.XCLOUD_GUIDE_SHOWN, async e => {
|
|
||||||
const where = (e as any).where as XcloudGuideWhere;
|
|
||||||
|
|
||||||
if (where !== XcloudGuideWhere.HOME || !STATES.isPlaying) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const $btnQuit = document.querySelector('#gamepass-dialog-root a[class*=QuitGameButton]');
|
const $btnQuit = document.querySelector('#gamepass-dialog-root a[class*=QuitGameButton]');
|
||||||
if (!$btnQuit) {
|
if ($btnQuit) {
|
||||||
return;
|
// Add badges
|
||||||
|
$btnQuit.insertAdjacentElement('beforebegin', await StreamBadges.getInstance().render());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add badges
|
|
||||||
$btnQuit.insertAdjacentElement('beforebegin', await StreamBadges.getInstance().render());
|
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,10 @@ import { getPref, setPref } from "@/utils/settings-storages/global-settings-stor
|
|||||||
|
|
||||||
export function onChangeVideoPlayerType() {
|
export function onChangeVideoPlayerType() {
|
||||||
const playerType = getPref(PrefKey.VIDEO_PLAYER_TYPE);
|
const playerType = getPref(PrefKey.VIDEO_PLAYER_TYPE);
|
||||||
const $videoProcessing = document.getElementById('bx_setting_video_processing') as HTMLSelectElement;
|
const $videoProcessing = document.getElementById(`bx_setting_${PrefKey.VIDEO_PROCESSING}`) as HTMLSelectElement;
|
||||||
const $videoSharpness = document.getElementById('bx_setting_video_sharpness') as HTMLElement;
|
const $videoSharpness = document.getElementById(`bx_setting_${PrefKey.VIDEO_SHARPNESS}`) as HTMLElement;
|
||||||
const $videoPowerPreference = document.getElementById('bx_setting_video_power_preference') as HTMLElement;
|
const $videoPowerPreference = document.getElementById(`bx_setting_${PrefKey.VIDEO_POWER_PREFERENCE}`) as HTMLElement;
|
||||||
|
const $videoMaxFps = document.getElementById(`bx_setting_${PrefKey.VIDEO_MAX_FPS}`) as HTMLElement;
|
||||||
|
|
||||||
if (!$videoProcessing) {
|
if (!$videoProcessing) {
|
||||||
return;
|
return;
|
||||||
@ -38,17 +39,27 @@ export function onChangeVideoPlayerType() {
|
|||||||
|
|
||||||
// Hide Power Preference setting if renderer isn't WebGL2
|
// Hide Power Preference setting if renderer isn't WebGL2
|
||||||
$videoPowerPreference.closest('.bx-settings-row')!.classList.toggle('bx-gone', playerType !== StreamPlayerType.WEBGL2);
|
$videoPowerPreference.closest('.bx-settings-row')!.classList.toggle('bx-gone', playerType !== StreamPlayerType.WEBGL2);
|
||||||
|
$videoMaxFps.closest('.bx-settings-row')!.classList.toggle('bx-gone', playerType !== StreamPlayerType.WEBGL2);
|
||||||
|
|
||||||
updateVideoPlayer();
|
updateVideoPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export function limitVideoPlayerFps() {
|
||||||
|
const targetFps = getPref(PrefKey.VIDEO_MAX_FPS);
|
||||||
|
const streamPlayer = STATES.currentStream.streamPlayer;
|
||||||
|
streamPlayer?.getWebGL2Player()?.setTargetFps(targetFps);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export function updateVideoPlayer() {
|
export function updateVideoPlayer() {
|
||||||
const streamPlayer = STATES.currentStream.streamPlayer;
|
const streamPlayer = STATES.currentStream.streamPlayer;
|
||||||
if (!streamPlayer) {
|
if (!streamPlayer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
limitVideoPlayerFps();
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
processing: getPref(PrefKey.VIDEO_PROCESSING),
|
processing: getPref(PrefKey.VIDEO_PROCESSING),
|
||||||
sharpness: getPref(PrefKey.VIDEO_SHARPNESS),
|
sharpness: getPref(PrefKey.VIDEO_SHARPNESS),
|
||||||
@ -60,6 +71,7 @@ export function updateVideoPlayer() {
|
|||||||
streamPlayer.setPlayerType(getPref(PrefKey.VIDEO_PLAYER_TYPE));
|
streamPlayer.setPlayerType(getPref(PrefKey.VIDEO_PLAYER_TYPE));
|
||||||
streamPlayer.updateOptions(options);
|
streamPlayer.updateOptions(options);
|
||||||
streamPlayer.refreshPlayer();
|
streamPlayer.refreshPlayer();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('resize', updateVideoPlayer);
|
window.addEventListener('resize', updateVideoPlayer);
|
||||||
|
@ -4,15 +4,8 @@ import { t } from "@utils/translation"
|
|||||||
import { STATES } from "@utils/global"
|
import { STATES } from "@utils/global"
|
||||||
import { PrefKey } from "@/enums/pref-keys"
|
import { PrefKey } from "@/enums/pref-keys"
|
||||||
import { getPref } from "@/utils/settings-storages/global-settings-storage"
|
import { getPref } from "@/utils/settings-storages/global-settings-storage"
|
||||||
|
import { StreamStat, StreamStatsCollector, type StreamStatGrade } from "@/utils/stream-stats-collector"
|
||||||
|
|
||||||
export enum StreamStat {
|
|
||||||
PING = 'ping',
|
|
||||||
FPS = 'fps',
|
|
||||||
BITRATE = 'btr',
|
|
||||||
DECODE_TIME = 'dt',
|
|
||||||
PACKETS_LOST = 'pl',
|
|
||||||
FRAMES_LOST = 'fl',
|
|
||||||
};
|
|
||||||
|
|
||||||
export class StreamStats {
|
export class StreamStats {
|
||||||
private static instance: StreamStats;
|
private static instance: StreamStats;
|
||||||
@ -24,58 +17,99 @@ export class StreamStats {
|
|||||||
return StreamStats.instance;
|
return StreamStats.instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
#timeoutId?: number | null;
|
private intervalId?: number | null;
|
||||||
readonly #updateInterval = 1000;
|
private readonly REFRESH_INTERVAL = 1 * 1000;
|
||||||
|
|
||||||
#$container: HTMLElement | undefined;
|
private stats = {
|
||||||
#$fps: HTMLElement | undefined;
|
[StreamStat.CLOCK]: {
|
||||||
#$ping: HTMLElement | undefined;
|
name: t('clock'),
|
||||||
#$dt: HTMLElement | undefined;
|
$element: CE('span'),
|
||||||
#$pl: HTMLElement | undefined;
|
},
|
||||||
#$fl: HTMLElement | undefined;
|
[StreamStat.PLAYTIME]: {
|
||||||
#$br: HTMLElement | undefined;
|
name: t('playtime'),
|
||||||
|
$element: CE('span'),
|
||||||
|
},
|
||||||
|
[StreamStat.BATTERY]: {
|
||||||
|
name: t('battery'),
|
||||||
|
$element: CE('span'),
|
||||||
|
},
|
||||||
|
[StreamStat.PING]: {
|
||||||
|
name: t('stat-ping'),
|
||||||
|
$element: CE('span'),
|
||||||
|
},
|
||||||
|
[StreamStat.JITTER]: {
|
||||||
|
name: t('jitter'),
|
||||||
|
$element: CE('span'),
|
||||||
|
},
|
||||||
|
[StreamStat.FPS]: {
|
||||||
|
name: t('stat-fps'),
|
||||||
|
$element: CE('span'),
|
||||||
|
},
|
||||||
|
[StreamStat.BITRATE]: {
|
||||||
|
name: t('stat-bitrate'),
|
||||||
|
$element: CE('span'),
|
||||||
|
},
|
||||||
|
[StreamStat.DECODE_TIME]: {
|
||||||
|
name: t('stat-decode-time'),
|
||||||
|
$element: CE('span'),
|
||||||
|
},
|
||||||
|
[StreamStat.PACKETS_LOST]: {
|
||||||
|
name: t('stat-packets-lost'),
|
||||||
|
$element: CE('span'),
|
||||||
|
},
|
||||||
|
[StreamStat.FRAMES_LOST]: {
|
||||||
|
name: t('stat-frames-lost'),
|
||||||
|
$element: CE('span'),
|
||||||
|
},
|
||||||
|
[StreamStat.DOWNLOAD]: {
|
||||||
|
name: t('downloaded'),
|
||||||
|
$element: CE('span'),
|
||||||
|
},
|
||||||
|
[StreamStat.UPLOAD]: {
|
||||||
|
name: t('uploaded'),
|
||||||
|
$element: CE('span'),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
#lastVideoStat?: RTCBasicStat | null;
|
private $container!: HTMLElement;
|
||||||
|
|
||||||
#quickGlanceObserver?: MutationObserver | null;
|
quickGlanceObserver?: MutationObserver | null;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.#render();
|
this.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
start(glancing=false) {
|
async start(glancing=false) {
|
||||||
if (!this.isHidden() || (glancing && this.isGlancing())) {
|
if (!this.isHidden() || (glancing && this.isGlancing())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.#$container) {
|
this.intervalId && clearInterval(this.intervalId);
|
||||||
this.#$container.classList.remove('bx-gone');
|
await this.update(true);
|
||||||
this.#$container.dataset.display = glancing ? 'glancing' : 'fixed';
|
|
||||||
}
|
|
||||||
|
|
||||||
this.#timeoutId = window.setTimeout(this.#update.bind(this), this.#updateInterval);
|
this.$container.classList.remove('bx-gone');
|
||||||
|
this.$container.dataset.display = glancing ? 'glancing' : 'fixed';
|
||||||
|
|
||||||
|
this.intervalId = window.setInterval(this.update.bind(this), this.REFRESH_INTERVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
stop(glancing=false) {
|
async stop(glancing=false) {
|
||||||
if (glancing && !this.isGlancing()) {
|
if (glancing && !this.isGlancing()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#timeoutId && clearTimeout(this.#timeoutId);
|
this.intervalId && clearInterval(this.intervalId);
|
||||||
this.#timeoutId = null;
|
this.intervalId = null;
|
||||||
this.#lastVideoStat = null;
|
|
||||||
|
|
||||||
if (this.#$container) {
|
this.$container.removeAttribute('data-display');
|
||||||
this.#$container.removeAttribute('data-display');
|
this.$container.classList.add('bx-gone');
|
||||||
this.#$container.classList.add('bx-gone');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toggle() {
|
async toggle() {
|
||||||
if (this.isGlancing()) {
|
if (this.isGlancing()) {
|
||||||
this.#$container && (this.#$container.dataset.display = 'fixed');
|
this.$container && (this.$container.dataset.display = 'fixed');
|
||||||
} else {
|
} else {
|
||||||
this.isHidden() ? this.start() : this.stop();
|
this.isHidden() ? await this.start() : await this.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,11 +119,11 @@ export class StreamStats {
|
|||||||
this.hideSettingsUi();
|
this.hideSettingsUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
isHidden = () => this.#$container && this.#$container.classList.contains('bx-gone');
|
isHidden = () => this.$container.classList.contains('bx-gone');
|
||||||
isGlancing = () => this.#$container && this.#$container.dataset.display === 'glancing';
|
isGlancing = () => this.$container.dataset.display === 'glancing';
|
||||||
|
|
||||||
quickGlanceSetup() {
|
quickGlanceSetup() {
|
||||||
if (!STATES.isPlaying || this.#quickGlanceObserver) {
|
if (!STATES.isPlaying || this.quickGlanceObserver) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,20 +132,23 @@ export class StreamStats {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#quickGlanceObserver = new MutationObserver((mutationList, observer) => {
|
this.quickGlanceObserver = new MutationObserver((mutationList, observer) => {
|
||||||
for (let record of mutationList) {
|
for (const record of mutationList) {
|
||||||
if (record.attributeName && record.attributeName === 'aria-expanded') {
|
const $target = record.target as HTMLElement;
|
||||||
const expanded = (record.target as HTMLElement).ariaExpanded;
|
if (!$target.className || !$target.className.startsWith('GripHandle')) {
|
||||||
if (expanded === 'true') {
|
continue;
|
||||||
this.isHidden() && this.start(true);
|
}
|
||||||
} else {
|
|
||||||
this.stop(true);
|
const expanded = (record.target as HTMLElement).ariaExpanded;
|
||||||
}
|
if (expanded === 'true') {
|
||||||
|
this.isHidden() && this.start(true);
|
||||||
|
} else {
|
||||||
|
this.stop(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.#quickGlanceObserver.observe($uiContainer, {
|
this.quickGlanceObserver.observe($uiContainer, {
|
||||||
attributes: true,
|
attributes: true,
|
||||||
attributeFilter: ['aria-expanded'],
|
attributeFilter: ['aria-expanded'],
|
||||||
subtree: true,
|
subtree: true,
|
||||||
@ -119,98 +156,52 @@ export class StreamStats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
quickGlanceStop() {
|
quickGlanceStop() {
|
||||||
this.#quickGlanceObserver && this.#quickGlanceObserver.disconnect();
|
this.quickGlanceObserver && this.quickGlanceObserver.disconnect();
|
||||||
this.#quickGlanceObserver = null;
|
this.quickGlanceObserver = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async #update() {
|
private async update(forceUpdate=false) {
|
||||||
if (this.isHidden() || !STATES.currentStream.peerConnection) {
|
if ((!forceUpdate && this.isHidden()) || !STATES.currentStream.peerConnection) {
|
||||||
this.onStoppedPlaying();
|
this.onStoppedPlaying();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#timeoutId = null;
|
|
||||||
const startTime = performance.now();
|
|
||||||
|
|
||||||
const PREF_STATS_CONDITIONAL_FORMATTING = getPref(PrefKey.STATS_CONDITIONAL_FORMATTING);
|
const PREF_STATS_CONDITIONAL_FORMATTING = getPref(PrefKey.STATS_CONDITIONAL_FORMATTING);
|
||||||
|
let grade: StreamStatGrade = '';
|
||||||
|
|
||||||
const stats = await STATES.currentStream.peerConnection.getStats();
|
// Collect stats
|
||||||
let grade = '';
|
const statsCollector = StreamStatsCollector.getInstance();
|
||||||
|
await statsCollector.collect();
|
||||||
|
|
||||||
stats.forEach(stat => {
|
let statKey: keyof typeof this.stats;
|
||||||
if (stat.type === 'inbound-rtp' && stat.kind === 'video') {
|
for (statKey in this.stats) {
|
||||||
// FPS
|
grade = '';
|
||||||
this.#$fps!.textContent = stat.framesPerSecond || 0;
|
|
||||||
|
|
||||||
// Packets Lost
|
const stat = this.stats[statKey];
|
||||||
const packetsLost = Math.max(0, stat.packetsLost); // packetsLost can be negative, but we don't care about that
|
const value = statsCollector.getStat(statKey);
|
||||||
const packetsReceived = stat.packetsReceived;
|
const $element = stat.$element;
|
||||||
const packetsLostPercentage = (packetsLost * 100 / ((packetsLost + packetsReceived) || 1)).toFixed(2);
|
$element.textContent = value.toString();
|
||||||
this.#$pl!.textContent = packetsLostPercentage === '0.00' ? packetsLost.toString() : `${packetsLost} (${packetsLostPercentage}%)`;
|
|
||||||
|
|
||||||
// Frames dropped
|
// Get stat's grade
|
||||||
const framesDropped = stat.framesDropped;
|
if (PREF_STATS_CONDITIONAL_FORMATTING && 'grades' in value) {
|
||||||
const framesReceived = stat.framesReceived;
|
grade = statsCollector.calculateGrade(value.current, value.grades);
|
||||||
const framesDroppedPercentage = (framesDropped * 100 / ((framesDropped + framesReceived) || 1)).toFixed(2);
|
|
||||||
this.#$fl!.textContent = framesDroppedPercentage === '0.00' ? framesDropped : `${framesDropped} (${framesDroppedPercentage}%)`;
|
|
||||||
|
|
||||||
if (!this.#lastVideoStat) {
|
|
||||||
this.#lastVideoStat = stat;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const lastStat = this.#lastVideoStat;
|
|
||||||
// Bitrate
|
|
||||||
const timeDiff = stat.timestamp - lastStat.timestamp;
|
|
||||||
const bitrate = 8 * (stat.bytesReceived - lastStat.bytesReceived) / timeDiff / 1000;
|
|
||||||
this.#$br!.textContent = `${bitrate.toFixed(2)} Mbps`;
|
|
||||||
|
|
||||||
// Decode time
|
|
||||||
const totalDecodeTimeDiff = stat.totalDecodeTime - lastStat.totalDecodeTime;
|
|
||||||
const framesDecodedDiff = stat.framesDecoded - lastStat.framesDecoded;
|
|
||||||
const currentDecodeTime = totalDecodeTimeDiff / framesDecodedDiff * 1000;
|
|
||||||
|
|
||||||
if (isNaN(currentDecodeTime)) {
|
|
||||||
this.#$dt!.textContent = '??ms';
|
|
||||||
} else {
|
|
||||||
this.#$dt!.textContent = `${currentDecodeTime.toFixed(2)}ms`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PREF_STATS_CONDITIONAL_FORMATTING) {
|
|
||||||
grade = (currentDecodeTime > 12) ? 'bad' : (currentDecodeTime > 9) ? 'ok' : (currentDecodeTime > 6) ? 'good' : '';
|
|
||||||
this.#$dt!.dataset.grade = grade;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.#lastVideoStat = stat;
|
|
||||||
} else if (stat.type === 'candidate-pair' && stat.packetsReceived > 0 && stat.state === 'succeeded') {
|
|
||||||
// Round Trip Time
|
|
||||||
const roundTripTime = !!stat.currentRoundTripTime ? stat.currentRoundTripTime * 1000 : -1;
|
|
||||||
this.#$ping!.textContent = roundTripTime === -1 ? '???' : roundTripTime.toString();
|
|
||||||
|
|
||||||
if (PREF_STATS_CONDITIONAL_FORMATTING) {
|
|
||||||
grade = (roundTripTime > 100) ? 'bad' : (roundTripTime > 75) ? 'ok' : (roundTripTime > 40) ? 'good' : '';
|
|
||||||
this.#$ping!.dataset.grade = grade;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
const lapsedTime = performance.now() - startTime;
|
if ($element.dataset.grade !== grade) {
|
||||||
this.#timeoutId = window.setTimeout(this.#update.bind(this), this.#updateInterval - lapsedTime);
|
$element.dataset.grade = grade;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshStyles() {
|
refreshStyles() {
|
||||||
const PREF_ITEMS = getPref(PrefKey.STATS_ITEMS);
|
const PREF_ITEMS = getPref(PrefKey.STATS_ITEMS);
|
||||||
const PREF_POSITION = getPref(PrefKey.STATS_POSITION);
|
|
||||||
const PREF_TRANSPARENT = getPref(PrefKey.STATS_TRANSPARENT);
|
|
||||||
const PREF_OPACITY = getPref(PrefKey.STATS_OPACITY);
|
|
||||||
const PREF_TEXT_SIZE = getPref(PrefKey.STATS_TEXT_SIZE);
|
|
||||||
|
|
||||||
const $container = this.#$container!;
|
const $container = this.$container;
|
||||||
$container.dataset.stats = '[' + PREF_ITEMS.join('][') + ']';
|
$container.dataset.stats = '[' + PREF_ITEMS.join('][') + ']';
|
||||||
$container.dataset.position = PREF_POSITION;
|
$container.dataset.position = getPref(PrefKey.STATS_POSITION);
|
||||||
$container.dataset.transparent = PREF_TRANSPARENT;
|
$container.dataset.transparent = getPref(PrefKey.STATS_TRANSPARENT);
|
||||||
$container.style.opacity = PREF_OPACITY + '%';
|
$container.style.opacity = getPref(PrefKey.STATS_OPACITY) + '%';
|
||||||
$container.style.fontSize = PREF_TEXT_SIZE;
|
$container.style.fontSize = getPref(PrefKey.STATS_TEXT_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
hideSettingsUi() {
|
hideSettingsUi() {
|
||||||
@ -219,34 +210,25 @@ export class StreamStats {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#render() {
|
private async render() {
|
||||||
const stats = {
|
this.$container = CE('div', {class: 'bx-stats-bar bx-gone'});
|
||||||
[StreamStat.PING]: [t('stat-ping'), this.#$ping = CE('span', {}, '0')],
|
|
||||||
[StreamStat.FPS]: [t('stat-fps'), this.#$fps = CE('span', {}, '0')],
|
|
||||||
[StreamStat.BITRATE]: [t('stat-bitrate'), this.#$br = CE('span', {}, '0 Mbps')],
|
|
||||||
[StreamStat.DECODE_TIME]: [t('stat-decode-time'), this.#$dt = CE('span', {}, '0ms')],
|
|
||||||
[StreamStat.PACKETS_LOST]: [t('stat-packets-lost'), this.#$pl = CE('span', {}, '0')],
|
|
||||||
[StreamStat.FRAMES_LOST]: [t('stat-frames-lost'), this.#$fl = CE('span', {}, '0')],
|
|
||||||
};
|
|
||||||
|
|
||||||
const $barFragment = document.createDocumentFragment();
|
let statKey: keyof typeof this.stats;
|
||||||
let statKey: keyof typeof stats;
|
for (statKey in this.stats) {
|
||||||
for (statKey in stats) {
|
const stat = this.stats[statKey];
|
||||||
const $div = CE('div', {
|
const $div = CE('div', {
|
||||||
'class': `bx-stat-${statKey}`,
|
class: `bx-stat-${statKey}`,
|
||||||
title: stats[statKey][0]
|
title: stat.name,
|
||||||
},
|
},
|
||||||
CE('label', {}, statKey.toUpperCase()),
|
CE('label', {}, statKey.toUpperCase()),
|
||||||
stats[statKey][1],
|
stat.$element,
|
||||||
);
|
);
|
||||||
|
|
||||||
$barFragment.appendChild($div);
|
this.$container.appendChild($div);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#$container = CE('div', {'class': 'bx-stats-bar bx-gone'}, $barFragment);
|
|
||||||
this.refreshStyles();
|
this.refreshStyles();
|
||||||
|
document.documentElement.appendChild(this.$container);
|
||||||
document.documentElement.appendChild(this.#$container!);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static setupEvents() {
|
static setupEvents() {
|
||||||
@ -255,8 +237,8 @@ export class StreamStats {
|
|||||||
const PREF_STATS_SHOW_WHEN_PLAYING = getPref(PrefKey.STATS_SHOW_WHEN_PLAYING);
|
const PREF_STATS_SHOW_WHEN_PLAYING = getPref(PrefKey.STATS_SHOW_WHEN_PLAYING);
|
||||||
|
|
||||||
const streamStats = StreamStats.getInstance();
|
const streamStats = StreamStats.getInstance();
|
||||||
// Setup Stat's Quick Glance mode
|
|
||||||
|
|
||||||
|
// Setup Stat's Quick Glance mode
|
||||||
if (PREF_STATS_SHOW_WHEN_PLAYING) {
|
if (PREF_STATS_SHOW_WHEN_PLAYING) {
|
||||||
streamStats.start();
|
streamStats.start();
|
||||||
} else if (PREF_STATS_QUICK_GLANCE) {
|
} else if (PREF_STATS_QUICK_GLANCE) {
|
||||||
|
@ -135,12 +135,6 @@ export class StreamUiHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static handleSystemMenu($streamHud: HTMLElement) {
|
private static handleSystemMenu($streamHud: HTMLElement) {
|
||||||
// Grip handle
|
|
||||||
const $gripHandle = $streamHud.querySelector('button[class^=GripHandle]') as HTMLElement;
|
|
||||||
if (!$gripHandle) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the last button
|
// Get the last button
|
||||||
const $orgButton = $streamHud.querySelector('div[class^=HUDButton]') as HTMLElement;
|
const $orgButton = $streamHud.querySelector('div[class^=HUDButton]') as HTMLElement;
|
||||||
if (!$orgButton) {
|
if (!$orgButton) {
|
||||||
@ -148,14 +142,14 @@ export class StreamUiHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const hideGripHandle = () => {
|
const hideGripHandle = () => {
|
||||||
if (!$gripHandle) {
|
// Grip handle
|
||||||
return;
|
const $gripHandle = document.querySelector('#StreamHud button[class^=GripHandle]') as HTMLElement;
|
||||||
|
if ($gripHandle && $gripHandle.ariaExpanded === 'true') {
|
||||||
|
$gripHandle.dispatchEvent(new PointerEvent('pointerdown'));
|
||||||
|
$gripHandle.click();
|
||||||
|
$gripHandle.dispatchEvent(new PointerEvent('pointerdown'));
|
||||||
|
$gripHandle.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
$gripHandle.dispatchEvent(new PointerEvent('pointerdown'));
|
|
||||||
$gripHandle.click();
|
|
||||||
$gripHandle.dispatchEvent(new PointerEvent('pointerdown'));
|
|
||||||
$gripHandle.click();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create Stream Settings button
|
// Create Stream Settings button
|
||||||
@ -178,12 +172,12 @@ export class StreamUiHandler {
|
|||||||
let $btnStreamStats = StreamUiHandler.$btnStreamStats;
|
let $btnStreamStats = StreamUiHandler.$btnStreamStats;
|
||||||
if (typeof $btnStreamStats === 'undefined') {
|
if (typeof $btnStreamStats === 'undefined') {
|
||||||
$btnStreamStats = StreamUiHandler.cloneStreamHudButton($orgButton, t('stream-stats'), BxIcon.STREAM_STATS);
|
$btnStreamStats = StreamUiHandler.cloneStreamHudButton($orgButton, t('stream-stats'), BxIcon.STREAM_STATS);
|
||||||
$btnStreamStats?.addEventListener('click', e => {
|
$btnStreamStats?.addEventListener('click', async (e) => {
|
||||||
hideGripHandle();
|
hideGripHandle();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
// Toggle Stream Stats
|
// Toggle Stream Stats
|
||||||
streamStats.toggle();
|
await streamStats.toggle();
|
||||||
|
|
||||||
const btnStreamStatsOn = (!streamStats.isHidden() && !streamStats.isGlancing());
|
const btnStreamStatsOn = (!streamStats.isHidden() && !streamStats.isGlancing());
|
||||||
$btnStreamStats!.classList.toggle('bx-stream-menu-button-on', btnStreamStatsOn);
|
$btnStreamStats!.classList.toggle('bx-stream-menu-button-on', btnStreamStatsOn);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { GamepadKey } from "@/enums/mkb";
|
import { GamepadKey } from "@/enums/mkb";
|
||||||
import { PrefKey } from "@/enums/pref-keys";
|
import { PrefKey } from "@/enums/pref-keys";
|
||||||
import { EmulatedMkbHandler } from "@/modules/mkb/mkb-handler";
|
import { VIRTUAL_GAMEPAD_ID } from "@/modules/mkb/mkb-handler";
|
||||||
import { BxEvent } from "@/utils/bx-event";
|
import { BxEvent } from "@/utils/bx-event";
|
||||||
import { STATES } from "@/utils/global";
|
import { STATES } from "@/utils/global";
|
||||||
import { CE, isElementVisible } from "@/utils/html";
|
import { CE, isElementVisible } from "@/utils/html";
|
||||||
@ -263,7 +263,7 @@ export class NavigationDialogManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ignore virtual controller
|
// Ignore virtual controller
|
||||||
if (gamepad.id === EmulatedMkbHandler.VIRTUAL_GAMEPAD_ID) {
|
if (gamepad.id === VIRTUAL_GAMEPAD_ID) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import { onChangeVideoPlayerType, updateVideoPlayer } from "@/modules/stream/stream-settings-utils";
|
import { isFullVersion } from "@macros/build" with {type: "macro"};
|
||||||
|
|
||||||
|
import { limitVideoPlayerFps, onChangeVideoPlayerType, updateVideoPlayer } from "@/modules/stream/stream-settings-utils";
|
||||||
import { ButtonStyle, CE, createButton, createSvgIcon, removeChildElements, type BxButton } from "@/utils/html";
|
import { ButtonStyle, CE, createButton, createSvgIcon, removeChildElements, type BxButton } from "@/utils/html";
|
||||||
import { NavigationDialog, NavigationDirection } from "./navigation-dialog";
|
import { NavigationDialog, NavigationDirection } from "./navigation-dialog";
|
||||||
import { ControllerShortcut } from "@/modules/controller-shortcut";
|
import { ControllerShortcut } from "@/modules/controller-shortcut";
|
||||||
@ -10,7 +12,7 @@ import { TouchController } from "@/modules/touch-controller";
|
|||||||
import { VibrationManager } from "@/modules/vibration-manager";
|
import { VibrationManager } from "@/modules/vibration-manager";
|
||||||
import { BxEvent } from "@/utils/bx-event";
|
import { BxEvent } from "@/utils/bx-event";
|
||||||
import { BxIcon } from "@/utils/bx-icon";
|
import { BxIcon } from "@/utils/bx-icon";
|
||||||
import { STATES, AppInterface, deepClone, SCRIPT_VERSION, STORAGE } from "@/utils/global";
|
import { STATES, AppInterface, deepClone, SCRIPT_VERSION, STORAGE, SCRIPT_VARIANT } from "@/utils/global";
|
||||||
import { t, Translations } from "@/utils/translation";
|
import { t, Translations } from "@/utils/translation";
|
||||||
import { BxSelectElement } from "@/web-components/bx-select";
|
import { BxSelectElement } from "@/web-components/bx-select";
|
||||||
import { setNearby } from "@/utils/navigation-utils";
|
import { setNearby } from "@/utils/navigation-utils";
|
||||||
@ -35,25 +37,29 @@ type SettingTabContentItem = Partial<{
|
|||||||
content: HTMLElement | (() => HTMLElement);
|
content: HTMLElement | (() => HTMLElement);
|
||||||
options: {[key: string]: string};
|
options: {[key: string]: string};
|
||||||
unsupported: boolean;
|
unsupported: boolean;
|
||||||
|
unsupportedNote: string;
|
||||||
onChange: (e: any, value: number) => void;
|
onChange: (e: any, value: number) => void;
|
||||||
onCreated: (setting: SettingTabContentItem, $control: any) => void;
|
onCreated: (setting: SettingTabContentItem, $control: any) => void;
|
||||||
params: any;
|
params: any;
|
||||||
|
requiredVariants?: BuildVariant | Array<BuildVariant>;
|
||||||
}>
|
}>
|
||||||
|
|
||||||
type SettingTabContent = {
|
type SettingTabContent = {
|
||||||
group: 'general' | 'server' | 'stream' | 'game-bar' | 'co-op' | 'mkb' | 'touch-control' | 'loading-screen' | 'ui' | 'other' | 'advanced' | 'footer' | 'audio' | 'video' | 'controller' | 'native-mkb' | 'stats' | 'controller-shortcuts';
|
group: 'general' | 'server' | 'stream' | 'game-bar' | 'co-op' | 'mkb' | 'touch-control' | 'loading-screen' | 'ui' | 'other' | 'advanced' | 'footer' | 'audio' | 'video' | 'controller' | 'native-mkb' | 'stats' | 'controller-shortcuts';
|
||||||
label?: string;
|
label?: string;
|
||||||
note?: string | Text | null;
|
|
||||||
unsupported?: boolean;
|
unsupported?: boolean;
|
||||||
|
unsupportedNote?: string | Text | null;
|
||||||
helpUrl?: string;
|
helpUrl?: string;
|
||||||
content?: any;
|
content?: any;
|
||||||
items?: Array<SettingTabContentItem | PrefKey | (($parent: HTMLElement) => void) | false>;
|
items?: Array<SettingTabContentItem | PrefKey | (($parent: HTMLElement) => void) | false>;
|
||||||
|
requiredVariants?: BuildVariant | Array<BuildVariant>;
|
||||||
};
|
};
|
||||||
|
|
||||||
type SettingTab = {
|
type SettingTab = {
|
||||||
icon: SVGElement;
|
icon: SVGElement;
|
||||||
group: 'global';
|
group: 'global';
|
||||||
items: Array<SettingTabContent | false>;
|
items: Array<SettingTabContent | false>;
|
||||||
|
requiredVariants?: BuildVariant | Array<BuildVariant>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export class SettingsNavigationDialog extends NavigationDialog {
|
export class SettingsNavigationDialog extends NavigationDialog {
|
||||||
@ -205,24 +211,33 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
PrefKey.STREAM_COMBINE_SOURCES,
|
PrefKey.STREAM_COMBINE_SOURCES,
|
||||||
],
|
],
|
||||||
}, {
|
}, {
|
||||||
|
requiredVariants: 'full',
|
||||||
group: 'co-op',
|
group: 'co-op',
|
||||||
label: t('local-co-op'),
|
label: t('local-co-op'),
|
||||||
items: [
|
items: [
|
||||||
PrefKey.LOCAL_CO_OP_ENABLED,
|
PrefKey.LOCAL_CO_OP_ENABLED,
|
||||||
],
|
],
|
||||||
}, {
|
}, {
|
||||||
|
requiredVariants: 'full',
|
||||||
group: 'mkb',
|
group: 'mkb',
|
||||||
label: t('mouse-and-keyboard'),
|
label: t('mouse-and-keyboard'),
|
||||||
|
unsupportedNote: !STATES.userAgent.capabilities.mkb ? CE('a', {
|
||||||
|
href: 'https://github.com/redphx/better-xcloud/issues/206#issuecomment-1920475657',
|
||||||
|
target: '_blank',
|
||||||
|
}, '⚠️ ' + t('browser-unsupported-feature')) : null,
|
||||||
|
unsupported: !STATES.userAgent.capabilities.mkb,
|
||||||
items: [
|
items: [
|
||||||
PrefKey.NATIVE_MKB_ENABLED,
|
PrefKey.NATIVE_MKB_ENABLED,
|
||||||
|
PrefKey.GAME_MSFS2020_FORCE_NATIVE_MKB,
|
||||||
PrefKey.MKB_ENABLED,
|
PrefKey.MKB_ENABLED,
|
||||||
PrefKey.MKB_HIDE_IDLE_CURSOR,
|
PrefKey.MKB_HIDE_IDLE_CURSOR,
|
||||||
],
|
],
|
||||||
}, {
|
}, {
|
||||||
|
requiredVariants: 'full',
|
||||||
group: 'touch-control',
|
group: 'touch-control',
|
||||||
label: t('touch-controller'),
|
label: t('touch-controller'),
|
||||||
note: !STATES.userAgent.capabilities.touch ? '⚠️ ' + t('device-unsupported-touch') : null,
|
|
||||||
unsupported: !STATES.userAgent.capabilities.touch,
|
unsupported: !STATES.userAgent.capabilities.touch,
|
||||||
|
unsupportedNote: !STATES.userAgent.capabilities.touch ? '⚠️ ' + t('device-unsupported-touch') : null,
|
||||||
items: [
|
items: [
|
||||||
PrefKey.STREAM_TOUCH_CONTROLLER,
|
PrefKey.STREAM_TOUCH_CONTROLLER,
|
||||||
PrefKey.STREAM_TOUCH_CONTROLLER_AUTO_OFF,
|
PrefKey.STREAM_TOUCH_CONTROLLER_AUTO_OFF,
|
||||||
@ -247,6 +262,7 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
PrefKey.UI_HIDE_SECTIONS,
|
PrefKey.UI_HIDE_SECTIONS,
|
||||||
],
|
],
|
||||||
}, {
|
}, {
|
||||||
|
requiredVariants: 'full',
|
||||||
group: 'game-bar',
|
group: 'game-bar',
|
||||||
label: t('game-bar'),
|
label: t('game-bar'),
|
||||||
items: [
|
items: [
|
||||||
@ -357,6 +373,7 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
}];
|
}];
|
||||||
|
|
||||||
private readonly TAB_DISPLAY_ITEMS: Array<SettingTabContent | false> = [{
|
private readonly TAB_DISPLAY_ITEMS: Array<SettingTabContent | false> = [{
|
||||||
|
requiredVariants: 'full',
|
||||||
group: 'audio',
|
group: 'audio',
|
||||||
label: t('audio'),
|
label: t('audio'),
|
||||||
helpUrl: 'https://better-xcloud.github.io/ingame-features/#audio',
|
helpUrl: 'https://better-xcloud.github.io/ingame-features/#audio',
|
||||||
@ -390,6 +407,9 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
items: [{
|
items: [{
|
||||||
pref: PrefKey.VIDEO_PLAYER_TYPE,
|
pref: PrefKey.VIDEO_PLAYER_TYPE,
|
||||||
onChange: onChangeVideoPlayerType,
|
onChange: onChangeVideoPlayerType,
|
||||||
|
}, {
|
||||||
|
pref: PrefKey.VIDEO_MAX_FPS,
|
||||||
|
onChange: limitVideoPlayerFps,
|
||||||
}, {
|
}, {
|
||||||
pref: PrefKey.VIDEO_POWER_PREFERENCE,
|
pref: PrefKey.VIDEO_POWER_PREFERENCE,
|
||||||
onChange: () => {
|
onChange: () => {
|
||||||
@ -441,7 +461,7 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
}],
|
}],
|
||||||
},
|
},
|
||||||
|
|
||||||
STATES.userAgent.capabilities.touch && {
|
isFullVersion() && STATES.userAgent.capabilities.touch && {
|
||||||
group: 'touch-control',
|
group: 'touch-control',
|
||||||
label: t('touch-controller'),
|
label: t('touch-controller'),
|
||||||
items: [{
|
items: [{
|
||||||
@ -499,13 +519,14 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
group: 'mkb',
|
group: 'mkb',
|
||||||
label: t('virtual-controller'),
|
label: t('virtual-controller'),
|
||||||
helpUrl: 'https://better-xcloud.github.io/mouse-and-keyboard/',
|
helpUrl: 'https://better-xcloud.github.io/mouse-and-keyboard/',
|
||||||
content: MkbRemapper.INSTANCE.render(),
|
content: isFullVersion() && MkbRemapper.INSTANCE.render(),
|
||||||
}];
|
}];
|
||||||
|
|
||||||
private readonly TAB_NATIVE_MKB_ITEMS: Array<SettingTabContent | false> = [{
|
private readonly TAB_NATIVE_MKB_ITEMS: Array<SettingTabContent | false> = [{
|
||||||
|
requiredVariants: 'full',
|
||||||
group: 'native-mkb',
|
group: 'native-mkb',
|
||||||
label: t('native-mkb'),
|
label: t('native-mkb'),
|
||||||
items: [{
|
items: isFullVersion() ? [{
|
||||||
pref: PrefKey.NATIVE_MKB_SCROLL_VERTICAL_SENSITIVITY,
|
pref: PrefKey.NATIVE_MKB_SCROLL_VERTICAL_SENSITIVITY,
|
||||||
onChange: (e: any, value: number) => {
|
onChange: (e: any, value: number) => {
|
||||||
NativeMkbHandler.getInstance().setVerticalScrollMultiplier(value / 100);
|
NativeMkbHandler.getInstance().setVerticalScrollMultiplier(value / 100);
|
||||||
@ -515,13 +536,14 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
onChange: (e: any, value: number) => {
|
onChange: (e: any, value: number) => {
|
||||||
NativeMkbHandler.getInstance().setHorizontalScrollMultiplier(value / 100);
|
NativeMkbHandler.getInstance().setHorizontalScrollMultiplier(value / 100);
|
||||||
},
|
},
|
||||||
}],
|
}] : [],
|
||||||
}];
|
}];
|
||||||
|
|
||||||
private readonly TAB_SHORTCUTS_ITEMS: Array<SettingTabContent | false> = [{
|
private readonly TAB_SHORTCUTS_ITEMS: Array<SettingTabContent | false> = [{
|
||||||
|
requiredVariants: 'full',
|
||||||
group: 'controller-shortcuts',
|
group: 'controller-shortcuts',
|
||||||
label: t('controller-shortcuts'),
|
label: t('controller-shortcuts'),
|
||||||
content: ControllerShortcut.renderSettings(),
|
content: isFullVersion() && ControllerShortcut.renderSettings(),
|
||||||
}];
|
}];
|
||||||
|
|
||||||
private readonly TAB_STATS_ITEMS: Array<SettingTabContent | false> = [{
|
private readonly TAB_STATS_ITEMS: Array<SettingTabContent | false> = [{
|
||||||
@ -575,24 +597,28 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
icon: BxIcon.CONTROLLER,
|
icon: BxIcon.CONTROLLER,
|
||||||
group: 'controller',
|
group: 'controller',
|
||||||
items: this.TAB_CONTROLLER_ITEMS,
|
items: this.TAB_CONTROLLER_ITEMS,
|
||||||
|
requiredVariants: 'full',
|
||||||
},
|
},
|
||||||
|
|
||||||
getPref(PrefKey.MKB_ENABLED) && {
|
isFullVersion() && getPref(PrefKey.MKB_ENABLED) && {
|
||||||
icon: BxIcon.VIRTUAL_CONTROLLER,
|
icon: BxIcon.VIRTUAL_CONTROLLER,
|
||||||
group: 'mkb',
|
group: 'mkb',
|
||||||
items: this.TAB_VIRTUAL_CONTROLLER_ITEMS,
|
items: this.TAB_VIRTUAL_CONTROLLER_ITEMS,
|
||||||
|
requiredVariants: 'full',
|
||||||
},
|
},
|
||||||
|
|
||||||
AppInterface && getPref(PrefKey.NATIVE_MKB_ENABLED) === 'on' && {
|
isFullVersion() && AppInterface && getPref(PrefKey.NATIVE_MKB_ENABLED) === 'on' && {
|
||||||
icon: BxIcon.NATIVE_MKB,
|
icon: BxIcon.NATIVE_MKB,
|
||||||
group: 'native-mkb',
|
group: 'native-mkb',
|
||||||
items: this.TAB_NATIVE_MKB_ITEMS,
|
items: this.TAB_NATIVE_MKB_ITEMS,
|
||||||
|
requiredVariants: 'full',
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
icon: BxIcon.COMMAND,
|
icon: BxIcon.COMMAND,
|
||||||
group: 'shortcuts',
|
group: 'shortcuts',
|
||||||
items: this.TAB_SHORTCUTS_ITEMS,
|
items: this.TAB_SHORTCUTS_ITEMS,
|
||||||
|
requiredVariants: 'full',
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -715,6 +741,15 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private isSupportedVariant(requiredVariants: BuildVariant | Array<BuildVariant> | undefined) {
|
||||||
|
if (typeof requiredVariants === 'undefined') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
requiredVariants = typeof requiredVariants === 'string' ? [requiredVariants] : requiredVariants;
|
||||||
|
return requiredVariants.includes(SCRIPT_VARIANT);
|
||||||
|
}
|
||||||
|
|
||||||
private async renderSuggestions(e: Event) {
|
private async renderSuggestions(e: Event) {
|
||||||
const $btnSuggest = (e.target as HTMLElement).closest('div')!;
|
const $btnSuggest = (e.target as HTMLElement).closest('div')!;
|
||||||
$btnSuggest.toggleAttribute('bx-open');
|
$btnSuggest.toggleAttribute('bx-open');
|
||||||
@ -966,7 +1001,7 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
|
|
||||||
private onGlobalSettingChanged(e: Event) {
|
private onGlobalSettingChanged(e: Event) {
|
||||||
// Clear PatcherCache;
|
// Clear PatcherCache;
|
||||||
PatcherCache.clear();
|
isFullVersion() && PatcherCache.clear();
|
||||||
|
|
||||||
this.$btnReload.classList.add('bx-danger');
|
this.$btnReload.classList.add('bx-danger');
|
||||||
|
|
||||||
@ -1101,8 +1136,13 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
prefDefinition = getPrefDefinition(pref);
|
prefDefinition = getPrefDefinition(pref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (prefDefinition && !this.isSupportedVariant(prefDefinition.requiredVariants)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let label = prefDefinition?.label || setting.label;
|
let label = prefDefinition?.label || setting.label;
|
||||||
let note = prefDefinition?.note || setting.note;
|
let note = prefDefinition?.note || setting.note;
|
||||||
|
let unsupportedNote = prefDefinition?.unsupportedNote || setting.unsupportedNote;
|
||||||
const experimental = prefDefinition?.experimental || setting.experimental;
|
const experimental = prefDefinition?.experimental || setting.experimental;
|
||||||
|
|
||||||
if (settingTabContent.label && setting.pref) {
|
if (settingTabContent.label && setting.pref) {
|
||||||
@ -1122,7 +1162,15 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let $note;
|
||||||
|
if (unsupportedNote) {
|
||||||
|
$note = CE('div', {class: 'bx-settings-dialog-note'}, unsupportedNote);
|
||||||
|
} else if (note) {
|
||||||
|
$note = CE('div', {class: 'bx-settings-dialog-note'}, note);
|
||||||
|
}
|
||||||
|
|
||||||
let $label;
|
let $label;
|
||||||
|
|
||||||
const $row = CE('label', {
|
const $row = CE('label', {
|
||||||
class: 'bx-settings-row',
|
class: 'bx-settings-row',
|
||||||
for: `bx_setting_${pref}`,
|
for: `bx_setting_${pref}`,
|
||||||
@ -1133,10 +1181,9 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
},
|
},
|
||||||
$label = CE('span', {class: 'bx-settings-label'},
|
$label = CE('span', {class: 'bx-settings-label'},
|
||||||
label,
|
label,
|
||||||
note && CE('div', {class: 'bx-settings-dialog-note'}, note),
|
$note,
|
||||||
setting.unsupported && CE('div', {class: 'bx-settings-dialog-note'}, t('browser-unsupported-feature')),
|
|
||||||
),
|
),
|
||||||
!setting.unsupported && $control,
|
!prefDefinition?.unsupported && $control,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Make link inside <label> focusable
|
// Make link inside <label> focusable
|
||||||
@ -1149,7 +1196,7 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$tabContent.appendChild($row);
|
$tabContent.appendChild($row);
|
||||||
setting.onCreated && setting.onCreated(setting, $control);
|
!prefDefinition?.unsupported && setting.onCreated && setting.onCreated(setting, $control);
|
||||||
}
|
}
|
||||||
|
|
||||||
private setupDialog() {
|
private setupDialog() {
|
||||||
@ -1237,6 +1284,11 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Don't render unsupported build variant
|
||||||
|
if (!this.isSupportedVariant(settingTab.requiredVariants)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Don't render other tabs in unsupported regions
|
// Don't render other tabs in unsupported regions
|
||||||
if (settingTab.group !== 'global' && !this.renderFullSettings) {
|
if (settingTab.group !== 'global' && !this.renderFullSettings) {
|
||||||
continue;
|
continue;
|
||||||
@ -1255,6 +1307,10 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.isSupportedVariant(settingTabContent.requiredVariants)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Don't render other settings in unsupported regions
|
// Don't render other settings in unsupported regions
|
||||||
if (!this.renderFullSettings && settingTab.group === 'global' && settingTabContent.group !== 'general' && settingTabContent.group !== 'footer') {
|
if (!this.renderFullSettings && settingTab.group === 'global' && settingTabContent.group !== 'general' && settingTabContent.group !== 'footer') {
|
||||||
continue;
|
continue;
|
||||||
@ -1265,6 +1321,11 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
// If label is "Better xCloud" => create a link to Releases page
|
// If label is "Better xCloud" => create a link to Releases page
|
||||||
if (label === t('better-xcloud')) {
|
if (label === t('better-xcloud')) {
|
||||||
label += ' ' + SCRIPT_VERSION;
|
label += ' ' + SCRIPT_VERSION;
|
||||||
|
|
||||||
|
if (SCRIPT_VARIANT === 'lite') {
|
||||||
|
label += ' (Lite)';
|
||||||
|
}
|
||||||
|
|
||||||
label = createButton({
|
label = createButton({
|
||||||
label: label,
|
label: label,
|
||||||
url: 'https://github.com/redphx/better-xcloud/releases',
|
url: 'https://github.com/redphx/better-xcloud/releases',
|
||||||
@ -1291,13 +1352,8 @@ export class SettingsNavigationDialog extends NavigationDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add note
|
// Add note
|
||||||
if (settingTabContent.note) {
|
if (settingTabContent.unsupportedNote) {
|
||||||
let $note;
|
const $note = CE('b', {class: 'bx-note-unsupported'}, settingTabContent.unsupportedNote);
|
||||||
if (typeof settingTabContent.note === 'string') {
|
|
||||||
$note = CE('b', {class: 'bx-note-unsupported'}, settingTabContent.note);
|
|
||||||
} else {
|
|
||||||
$note = settingTabContent.note;
|
|
||||||
}
|
|
||||||
|
|
||||||
$tabContent.appendChild($note);
|
$tabContent.appendChild($note);
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,11 @@
|
|||||||
import { BxEvent } from "@/utils/bx-event";
|
import { BxEvent } from "@/utils/bx-event";
|
||||||
import { BxIcon } from "@/utils/bx-icon";
|
import { BxIcon } from "@/utils/bx-icon";
|
||||||
import { CE, createSvgIcon, getReactProps, isElementVisible } from "@/utils/html";
|
import { CE, createSvgIcon, getReactProps, isElementVisible, secondsToHms } from "@/utils/html";
|
||||||
import { XcloudApi } from "@/utils/xcloud-api";
|
import { XcloudApi } from "@/utils/xcloud-api";
|
||||||
|
|
||||||
export class GameTile {
|
export class GameTile {
|
||||||
static #timeout: number | null;
|
static #timeout: number | null;
|
||||||
|
|
||||||
static #secondsToHms(seconds: number) {
|
|
||||||
let h = Math.floor(seconds / 3600);
|
|
||||||
seconds %= 3600;
|
|
||||||
let m = Math.floor(seconds / 60);
|
|
||||||
let s = seconds % 60;
|
|
||||||
|
|
||||||
const output = [];
|
|
||||||
h > 0 && output.push(`${h}h`);
|
|
||||||
m > 0 && output.push(`${m}m`);
|
|
||||||
if (s > 0 || output.length === 0) {
|
|
||||||
output.push(`${s}s`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return output.join(' ');
|
|
||||||
}
|
|
||||||
|
|
||||||
static async #showWaitTime($elm: HTMLElement, productId: string) {
|
static async #showWaitTime($elm: HTMLElement, productId: string) {
|
||||||
if (($elm as any).hasWaitTime) {
|
if (($elm as any).hasWaitTime) {
|
||||||
return;
|
return;
|
||||||
@ -42,7 +26,7 @@ export class GameTile {
|
|||||||
if (typeof totalWaitTime === 'number' && isElementVisible($elm)) {
|
if (typeof totalWaitTime === 'number' && isElementVisible($elm)) {
|
||||||
const $div = CE('div', {'class': 'bx-game-tile-wait-time'},
|
const $div = CE('div', {'class': 'bx-game-tile-wait-time'},
|
||||||
createSvgIcon(BxIcon.PLAYTIME),
|
createSvgIcon(BxIcon.PLAYTIME),
|
||||||
CE('span', {}, GameTile.#secondsToHms(totalWaitTime)),
|
CE('span', {}, secondsToHms(totalWaitTime)),
|
||||||
);
|
);
|
||||||
$elm.insertAdjacentElement('afterbegin', $div);
|
$elm.insertAdjacentElement('afterbegin', $div);
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { isFullVersion } from "@macros/build" with {type: "macro"};
|
||||||
|
|
||||||
import { BxEvent } from "@/utils/bx-event";
|
import { BxEvent } from "@/utils/bx-event";
|
||||||
import { AppInterface, STATES } from "@/utils/global";
|
import { AppInterface, STATES } from "@/utils/global";
|
||||||
import { createButton, ButtonStyle, CE } from "@/utils/html";
|
import { createButton, ButtonStyle, CE } from "@/utils/html";
|
||||||
@ -22,7 +24,7 @@ export class GuideMenu {
|
|||||||
}, {once: true});
|
}, {once: true});
|
||||||
|
|
||||||
// Close all xCloud's dialogs
|
// Close all xCloud's dialogs
|
||||||
window.BX_EXPOSED.dialogRoutes.closeAll();
|
GuideMenu.#closeGuideMenu();
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
@ -53,7 +55,7 @@ export class GuideMenu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Close all xCloud's dialogs
|
// Close all xCloud's dialogs
|
||||||
window.BX_EXPOSED.dialogRoutes.closeAll();
|
GuideMenu.#closeGuideMenu();
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
@ -66,7 +68,7 @@ export class GuideMenu {
|
|||||||
confirm(t('back-to-home-confirm')) && (window.location.href = window.location.href.substring(0, 31));
|
confirm(t('back-to-home-confirm')) && (window.location.href = window.location.href.substring(0, 31));
|
||||||
|
|
||||||
// Close all xCloud's dialogs
|
// Close all xCloud's dialogs
|
||||||
window.BX_EXPOSED.dialogRoutes.closeAll();
|
GuideMenu.#closeGuideMenu();
|
||||||
},
|
},
|
||||||
attributes: {
|
attributes: {
|
||||||
'data-state': 'playing',
|
'data-state': 'playing',
|
||||||
@ -76,6 +78,17 @@ export class GuideMenu {
|
|||||||
|
|
||||||
static #$renderedButtons: HTMLElement;
|
static #$renderedButtons: HTMLElement;
|
||||||
|
|
||||||
|
static #closeGuideMenu() {
|
||||||
|
if (window.BX_EXPOSED.dialogRoutes) {
|
||||||
|
window.BX_EXPOSED.dialogRoutes.closeAll();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use alternative method for Lite version
|
||||||
|
const $btnClose = document.querySelector('#gamepass-dialog-root button[class^=Header-module__closeButton]') as HTMLElement;
|
||||||
|
$btnClose && $btnClose.click();
|
||||||
|
}
|
||||||
|
|
||||||
static #renderButtons() {
|
static #renderButtons() {
|
||||||
if (GuideMenu.#$renderedButtons) {
|
if (GuideMenu.#$renderedButtons) {
|
||||||
return GuideMenu.#$renderedButtons;
|
return GuideMenu.#$renderedButtons;
|
||||||
@ -115,9 +128,11 @@ export class GuideMenu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static #injectHome($root: HTMLElement, isPlaying = false) {
|
static #injectHome($root: HTMLElement, isPlaying = false) {
|
||||||
const $achievementsProgress = $root.querySelector('button[class*=AchievementsButton-module__progressBarContainer]');
|
if (isFullVersion()) {
|
||||||
if ($achievementsProgress) {
|
const $achievementsProgress = $root.querySelector('button[class*=AchievementsButton-module__progressBarContainer]');
|
||||||
TrueAchievements.injectAchievementsProgress($achievementsProgress as HTMLElement);
|
if ($achievementsProgress) {
|
||||||
|
TrueAchievements.injectAchievementsProgress($achievementsProgress as HTMLElement);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the element to add buttons to
|
// Find the element to add buttons to
|
||||||
@ -162,7 +177,7 @@ export class GuideMenu {
|
|||||||
static observe($addedElm: HTMLElement) {
|
static observe($addedElm: HTMLElement) {
|
||||||
const className = $addedElm.className;
|
const className = $addedElm.className;
|
||||||
|
|
||||||
if (className.includes('AchievementsButton-module__progressBarContainer')) {
|
if (isFullVersion() && className.includes('AchievementsButton-module__progressBarContainer')) {
|
||||||
TrueAchievements.injectAchievementsProgress($addedElm);
|
TrueAchievements.injectAchievementsProgress($addedElm);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -174,10 +189,12 @@ export class GuideMenu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Achievement Details page
|
// Achievement Details page
|
||||||
const $achievDetailPage = $addedElm.querySelector('div[class*=AchievementDetailPage]');
|
if (isFullVersion()) {
|
||||||
if ($achievDetailPage) {
|
const $achievDetailPage = $addedElm.querySelector('div[class*=AchievementDetailPage]');
|
||||||
TrueAchievements.injectAchievementDetailPage($achievDetailPage as HTMLElement);
|
if ($achievDetailPage) {
|
||||||
return;
|
TrueAchievements.injectAchievementDetailPage($achievDetailPage as HTMLElement);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find navigation bar
|
// Find navigation bar
|
||||||
|
@ -63,7 +63,7 @@ export class HeaderSection {
|
|||||||
static checkHeader() {
|
static checkHeader() {
|
||||||
let $target = document.querySelector('#PageContent div[class*=EdgewaterHeader-module__rightSectionSpacing]');
|
let $target = document.querySelector('#PageContent div[class*=EdgewaterHeader-module__rightSectionSpacing]');
|
||||||
if (!$target) {
|
if (!$target) {
|
||||||
$target = document.querySelector("div[class^=UnsupportedMarketPage-module__buttons]");
|
$target = document.querySelector('div[class^=UnsupportedMarketPage-module__buttons]');
|
||||||
}
|
}
|
||||||
|
|
||||||
$target && HeaderSection.#injectSettingsButton($target as HTMLElement);
|
$target && HeaderSection.#injectSettingsButton($target as HTMLElement);
|
||||||
|
5
src/types/index.d.ts
vendored
5
src/types/index.d.ts
vendored
@ -1,7 +1,9 @@
|
|||||||
|
type BuildVariant = 'full' | 'lite';
|
||||||
|
|
||||||
// Get type of an array's element
|
// Get type of an array's element
|
||||||
type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType extends readonly (infer ElementType)[] ? ElementType : never;
|
type ArrayElement<ArrayType extends readonly unknown[]> = ArrayType extends readonly (infer ElementType)[] ? ElementType : never;
|
||||||
|
|
||||||
type PartialRecord<K extends keyof any, T> = Partial<Record<K, T>>
|
type PartialRecord<K extends keyof any, T> = Partial<Record<K, T>>;
|
||||||
|
|
||||||
interface Window {
|
interface Window {
|
||||||
AppInterface: any;
|
AppInterface: any;
|
||||||
@ -44,6 +46,7 @@ type BxStates = {
|
|||||||
isTv: boolean;
|
isTv: boolean;
|
||||||
capabilities: {
|
capabilities: {
|
||||||
touch: boolean;
|
touch: boolean;
|
||||||
|
mkb: boolean;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
3
src/types/preferences.d.ts
vendored
3
src/types/preferences.d.ts
vendored
@ -3,7 +3,8 @@ export type PreferenceSetting = {
|
|||||||
optionsGroup?: string;
|
optionsGroup?: string;
|
||||||
options?: {[index: string]: string};
|
options?: {[index: string]: string};
|
||||||
multipleOptions?: {[index: string]: string};
|
multipleOptions?: {[index: string]: string};
|
||||||
unsupported?: string | boolean;
|
unsupported?: boolean;
|
||||||
|
unsupported_note?: string | HTMLElement;
|
||||||
note?: string | HTMLElement;
|
note?: string | HTMLElement;
|
||||||
type?: SettingElementType;
|
type?: SettingElementType;
|
||||||
ready?: (setting: PreferenceSetting) => void;
|
ready?: (setting: PreferenceSetting) => void;
|
||||||
|
4
src/types/setting-definition.d.ts
vendored
4
src/types/setting-definition.d.ts
vendored
@ -20,10 +20,12 @@ export type SettingDefinition = {
|
|||||||
label: string;
|
label: string;
|
||||||
note: string | HTMLElement;
|
note: string | HTMLElement;
|
||||||
experimental: boolean;
|
experimental: boolean;
|
||||||
unsupported: string | boolean;
|
unsupported: boolean;
|
||||||
|
unsupportedNote: string | HTMLElement;
|
||||||
suggest: PartialRecord<SuggestedSettingCategory, any>,
|
suggest: PartialRecord<SuggestedSettingCategory, any>,
|
||||||
ready: (setting: SettingDefinition) => void;
|
ready: (setting: SettingDefinition) => void;
|
||||||
type: SettingElementType,
|
type: SettingElementType,
|
||||||
|
requiredVariants: BuildVariant | Array<BuildVariant>;
|
||||||
// migrate?: (this: Preferences, savedPrefs: any, value: any) => void;
|
// migrate?: (this: Preferences, savedPrefs: any, value: any) => void;
|
||||||
}> & (
|
}> & (
|
||||||
{} | {
|
{} | {
|
||||||
|
2
src/types/stream-stats.d.ts
vendored
2
src/types/stream-stats.d.ts
vendored
@ -3,6 +3,8 @@ type RTCBasicStat = {
|
|||||||
bytesReceived: number,
|
bytesReceived: number,
|
||||||
clockRate: number,
|
clockRate: number,
|
||||||
codecId: string,
|
codecId: string,
|
||||||
|
frameWidth: number,
|
||||||
|
frameHeight: number,
|
||||||
framesDecoded: number,
|
framesDecoded: number,
|
||||||
id: string,
|
id: string,
|
||||||
kind: string,
|
kind: string,
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { isFullVersion } from "@macros/build" with {type: "macro"};
|
||||||
|
|
||||||
import { ControllerShortcut } from "@/modules/controller-shortcut";
|
import { ControllerShortcut } from "@/modules/controller-shortcut";
|
||||||
import { BxEvent } from "@utils/bx-event";
|
import { BxEvent } from "@utils/bx-event";
|
||||||
import { deepClone, STATES } from "@utils/global";
|
import { deepClone, STATES } from "@utils/global";
|
||||||
@ -20,7 +22,7 @@ export type SupportedInputTypeValue = (typeof SupportedInputType)[keyof typeof S
|
|||||||
export const BxExposed = {
|
export const BxExposed = {
|
||||||
getTitleInfo: () => STATES.currentStream.titleInfo,
|
getTitleInfo: () => STATES.currentStream.titleInfo,
|
||||||
|
|
||||||
modifyTitleInfo: (titleInfo: XcloudTitleInfo): XcloudTitleInfo => {
|
modifyTitleInfo: isFullVersion() && function(titleInfo: XcloudTitleInfo): XcloudTitleInfo {
|
||||||
// Clone the object since the original is read-only
|
// Clone the object since the original is read-only
|
||||||
titleInfo = deepClone(titleInfo);
|
titleInfo = deepClone(titleInfo);
|
||||||
|
|
||||||
@ -110,8 +112,8 @@ export const BxExposed = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
handleControllerShortcut: ControllerShortcut.handle,
|
handleControllerShortcut: isFullVersion() && ControllerShortcut.handle,
|
||||||
resetControllerShortcut: ControllerShortcut.reset,
|
resetControllerShortcut: isFullVersion() && ControllerShortcut.reset,
|
||||||
|
|
||||||
overrideSettings: {
|
overrideSettings: {
|
||||||
'Tv_settings': {
|
'Tv_settings': {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { EmulatedMkbHandler } from "@modules/mkb/mkb-handler";
|
import { VIRTUAL_GAMEPAD_ID } from "@modules/mkb/mkb-handler";
|
||||||
import { t } from "@utils/translation";
|
import { t } from "@utils/translation";
|
||||||
import { Toast } from "@utils/toast";
|
import { Toast } from "@utils/toast";
|
||||||
import { BxLogger } from "@utils/bx-logger";
|
import { BxLogger } from "@utils/bx-logger";
|
||||||
@ -8,7 +8,7 @@ import { getPref } from "./settings-storages/global-settings-storage";
|
|||||||
// Show a toast when connecting/disconecting controller
|
// Show a toast when connecting/disconecting controller
|
||||||
export function showGamepadToast(gamepad: Gamepad) {
|
export function showGamepadToast(gamepad: Gamepad) {
|
||||||
// Don't show Toast for virtual controller
|
// Don't show Toast for virtual controller
|
||||||
if (gamepad.id === EmulatedMkbHandler.VIRTUAL_GAMEPAD_ID) {
|
if (gamepad.id === VIRTUAL_GAMEPAD_ID) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ import type { BaseSettingsStore } from "./settings-storages/base-settings-storag
|
|||||||
import { UserAgent } from "./user-agent";
|
import { UserAgent } from "./user-agent";
|
||||||
|
|
||||||
export const SCRIPT_VERSION = Bun.env.SCRIPT_VERSION!;
|
export const SCRIPT_VERSION = Bun.env.SCRIPT_VERSION!;
|
||||||
|
export const SCRIPT_VARIANT = Bun.env.BUILD_VARIANT! as BuildVariant;
|
||||||
|
|
||||||
export const AppInterface = window.AppInterface;
|
export const AppInterface = window.AppInterface;
|
||||||
|
|
||||||
@ -12,6 +13,7 @@ const isTv = userAgent.includes('smart-tv') || userAgent.includes('smarttv') ||
|
|||||||
const isVr = window.navigator.userAgent.includes('VR') && window.navigator.userAgent.includes('OculusBrowser');
|
const isVr = window.navigator.userAgent.includes('VR') && window.navigator.userAgent.includes('OculusBrowser');
|
||||||
const browserHasTouchSupport = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
|
const browserHasTouchSupport = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
|
||||||
const userAgentHasTouchSupport = !isTv && !isVr && browserHasTouchSupport;
|
const userAgentHasTouchSupport = !isTv && !isVr && browserHasTouchSupport;
|
||||||
|
const supportMkb = AppInterface || !userAgent.match(/(android|iphone|ipad)/);
|
||||||
|
|
||||||
export const STATES: BxStates = {
|
export const STATES: BxStates = {
|
||||||
supportedRegion: true,
|
supportedRegion: true,
|
||||||
@ -34,6 +36,7 @@ export const STATES: BxStates = {
|
|||||||
isTv: isTv,
|
isTv: isTv,
|
||||||
capabilities: {
|
capabilities: {
|
||||||
touch: userAgentHasTouchSupport,
|
touch: userAgentHasTouchSupport,
|
||||||
|
mkb: supportMkb,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -181,9 +181,47 @@ export function clearFocus() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function clearDataSet($elm: HTMLElement) {
|
export function clearDataSet($elm: HTMLElement) {
|
||||||
Object.keys($elm.dataset).forEach(key => {
|
Object.keys($elm.dataset).forEach(key => {
|
||||||
delete $elm.dataset[key];
|
delete $elm.dataset[key];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://stackoverflow.com/a/20732091
|
||||||
|
const FILE_SIZE_UNITS = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||||
|
export function humanFileSize(size: number) {
|
||||||
|
const i = size == 0 ? 0 : Math.floor(Math.log(size) / Math.log(1024));
|
||||||
|
return (size / Math.pow(1024, i)).toFixed(2) + ' ' + FILE_SIZE_UNITS[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function secondsToHm(seconds: number) {
|
||||||
|
let h = Math.floor(seconds / 3600);
|
||||||
|
let m = Math.floor(seconds % 3600 / 60) + 1;
|
||||||
|
|
||||||
|
if (m === 60) {
|
||||||
|
h += 1;
|
||||||
|
m = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const output = [];
|
||||||
|
h > 0 && output.push(`${h}h`);
|
||||||
|
m > 0 && output.push(`${m}m`);
|
||||||
|
|
||||||
|
return output.join(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
export function secondsToHms(seconds: number) {
|
||||||
|
let h = Math.floor(seconds / 3600);
|
||||||
|
seconds %= 3600;
|
||||||
|
let m = Math.floor(seconds / 60);
|
||||||
|
let s = seconds % 60;
|
||||||
|
|
||||||
|
const output = [];
|
||||||
|
h > 0 && output.push(`${h}h`);
|
||||||
|
m > 0 && output.push(`${m}m`);
|
||||||
|
if (s > 0 || output.length === 0) {
|
||||||
|
output.push(`${s}s`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return output.join(' ');
|
||||||
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { isFullVersion } from "@macros/build" with {type: "macro"};
|
||||||
|
|
||||||
import { BxEvent } from "@utils/bx-event";
|
import { BxEvent } from "@utils/bx-event";
|
||||||
import { BX_FLAGS, NATIVE_FETCH } from "@utils/bx-flags";
|
import { BX_FLAGS, NATIVE_FETCH } from "@utils/bx-flags";
|
||||||
import { TouchController } from "@modules/touch-controller";
|
import { TouchController } from "@modules/touch-controller";
|
||||||
@ -222,7 +224,7 @@ export function interceptHttpRequests() {
|
|||||||
for (let i = 1; i < obj.length; i++) {
|
for (let i = 1; i < obj.length; i++) {
|
||||||
gamepassAllGames.push(obj[i].id);
|
gamepassAllGames.push(obj[i].id);
|
||||||
}
|
}
|
||||||
} else if (url.includes(GamePassCloudGallery.TOUCH)) {
|
} else if (isFullVersion() && url.includes(GamePassCloudGallery.TOUCH)) {
|
||||||
try {
|
try {
|
||||||
let customList = TouchController.getCustomList();
|
let customList = TouchController.getCustomList();
|
||||||
|
|
||||||
@ -262,7 +264,7 @@ export function interceptHttpRequests() {
|
|||||||
requestType = 'xcloud';
|
requestType = 'xcloud';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requestType === 'xhome') {
|
if (isFullVersion() && requestType === 'xhome') {
|
||||||
return XhomeInterceptor.handle(request as Request);
|
return XhomeInterceptor.handle(request as Request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ export class Screenshot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static updateCanvasFilters(filters: string) {
|
static updateCanvasFilters(filters: string) {
|
||||||
Screenshot.#canvasContext.filter = filters;
|
Screenshot.#canvasContext && (Screenshot.#canvasContext.filter = filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
static #onAnimationEnd(e: Event) {
|
static #onAnimationEnd(e: Event) {
|
||||||
|
@ -3,6 +3,7 @@ import type { NumberStepperParams, SettingDefinitions } from "@/types/setting-de
|
|||||||
import { BxEvent } from "../bx-event";
|
import { BxEvent } from "../bx-event";
|
||||||
import { SettingElementType } from "../setting-element";
|
import { SettingElementType } from "../setting-element";
|
||||||
import { t } from "../translation";
|
import { t } from "../translation";
|
||||||
|
import { SCRIPT_VARIANT } from "../global";
|
||||||
|
|
||||||
export class BaseSettingsStore {
|
export class BaseSettingsStore {
|
||||||
private storage: Storage;
|
private storage: Storage;
|
||||||
@ -18,6 +19,11 @@ export class BaseSettingsStore {
|
|||||||
for (settingId in definitions) {
|
for (settingId in definitions) {
|
||||||
const setting = definitions[settingId];
|
const setting = definitions[settingId];
|
||||||
|
|
||||||
|
// Convert requiredVariants to array
|
||||||
|
if (typeof setting.requiredVariants === 'string') {
|
||||||
|
setting.requiredVariants = [setting.requiredVariants];
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (setting.migrate && settingId in savedPrefs) {
|
if (setting.migrate && settingId in savedPrefs) {
|
||||||
setting.migrate.call(this, savedPrefs, savedPrefs[settingId]);
|
setting.migrate.call(this, savedPrefs, savedPrefs[settingId]);
|
||||||
@ -58,9 +64,16 @@ export class BaseSettingsStore {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const definition = this.definitions[key];
|
||||||
|
|
||||||
|
// Return default value if build variant is different
|
||||||
|
if (definition.requiredVariants && !definition.requiredVariants.includes(SCRIPT_VARIANT)) {
|
||||||
|
return definition.default;
|
||||||
|
}
|
||||||
|
|
||||||
// Return default value if the feature is not supported
|
// Return default value if the feature is not supported
|
||||||
if (checkUnsupported && this.definitions[key].unsupported) {
|
if (checkUnsupported && definition.unsupported) {
|
||||||
return this.definitions[key].default;
|
return definition.default;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(key in this.settings)) {
|
if (!(key in this.settings)) {
|
||||||
|
@ -3,7 +3,6 @@ import { PrefKey, StorageKey } from "@/enums/pref-keys";
|
|||||||
import { StreamPlayerType, StreamVideoProcessing } from "@/enums/stream-player";
|
import { StreamPlayerType, StreamVideoProcessing } from "@/enums/stream-player";
|
||||||
import { UiSection } from "@/enums/ui-sections";
|
import { UiSection } from "@/enums/ui-sections";
|
||||||
import { UserAgentProfile } from "@/enums/user-agent";
|
import { UserAgentProfile } from "@/enums/user-agent";
|
||||||
import { StreamStat } from "@/modules/stream/stream-stats";
|
|
||||||
import { type SettingDefinition, type SettingDefinitions } from "@/types/setting-definition";
|
import { type SettingDefinition, type SettingDefinitions } from "@/types/setting-definition";
|
||||||
import { BX_FLAGS } from "../bx-flags";
|
import { BX_FLAGS } from "../bx-flags";
|
||||||
import { STATES, AppInterface, STORAGE } from "../global";
|
import { STATES, AppInterface, STORAGE } from "../global";
|
||||||
@ -12,6 +11,7 @@ import { t, SUPPORTED_LANGUAGES } from "../translation";
|
|||||||
import { UserAgent } from "../user-agent";
|
import { UserAgent } from "../user-agent";
|
||||||
import { BaseSettingsStore as BaseSettingsStorage } from "./base-settings-storage";
|
import { BaseSettingsStore as BaseSettingsStorage } from "./base-settings-storage";
|
||||||
import { SettingElementType } from "../setting-element";
|
import { SettingElementType } from "../setting-element";
|
||||||
|
import { StreamStat } from "../stream-stats-collector";
|
||||||
|
|
||||||
|
|
||||||
export const enum StreamResolution {
|
export const enum StreamResolution {
|
||||||
@ -96,7 +96,7 @@ function getSupportedCodecProfiles() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class GlobalSettingsStorage extends BaseSettingsStorage {
|
export class GlobalSettingsStorage extends BaseSettingsStorage {
|
||||||
private static readonly DEFINITIONS: SettingDefinitions = {
|
private static readonly DEFINITIONS = {
|
||||||
[PrefKey.LAST_UPDATE_CHECK]: {
|
[PrefKey.LAST_UPDATE_CHECK]: {
|
||||||
default: 0,
|
default: 0,
|
||||||
},
|
},
|
||||||
@ -182,7 +182,7 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
|
|
||||||
if (keys.length <= 1) { // Unsupported
|
if (keys.length <= 1) { // Unsupported
|
||||||
setting.unsupported = true;
|
setting.unsupported = true;
|
||||||
setting.note = '⚠️ ' + t('browser-unsupported-feature');
|
setting.unsupportedNote = '⚠️ ' + t('browser-unsupported-feature');
|
||||||
}
|
}
|
||||||
|
|
||||||
setting.suggest = {
|
setting.suggest = {
|
||||||
@ -197,6 +197,7 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.SCREENSHOT_APPLY_FILTERS]: {
|
[PrefKey.SCREENSHOT_APPLY_FILTERS]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
label: t('screenshot-apply-filters'),
|
label: t('screenshot-apply-filters'),
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
@ -211,6 +212,8 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.STREAM_COMBINE_SOURCES]: {
|
[PrefKey.STREAM_COMBINE_SOURCES]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
|
|
||||||
label: t('combine-audio-video-streams'),
|
label: t('combine-audio-video-streams'),
|
||||||
default: false,
|
default: false,
|
||||||
experimental: true,
|
experimental: true,
|
||||||
@ -218,6 +221,7 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.STREAM_TOUCH_CONTROLLER]: {
|
[PrefKey.STREAM_TOUCH_CONTROLLER]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
label: t('tc-availability'),
|
label: t('tc-availability'),
|
||||||
default: StreamTouchController.ALL,
|
default: StreamTouchController.ALL,
|
||||||
options: {
|
options: {
|
||||||
@ -233,11 +237,13 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
[PrefKey.STREAM_TOUCH_CONTROLLER_AUTO_OFF]: {
|
[PrefKey.STREAM_TOUCH_CONTROLLER_AUTO_OFF]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
label: t('tc-auto-off'),
|
label: t('tc-auto-off'),
|
||||||
default: false,
|
default: false,
|
||||||
unsupported: !STATES.userAgent.capabilities.touch,
|
unsupported: !STATES.userAgent.capabilities.touch,
|
||||||
},
|
},
|
||||||
[PrefKey.STREAM_TOUCH_CONTROLLER_DEFAULT_OPACITY]: {
|
[PrefKey.STREAM_TOUCH_CONTROLLER_DEFAULT_OPACITY]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
type: SettingElementType.NUMBER_STEPPER,
|
type: SettingElementType.NUMBER_STEPPER,
|
||||||
label: t('tc-default-opacity'),
|
label: t('tc-default-opacity'),
|
||||||
default: 100,
|
default: 100,
|
||||||
@ -252,6 +258,7 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
unsupported: !STATES.userAgent.capabilities.touch,
|
unsupported: !STATES.userAgent.capabilities.touch,
|
||||||
},
|
},
|
||||||
[PrefKey.STREAM_TOUCH_CONTROLLER_STYLE_STANDARD]: {
|
[PrefKey.STREAM_TOUCH_CONTROLLER_STYLE_STANDARD]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
label: t('tc-standard-layout-style'),
|
label: t('tc-standard-layout-style'),
|
||||||
default: 'default',
|
default: 'default',
|
||||||
options: {
|
options: {
|
||||||
@ -262,6 +269,7 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
unsupported: !STATES.userAgent.capabilities.touch,
|
unsupported: !STATES.userAgent.capabilities.touch,
|
||||||
},
|
},
|
||||||
[PrefKey.STREAM_TOUCH_CONTROLLER_STYLE_CUSTOM]: {
|
[PrefKey.STREAM_TOUCH_CONTROLLER_STYLE_CUSTOM]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
label: t('tc-custom-layout-style'),
|
label: t('tc-custom-layout-style'),
|
||||||
default: 'default',
|
default: 'default',
|
||||||
options: {
|
options: {
|
||||||
@ -276,15 +284,18 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
[PrefKey.MKB_HIDE_IDLE_CURSOR]: {
|
[PrefKey.MKB_HIDE_IDLE_CURSOR]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
label: t('hide-idle-cursor'),
|
label: t('hide-idle-cursor'),
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
[PrefKey.STREAM_DISABLE_FEEDBACK_DIALOG]: {
|
[PrefKey.STREAM_DISABLE_FEEDBACK_DIALOG]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
label: t('disable-post-stream-feedback-dialog'),
|
label: t('disable-post-stream-feedback-dialog'),
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.BITRATE_VIDEO_MAX]: {
|
[PrefKey.BITRATE_VIDEO_MAX]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
type: SettingElementType.NUMBER_STEPPER,
|
type: SettingElementType.NUMBER_STEPPER,
|
||||||
label: t('bitrate-video-maximum'),
|
label: t('bitrate-video-maximum'),
|
||||||
note: '⚠️ ' + t('unexpected-behavior'),
|
note: '⚠️ ' + t('unexpected-behavior'),
|
||||||
@ -306,10 +317,11 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
},
|
},
|
||||||
suggest: {
|
suggest: {
|
||||||
highest: 0,
|
highest: 0,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.GAME_BAR_POSITION]: {
|
[PrefKey.GAME_BAR_POSITION]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
label: t('position'),
|
label: t('position'),
|
||||||
default: 'bottom-left',
|
default: 'bottom-left',
|
||||||
options: {
|
options: {
|
||||||
@ -320,6 +332,7 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.LOCAL_CO_OP_ENABLED]: {
|
[PrefKey.LOCAL_CO_OP_ENABLED]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
label: t('enable-local-co-op-support'),
|
label: t('enable-local-co-op-support'),
|
||||||
default: false,
|
default: false,
|
||||||
note: CE<HTMLAnchorElement>('a', {
|
note: CE<HTMLAnchorElement>('a', {
|
||||||
@ -341,15 +354,18 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.CONTROLLER_ENABLE_SHORTCUTS]: {
|
[PrefKey.CONTROLLER_ENABLE_SHORTCUTS]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.CONTROLLER_ENABLE_VIBRATION]: {
|
[PrefKey.CONTROLLER_ENABLE_VIBRATION]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
label: t('controller-vibration'),
|
label: t('controller-vibration'),
|
||||||
default: true,
|
default: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.CONTROLLER_DEVICE_VIBRATION]: {
|
[PrefKey.CONTROLLER_DEVICE_VIBRATION]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
label: t('device-vibration'),
|
label: t('device-vibration'),
|
||||||
default: ControllerDeviceVibration.OFF,
|
default: ControllerDeviceVibration.OFF,
|
||||||
options: {
|
options: {
|
||||||
@ -360,6 +376,7 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.CONTROLLER_VIBRATION_INTENSITY]: {
|
[PrefKey.CONTROLLER_VIBRATION_INTENSITY]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
label: t('vibration-intensity'),
|
label: t('vibration-intensity'),
|
||||||
type: SettingElementType.NUMBER_STEPPER,
|
type: SettingElementType.NUMBER_STEPPER,
|
||||||
default: 100,
|
default: 100,
|
||||||
@ -373,12 +390,10 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.MKB_ENABLED]: {
|
[PrefKey.MKB_ENABLED]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
label: t('enable-mkb'),
|
label: t('enable-mkb'),
|
||||||
default: false,
|
default: false,
|
||||||
unsupported: ((): string | boolean => {
|
unsupported: !STATES.userAgent.capabilities.mkb,
|
||||||
const userAgent = ((window.navigator as any).orgUserAgent || window.navigator.userAgent || '').toLowerCase();
|
|
||||||
return !AppInterface && userAgent.match(/(android|iphone|ipad)/) ? t('browser-unsupported-feature') : false;
|
|
||||||
})(),
|
|
||||||
ready: (setting: SettingDefinition) => {
|
ready: (setting: SettingDefinition) => {
|
||||||
let note;
|
let note;
|
||||||
let url;
|
let url;
|
||||||
@ -390,7 +405,7 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
url = 'https://better-xcloud.github.io/mouse-and-keyboard/#disclaimer';
|
url = 'https://better-xcloud.github.io/mouse-and-keyboard/#disclaimer';
|
||||||
}
|
}
|
||||||
|
|
||||||
setting.note = CE('a', {
|
setting.unsupportedNote = CE('a', {
|
||||||
href: url,
|
href: url,
|
||||||
target: '_blank',
|
target: '_blank',
|
||||||
}, '⚠️ ' + note);
|
}, '⚠️ ' + note);
|
||||||
@ -398,6 +413,7 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.NATIVE_MKB_ENABLED]: {
|
[PrefKey.NATIVE_MKB_ENABLED]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
label: t('native-mkb'),
|
label: t('native-mkb'),
|
||||||
default: 'default',
|
default: 'default',
|
||||||
options: {
|
options: {
|
||||||
@ -419,6 +435,7 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.NATIVE_MKB_SCROLL_HORIZONTAL_SENSITIVITY]: {
|
[PrefKey.NATIVE_MKB_SCROLL_HORIZONTAL_SENSITIVITY]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
label: t('horizontal-scroll-sensitivity'),
|
label: t('horizontal-scroll-sensitivity'),
|
||||||
type: SettingElementType.NUMBER_STEPPER,
|
type: SettingElementType.NUMBER_STEPPER,
|
||||||
default: 0,
|
default: 0,
|
||||||
@ -438,6 +455,7 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.NATIVE_MKB_SCROLL_VERTICAL_SENSITIVITY]: {
|
[PrefKey.NATIVE_MKB_SCROLL_VERTICAL_SENSITIVITY]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
label: t('vertical-scroll-sensitivity'),
|
label: t('vertical-scroll-sensitivity'),
|
||||||
type: SettingElementType.NUMBER_STEPPER,
|
type: SettingElementType.NUMBER_STEPPER,
|
||||||
default: 0,
|
default: 0,
|
||||||
@ -457,10 +475,12 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.MKB_DEFAULT_PRESET_ID]: {
|
[PrefKey.MKB_DEFAULT_PRESET_ID]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
default: 0,
|
default: 0,
|
||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.MKB_ABSOLUTE_MOUSE]: {
|
[PrefKey.MKB_ABSOLUTE_MOUSE]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -470,6 +490,7 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.UI_LOADING_SCREEN_GAME_ART]: {
|
[PrefKey.UI_LOADING_SCREEN_GAME_ART]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
label: t('show-game-art'),
|
label: t('show-game-art'),
|
||||||
default: true,
|
default: true,
|
||||||
},
|
},
|
||||||
@ -493,6 +514,7 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.UI_LAYOUT]: {
|
[PrefKey.UI_LAYOUT]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
label: t('layout'),
|
label: t('layout'),
|
||||||
default: 'default',
|
default: 'default',
|
||||||
options: {
|
options: {
|
||||||
@ -508,11 +530,13 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.UI_HOME_CONTEXT_MENU_DISABLED]: {
|
[PrefKey.UI_HOME_CONTEXT_MENU_DISABLED]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
label: t('disable-home-context-menu'),
|
label: t('disable-home-context-menu'),
|
||||||
default: STATES.browser.capabilities.touch,
|
default: STATES.browser.capabilities.touch,
|
||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.UI_HIDE_SECTIONS]: {
|
[PrefKey.UI_HIDE_SECTIONS]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
label: t('hide-sections'),
|
label: t('hide-sections'),
|
||||||
default: [],
|
default: [],
|
||||||
multipleOptions: {
|
multipleOptions: {
|
||||||
@ -529,6 +553,7 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.UI_GAME_CARD_SHOW_WAIT_TIME]: {
|
[PrefKey.UI_GAME_CARD_SHOW_WAIT_TIME]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
label: t('show-wait-time-in-game-card'),
|
label: t('show-wait-time-in-game-card'),
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
@ -591,6 +616,21 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
highest: 'low-power',
|
highest: 'low-power',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
[PrefKey.VIDEO_MAX_FPS]: {
|
||||||
|
label: t('max-fps'),
|
||||||
|
type: SettingElementType.NUMBER_STEPPER,
|
||||||
|
default: 60,
|
||||||
|
min: 10,
|
||||||
|
max: 60,
|
||||||
|
steps: 10,
|
||||||
|
params: {
|
||||||
|
exactTicks: 10,
|
||||||
|
customTextValue: (value: any) => {
|
||||||
|
value = parseInt(value);
|
||||||
|
return value === 60 ? t('unlimited') : value + 'fps';
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
[PrefKey.VIDEO_SHARPNESS]: {
|
[PrefKey.VIDEO_SHARPNESS]: {
|
||||||
label: t('sharpness'),
|
label: t('sharpness'),
|
||||||
type: SettingElementType.NUMBER_STEPPER,
|
type: SettingElementType.NUMBER_STEPPER,
|
||||||
@ -606,7 +646,7 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
},
|
},
|
||||||
suggest: {
|
suggest: {
|
||||||
lowest: 0,
|
lowest: 0,
|
||||||
highest: 4,
|
highest: 2,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
[PrefKey.VIDEO_RATIO]: {
|
[PrefKey.VIDEO_RATIO]: {
|
||||||
@ -663,6 +703,7 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
[PrefKey.AUDIO_ENABLE_VOLUME_CONTROL]: {
|
[PrefKey.AUDIO_ENABLE_VOLUME_CONTROL]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
label: t('enable-volume-control'),
|
label: t('enable-volume-control'),
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
@ -684,16 +725,29 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
label: t('stats'),
|
label: t('stats'),
|
||||||
default: [StreamStat.PING, StreamStat.FPS, StreamStat.BITRATE, StreamStat.DECODE_TIME, StreamStat.PACKETS_LOST, StreamStat.FRAMES_LOST],
|
default: [StreamStat.PING, StreamStat.FPS, StreamStat.BITRATE, StreamStat.DECODE_TIME, StreamStat.PACKETS_LOST, StreamStat.FRAMES_LOST],
|
||||||
multipleOptions: {
|
multipleOptions: {
|
||||||
|
[StreamStat.CLOCK]: `${StreamStat.CLOCK.toUpperCase()}: ${t('clock')}`,
|
||||||
|
[StreamStat.PLAYTIME]: `${StreamStat.PLAYTIME.toUpperCase()}: ${t('playtime')}`,
|
||||||
|
[StreamStat.BATTERY]: `${StreamStat.BATTERY.toUpperCase()}: ${t('battery')}`,
|
||||||
[StreamStat.PING]: `${StreamStat.PING.toUpperCase()}: ${t('stat-ping')}`,
|
[StreamStat.PING]: `${StreamStat.PING.toUpperCase()}: ${t('stat-ping')}`,
|
||||||
|
[StreamStat.JITTER]: `${StreamStat.JITTER.toUpperCase()}: ${t('jitter')}`,
|
||||||
[StreamStat.FPS]: `${StreamStat.FPS.toUpperCase()}: ${t('stat-fps')}`,
|
[StreamStat.FPS]: `${StreamStat.FPS.toUpperCase()}: ${t('stat-fps')}`,
|
||||||
[StreamStat.BITRATE]: `${StreamStat.BITRATE.toUpperCase()}: ${t('stat-bitrate')}`,
|
[StreamStat.BITRATE]: `${StreamStat.BITRATE.toUpperCase()}: ${t('stat-bitrate')}`,
|
||||||
[StreamStat.DECODE_TIME]: `${StreamStat.DECODE_TIME.toUpperCase()}: ${t('stat-decode-time')}`,
|
[StreamStat.DECODE_TIME]: `${StreamStat.DECODE_TIME.toUpperCase()}: ${t('stat-decode-time')}`,
|
||||||
[StreamStat.PACKETS_LOST]: `${StreamStat.PACKETS_LOST.toUpperCase()}: ${t('stat-packets-lost')}`,
|
[StreamStat.PACKETS_LOST]: `${StreamStat.PACKETS_LOST.toUpperCase()}: ${t('stat-packets-lost')}`,
|
||||||
[StreamStat.FRAMES_LOST]: `${StreamStat.FRAMES_LOST.toUpperCase()}: ${t('stat-frames-lost')}`,
|
[StreamStat.FRAMES_LOST]: `${StreamStat.FRAMES_LOST.toUpperCase()}: ${t('stat-frames-lost')}`,
|
||||||
|
[StreamStat.DOWNLOAD]: `${StreamStat.DOWNLOAD.toUpperCase()}: ${t('downloaded')}`,
|
||||||
|
[StreamStat.UPLOAD]: `${StreamStat.UPLOAD.toUpperCase()}: ${t('uploaded')}`,
|
||||||
},
|
},
|
||||||
params: {
|
params: {
|
||||||
size: 6,
|
size: 6,
|
||||||
},
|
},
|
||||||
|
ready: setting => {
|
||||||
|
// Remove Battery option in unsupported browser
|
||||||
|
const multipleOptions = (setting as any).multipleOptions;
|
||||||
|
if (!STATES.browser.capabilities.batteryApi) {
|
||||||
|
delete multipleOptions[StreamStat.BATTERY];
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
[PrefKey.STATS_SHOW_WHEN_PLAYING]: {
|
[PrefKey.STATS_SHOW_WHEN_PLAYING]: {
|
||||||
label: t('show-stats-on-startup'),
|
label: t('show-stats-on-startup'),
|
||||||
@ -743,11 +797,13 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.REMOTE_PLAY_ENABLED]: {
|
[PrefKey.REMOTE_PLAY_ENABLED]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
label: t('enable-remote-play-feature'),
|
label: t('enable-remote-play-feature'),
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.REMOTE_PLAY_RESOLUTION]: {
|
[PrefKey.REMOTE_PLAY_RESOLUTION]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
default: StreamResolution.DIM_1080P,
|
default: StreamResolution.DIM_1080P,
|
||||||
options: {
|
options: {
|
||||||
[StreamResolution.DIM_1080P]: '1080p',
|
[StreamResolution.DIM_1080P]: '1080p',
|
||||||
@ -756,11 +812,19 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
|
|||||||
},
|
},
|
||||||
|
|
||||||
[PrefKey.GAME_FORTNITE_FORCE_CONSOLE]: {
|
[PrefKey.GAME_FORTNITE_FORCE_CONSOLE]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
label: '🎮 ' + t('fortnite-force-console-version'),
|
label: '🎮 ' + t('fortnite-force-console-version'),
|
||||||
default: false,
|
default: false,
|
||||||
note: t('fortnite-allow-stw-mode'),
|
note: t('fortnite-allow-stw-mode'),
|
||||||
},
|
},
|
||||||
};
|
|
||||||
|
[PrefKey.GAME_MSFS2020_FORCE_NATIVE_MKB]: {
|
||||||
|
requiredVariants: 'full',
|
||||||
|
label: '✈️ ' + t('msfs2020-force-native-mkb'),
|
||||||
|
default: false,
|
||||||
|
note: t('may-not-work-properly'),
|
||||||
|
},
|
||||||
|
} satisfies SettingDefinitions;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super(StorageKey.GLOBAL, GlobalSettingsStorage.DEFINITIONS);
|
super(StorageKey.GLOBAL, GlobalSettingsStorage.DEFINITIONS);
|
||||||
|
329
src/utils/stream-stats-collector.ts
Normal file
329
src/utils/stream-stats-collector.ts
Normal file
@ -0,0 +1,329 @@
|
|||||||
|
import { BxEvent } from "./bx-event";
|
||||||
|
import { STATES } from "./global";
|
||||||
|
import { humanFileSize, secondsToHm } from "./html";
|
||||||
|
|
||||||
|
export enum StreamStat {
|
||||||
|
PING = 'ping',
|
||||||
|
JITTER = 'jit',
|
||||||
|
FPS = 'fps',
|
||||||
|
BITRATE = 'btr',
|
||||||
|
DECODE_TIME = 'dt',
|
||||||
|
PACKETS_LOST = 'pl',
|
||||||
|
FRAMES_LOST = 'fl',
|
||||||
|
DOWNLOAD = 'dl',
|
||||||
|
UPLOAD = 'ul',
|
||||||
|
PLAYTIME = 'play',
|
||||||
|
BATTERY = 'batt',
|
||||||
|
CLOCK = 'time',
|
||||||
|
};
|
||||||
|
|
||||||
|
export type StreamStatGrade = '' | 'bad' | 'ok' | 'good';
|
||||||
|
|
||||||
|
type CurrentStats = {
|
||||||
|
[StreamStat.PING]: {
|
||||||
|
current: number;
|
||||||
|
grades: [number, number, number];
|
||||||
|
toString: () => string;
|
||||||
|
};
|
||||||
|
|
||||||
|
[StreamStat.JITTER]: {
|
||||||
|
current: number;
|
||||||
|
grades: [number, number, number];
|
||||||
|
toString: () => string;
|
||||||
|
};
|
||||||
|
|
||||||
|
[StreamStat.FPS]: {
|
||||||
|
current: number;
|
||||||
|
toString: () => string;
|
||||||
|
};
|
||||||
|
|
||||||
|
[StreamStat.BITRATE]: {
|
||||||
|
current: number;
|
||||||
|
toString: () => string;
|
||||||
|
};
|
||||||
|
|
||||||
|
[StreamStat.FRAMES_LOST]: {
|
||||||
|
received: number;
|
||||||
|
dropped: number;
|
||||||
|
toString: () => string;
|
||||||
|
};
|
||||||
|
|
||||||
|
[StreamStat.PACKETS_LOST]: {
|
||||||
|
received: number;
|
||||||
|
dropped: number;
|
||||||
|
toString: () => string;
|
||||||
|
};
|
||||||
|
|
||||||
|
[StreamStat.DECODE_TIME]: {
|
||||||
|
current: number;
|
||||||
|
total: number;
|
||||||
|
grades: [number, number, number];
|
||||||
|
toString: () => string;
|
||||||
|
};
|
||||||
|
|
||||||
|
[StreamStat.DOWNLOAD]: {
|
||||||
|
total: number;
|
||||||
|
toString: () => string;
|
||||||
|
};
|
||||||
|
|
||||||
|
[StreamStat.UPLOAD]: {
|
||||||
|
total: number;
|
||||||
|
toString: () => string;
|
||||||
|
};
|
||||||
|
|
||||||
|
[StreamStat.PLAYTIME]: {
|
||||||
|
seconds: number;
|
||||||
|
startTime: number;
|
||||||
|
toString: () => string;
|
||||||
|
};
|
||||||
|
|
||||||
|
[StreamStat.BATTERY]: {
|
||||||
|
current: number;
|
||||||
|
start: number;
|
||||||
|
isCharging: boolean;
|
||||||
|
toString: () => string;
|
||||||
|
},
|
||||||
|
|
||||||
|
[StreamStat.CLOCK]: {
|
||||||
|
toString: () => string;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export class StreamStatsCollector {
|
||||||
|
private static instance: StreamStatsCollector;
|
||||||
|
public static getInstance(): StreamStatsCollector {
|
||||||
|
if (!StreamStatsCollector.instance) {
|
||||||
|
StreamStatsCollector.instance = new StreamStatsCollector();
|
||||||
|
}
|
||||||
|
|
||||||
|
return StreamStatsCollector.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect in background - 60 seconds
|
||||||
|
static readonly INTERVAL_BACKGROUND = 60 * 1000;
|
||||||
|
|
||||||
|
public calculateGrade(value: number, grades: [number, number, number]): StreamStatGrade {
|
||||||
|
return (value > grades[2]) ? 'bad' : (value > grades[1]) ? 'ok' : (value > grades[0]) ? 'good' : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
private currentStats: CurrentStats = {
|
||||||
|
[StreamStat.PING]: {
|
||||||
|
current: -1,
|
||||||
|
grades: [40, 75, 100],
|
||||||
|
toString() {
|
||||||
|
return this.current === -1 ? '???' : this.current.toString();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
[StreamStat.JITTER]: {
|
||||||
|
current: 0,
|
||||||
|
grades: [30, 40, 60],
|
||||||
|
toString() {
|
||||||
|
return `${this.current.toFixed(2)}ms`;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
[StreamStat.FPS]: {
|
||||||
|
current: 0,
|
||||||
|
toString() {
|
||||||
|
return this.current.toString();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
[StreamStat.BITRATE]: {
|
||||||
|
current: 0,
|
||||||
|
toString() {
|
||||||
|
return `${this.current.toFixed(2)} Mbps`;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
[StreamStat.FRAMES_LOST]: {
|
||||||
|
received: 0,
|
||||||
|
dropped: 0,
|
||||||
|
toString() {
|
||||||
|
const framesDroppedPercentage = (this.dropped * 100 / ((this.dropped + this.received) || 1)).toFixed(2);
|
||||||
|
return framesDroppedPercentage === '0.00' ? this.dropped.toString() : `${this.dropped} (${framesDroppedPercentage}%)`;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
[StreamStat.PACKETS_LOST]: {
|
||||||
|
received: 0,
|
||||||
|
dropped: 0,
|
||||||
|
toString() {
|
||||||
|
const packetsLostPercentage = (this.dropped * 100 / ((this.dropped + this.received) || 1)).toFixed(2);
|
||||||
|
return packetsLostPercentage === '0.00' ? this.dropped.toString() : `${this.dropped} (${packetsLostPercentage}%)`;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
[StreamStat.DECODE_TIME]: {
|
||||||
|
current: 0,
|
||||||
|
total: 0,
|
||||||
|
grades: [6, 9, 12],
|
||||||
|
toString() {
|
||||||
|
return isNaN(this.current) ? '??ms' : `${this.current.toFixed(2)}ms`;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
[StreamStat.DOWNLOAD]: {
|
||||||
|
total: 0,
|
||||||
|
toString() {
|
||||||
|
return humanFileSize(this.total);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
[StreamStat.UPLOAD]: {
|
||||||
|
total: 0,
|
||||||
|
toString() {
|
||||||
|
return humanFileSize(this.total);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
[StreamStat.PLAYTIME]: {
|
||||||
|
seconds: 0,
|
||||||
|
startTime: 0,
|
||||||
|
toString() {
|
||||||
|
return secondsToHm(this.seconds);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
[StreamStat.BATTERY]: {
|
||||||
|
current: 100,
|
||||||
|
start: 100,
|
||||||
|
isCharging: false,
|
||||||
|
toString() {
|
||||||
|
let text = `${this.current}%`;
|
||||||
|
|
||||||
|
if (this.current !== this.start) {
|
||||||
|
const diffLevel = Math.round(this.current - this.start);
|
||||||
|
const sign = diffLevel > 0 ? '+' : '';
|
||||||
|
text += ` (${sign}${diffLevel}%)`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return text;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
[StreamStat.CLOCK]: {
|
||||||
|
toString() {
|
||||||
|
return new Date().toLocaleTimeString([], {
|
||||||
|
hour: '2-digit',
|
||||||
|
minute:'2-digit',
|
||||||
|
hour12: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
private lastVideoStat?: RTCInboundRtpStreamStats | null;
|
||||||
|
|
||||||
|
async collect() {
|
||||||
|
const stats = await STATES.currentStream.peerConnection?.getStats();
|
||||||
|
if (!stats) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
stats.forEach(stat => {
|
||||||
|
if (stat.type === 'inbound-rtp' && stat.kind === 'video') {
|
||||||
|
// FPS
|
||||||
|
const fps = this.currentStats[StreamStat.FPS];
|
||||||
|
fps.current = stat.framesPerSecond || 0;
|
||||||
|
|
||||||
|
// Packets Lost
|
||||||
|
// packetsLost can be negative, but we don't care about that
|
||||||
|
const pl = this.currentStats[StreamStat.PACKETS_LOST];
|
||||||
|
pl.dropped = Math.max(0, stat.packetsLost);
|
||||||
|
pl.received = stat.packetsReceived;
|
||||||
|
|
||||||
|
// Frames lost
|
||||||
|
const fl = this.currentStats[StreamStat.FRAMES_LOST];
|
||||||
|
fl.dropped = stat.framesDropped;
|
||||||
|
fl.received = stat.framesReceived;
|
||||||
|
|
||||||
|
if (!this.lastVideoStat) {
|
||||||
|
this.lastVideoStat = stat;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const lastStat = this.lastVideoStat;
|
||||||
|
|
||||||
|
// Jitter
|
||||||
|
const jit = this.currentStats[StreamStat.JITTER];
|
||||||
|
const bufferDelayDiff = (stat as RTCInboundRtpStreamStats).jitterBufferDelay! - lastStat.jitterBufferDelay!;
|
||||||
|
const emittedCountDiff = (stat as RTCInboundRtpStreamStats).jitterBufferEmittedCount! - lastStat.jitterBufferEmittedCount!;
|
||||||
|
if (emittedCountDiff > 0) {
|
||||||
|
jit.current = bufferDelayDiff / emittedCountDiff * 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bitrate
|
||||||
|
const btr = this.currentStats[StreamStat.BITRATE];
|
||||||
|
const timeDiff = stat.timestamp - lastStat.timestamp;
|
||||||
|
btr.current = 8 * (stat.bytesReceived - lastStat.bytesReceived!) / timeDiff / 1000;
|
||||||
|
|
||||||
|
// Decode time
|
||||||
|
const dt = this.currentStats[StreamStat.DECODE_TIME];
|
||||||
|
dt.total = stat.totalDecodeTime - lastStat.totalDecodeTime!;
|
||||||
|
const framesDecodedDiff = stat.framesDecoded - lastStat.framesDecoded!;
|
||||||
|
dt.current = dt.total / framesDecodedDiff * 1000;
|
||||||
|
|
||||||
|
this.lastVideoStat = stat;
|
||||||
|
} else if (stat.type === 'candidate-pair' && stat.packetsReceived > 0 && stat.state === 'succeeded') {
|
||||||
|
// Round Trip Time
|
||||||
|
const ping = this.currentStats[StreamStat.PING];
|
||||||
|
ping.current = stat.currentRoundTripTime ? stat.currentRoundTripTime * 1000 : -1;
|
||||||
|
|
||||||
|
// Download
|
||||||
|
const dl = this.currentStats[StreamStat.DOWNLOAD];
|
||||||
|
dl.total = stat.bytesReceived;
|
||||||
|
|
||||||
|
// Upload
|
||||||
|
const ul = this.currentStats[StreamStat.UPLOAD];
|
||||||
|
ul.total = stat.bytesSent;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Battery
|
||||||
|
let batteryLevel = 100;
|
||||||
|
let isCharging = false;
|
||||||
|
if (STATES.browser.capabilities.batteryApi) {
|
||||||
|
try {
|
||||||
|
const bm = await (navigator as NavigatorBattery).getBattery();
|
||||||
|
isCharging = bm.charging;
|
||||||
|
batteryLevel = Math.round(bm.level * 100);
|
||||||
|
} catch(e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
const battery = this.currentStats[StreamStat.BATTERY];
|
||||||
|
battery.current = batteryLevel;
|
||||||
|
battery.isCharging = isCharging;
|
||||||
|
|
||||||
|
// Playtime
|
||||||
|
const playTime = this.currentStats[StreamStat.PLAYTIME];
|
||||||
|
const now = +new Date;
|
||||||
|
playTime.seconds = Math.ceil((now - playTime.startTime) / 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
getStat<T extends StreamStat>(kind: T): CurrentStats[T] {
|
||||||
|
return this.currentStats[kind];
|
||||||
|
}
|
||||||
|
|
||||||
|
reset() {
|
||||||
|
const playTime = this.currentStats[StreamStat.PLAYTIME];
|
||||||
|
playTime.seconds = 0;
|
||||||
|
playTime.startTime = +new Date;
|
||||||
|
|
||||||
|
// Get battery level
|
||||||
|
try {
|
||||||
|
STATES.browser.capabilities.batteryApi && (navigator as NavigatorBattery).getBattery().then(bm => {
|
||||||
|
this.currentStats[StreamStat.BATTERY].start = Math.round(bm.level * 100);
|
||||||
|
});
|
||||||
|
} catch(e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
static setupEvents() {
|
||||||
|
window.addEventListener(BxEvent.STREAM_PLAYING, e => {
|
||||||
|
const statsCollector = StreamStatsCollector.getInstance();
|
||||||
|
statsCollector.reset();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -40,13 +40,7 @@ const Texts = {
|
|||||||
"auto": "Auto",
|
"auto": "Auto",
|
||||||
"back-to-home": "Back to home",
|
"back-to-home": "Back to home",
|
||||||
"back-to-home-confirm": "Do you want to go back to the home page (without disconnecting)?",
|
"back-to-home-confirm": "Do you want to go back to the home page (without disconnecting)?",
|
||||||
"badge-audio": "Audio",
|
"battery": "Battery",
|
||||||
"badge-battery": "Battery",
|
|
||||||
"badge-in": "In",
|
|
||||||
"badge-out": "Out",
|
|
||||||
"badge-playtime": "Playtime",
|
|
||||||
"badge-server": "Server",
|
|
||||||
"badge-video": "Video",
|
|
||||||
"battery-saving": "Battery saving",
|
"battery-saving": "Battery saving",
|
||||||
"better-xcloud": "Better xCloud",
|
"better-xcloud": "Better xCloud",
|
||||||
"bitrate-audio-maximum": "Maximum audio bitrate",
|
"bitrate-audio-maximum": "Maximum audio bitrate",
|
||||||
@ -63,6 +57,7 @@ const Texts = {
|
|||||||
"clarity-boost": "Clarity boost",
|
"clarity-boost": "Clarity boost",
|
||||||
"clarity-boost-warning": "These settings don't work when the Clarity Boost mode is ON",
|
"clarity-boost-warning": "These settings don't work when the Clarity Boost mode is ON",
|
||||||
"clear": "Clear",
|
"clear": "Clear",
|
||||||
|
"clock": "Clock",
|
||||||
"close": "Close",
|
"close": "Close",
|
||||||
"close-app": "Close app",
|
"close-app": "Close app",
|
||||||
"combine-audio-video-streams": "Combine audio & video streams",
|
"combine-audio-video-streams": "Combine audio & video streams",
|
||||||
@ -97,10 +92,12 @@ const Texts = {
|
|||||||
"disable-xcloud-analytics": "Disable xCloud analytics",
|
"disable-xcloud-analytics": "Disable xCloud analytics",
|
||||||
"disabled": "Disabled",
|
"disabled": "Disabled",
|
||||||
"disconnected": "Disconnected",
|
"disconnected": "Disconnected",
|
||||||
|
"download": "Download",
|
||||||
|
"downloaded": "Downloaded",
|
||||||
"edit": "Edit",
|
"edit": "Edit",
|
||||||
"enable-controller-shortcuts": "Enable controller shortcuts",
|
"enable-controller-shortcuts": "Enable controller shortcuts",
|
||||||
"enable-local-co-op-support": "Enable local co-op support",
|
"enable-local-co-op-support": "Enable local co-op support",
|
||||||
"enable-local-co-op-support-note": "Only works if the game doesn't require a different profile",
|
"enable-local-co-op-support-note": "Only works with some games",
|
||||||
"enable-mic-on-startup": "Enable microphone on game launch",
|
"enable-mic-on-startup": "Enable microphone on game launch",
|
||||||
"enable-mkb": "Emulate controller with Mouse & Keyboard",
|
"enable-mkb": "Emulate controller with Mouse & Keyboard",
|
||||||
"enable-quick-glance-mode": "Enable \"Quick Glance\" mode",
|
"enable-quick-glance-mode": "Enable \"Quick Glance\" mode",
|
||||||
@ -110,7 +107,7 @@ const Texts = {
|
|||||||
"experimental": "Experimental",
|
"experimental": "Experimental",
|
||||||
"export": "Export",
|
"export": "Export",
|
||||||
"fast": "Fast",
|
"fast": "Fast",
|
||||||
"fortnite-allow-stw-mode": "Allows playing STW mode on mobile",
|
"fortnite-allow-stw-mode": "Allows playing \"Save the World\" mode on mobile",
|
||||||
"fortnite-force-console-version": "Fortnite: force console version",
|
"fortnite-force-console-version": "Fortnite: force console version",
|
||||||
"game-bar": "Game Bar",
|
"game-bar": "Game Bar",
|
||||||
"getting-consoles-list": "Getting the list of consoles...",
|
"getting-consoles-list": "Getting the list of consoles...",
|
||||||
@ -134,6 +131,7 @@ const Texts = {
|
|||||||
"increase": "Increase",
|
"increase": "Increase",
|
||||||
"install-android": "Better xCloud app for Android",
|
"install-android": "Better xCloud app for Android",
|
||||||
"japan": "Japan",
|
"japan": "Japan",
|
||||||
|
"jitter": "Jitter",
|
||||||
"keyboard-shortcuts": "Keyboard shortcuts",
|
"keyboard-shortcuts": "Keyboard shortcuts",
|
||||||
"korea": "Korea",
|
"korea": "Korea",
|
||||||
"language": "Language",
|
"language": "Language",
|
||||||
@ -145,6 +143,7 @@ const Texts = {
|
|||||||
"local-co-op": "Local co-op",
|
"local-co-op": "Local co-op",
|
||||||
"lowest-quality": "Lowest quality",
|
"lowest-quality": "Lowest quality",
|
||||||
"map-mouse-to": "Map mouse to",
|
"map-mouse-to": "Map mouse to",
|
||||||
|
"max-fps": "Max FPS",
|
||||||
"may-not-work-properly": "May not work properly!",
|
"may-not-work-properly": "May not work properly!",
|
||||||
"menu": "Menu",
|
"menu": "Menu",
|
||||||
"microphone": "Microphone",
|
"microphone": "Microphone",
|
||||||
@ -153,6 +152,7 @@ const Texts = {
|
|||||||
"mkb-disclaimer": "Using this feature when playing online could be viewed as cheating",
|
"mkb-disclaimer": "Using this feature when playing online could be viewed as cheating",
|
||||||
"mouse-and-keyboard": "Mouse & Keyboard",
|
"mouse-and-keyboard": "Mouse & Keyboard",
|
||||||
"mouse-wheel": "Mouse wheel",
|
"mouse-wheel": "Mouse wheel",
|
||||||
|
"msfs2020-force-native-mkb": "MSFS2020: force native M&KB support",
|
||||||
"muted": "Muted",
|
"muted": "Muted",
|
||||||
"name": "Name",
|
"name": "Name",
|
||||||
"native-mkb": "Native Mouse & Keyboard",
|
"native-mkb": "Native Mouse & Keyboard",
|
||||||
@ -172,7 +172,7 @@ const Texts = {
|
|||||||
(e: any) => `Versão ${e.version} disponível`,
|
(e: any) => `Versão ${e.version} disponível`,
|
||||||
,
|
,
|
||||||
(e: any) => `เวอร์ชัน ${e.version} พร้อมใช้งานแล้ว`,
|
(e: any) => `เวอร์ชัน ${e.version} พร้อมใช้งานแล้ว`,
|
||||||
,
|
(e: any) => `${e.version} sayılı yeni sürüm mevcut`,
|
||||||
(e: any) => `Доступна версія ${e.version}`,
|
(e: any) => `Доступна версія ${e.version}`,
|
||||||
(e: any) => `Đã có phiên bản ${e.version}`,
|
(e: any) => `Đã có phiên bản ${e.version}`,
|
||||||
(e: any) => `版本 ${e.version} 可供更新`,
|
(e: any) => `版本 ${e.version} 可供更新`,
|
||||||
@ -186,6 +186,7 @@ const Texts = {
|
|||||||
"opacity": "Opacity",
|
"opacity": "Opacity",
|
||||||
"other": "Other",
|
"other": "Other",
|
||||||
"playing": "Playing",
|
"playing": "Playing",
|
||||||
|
"playtime": "Playtime",
|
||||||
"poland": "Poland",
|
"poland": "Poland",
|
||||||
"position": "Position",
|
"position": "Position",
|
||||||
"powered-off": "Powered off",
|
"powered-off": "Powered off",
|
||||||
@ -350,6 +351,8 @@ const Texts = {
|
|||||||
"unlimited": "Unlimited",
|
"unlimited": "Unlimited",
|
||||||
"unmuted": "Unmuted",
|
"unmuted": "Unmuted",
|
||||||
"unsharp-masking": "Unsharp masking",
|
"unsharp-masking": "Unsharp masking",
|
||||||
|
"upload": "Upload",
|
||||||
|
"uploaded": "Uploaded",
|
||||||
"use-mouse-absolute-position": "Use mouse's absolute position",
|
"use-mouse-absolute-position": "Use mouse's absolute position",
|
||||||
"use-this-at-your-own-risk": "Use this at your own risk",
|
"use-this-at-your-own-risk": "Use this at your own risk",
|
||||||
"user-agent-profile": "User-Agent profile",
|
"user-agent-profile": "User-Agent profile",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { BxIcon } from "./bx-icon";
|
import { BxIcon } from "./bx-icon";
|
||||||
import { AppInterface, STATES } from "./global";
|
import { AppInterface, SCRIPT_VARIANT, STATES } from "./global";
|
||||||
import { ButtonStyle, CE, clearDataSet, createButton, getReactProps } from "./html";
|
import { ButtonStyle, CE, clearDataSet, createButton, getReactProps } from "./html";
|
||||||
import { t } from "./translation";
|
import { t } from "./translation";
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ export class TrueAchievements {
|
|||||||
TrueAchievements.open(true, dataset.xboxTitleId, dataset.id);
|
TrueAchievements.open(true, dataset.xboxTitleId, dataset.id);
|
||||||
|
|
||||||
// Close all xCloud's dialogs
|
// Close all xCloud's dialogs
|
||||||
window.BX_EXPOSED.dialogRoutes.closeAll();
|
window.BX_EXPOSED.dialogRoutes?.closeAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static $hiddenLink = CE<HTMLAnchorElement>('a', {
|
private static $hiddenLink = CE<HTMLAnchorElement>('a', {
|
||||||
@ -53,6 +53,11 @@ export class TrueAchievements {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static injectAchievementsProgress($elm: HTMLElement) {
|
static injectAchievementsProgress($elm: HTMLElement) {
|
||||||
|
// Only do this in Full version
|
||||||
|
if (SCRIPT_VARIANT !== 'full') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const $parent = $elm.parentElement!;
|
const $parent = $elm.parentElement!;
|
||||||
|
|
||||||
// Wrap xCloud's element with our own
|
// Wrap xCloud's element with our own
|
||||||
@ -89,6 +94,11 @@ export class TrueAchievements {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static injectAchievementDetailPage($parent: HTMLElement) {
|
static injectAchievementDetailPage($parent: HTMLElement) {
|
||||||
|
// Only do this in Full version
|
||||||
|
if (SCRIPT_VARIANT !== 'full') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const props = getReactProps($parent);
|
const props = getReactProps($parent);
|
||||||
if (!props) {
|
if (!props) {
|
||||||
return;
|
return;
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { isFullVersion } from "@macros/build" with {type: "macro"};
|
||||||
|
|
||||||
import { LoadingScreen } from "@modules/loading-screen";
|
import { LoadingScreen } from "@modules/loading-screen";
|
||||||
import { RemotePlayManager } from "@/modules/remote-play-manager";
|
import { RemotePlayManager } from "@/modules/remote-play-manager";
|
||||||
import { StreamBadges } from "@modules/stream/stream-badges";
|
import { StreamBadges } from "@modules/stream/stream-badges";
|
||||||
@ -147,7 +149,7 @@ class XcloudInterceptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Touch controller for all games
|
// Touch controller for all games
|
||||||
if (getPref(PrefKey.STREAM_TOUCH_CONTROLLER) === StreamTouchController.ALL) {
|
if (isFullVersion() && getPref(PrefKey.STREAM_TOUCH_CONTROLLER) === StreamTouchController.ALL) {
|
||||||
const titleInfo = STATES.currentStream.titleInfo;
|
const titleInfo = STATES.currentStream.titleInfo;
|
||||||
if (titleInfo?.details.hasTouchSupport) {
|
if (titleInfo?.details.hasTouchSupport) {
|
||||||
TouchController.disable();
|
TouchController.disable();
|
||||||
@ -187,7 +189,7 @@ class XcloudInterceptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Enable touch controller
|
// Enable touch controller
|
||||||
if (TouchController.isEnabled()) {
|
if (isFullVersion() && TouchController.isEnabled()) {
|
||||||
overrides.inputConfiguration.enableTouchInput = true;
|
overrides.inputConfiguration.enableTouchInput = true;
|
||||||
overrides.inputConfiguration.maxTouchPoints = 10;
|
overrides.inputConfiguration.maxTouchPoints = 10;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user