owncast/web/components/video/settings-menu.ts

112 lines
3.3 KiB
TypeScript
Raw Normal View History

2022-11-13 10:28:49 +03:00
/* eslint-disable max-classes-per-file */
reafctor: normalize component formatting (#2082) * refactor: move/rename BanUserButton file * refactor: move/rename Chart file * refactor: update generic component filenames to PascalCase * refactor: update config component filenames to PascalCase * refactor: update AdminLayout component filename to PascalCase * refactor: update/move VideoJS component * chore(eslint): disable bad react/require-default-props rule * refactor: normalize ActionButton component * refactor: normalize ActionButtonRow component * refactor: normalize FollowButton component * refactor: normalize NotifyButton component * refactor: normalize ChatActionMessage component * refactor: normalize ChatContainer component * refactor: normalize ChatJoinMessage component * refactor: normalize ChatModerationActionMenu component * refactor: normalize ChatModerationDetailsModal component * refactor: normalize ChatModeratorNotification component * refactor: normalize ChatSocialMessage component * refactor: normalize ChatSystemMessage component * refactor: normalize ChatTextField component * refactor: normalize ChatUserBadge component * refactor: normalize ChatUserMessage component * refactor: normalize ContentHeader component * refactor: normalize OwncastLogo component * refactor: normalize UserDropdown component * chore(eslint): modify react/function-component-definition rule * refactor: normalize CodecSelector component * refactor: update a bunch of functional components using eslint * refactor: update a bunch of functional components using eslint, pt2 * refactor: update a bunch of functional components using eslint, pt3 * refactor: replace all component->component default imports with named imports * refactor: replace all component-stories->component default imports with named imports * refactor: remove default exports from most components * chore(eslint): add eslint config files for the components and pages dirs * fix: use-before-define error in ChatContainer * Fix ChatContainer import * Only process .tsx files in Next builds Co-authored-by: Gabe Kangas <gabek@real-ity.com>
2022-09-07 10:00:28 +03:00
export function createVideoSettingsMenuButton(player, videojs, qualities, latencyItemPressed): any {
const VjsMenuItem = videojs.getComponent('MenuItem');
2022-06-19 23:49:42 +03:00
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 }) {
super(p, options);
}
createEl(tag = 'button', props = {}, attributes = {}) {
const el = super.createEl(tag, props, attributes);
el.innerHTML = '<hr style="opacity: 0.3; margin-left: 10px; margin-right: 10px;" />';
return el;
}
}
2022-06-19 23:49:42 +03:00
const lowLatencyItem = new MenuItem(player, {
selectable: true,
});
lowLatencyItem.setAttribute('class', 'latency-toggle-item');
lowLatencyItem.on('click', () => {
latencyItemPressed();
2022-06-19 23:49:42 +03:00
});
const separator = new MenuSeparator(player, {
selectable: false,
});
2022-06-19 23:49:42 +03:00
2022-11-13 10:28:49 +03:00
class MenuButton extends MenuButtonClass {
2022-06-19 23:49:42 +03:00
constructor() {
2022-11-13 10:28:49 +03:00
super(player);
}
2022-06-19 23:49:42 +03:00
2022-11-13 10:28:49 +03:00
// eslint-disable-next-line class-methods-use-this
2022-06-19 23:49:42 +03:00
createItems() {
const tech = player.tech({ IWillNotUseThisInPlugins: true });
const defaultAutoItem = new MenuItem(player, {
selectable: true,
label: 'Auto',
});
2022-11-13 10:42:33 +03:00
const items = qualities.map(item => {
2022-06-19 23:49:42 +03:00
const newMenuItem = new MenuItem(player, {
selectable: true,
label: item.name,
});
// Quality selected
newMenuItem.on('click', () => {
// If for some reason tech doesn't exist, then don't do anything
if (!tech) {
console.warn('Invalid attempt to access null player tech');
return;
}
// Only enable this single, selected representation.
tech.vhs.representations().forEach((rep, index) => {
rep.enabled(index === item.index);
});
newMenuItem.selected(false);
});
return newMenuItem;
});
defaultAutoItem.on('click', () => {
// Re-enable all representations.
tech.vhs.representations().forEach(rep => {
rep.enabled(true);
});
defaultAutoItem.selected(false);
});
const supportsLatencyCompensator = !!tech && !!tech.vhs;
2022-06-19 23:49:42 +03:00
// Only show the quality selector if there is more than one option.
if (qualities.length < 2 && supportsLatencyCompensator) {
return [lowLatencyItem];
}
2022-06-19 23:49:42 +03:00
if (qualities.length > 1 && supportsLatencyCompensator) {
return [defaultAutoItem, ...items, separator, lowLatencyItem];
}
2022-06-19 23:49:42 +03:00
if (!supportsLatencyCompensator && qualities.length === 1) {
return [];
}
return [defaultAutoItem, ...items];
2022-11-13 10:28:49 +03:00
}
}
2022-06-19 23:49:42 +03:00
// If none of the settings in this menu are applicable then don't show it.
const tech = player.tech({ IWillNotUseThisInPlugins: true });
if (qualities.length < 2 && (!tech || !tech.vhs)) {
return;
}
2022-11-13 10:28:49 +03:00
videojs.registerComponent('MenuButton', MenuButton);
2022-06-19 23:49:42 +03:00
const menuButton = new MenuButton();
menuButton.addClass('vjs-quality-selector');
// eslint-disable-next-line consistent-return
return menuButton;
}
2022-11-13 10:28:49 +03:00
reafctor: normalize component formatting (#2082) * refactor: move/rename BanUserButton file * refactor: move/rename Chart file * refactor: update generic component filenames to PascalCase * refactor: update config component filenames to PascalCase * refactor: update AdminLayout component filename to PascalCase * refactor: update/move VideoJS component * chore(eslint): disable bad react/require-default-props rule * refactor: normalize ActionButton component * refactor: normalize ActionButtonRow component * refactor: normalize FollowButton component * refactor: normalize NotifyButton component * refactor: normalize ChatActionMessage component * refactor: normalize ChatContainer component * refactor: normalize ChatJoinMessage component * refactor: normalize ChatModerationActionMenu component * refactor: normalize ChatModerationDetailsModal component * refactor: normalize ChatModeratorNotification component * refactor: normalize ChatSocialMessage component * refactor: normalize ChatSystemMessage component * refactor: normalize ChatTextField component * refactor: normalize ChatUserBadge component * refactor: normalize ChatUserMessage component * refactor: normalize ContentHeader component * refactor: normalize OwncastLogo component * refactor: normalize UserDropdown component * chore(eslint): modify react/function-component-definition rule * refactor: normalize CodecSelector component * refactor: update a bunch of functional components using eslint * refactor: update a bunch of functional components using eslint, pt2 * refactor: update a bunch of functional components using eslint, pt3 * refactor: replace all component->component default imports with named imports * refactor: replace all component-stories->component default imports with named imports * refactor: remove default exports from most components * chore(eslint): add eslint config files for the components and pages dirs * fix: use-before-define error in ChatContainer * Fix ChatContainer import * Only process .tsx files in Next builds Co-authored-by: Gabe Kangas <gabek@real-ity.com>
2022-09-07 10:00:28 +03:00
export default createVideoSettingsMenuButton;