Add Theater Mode to its own class and fix bar text display

This commit is contained in:
saltrafael 2021-08-24 07:36:08 -03:00 committed by zeppi
parent db848fd961
commit 10087891f4
4 changed files with 33 additions and 12 deletions

View file

@ -33,6 +33,7 @@ const select = (state, props) => {
authenticated: selectUserVerifiedEmail(state), authenticated: selectUserVerifiedEmail(state),
userId: userId, userId: userId,
shareTelemetry: IS_WEB || selectDaemonSettings(state).share_usage_data, shareTelemetry: IS_WEB || selectDaemonSettings(state).share_usage_data,
videoTheaterMode: makeSelectClientSetting(SETTINGS.VIDEO_THEATER_MODE)(state),
}; };
}; };

View file

@ -1,16 +1,25 @@
// @flow // @flow
import type { Player } from './videojs'; import type { Player } from './videojs';
import videojs from 'video.js';
class TheaterModeButton extends videojs.getComponent('Button') {
constructor(player, options = {}) {
super(player, options);
this.addClass('vjs-button--theater-mode');
this.controlText('Theater Mode');
}
}
export function addTheaterModeButton(player: Player, toggleVideoTheaterMode: () => void) { export function addTheaterModeButton(player: Player, toggleVideoTheaterMode: () => void) {
var myButton = player.controlBar.addChild('button', { const controlBar = player.getChild('controlBar');
const theaterMode = new TheaterModeButton(player, {
name: 'TheaterModeButton',
text: __('Theater mode'), text: __('Theater mode'),
clickHandler: () => { clickHandler: () => {
toggleVideoTheaterMode(); toggleVideoTheaterMode();
}, },
}); });
// $FlowFixMe controlBar.addChild(theaterMode);
myButton.addClass('vjs-button--theater-mode');
// $FlowFixMe
myButton.setAttribute('title', __('Theater mode'));
} }

View file

@ -60,6 +60,7 @@ type Props = {
// allowPreRoll: ?boolean, // allowPreRoll: ?boolean,
shareTelemetry: boolean, shareTelemetry: boolean,
replay: boolean, replay: boolean,
videoTheaterMode: boolean,
}; };
// type VideoJSOptions = { // type VideoJSOptions = {
@ -210,6 +211,7 @@ export default React.memo<Props>(function VideoJs(props: Props) {
// allowPreRoll, // allowPreRoll,
shareTelemetry, shareTelemetry,
replay, replay,
videoTheaterMode,
} = props; } = props;
const [reload, setReload] = useState('initial'); const [reload, setReload] = useState('initial');
@ -336,13 +338,9 @@ export default React.memo<Props>(function VideoJs(props: Props) {
resolveCtrlText({ type: 'pause' }); resolveCtrlText({ type: 'pause' });
resolveCtrlText({ type: 'volumechange' }); resolveCtrlText({ type: 'volumechange' });
resolveCtrlText({ type: 'fullscreenchange' }); resolveCtrlText({ type: 'fullscreenchange' });
// (1) The 'Theater mode' button should probably be changed to a class controlBar
// so that we can use getChild() with a specific name. There might be .getChild('TheaterModeButton')
// clashes if we add a new button in the future. .controlText(videoTheaterMode ? __('Default Mode (t)') : __('Theater Mode (t)'));
// (2) We'll have to get 'makeSelectClientSetting(SETTINGS.VIDEO_THEATER_MODE)'
// as a prop here so we can say "Theater mode|Default mode" instead of
// "Toggle Theater mode".
controlBar.getChild('Button').controlText(__('Toggle Theater mode (t)'));
break; break;
default: default:
if (isDev) throw Error('Unexpected: ' + e.type); if (isDev) throw Error('Unexpected: ' + e.type);
@ -642,6 +640,16 @@ export default React.memo<Props>(function VideoJs(props: Props) {
} }
}, [replay]); }, [replay]);
useEffect(() => {
const player = playerRef.current;
if (player) {
const controlBar = player.getChild('controlBar');
controlBar
.getChild('TheaterModeButton')
.controlText(videoTheaterMode ? __('Default Mode (t)') : __('Theater Mode (t)'));
}
}, [videoTheaterMode]);
// This lifecycle hook is only called once (on mount), or when `isAudio` changes. // This lifecycle hook is only called once (on mount), or when `isAudio` changes.
useEffect(() => { useEffect(() => {
const vjsElement = createVideoPlayerDOM(containerRef.current); const vjsElement = createVideoPlayerDOM(containerRef.current);

View file

@ -52,6 +52,7 @@ type Props = {
userId: number, userId: number,
homepageData?: { [string]: HomepageCat }, homepageData?: { [string]: HomepageCat },
shareTelemetry: boolean, shareTelemetry: boolean,
videoTheaterMode: boolean,
}; };
/* /*
@ -86,6 +87,7 @@ function VideoViewer(props: Props) {
authenticated, authenticated,
userId, userId,
shareTelemetry, shareTelemetry,
videoTheaterMode,
} = props; } = props;
const adApprovedChannelIds = homepageData ? getAllIds(homepageData) : []; const adApprovedChannelIds = homepageData ? getAllIds(homepageData) : [];
@ -339,6 +341,7 @@ function VideoViewer(props: Props) {
allowPreRoll={!embedded && !authenticated} allowPreRoll={!embedded && !authenticated}
shareTelemetry={shareTelemetry} shareTelemetry={shareTelemetry}
replay={replay} replay={replay}
videoTheaterMode={videoTheaterMode}
/> />
)} )}
</div> </div>