2024-03-15 19:46:17 +01:00
|
|
|
import {
|
|
|
|
useHashState,
|
2024-03-14 15:27:27 +01:00
|
|
|
usePersistedOverlayState,
|
|
|
|
} from "@/hooks/use-overlay-state";
|
2023-12-16 00:24:50 +01:00
|
|
|
import { FrigateConfig } from "@/types/frigateConfig";
|
2024-03-16 00:28:32 +01:00
|
|
|
import LiveBirdseyeView from "@/views/live/LiveBirdseyeView";
|
2024-03-02 01:43:02 +01:00
|
|
|
import LiveCameraView from "@/views/live/LiveCameraView";
|
|
|
|
import LiveDashboardView from "@/views/live/LiveDashboardView";
|
2024-04-12 14:31:30 +02:00
|
|
|
import { useEffect, useMemo } from "react";
|
2023-12-16 00:24:50 +01:00
|
|
|
import useSWR from "swr";
|
2023-12-08 14:33:22 +01:00
|
|
|
|
|
|
|
function Live() {
|
2023-12-16 00:24:50 +01:00
|
|
|
const { data: config } = useSWR<FrigateConfig>("config");
|
2024-03-05 00:18:30 +01:00
|
|
|
|
2024-04-12 14:31:30 +02:00
|
|
|
// selection
|
|
|
|
|
2024-03-15 19:46:17 +01:00
|
|
|
const [selectedCameraName, setSelectedCameraName] = useHashState();
|
2024-03-15 15:59:41 +01:00
|
|
|
const [cameraGroup] = usePersistedOverlayState(
|
|
|
|
"cameraGroup",
|
|
|
|
"default" as string,
|
|
|
|
);
|
2023-12-16 00:24:50 +01:00
|
|
|
|
2024-04-12 14:31:30 +02:00
|
|
|
// document title
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (selectedCameraName) {
|
|
|
|
const capitalized = selectedCameraName
|
|
|
|
.split("_")
|
|
|
|
.map((text) => text[0].toUpperCase() + text.substring(1));
|
|
|
|
document.title = `${capitalized.join(" ")} - Live - Frigate`;
|
|
|
|
} else if (cameraGroup && cameraGroup != "default") {
|
|
|
|
document.title = `${cameraGroup[0].toUpperCase()}${cameraGroup.substring(1)} - Live - Frigate`;
|
|
|
|
} else {
|
|
|
|
document.title = "Live - Frigate";
|
|
|
|
}
|
|
|
|
}, [cameraGroup, selectedCameraName]);
|
|
|
|
|
|
|
|
// settings
|
|
|
|
|
2024-03-12 20:53:01 +01:00
|
|
|
const includesBirdseye = useMemo(() => {
|
2024-04-26 01:19:31 +02:00
|
|
|
if (
|
|
|
|
config &&
|
|
|
|
Object.keys(config.camera_groups).length &&
|
|
|
|
cameraGroup &&
|
|
|
|
config.camera_groups[cameraGroup] &&
|
|
|
|
cameraGroup != "default"
|
|
|
|
) {
|
2024-03-12 20:53:01 +01:00
|
|
|
return config.camera_groups[cameraGroup].cameras.includes("birdseye");
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}, [config, cameraGroup]);
|
|
|
|
|
2024-02-10 13:30:53 +01:00
|
|
|
const cameras = useMemo(() => {
|
|
|
|
if (!config) {
|
|
|
|
return [];
|
2023-12-16 00:24:50 +01:00
|
|
|
}
|
|
|
|
|
2024-04-26 01:19:31 +02:00
|
|
|
if (
|
|
|
|
Object.keys(config.camera_groups).length &&
|
|
|
|
cameraGroup &&
|
|
|
|
config.camera_groups[cameraGroup] &&
|
|
|
|
cameraGroup != "default"
|
|
|
|
) {
|
2024-03-05 00:18:30 +01:00
|
|
|
const group = config.camera_groups[cameraGroup];
|
|
|
|
return Object.values(config.cameras)
|
|
|
|
.filter((conf) => conf.enabled && group.cameras.includes(conf.name))
|
|
|
|
.sort((aConf, bConf) => aConf.ui.order - bConf.ui.order);
|
|
|
|
}
|
|
|
|
|
2024-02-10 13:30:53 +01:00
|
|
|
return Object.values(config.cameras)
|
|
|
|
.filter((conf) => conf.ui.dashboard && conf.enabled)
|
|
|
|
.sort((aConf, bConf) => aConf.ui.order - bConf.ui.order);
|
2024-03-05 00:18:30 +01:00
|
|
|
}, [config, cameraGroup]);
|
2023-12-16 00:24:50 +01:00
|
|
|
|
2024-03-02 01:43:02 +01:00
|
|
|
const selectedCamera = useMemo(
|
|
|
|
() => cameras.find((cam) => cam.name == selectedCameraName),
|
|
|
|
[cameras, selectedCameraName],
|
|
|
|
);
|
2024-02-13 02:28:36 +01:00
|
|
|
|
2024-03-16 00:28:32 +01:00
|
|
|
if (selectedCameraName == "birdseye") {
|
|
|
|
return <LiveBirdseyeView />;
|
|
|
|
}
|
|
|
|
|
2024-03-02 01:43:02 +01:00
|
|
|
if (selectedCamera) {
|
|
|
|
return <LiveCameraView camera={selectedCamera} />;
|
|
|
|
}
|
2024-02-13 02:28:36 +01:00
|
|
|
|
2023-12-08 14:33:22 +01:00
|
|
|
return (
|
2024-03-02 01:43:02 +01:00
|
|
|
<LiveDashboardView
|
|
|
|
cameras={cameras}
|
2024-03-12 20:53:01 +01:00
|
|
|
includeBirdseye={includesBirdseye}
|
2024-03-02 01:43:02 +01:00
|
|
|
onSelectCamera={setSelectedCameraName}
|
|
|
|
/>
|
2023-12-08 14:33:22 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Live;
|