This commit is contained in:
redphx
2024-12-05 17:10:39 +07:00
parent c836e33f7b
commit 9199351af1
207 changed files with 9833 additions and 6953 deletions

7
src/modules/stream/stream-badges.ts Normal file → Executable file
View File

@@ -7,7 +7,8 @@ import { STATES } from "@utils/global";
import { BxLogger } from "@/utils/bx-logger";
import { BxIcon } from "@/utils/bx-icon";
import { GuideMenuTab } from "../ui/guide-menu";
import { StreamStat, StreamStatsCollector } from "@/utils/stream-stats-collector";
import { StreamStatsCollector } from "@/utils/stream-stats-collector";
import { StreamStat } from "@/enums/pref-values";
type StreamBadgeInfo = {
@@ -130,7 +131,7 @@ export class StreamBadges {
return $badge;
}
private async updateBadges(forceUpdate = false) {
private updateBadges = async (forceUpdate = false) => {
if (!this.$container || (!forceUpdate && !this.$container.isConnected)) {
this.stop();
return;
@@ -181,7 +182,7 @@ export class StreamBadges {
private async start() {
await this.updateBadges(true);
this.stop();
this.intervalId = window.setInterval(this.updateBadges.bind(this), this.REFRESH_INTERVAL);
this.intervalId = window.setInterval(this.updateBadges, this.REFRESH_INTERVAL);
}
private stop() {

13
src/modules/stream/stream-settings-utils.ts Normal file → Executable file
View File

@@ -1,16 +1,17 @@
import { StreamPlayerType, StreamVideoProcessing } from "@enums/stream-player";
import { STATES } from "@utils/global";
import { UserAgent } from "@utils/user-agent";
import type { StreamPlayerOptions } from "../stream-player";
import { PrefKey } from "@/enums/pref-keys";
import { getPref, setPref } from "@/utils/settings-storages/global-settings-storage";
import { StreamVideoProcessing, StreamPlayerType } from "@/enums/pref-values";
import { escapeCssSelector } from "@/utils/html";
export function onChangeVideoPlayerType() {
const playerType = getPref(PrefKey.VIDEO_PLAYER_TYPE);
const $videoProcessing = document.getElementById(`bx_setting_${PrefKey.VIDEO_PROCESSING}`) as HTMLSelectElement;
const $videoSharpness = document.getElementById(`bx_setting_${PrefKey.VIDEO_SHARPNESS}`) 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;
const playerType = getPref<StreamPlayerType>(PrefKey.VIDEO_PLAYER_TYPE);
const $videoProcessing = document.getElementById(`bx_setting_${escapeCssSelector(PrefKey.VIDEO_PROCESSING)}`) as HTMLSelectElement;
const $videoSharpness = document.getElementById(`bx_setting_${escapeCssSelector(PrefKey.VIDEO_SHARPNESS)}`) as HTMLElement;
const $videoPowerPreference = document.getElementById(`bx_setting_${escapeCssSelector(PrefKey.VIDEO_POWER_PREFERENCE)}`) as HTMLElement;
const $videoMaxFps = document.getElementById(`bx_setting_${escapeCssSelector(PrefKey.VIDEO_MAX_FPS)}`) as HTMLElement;
if (!$videoProcessing) {
return;

13
src/modules/stream/stream-stats.ts Normal file → Executable file
View File

@@ -4,8 +4,9 @@ import { t } from "@utils/translation"
import { STATES } from "@utils/global"
import { PrefKey } from "@/enums/pref-keys"
import { getPref } from "@/utils/settings-storages/global-settings-storage"
import { StreamStat, StreamStatsCollector, type StreamStatGrade } from "@/utils/stream-stats-collector"
import { StreamStatsCollector, type StreamStatGrade } from "@/utils/stream-stats-collector"
import { BxLogger } from "@/utils/bx-logger"
import { StreamStat } from "@/enums/pref-values"
export class StreamStats {
@@ -87,7 +88,7 @@ export class StreamStats {
this.$container.classList.remove('bx-gone');
this.$container.dataset.display = glancing ? 'glancing' : 'fixed';
this.intervalId = window.setInterval(this.update.bind(this), this.REFRESH_INTERVAL);
this.intervalId = window.setInterval(this.update, this.REFRESH_INTERVAL);
}
async stop(glancing=false) {
@@ -157,7 +158,7 @@ export class StreamStats {
this.quickGlanceObserver = null;
}
private async update(forceUpdate=false) {
private update = async (forceUpdate=false) => {
if ((!forceUpdate && this.isHidden()) || !STATES.currentStream.peerConnection) {
this.destroy();
return;
@@ -191,7 +192,7 @@ export class StreamStats {
}
refreshStyles() {
const PREF_ITEMS = getPref(PrefKey.STATS_ITEMS);
const PREF_ITEMS = getPref<StreamStat[]>(PrefKey.STATS_ITEMS);
const $container = this.$container;
$container.dataset.stats = '[' + PREF_ITEMS.join('][') + ']';
@@ -202,7 +203,7 @@ export class StreamStats {
}
hideSettingsUi() {
if (this.isGlancing() && !getPref(PrefKey.STATS_QUICK_GLANCE)) {
if (this.isGlancing() && !getPref(PrefKey.STATS_QUICK_GLANCE_ENABLED)) {
this.stop();
}
}
@@ -230,7 +231,7 @@ export class StreamStats {
static setupEvents() {
window.addEventListener(BxEvent.STREAM_PLAYING, e => {
const PREF_STATS_QUICK_GLANCE = getPref(PrefKey.STATS_QUICK_GLANCE);
const PREF_STATS_QUICK_GLANCE = getPref(PrefKey.STATS_QUICK_GLANCE_ENABLED);
const PREF_STATS_SHOW_WHEN_PLAYING = getPref(PrefKey.STATS_SHOW_WHEN_PLAYING);
const streamStats = StreamStats.getInstance();

4
src/modules/stream/stream-ui.ts Normal file → Executable file
View File

@@ -5,7 +5,7 @@ import { BxEvent } from "@utils/bx-event.ts";
import { t } from "@utils/translation.ts";
import { StreamBadges } from "./stream-badges.ts";
import { StreamStats } from "./stream-stats.ts";
import { SettingsNavigationDialog } from "../ui/dialog/settings-dialog.ts";
import { SettingsDialog } from "../ui/dialog/settings-dialog.ts";
export class StreamUiHandler {
@@ -161,7 +161,7 @@ export class StreamUiHandler {
e.preventDefault();
// Show Stream Settings dialog
SettingsNavigationDialog.getInstance().show();
SettingsDialog.getInstance().show();
});
StreamUiHandler.$btnStreamSettings = $btnStreamSettings;