mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-08 12:15:25 +03:00
Get live mode working for jsmpeg
This commit is contained in:
parent
30c9a958f2
commit
68a74cad04
@ -29,7 +29,7 @@ export default function Chip({
|
|||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
ref={nodeRef}
|
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}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import JSMpeg from "@cycjimmy/jsmpeg-player";
|
|||||||
import { useEffect, useMemo, useRef } from "react";
|
import { useEffect, useMemo, useRef } from "react";
|
||||||
|
|
||||||
type JSMpegPlayerProps = {
|
type JSMpegPlayerProps = {
|
||||||
|
className?: string;
|
||||||
camera: string;
|
camera: string;
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
@ -14,11 +15,13 @@ export default function JSMpegPlayer({
|
|||||||
camera,
|
camera,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
|
className,
|
||||||
}: JSMpegPlayerProps) {
|
}: JSMpegPlayerProps) {
|
||||||
const url = `${baseUrl.replace(/^http/, "ws")}live/jsmpeg/${camera}`;
|
const url = `${baseUrl.replace(/^http/, "ws")}live/jsmpeg/${camera}`;
|
||||||
const playerRef = useRef<HTMLDivElement | null>(null);
|
const playerRef = useRef<HTMLDivElement | null>(null);
|
||||||
const containerRef = 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.
|
// Add scrollbar width (when visible) to the available observer width to eliminate screen juddering.
|
||||||
// https://github.com/blakeblackshear/frigate/issues/1657
|
// https://github.com/blakeblackshear/frigate/issues/1657
|
||||||
@ -34,6 +37,11 @@ export default function JSMpegPlayer({
|
|||||||
const scaledHeight = useMemo(() => {
|
const scaledHeight = useMemo(() => {
|
||||||
const scaledHeight = Math.floor(availableWidth / aspectRatio);
|
const scaledHeight = Math.floor(availableWidth / aspectRatio);
|
||||||
const finalHeight = Math.min(scaledHeight, height);
|
const finalHeight = Math.min(scaledHeight, height);
|
||||||
|
console.log(`${containerWidth} / ${aspectRatio} -< ${containerHeight}`);
|
||||||
|
|
||||||
|
if (containerHeight < finalHeight) {
|
||||||
|
return containerHeight;
|
||||||
|
}
|
||||||
|
|
||||||
if (finalHeight > 0) {
|
if (finalHeight > 0) {
|
||||||
return finalHeight;
|
return finalHeight;
|
||||||
@ -79,7 +87,7 @@ export default function JSMpegPlayer({
|
|||||||
}, [url]);
|
}, [url]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={containerRef}>
|
<div className={className} ref={containerRef}>
|
||||||
<div
|
<div
|
||||||
ref={playerRef}
|
ref={playerRef}
|
||||||
className={`jsmpeg`}
|
className={`jsmpeg`}
|
||||||
|
|||||||
@ -33,7 +33,7 @@ type Options = { [key: string]: boolean };
|
|||||||
export default function LivePlayer({
|
export default function LivePlayer({
|
||||||
className,
|
className,
|
||||||
cameraConfig,
|
cameraConfig,
|
||||||
liveMode = "mse",
|
liveMode = "jsmpeg",
|
||||||
showStillWithoutActivity = true,
|
showStillWithoutActivity = true,
|
||||||
}: LivePlayerProps) {
|
}: LivePlayerProps) {
|
||||||
// camera activity
|
// camera activity
|
||||||
@ -43,6 +43,10 @@ export default function LivePlayer({
|
|||||||
const [liveReady, setLiveReady] = useState(false);
|
const [liveReady, setLiveReady] = useState(false);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!liveReady) {
|
if (!liveReady) {
|
||||||
|
if (activeMotion && liveMode == "jsmpeg") {
|
||||||
|
setLiveReady(true);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,6 +119,7 @@ export default function LivePlayer({
|
|||||||
} else if (liveMode == "jsmpeg") {
|
} else if (liveMode == "jsmpeg") {
|
||||||
player = (
|
player = (
|
||||||
<JSMpegPlayer
|
<JSMpegPlayer
|
||||||
|
className="w-full flex justify-center"
|
||||||
camera={cameraConfig.name}
|
camera={cameraConfig.name}
|
||||||
width={cameraConfig.detect.width}
|
width={cameraConfig.detect.width}
|
||||||
height={cameraConfig.detect.height}
|
height={cameraConfig.detect.height}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user