From a29e6c07daa6a1b8063a08bf7011c20d217aa6a8 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Mon, 14 Feb 2022 00:53:34 +0300 Subject: [PATCH] Round Video: Fix failing to play --- src/components/middle/message/RoundVideo.tsx | 27 +++++++++----------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/components/middle/message/RoundVideo.tsx b/src/components/middle/message/RoundVideo.tsx index 7c375307f..1dcde9c2b 100644 --- a/src/components/middle/message/RoundVideo.tsx +++ b/src/components/middle/message/RoundVideo.tsx @@ -38,17 +38,7 @@ type OwnProps = { isDownloading?: boolean; }; -let currentOnRelease: NoneToVoidFunction; - -function createCapture(onRelease: NoneToVoidFunction) { - return () => { - if (currentOnRelease) { - currentOnRelease(); - } - - currentOnRelease = onRelease; - }; -} +let stopPrevious: NoneToVoidFunction; const RoundVideo: FC = ({ message, @@ -130,17 +120,24 @@ const RoundVideo: FC = ({ const shouldPlay = Boolean(mediaData && isIntersecting); - const stopPlaying = () => { + const stopPlaying = useCallback(() => { + if (!playerRef.current) { + return; + } + setIsActivated(false); setProgress(0); - safePlay(playerRef.current!); + safePlay(playerRef.current); fastRaf(() => { playingProgressRef.current!.innerHTML = ''; }); - }; + }, []); - const capturePlaying = createCapture(stopPlaying); + const capturePlaying = useCallback(() => { + stopPrevious?.(); + stopPrevious = stopPlaying; + }, [stopPlaying]); useEffect(() => { if (!playerRef.current) {