* feat ui: login flow for spot extension * spot list, store and service created * some fixing for header * start work on single spot * spot player start * header for player, comments, icons, etc * split stuff into compoennts, create player state manager * player controls, activity panel etc etc * comments, empty page, rename and stuff * interval buttons etc * access modal * pubkey support * fix tooltip * limit 10 -> 9 * hls lib instead of videojs * some warnings * fix date display for exp * change public links * display more client data * fix cleaning, init comment * map network to replay player network ev * stream support, console panel, close panels on X * fixing streaming, destroy on leave * fix autoplay * show notification on spot login * fix spot login * backup player added, fix audio issue * show thumbnail when no video, add spot roles * add poster thumbnail * some fixes to video check * fix events jump * fix play btn * try catch over pubkey * icons * spot login pinging * move spot login flow to login comp, use separate spot login path for unique jwt * invalidate spot jwt on logout * add visual data on page load event * typo fix * issue to copy change * share spot url f
58 lines
1.4 KiB
TypeScript
58 lines
1.4 KiB
TypeScript
import React from 'react';
|
|
import videojs from 'video.js';
|
|
import 'video.js/dist/video-js.css';
|
|
|
|
function VideoJS(props: {
|
|
options: Record<string, any>;
|
|
onReady: (pl: any) => void;
|
|
}) {
|
|
const videoRef = React.useRef<HTMLDivElement>(null);
|
|
const playerRef = React.useRef<ReturnType<typeof videojs>>(null);
|
|
const { options, onReady } = props;
|
|
|
|
React.useEffect(() => {
|
|
if (!playerRef.current) {
|
|
const videoElement = document.createElement('video-js');
|
|
|
|
videoElement.classList.add('vjs-big-play-centered');
|
|
if (videoRef.current) {
|
|
videoRef.current.appendChild(videoElement);
|
|
}
|
|
|
|
const player = (playerRef.current = videojs(videoElement, options, () => {
|
|
videojs.log('player is ready');
|
|
onReady && onReady(player);
|
|
}));
|
|
player.volume(1); // Set volume to maximum
|
|
player.muted(false)
|
|
} else {
|
|
const player = playerRef.current;
|
|
|
|
player.autoplay(options.autoplay);
|
|
player.src(options.sources);
|
|
player.volume(1); // Set volume to maximum
|
|
player.muted(false)
|
|
}
|
|
}, [options, videoRef]);
|
|
|
|
React.useEffect(() => {
|
|
const player = playerRef.current;
|
|
|
|
return () => {
|
|
if (player && !player.isDisposed()) {
|
|
player.dispose();
|
|
playerRef.current = null;
|
|
}
|
|
};
|
|
}, [playerRef]);
|
|
|
|
return (
|
|
<div
|
|
ref={videoRef}
|
|
data-vjs-player
|
|
style={{ height: '100%', width: '100%' }}
|
|
/>
|
|
);
|
|
}
|
|
|
|
export default VideoJS;
|