Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small jsmpeg and mse player fixes #12032

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Small jsmpeg and mse player fixes
  • Loading branch information
hawkeye217 committed Jun 17, 2024
commit c9fad0f50c2a2cb712c119b4d7353beaa6ee8936
17 changes: 5 additions & 12 deletions web/src/components/player/JSMpegPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default function JSMpegPlayer({
}: JSMpegPlayerProps) {
const url = `${baseUrl.replace(/^http/, "ws")}live/jsmpeg/${camera}`;
const playerRef = useRef<HTMLDivElement | null>(null);
const videoRef = useRef(null);
const internalContainerRef = useRef<HTMLDivElement | null>(null);

const selectedContainerRef = useMemo(
Expand Down Expand Up @@ -86,7 +87,7 @@ export default function JSMpegPlayer({
return;
}

const video = new JSMpeg.VideoElement(
videoRef.current = new JSMpeg.VideoElement(
playerRef.current,
url,
{ canvas: `#${CSS.escape(uniqueId)}` },
Expand All @@ -99,17 +100,9 @@ export default function JSMpegPlayer({
},
},
);

return () => {
if (playerRef.current) {
try {
video.destroy();
// eslint-disable-next-line no-empty
} catch (e) {}
playerRef.current = null;
}
};
}, [url, uniqueId, onPlaying]);
// we know that these deps are correct
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [url, uniqueId]);

return (
<div className={className}>
Expand Down
6 changes: 5 additions & 1 deletion web/src/components/player/MsePlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,14 @@ function MSEPlayer({

return () => {
onDisconnect();
if (bufferTimeout) {
clearTimeout(bufferTimeout);
setBufferTimeout(undefined);
}
};
// we know that these deps are correct
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [playbackEnabled, onDisconnect, onConnect]);
}, [playbackEnabled]);

// check visibility

Expand Down
Loading