Skip to content

Commit

Permalink
Use valid/unique css identifier for jsmpeg canvas elements (#11704)
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkeye217 committed Jun 3, 2024
1 parent 7a4eb0b commit 13f250f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions web/src/components/player/JSMpegPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { baseUrl } from "@/api/baseUrl";
import { useResizeObserver } from "@/hooks/resize-observer";
// @ts-expect-error we know this doesn't have types
import JSMpeg from "@cycjimmy/jsmpeg-player";
import React, { useEffect, useMemo, useRef } from "react";
import React, { useEffect, useMemo, useRef, useId } from "react";

type JSMpegPlayerProps = {
className?: string;
Expand Down Expand Up @@ -77,6 +77,8 @@ export default function JSMpegPlayer({
}
}, [scaledHeight, aspectRatio]);

const uniqueId = useId();

useEffect(() => {
if (!playerRef.current) {
return;
Expand All @@ -85,7 +87,7 @@ export default function JSMpegPlayer({
const video = new JSMpeg.VideoElement(
playerRef.current,
url,
{ canvas: `#${camera}-canvas` },
{ canvas: `#${CSS.escape(uniqueId)}` },
{ protocols: [], audio: false, videoBufferSize: 1024 * 1024 * 4 },
);

Expand All @@ -98,14 +100,14 @@ export default function JSMpegPlayer({
playerRef.current = null;
}
};
}, [url, camera]);
}, [url, uniqueId]);

return (
<div className={className}>
<div className="size-full" ref={internalContainerRef}>
<div ref={playerRef} className="jsmpeg">
<canvas
id={`${camera}-canvas`}
id={uniqueId}
style={{
width: scaledWidth ?? width,
height: scaledHeight ?? height,
Expand Down

0 comments on commit 13f250f

Please sign in to comment.