Fix highlight in video quality selection menu (#3102)
Also removed dead code in video quality selection menu. Also 'minimize latency (experimental)' button is no longer renamed when pressed (it is now highlighted when enabled). Co-authored-by: janWilejan <>
This commit is contained in:
parent
2b7042ff98
commit
7930747cbb
@ -81,15 +81,6 @@ export const OwncastPlayer: FC<OwncastPlayerProps> = ({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const setLatencyCompensatorItemTitle = t => {
|
|
||||||
const item = document.querySelector('.latency-toggle-item > .vjs-menu-item-text');
|
|
||||||
if (!item) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
item.innerHTML = t;
|
|
||||||
};
|
|
||||||
|
|
||||||
const startLatencyCompensator = () => {
|
const startLatencyCompensator = () => {
|
||||||
if (latencyCompensator) {
|
if (latencyCompensator) {
|
||||||
latencyCompensator.stop();
|
latencyCompensator.stop();
|
||||||
@ -101,8 +92,6 @@ export const OwncastPlayer: FC<OwncastPlayerProps> = ({
|
|||||||
latencyCompensator.setClockSkew(clockSkew);
|
latencyCompensator.setClockSkew(clockSkew);
|
||||||
latencyCompensator.enable();
|
latencyCompensator.enable();
|
||||||
setLocalStorage(LATENCY_COMPENSATION_ENABLED, true);
|
setLocalStorage(LATENCY_COMPENSATION_ENABLED, true);
|
||||||
|
|
||||||
setLatencyCompensatorItemTitle('disable minimized latency');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const stopLatencyCompensator = () => {
|
const stopLatencyCompensator = () => {
|
||||||
@ -112,17 +101,16 @@ export const OwncastPlayer: FC<OwncastPlayerProps> = ({
|
|||||||
latencyCompensator = null;
|
latencyCompensator = null;
|
||||||
latencyCompensatorEnabled = false;
|
latencyCompensatorEnabled = false;
|
||||||
setLocalStorage(LATENCY_COMPENSATION_ENABLED, false);
|
setLocalStorage(LATENCY_COMPENSATION_ENABLED, false);
|
||||||
setLatencyCompensatorItemTitle(
|
|
||||||
'<span style="font-size: 0.8em">enable minimized latency (experimental)</span>',
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Toggle minimized latency mode. Return the new state.
|
||||||
const toggleLatencyCompensator = () => {
|
const toggleLatencyCompensator = () => {
|
||||||
if (latencyCompensatorEnabled) {
|
if (latencyCompensatorEnabled) {
|
||||||
stopLatencyCompensator();
|
stopLatencyCompensator();
|
||||||
} else {
|
} else {
|
||||||
startLatencyCompensator();
|
startLatencyCompensator();
|
||||||
}
|
}
|
||||||
|
return latencyCompensatorEnabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
const setupLatencyCompensator = player => {
|
const setupLatencyCompensator = player => {
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
/* eslint-disable max-classes-per-file */
|
/* eslint-disable max-classes-per-file */
|
||||||
export function createVideoSettingsMenuButton(player, videojs, qualities, latencyItemPressed): any {
|
export function createVideoSettingsMenuButton(
|
||||||
|
player,
|
||||||
|
videojs,
|
||||||
|
qualities,
|
||||||
|
latencyItemPressed: () => boolean,
|
||||||
|
): any {
|
||||||
const VjsMenuItem = videojs.getComponent('MenuItem');
|
const VjsMenuItem = videojs.getComponent('MenuItem');
|
||||||
const MenuItem = videojs.getComponent('MenuItem');
|
const MenuItem = videojs.getComponent('MenuItem');
|
||||||
const MenuButtonClass = videojs.getComponent('MenuButton');
|
const MenuButtonClass = videojs.getComponent('MenuButton');
|
||||||
@ -19,10 +24,11 @@ export function createVideoSettingsMenuButton(player, videojs, qualities, latenc
|
|||||||
|
|
||||||
const lowLatencyItem = new MenuItem(player, {
|
const lowLatencyItem = new MenuItem(player, {
|
||||||
selectable: true,
|
selectable: true,
|
||||||
|
label: 'minimize latency (experimental)',
|
||||||
});
|
});
|
||||||
lowLatencyItem.setAttribute('class', 'latency-toggle-item');
|
|
||||||
lowLatencyItem.on('click', () => {
|
lowLatencyItem.on('click', () => {
|
||||||
latencyItemPressed();
|
const enabled: boolean = latencyItemPressed();
|
||||||
|
lowLatencyItem.selected(enabled);
|
||||||
});
|
});
|
||||||
|
|
||||||
const separator = new MenuSeparator(player, {
|
const separator = new MenuSeparator(player, {
|
||||||
@ -40,38 +46,45 @@ export function createVideoSettingsMenuButton(player, videojs, qualities, latenc
|
|||||||
|
|
||||||
const defaultAutoItem = new MenuItem(player, {
|
const defaultAutoItem = new MenuItem(player, {
|
||||||
selectable: true,
|
selectable: true,
|
||||||
|
selected: true,
|
||||||
label: 'Auto',
|
label: 'Auto',
|
||||||
});
|
});
|
||||||
|
|
||||||
const items = qualities.map(item => {
|
const items = Array(qualities.length);
|
||||||
const newMenuItem = new MenuItem(player, {
|
qualities.forEach(item => {
|
||||||
|
items[item.index] = new MenuItem(player, {
|
||||||
selectable: true,
|
selectable: true,
|
||||||
label: item.name,
|
label: item.name,
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
for (let i = 0; i < items.length; i += 1) {
|
||||||
|
const item = items[i];
|
||||||
// Quality selected
|
// Quality selected
|
||||||
newMenuItem.on('click', () => {
|
item.on('click', () => {
|
||||||
// If for some reason tech doesn't exist, then don't do anything
|
// If for some reason tech doesn't exist, then don't do anything
|
||||||
if (!tech) {
|
if (!tech) {
|
||||||
console.warn('Invalid attempt to access null player tech');
|
console.warn('Invalid attempt to access null player tech');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Only enable this single, selected representation.
|
// Only enable and highlight this single, selected representation.
|
||||||
tech.vhs.representations().forEach((rep, index) => {
|
tech.vhs.representations().forEach((rep, index) => {
|
||||||
rep.enabled(index === item.index);
|
const isCurrent: boolean = index === i;
|
||||||
|
rep.enabled(isCurrent);
|
||||||
|
items[index].selected(isCurrent);
|
||||||
});
|
});
|
||||||
newMenuItem.selected(false);
|
defaultAutoItem.selected(false);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
return newMenuItem;
|
|
||||||
});
|
|
||||||
|
|
||||||
defaultAutoItem.on('click', () => {
|
defaultAutoItem.on('click', () => {
|
||||||
// Re-enable all representations.
|
// Re-enable all representations.
|
||||||
tech.vhs.representations().forEach(rep => {
|
tech.vhs.representations().forEach(rep => {
|
||||||
rep.enabled(true);
|
rep.enabled(true);
|
||||||
});
|
});
|
||||||
defaultAutoItem.selected(false);
|
// Only highlight "Auto"
|
||||||
|
items.forEach(item => item.selected(false));
|
||||||
|
defaultAutoItem.selected(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
const supportsLatencyCompensator = !!tech && !!tech.vhs;
|
const supportsLatencyCompensator = !!tech && !!tech.vhs;
|
||||||
@ -95,19 +108,8 @@ export function createVideoSettingsMenuButton(player, videojs, qualities, latenc
|
|||||||
const menuButton = new MenuButton();
|
const menuButton = new MenuButton();
|
||||||
menuButton.el().setAttribute('aria-label', 'Settings');
|
menuButton.el().setAttribute('aria-label', 'Settings');
|
||||||
|
|
||||||
// If none of the settings in this menu are applicable then don't show it.
|
|
||||||
const tech = player.tech({ IWillNotUseThisInPlugins: true });
|
|
||||||
menuButton.addClass('vjs-quality-selector');
|
menuButton.addClass('vjs-quality-selector');
|
||||||
videojs.registerComponent('MenuButton', MenuButton);
|
videojs.registerComponent('MenuButton', MenuButton);
|
||||||
|
|
||||||
if (!tech.vhs) {
|
|
||||||
return menuButton;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qualities.length < 2 && (!tech || !tech.vhs)) {
|
|
||||||
return menuButton;
|
|
||||||
}
|
|
||||||
|
|
||||||
// eslint-disable-next-line consistent-return
|
|
||||||
return menuButton;
|
return menuButton;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user