Take control over your live stream video by running it yourself. Streaming + chat out of the box.
HTML activitypubbroadcastingchatdecentralizedfederationfediversegolanghacktoberfesthlslivelivestreamowncastrtmpself-hostedstreaming-videovideo
feat(video): show a clear on and off state on the minimize latency item
Gabe Kangasf556463e002c
diff --git a/web/components/video/OwncastPlayer/OwncastPlayer.tsx b/web/components/video/OwncastPlayer/OwncastPlayer.tsxindex 7968636f44..db6c3e0a55 100644--- a/web/components/video/OwncastPlayer/OwncastPlayer.tsx+++ b/web/components/video/OwncastPlayer/OwncastPlayer.tsx@@ -13,14 +13,13 @@ import { autoplayModeForSetting } from '../../../utils/autoplay';import { Localization } from '../../../types/localization';import { isVideoPlayingAtom, clockSkewAtom } from '../../stores/ClientConfigStore';import PlaybackMetrics from '../metrics/playback';-import { createVideoSettingsMenuButton } from '../settings-menu';+import { createVideoSettingsMenuButton, LATENCY_COMPENSATION_ENABLED } from '../settings-menu';import LatencyCompensator from '../latencyCompensator';import styles from './OwncastPlayer.module.scss';import { VideoSettingsServiceContext } from '../../../services/video-settings-service';import { ComponentError } from '../../ui/ComponentError/ComponentError';const PLAYER_VOLUME = 'owncast_volume';-const LATENCY_COMPENSATION_ENABLED = 'latencyCompensatorEnabled';const ping = new ViewerPing();let playbackMetrics = null;diff --git a/web/components/video/settings-menu.ts b/web/components/video/settings-menu.tsindex f4403f1faf..a9a4b8e3ec 100644--- a/web/components/video/settings-menu.ts+++ b/web/components/video/settings-menu.ts@@ -1,17 +1,29 @@/* eslint-disable max-classes-per-file */+import { getLocalStorage } from '../../utils/localStorage';++export const LATENCY_COMPENSATION_ENABLED = 'latencyCompensatorEnabled';++const toggleBadgeStyle = (enabled: boolean): string =>+ `display: inline-block; min-width: 34px; text-align: center; padding: 1px 8px; ` ++ `border-radius: 9px; font-size: 0.75em; font-weight: 600; letter-spacing: 0.5px; ${+ enabled+ ? 'background: #12b76a; color: #fff; border: 1px solid #12b76a;'+ : 'background: transparent; color: #999; border: 1px solid #777;'+ }`;+export function createVideoSettingsMenuButton(player,videojs,qualities,latencyItemPressed: () => boolean,-): any {+): unknown {const VjsMenuItem = videojs.getComponent('MenuItem');const MenuItem = videojs.getComponent('MenuItem');const MenuButtonClass = videojs.getComponent('MenuButton');class MenuSeparator extends VjsMenuItem {// eslint-disable-next-line no-useless-constructor- constructor(p: any, options: { selectable: boolean }) {+ constructor(p: unknown, options: { selectable: boolean }) {super(p, options);}@@ -22,13 +34,49 @@ export function createVideoSettingsMenuButton(}}- const lowLatencyItem = new MenuItem(player, {+ // The "Minimize latency" toggle renders its own on/off pill so the state+ // is obvious at a glance, instead of relying on the subtle vjs-selected+ // styling.+ class LowLatencyMenuItem extends VjsMenuItem {+ // eslint-disable-next-line no-useless-constructor+ constructor(p: unknown, options: { selectable: boolean; label: string }) {+ super(p, options);+ }++ createEl(tag = 'button', props = {}, attributes = {}) {+ const el = super.createEl(tag, props, attributes);+ el.setAttribute(+ 'title',+ 'Experimental: slightly speeds up playback to keep you closer to live',+ );+ el.innerHTML =+ '<span style="display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 10px;">' ++ '<span>Minimize latency</span>' ++ `<span class="latency-toggle-state" style="${toggleBadgeStyle(false)}">OFF</span>` ++ '</span>';+ return el;+ }++ setToggleState(enabled: boolean) {+ this.selected(enabled);+ const badge = this.el().querySelector('.latency-toggle-state') as HTMLElement | null;+ if (badge) {+ badge.textContent = enabled ? 'ON' : 'OFF';+ badge.setAttribute('style', toggleBadgeStyle(enabled));+ }+ }+ }++ const lowLatencyItem = new LowLatencyMenuItem(player, {selectable: true,- label: 'minimize latency (experimental)',+ label: 'Minimize latency',});+ // Reflect the saved preference: the player auto-starts the compensator+ // from local storage, and the menu item should agree with it on load.+ lowLatencyItem.setToggleState(getLocalStorage(LATENCY_COMPENSATION_ENABLED) === 'true');lowLatencyItem.on('click', () => {const enabled: boolean = latencyItemPressed();- lowLatencyItem.selected(enabled);+ lowLatencyItem.setToggleState(enabled);});const separator = new MenuSeparator(player, {