2022-05-11 01:36:09 +03:00
|
|
|
import { useEffect, useState } from 'react';
|
2022-09-03 21:38:52 +03:00
|
|
|
import CrossfadeImage from '../../ui/CrossfadeImage/CrossfadeImage';
|
2022-05-11 01:36:09 +03:00
|
|
|
import s from './VideoPoster.module.scss';
|
2022-04-26 23:39:35 +03:00
|
|
|
|
2022-05-11 01:36:09 +03:00
|
|
|
const REFRESH_INTERVAL = 20_000;
|
2022-04-26 23:39:35 +03:00
|
|
|
|
2022-05-11 01:36:09 +03:00
|
|
|
interface Props {
|
|
|
|
initialSrc: string;
|
|
|
|
src: string;
|
|
|
|
online: boolean;
|
|
|
|
}
|
2022-04-26 23:39:35 +03:00
|
|
|
|
2022-05-11 01:36:09 +03:00
|
|
|
export default function VideoPoster(props: Props) {
|
|
|
|
const { online, initialSrc, src: base } = props;
|
2022-04-26 23:39:35 +03:00
|
|
|
|
2022-05-11 01:36:09 +03:00
|
|
|
let timer: ReturnType<typeof setInterval>;
|
|
|
|
const [src, setSrc] = useState(initialSrc);
|
|
|
|
const [duration, setDuration] = useState('0s');
|
2022-04-26 23:39:35 +03:00
|
|
|
|
|
|
|
useEffect(() => {
|
2022-05-11 01:36:09 +03:00
|
|
|
clearInterval(timer);
|
|
|
|
timer = setInterval(() => {
|
|
|
|
if (duration === '0s') {
|
|
|
|
setDuration('3s');
|
|
|
|
}
|
|
|
|
setSrc(`${base}?${Date.now()}`);
|
|
|
|
}, REFRESH_INTERVAL);
|
|
|
|
}, []);
|
2022-04-26 23:39:35 +03:00
|
|
|
|
|
|
|
return (
|
2022-05-11 01:36:09 +03:00
|
|
|
<div className={s.poster}>
|
2022-06-30 00:01:41 +03:00
|
|
|
{!online && <img src={initialSrc} alt="logo" />}
|
2022-05-11 01:36:09 +03:00
|
|
|
|
|
|
|
{online && (
|
|
|
|
<CrossfadeImage
|
|
|
|
src={src}
|
|
|
|
duration={duration}
|
2022-07-08 10:10:18 +03:00
|
|
|
objectFit="cover"
|
2022-05-11 01:36:09 +03:00
|
|
|
width="100%"
|
2022-06-30 00:01:41 +03:00
|
|
|
height="100%"
|
2022-05-11 01:36:09 +03:00
|
|
|
/>
|
|
|
|
)}
|
2022-04-26 23:39:35 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|