openreplay/frontend/app/components/Spots/SpotPlayer/components/Vjs.tsx
Andrey Babushkin fd5c0c9747
Add lokalisation (#3092)
* applied eslint

* add locales and lint the project

* removed error boundary

* updated locales

* fix min files

* fix locales
2025-03-06 17:43:15 +01:00

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;