Get live mode working for jsmpeg

This commit is contained in:
Nicolas Mowen 2024-02-09 10:53:55 -07:00
parent 30c9a958f2
commit 68a74cad04
3 changed files with 17 additions and 4 deletions

View File

@ -29,7 +29,7 @@ export default function Chip({
>
<div
ref={nodeRef}
className={`flex px-2 py-1.5 rounded-2xl items-center ${className}`}
className={`flex px-2 py-1.5 rounded-2xl items-center z-10 ${className}`}
>
{children}
</div>

View File

@ -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<HTMLDivElement | null>(null);
const containerRef = useRef<HTMLDivElement | null>(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 (
<div ref={containerRef}>
<div className={className} ref={containerRef}>
<div
ref={playerRef}
className={`jsmpeg`}

View File

@ -33,7 +33,7 @@ type Options = { [key: string]: boolean };
export default function LivePlayer({
className,
cameraConfig,
liveMode = "mse",
liveMode = "jsmpeg",
showStillWithoutActivity = true,
}: LivePlayerProps) {
// camera activity
@ -43,6 +43,10 @@ export default function LivePlayer({
const [liveReady, setLiveReady] = useState(false);
useEffect(() => {
if (!liveReady) {
if (activeMotion && liveMode == "jsmpeg") {
setLiveReady(true);
}
return;
}
@ -115,6 +119,7 @@ export default function LivePlayer({
} else if (liveMode == "jsmpeg") {
player = (
<JSMpegPlayer
className="w-full flex justify-center"
camera={cameraConfig.name}
width={cameraConfig.detect.width}
height={cameraConfig.detect.height}