mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-08 20:25:26 +03:00
Create live mode hook and make sure jsmpeg can be used
This commit is contained in:
parent
68a74cad04
commit
3e1185dfb0
@ -16,15 +16,15 @@ import { BsSoundwave } from "react-icons/bs";
|
|||||||
import Chip from "../Chip";
|
import Chip from "../Chip";
|
||||||
import useCameraActivity from "@/hooks/use-camera-activity";
|
import useCameraActivity from "@/hooks/use-camera-activity";
|
||||||
import { useRecordingsState } from "@/api/ws";
|
import { useRecordingsState } from "@/api/ws";
|
||||||
|
import { LivePlayerMode } from "@/types/live";
|
||||||
|
import useCameraLiveMode from "@/hooks/use-camera-live-mode";
|
||||||
|
|
||||||
const emptyObject = Object.freeze({});
|
const emptyObject = Object.freeze({});
|
||||||
|
|
||||||
type LivePlayerMode = "webrtc" | "mse" | "jsmpeg" | "debug";
|
|
||||||
|
|
||||||
type LivePlayerProps = {
|
type LivePlayerProps = {
|
||||||
className?: string;
|
className?: string;
|
||||||
cameraConfig: CameraConfig;
|
cameraConfig: CameraConfig;
|
||||||
liveMode?: LivePlayerMode;
|
preferredLiveMode?: LivePlayerMode;
|
||||||
showStillWithoutActivity?: boolean;
|
showStillWithoutActivity?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -33,13 +33,15 @@ type Options = { [key: string]: boolean };
|
|||||||
export default function LivePlayer({
|
export default function LivePlayer({
|
||||||
className,
|
className,
|
||||||
cameraConfig,
|
cameraConfig,
|
||||||
liveMode = "jsmpeg",
|
preferredLiveMode,
|
||||||
showStillWithoutActivity = true,
|
showStillWithoutActivity = true,
|
||||||
}: LivePlayerProps) {
|
}: LivePlayerProps) {
|
||||||
// camera activity
|
// camera activity
|
||||||
const { activeMotion, activeAudio, activeTracking } =
|
const { activeMotion, activeAudio, activeTracking } =
|
||||||
useCameraActivity(cameraConfig);
|
useCameraActivity(cameraConfig);
|
||||||
|
|
||||||
|
const liveMode = useCameraLiveMode(cameraConfig, preferredLiveMode);
|
||||||
|
|
||||||
const [liveReady, setLiveReady] = useState(false);
|
const [liveReady, setLiveReady] = useState(false);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!liveReady) {
|
if (!liveReady) {
|
||||||
|
|||||||
49
web/src/hooks/use-camera-live-mode.ts
Normal file
49
web/src/hooks/use-camera-live-mode.ts
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import { CameraConfig, FrigateConfig } from "@/types/frigateConfig";
|
||||||
|
import { useMemo } from "react";
|
||||||
|
import useSWR from "swr";
|
||||||
|
import { usePersistence } from "./use-persistence";
|
||||||
|
import { LivePlayerMode } from "@/types/live";
|
||||||
|
|
||||||
|
export default function useCameraLiveMode(
|
||||||
|
cameraConfig: CameraConfig,
|
||||||
|
preferredMode?: string
|
||||||
|
): LivePlayerMode {
|
||||||
|
const { data: config } = useSWR<FrigateConfig>("config");
|
||||||
|
|
||||||
|
const restreamEnabled = useMemo(() => {
|
||||||
|
if (!config) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
cameraConfig &&
|
||||||
|
Object.keys(config.go2rtc.streams || {}).includes(
|
||||||
|
cameraConfig.live.stream_name
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}, [config, cameraConfig]);
|
||||||
|
const defaultLiveMode = useMemo(() => {
|
||||||
|
if (config && cameraConfig) {
|
||||||
|
if (restreamEnabled) {
|
||||||
|
return cameraConfig.ui.live_mode || config?.ui.live_mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "jsmpeg";
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}, [cameraConfig, restreamEnabled]);
|
||||||
|
const [viewSource] = usePersistence(
|
||||||
|
`${cameraConfig.name}-source`,
|
||||||
|
defaultLiveMode
|
||||||
|
);
|
||||||
|
|
||||||
|
if (
|
||||||
|
restreamEnabled &&
|
||||||
|
(preferredMode == "mse" || preferredMode == "webrtc")
|
||||||
|
) {
|
||||||
|
return preferredMode;
|
||||||
|
} else {
|
||||||
|
return viewSource;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -87,6 +87,7 @@ function Live() {
|
|||||||
key={camera.name}
|
key={camera.name}
|
||||||
className={`mb-2 md:mb-0 rounded-2xl bg-black ${grow}`}
|
className={`mb-2 md:mb-0 rounded-2xl bg-black ${grow}`}
|
||||||
cameraConfig={camera}
|
cameraConfig={camera}
|
||||||
|
preferredLiveMode="mse"
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
1
web/src/types/live.ts
Normal file
1
web/src/types/live.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export type LivePlayerMode = "webrtc" | "mse" | "jsmpeg" | "debug";
|
||||||
Loading…
Reference in New Issue
Block a user