2020-12-14 17:40:59 +01:00
|
|
|
import React from 'react';
|
|
|
|
import Icon from 'component/common/icon';
|
|
|
|
import * as ICONS from 'constants/icons';
|
|
|
|
import ReactDOMServer from 'react-dom/server';
|
|
|
|
|
|
|
|
import './plugins/videojs-overlay/plugin';
|
2021-07-06 11:02:05 +02:00
|
|
|
import './plugins/videojs-overlay/plugin.scss';
|
2020-12-14 17:40:59 +01:00
|
|
|
|
|
|
|
// ****************************************************************************
|
|
|
|
// ****************************************************************************
|
|
|
|
|
|
|
|
const OVERLAY_NAME_ONE_OFF = 'one-off';
|
|
|
|
const OVERLAY_CLASS_PLAYBACK_RATE = 'vjs-overlay-playrate';
|
|
|
|
const OVERLAY_CLASS_SEEKED = 'vjs-overlay-seeked';
|
|
|
|
|
|
|
|
// ****************************************************************************
|
|
|
|
// ****************************************************************************
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Overlays that will always be registered with the plugin.
|
|
|
|
* @type {*[]}
|
|
|
|
*/
|
|
|
|
const PERMANENT_OVERLAYS = [
|
|
|
|
// Nothing for now.
|
|
|
|
// --- Example: ---
|
|
|
|
// {
|
|
|
|
// content: 'Video is now playing',
|
|
|
|
// start: 'play',
|
|
|
|
// end: 'pause',
|
|
|
|
// align: 'center',
|
|
|
|
// },
|
|
|
|
];
|
|
|
|
|
|
|
|
export const OVERLAY_DATA = {
|
|
|
|
// https://github.com/brightcove/videojs-overlay/blob/master/README.md#documentation
|
|
|
|
overlays: [...PERMANENT_OVERLAYS],
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapper to hide away the complexity of adding dynamic content, which the
|
|
|
|
* plugin currently does not support. To change the 'content' of an overlay,
|
|
|
|
* we need to re-create the entire array.
|
|
|
|
* This wrapper ensures the PERMANENT_OVERLAYS (and potentially other overlays)
|
|
|
|
* don't get lost.
|
|
|
|
*/
|
|
|
|
function showOneOffOverlay(player, className, overlayJsx, align) {
|
|
|
|
// Delete existing:
|
2021-07-01 09:22:49 +02:00
|
|
|
OVERLAY_DATA.overlays = OVERLAY_DATA.overlays.filter((x) => x.name !== OVERLAY_NAME_ONE_OFF);
|
2020-12-14 17:40:59 +01:00
|
|
|
// Create new one:
|
|
|
|
OVERLAY_DATA.overlays.push({
|
|
|
|
name: OVERLAY_NAME_ONE_OFF,
|
|
|
|
class: className,
|
|
|
|
content: ReactDOMServer.renderToStaticMarkup(overlayJsx),
|
|
|
|
start: 'immediate',
|
|
|
|
align: align,
|
|
|
|
});
|
|
|
|
// Display it:
|
|
|
|
player.overlay(OVERLAY_DATA);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays a transient "Playback Rate" overlay.
|
|
|
|
*
|
|
|
|
* @param player The videojs instance.
|
|
|
|
* @param newRate The current playback rate value.
|
|
|
|
* @param isSpeedUp true if the change was speeding up, false otherwise.
|
|
|
|
*/
|
|
|
|
export function showPlaybackRateOverlay(player, newRate, isSpeedUp) {
|
|
|
|
const overlayJsx = (
|
|
|
|
<div>
|
|
|
|
<p>{newRate}x</p>
|
|
|
|
<p>
|
|
|
|
<Icon icon={isSpeedUp ? ICONS.ARROW_RIGHT : ICONS.ARROW_LEFT} size={48} />
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
showOneOffOverlay(player, OVERLAY_CLASS_PLAYBACK_RATE, overlayJsx, 'center');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays a transient "Seeked" overlay.
|
|
|
|
*
|
|
|
|
* @param player The videojs instance.
|
|
|
|
* @param duration The seek delta duration.
|
|
|
|
* @param isForward true if seeking forward, false otherwise.
|
|
|
|
*/
|
2022-03-29 22:40:21 +02:00
|
|
|
export function showSeekedOverlay(player, duration, isForward, isJumpTo) {
|
2020-12-14 17:40:59 +01:00
|
|
|
const overlayJsx = (
|
|
|
|
<div>
|
|
|
|
<p>
|
2022-03-29 22:40:21 +02:00
|
|
|
{!isJumpTo && (isForward ? '+' : '-')}
|
2020-12-14 17:40:59 +01:00
|
|
|
{duration}
|
2022-03-29 22:40:21 +02:00
|
|
|
{isJumpTo && '%'}
|
2020-12-14 17:40:59 +01:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
showOneOffOverlay(player, OVERLAY_CLASS_SEEKED, overlayJsx, 'center');
|
|
|
|
}
|
2021-03-19 21:18:39 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays a transient "Volume Percentage" overlay.
|
|
|
|
*
|
|
|
|
* @param player The videojs instance.
|
|
|
|
* @param percentage how much % of volume active.
|
|
|
|
*/
|
|
|
|
export function showVolumeverlay(player, percentage) {
|
|
|
|
const overlayJsx = (
|
|
|
|
<div>
|
|
|
|
<p>
|
|
|
|
{percentage}
|
|
|
|
{'%'}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
showOneOffOverlay(player, OVERLAY_CLASS_SEEKED, overlayJsx, 'center');
|
|
|
|
}
|