diff --git a/src/components/story/Story.tsx b/src/components/story/Story.tsx index 6b030263e..18615f888 100644 --- a/src/components/story/Story.tsx +++ b/src/components/story/Story.tsx @@ -348,9 +348,11 @@ function Story({ useEffect(() => { if (!isLoadedStory || isDeletedStory || areViewsExpired) return; + if (!isOut && !isChannelStory) return; + // Refresh counters each time loadStoryViews({ peerId, storyId }); - }, [isDeletedStory, areViewsExpired, isLoadedStory, peerId, storyId]); + }, [isDeletedStory, areViewsExpired, isLoadedStory, peerId, storyId, isOut, isChannelStory]); useEffect(() => { if ( diff --git a/src/components/story/hooks/useStoryPreloader.ts b/src/components/story/hooks/useStoryPreloader.ts index cb078d5d5..b257740e0 100644 --- a/src/components/story/hooks/useStoryPreloader.ts +++ b/src/components/story/hooks/useStoryPreloader.ts @@ -5,6 +5,7 @@ import { ApiMediaFormat } from '../../../api/types'; import { getStoryMediaHash } from '../../../global/helpers'; import { selectPeerStories } from '../../../global/selectors'; +import unloadVideo from '../../../util/browser/unloadVideo'; import { preloadImage } from '../../../util/files'; import * as mediaLoader from '../../../util/mediaLoader'; import { getProgressiveUrl } from '../../../util/mediaLoader'; @@ -125,9 +126,7 @@ function preloadProgressive(url: string) { head.appendChild(video); video.load(); setTimeout(() => { - video.pause(); - video.src = ''; - video.load(); + unloadVideo(video); head.removeChild(video); }, PROGRESSIVE_PRELOAD_DURATION); } diff --git a/src/hooks/useStreaming.ts b/src/hooks/useStreaming.ts index d00e6b785..500876d00 100644 --- a/src/hooks/useStreaming.ts +++ b/src/hooks/useStreaming.ts @@ -4,6 +4,7 @@ import { useEffect } from '../lib/teact/teact'; import { DEBUG } from '../config'; import { requestMutation } from '../lib/fasterdom/fasterdom'; import { applyStyles } from '../util/animation'; +import unloadVideo from '../util/browser/unloadVideo'; import { makeProgressiveLoader } from '../util/progressieveLoader'; import { IS_SAFARI } from '../util/windowEnvironment'; @@ -78,9 +79,7 @@ export function useStreaming(videoRef: RefObject, url?: string return () => { requestMutation(() => { const src = video.src; - video.pause(); - video.src = ''; - video.load(); + unloadVideo(video); mediaSource.removeEventListener('sourceopen', onSourceOpen); if (mediaSource.readyState === 'open') { endOfStream(mediaSource); diff --git a/src/hooks/useVideoCleanup.ts b/src/hooks/useVideoCleanup.ts index a269d1487..5750acf15 100644 --- a/src/hooks/useVideoCleanup.ts +++ b/src/hooks/useVideoCleanup.ts @@ -2,6 +2,7 @@ import type { RefObject } from 'react'; import { useEffect } from '../lib/teact/teact'; import { requestNextMutation } from '../lib/fasterdom/fasterdom'; +import unloadVideo from '../util/browser/unloadVideo'; // Fix for memory leak when unmounting video element export default function useVideoCleanup(videoRef: RefObject, dependencies: any[]) { @@ -12,9 +13,7 @@ export default function useVideoCleanup(videoRef: RefObject, d if (videoEl) { // It may be slow (specifically on iOS), so we postpone it after unmounting requestNextMutation(() => { - videoEl.pause(); - videoEl.src = ''; - videoEl.load(); + unloadVideo(videoEl); }); } }; diff --git a/src/util/browser/unloadVideo.ts b/src/util/browser/unloadVideo.ts new file mode 100644 index 000000000..bbd831ba8 --- /dev/null +++ b/src/util/browser/unloadVideo.ts @@ -0,0 +1,6 @@ +export default function unloadVideo(video: HTMLVideoElement) { + video.pause(); + // https://github.com/shaka-project/shaka-player/commit/0e3d10e61cb08cc35750e48face4e58f24542fc8 + video.removeAttribute('src'); + video.load(); +}