From 68a74cad04678169221d6e160af2e92d72c06948 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Fri, 9 Feb 2024 10:53:55 -0700 Subject: [PATCH] Get live mode working for jsmpeg --- web/src/components/Chip.tsx | 2 +- web/src/components/player/JSMpegPlayer.tsx | 12 ++++++++++-- web/src/components/player/LivePlayer.tsx | 7 ++++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/web/src/components/Chip.tsx b/web/src/components/Chip.tsx index e458151f2..8d1b6555d 100644 --- a/web/src/components/Chip.tsx +++ b/web/src/components/Chip.tsx @@ -29,7 +29,7 @@ export default function Chip({ >
{children}
diff --git a/web/src/components/player/JSMpegPlayer.tsx b/web/src/components/player/JSMpegPlayer.tsx index 567f94a91..9b5905a10 100644 --- a/web/src/components/player/JSMpegPlayer.tsx +++ b/web/src/components/player/JSMpegPlayer.tsx @@ -5,6 +5,7 @@ import JSMpeg from "@cycjimmy/jsmpeg-player"; import { useEffect, useMemo, useRef } from "react"; type JSMpegPlayerProps = { + className?: string; camera: string; width: number; height: number; @@ -14,11 +15,13 @@ export default function JSMpegPlayer({ camera, width, height, + className, }: JSMpegPlayerProps) { const url = `${baseUrl.replace(/^http/, "ws")}live/jsmpeg/${camera}`; const playerRef = useRef(null); const containerRef = useRef(null); - const [{ width: containerWidth }] = useResizeObserver(containerRef); + const [{ width: containerWidth, height: containerHeight }] = + useResizeObserver(containerRef); // Add scrollbar width (when visible) to the available observer width to eliminate screen juddering. // https://github.com/blakeblackshear/frigate/issues/1657 @@ -34,6 +37,11 @@ export default function JSMpegPlayer({ const scaledHeight = useMemo(() => { const scaledHeight = Math.floor(availableWidth / aspectRatio); const finalHeight = Math.min(scaledHeight, height); + console.log(`${containerWidth} / ${aspectRatio} -< ${containerHeight}`); + + if (containerHeight < finalHeight) { + return containerHeight; + } if (finalHeight > 0) { return finalHeight; @@ -79,7 +87,7 @@ export default function JSMpegPlayer({ }, [url]); return ( -
+
{ if (!liveReady) { + if (activeMotion && liveMode == "jsmpeg") { + setLiveReady(true); + } + return; } @@ -115,6 +119,7 @@ export default function LivePlayer({ } else if (liveMode == "jsmpeg") { player = (