diff --git a/web/src/components/player/MsePlayer.tsx b/web/src/components/player/MsePlayer.tsx index 716817407..382c879f8 100644 --- a/web/src/components/player/MsePlayer.tsx +++ b/web/src/components/player/MsePlayer.tsx @@ -79,6 +79,9 @@ function MSEPlayer({ ); const videoRef = useRef(null); + const playerContainerRef = useRef(null); + const [containerSize, setContainerSize] = useState({ width: 0, height: 0 }); + const [isRotatedGrid, setIsRotatedGrid] = useState(false); const wsRef = useRef(null); const reconnectTIDRef = useRef(null); const intentionalDisconnectRef = useRef(false); @@ -796,7 +799,51 @@ function MSEPlayer({ }; }, [setStats, getStats]); - return ( + useEffect(() => { + const video = videoRef.current; + + if (!video) { + setIsRotatedGrid(false); + return; + } + + const rotatedMarker = window + .getComputedStyle(video) + .getPropertyValue("--frigate-mse-grid-rotated") + .trim(); + + setIsRotatedGrid(rotatedMarker === "1"); + }, [className]); + + useEffect(() => { + if (!isRotatedGrid) { + return; + } + + const container = playerContainerRef.current; + + if (!container) { + return; + } + + const updateSize = () => { + setContainerSize({ + width: container.clientWidth, + height: container.clientHeight, + }); + }; + + updateSize(); + + const resizeObserver = new ResizeObserver(updateSize); + resizeObserver.observe(container); + + return () => { + resizeObserver.disconnect(); + }; + }, [isRotatedGrid]); + + const videoElement = (