2024-03-15 21:46:17 +03:00
|
|
|
import {
|
|
|
|
|
useHashState,
|
2024-03-14 17:27:27 +03:00
|
|
|
usePersistedOverlayState,
|
|
|
|
|
} from "@/hooks/use-overlay-state";
|
2023-12-16 02:24:50 +03:00
|
|
|
import { FrigateConfig } from "@/types/frigateConfig";
|
2024-03-16 02:28:32 +03:00
|
|
|
import LiveBirdseyeView from "@/views/live/LiveBirdseyeView";
|
2024-03-02 03:43:02 +03:00
|
|
|
import LiveCameraView from "@/views/live/LiveCameraView";
|
|
|
|
|
import LiveDashboardView from "@/views/live/LiveDashboardView";
|
2024-04-12 15:31:30 +03:00
|
|
|
import { useEffect, useMemo } from "react";
|
2023-12-16 02:24:50 +03:00
|
|
|
import useSWR from "swr";
|
2023-12-08 16:33:22 +03:00
|
|
|
|
|
|
|
|
function Live() {
|
2023-12-16 02:24:50 +03:00
|
|
|
const { data: config } = useSWR<FrigateConfig>("config");
|
2024-03-05 02:18:30 +03:00
|
|
|
|
2024-04-12 15:31:30 +03:00
|
|
|
// selection
|
|
|
|
|
|
2024-03-15 21:46:17 +03:00
|
|
|
const [selectedCameraName, setSelectedCameraName] = useHashState();
|
2024-03-15 17:59:41 +03:00
|
|
|
const [cameraGroup] = usePersistedOverlayState(
|
|
|
|
|
"cameraGroup",
|
|
|
|
|
"default" as string,
|
|
|
|
|
);
|
2023-12-16 02:24:50 +03:00
|
|
|
|
2024-04-12 15:31:30 +03: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 22:53:01 +03:00
|
|
|
const includesBirdseye = useMemo(() => {
|
2024-04-26 02:19:31 +03:00
|
|
|
if (
|
|
|
|
|
config &&
|
|
|
|
|
Object.keys(config.camera_groups).length &&
|
|
|
|
|
cameraGroup &&
|
|
|
|
|
config.camera_groups[cameraGroup] &&
|
|
|
|
|
cameraGroup != "default"
|
|
|
|
|
) {
|
2024-03-12 22:53:01 +03:00
|
|
|
return config.camera_groups[cameraGroup].cameras.includes("birdseye");
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}, [config, cameraGroup]);
|
|
|
|
|
|
2024-02-10 15:30:53 +03:00
|
|
|
const cameras = useMemo(() => {
|
|
|
|
|
if (!config) {
|
|
|
|
|
return [];
|
2023-12-16 02:24:50 +03:00
|
|
|
}
|
|
|
|
|
|
2024-04-26 02:19:31 +03:00
|
|
|
if (
|
|
|
|
|
Object.keys(config.camera_groups).length &&
|
|
|
|
|
cameraGroup &&
|
|
|
|
|
config.camera_groups[cameraGroup] &&
|
|
|
|
|
cameraGroup != "default"
|
|
|
|
|
) {
|
2024-03-05 02:18:30 +03: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 15:30:53 +03: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 02:18:30 +03:00
|
|
|
}, [config, cameraGroup]);
|
2023-12-16 02:24:50 +03:00
|
|
|
|
2024-03-02 03:43:02 +03:00
|
|
|
const selectedCamera = useMemo(
|
|
|
|
|
() => cameras.find((cam) => cam.name == selectedCameraName),
|
|
|
|
|
[cameras, selectedCameraName],
|
|
|
|
|
);
|
2024-02-13 04:28:36 +03:00
|
|
|
|
2024-03-16 02:28:32 +03:00
|
|
|
if (selectedCameraName == "birdseye") {
|
|
|
|
|
return <LiveBirdseyeView />;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-02 03:43:02 +03:00
|
|
|
if (selectedCamera) {
|
2024-05-19 15:39:17 +03:00
|
|
|
return <LiveCameraView config={config} camera={selectedCamera} />;
|
2024-03-02 03:43:02 +03:00
|
|
|
}
|
2024-02-13 04:28:36 +03:00
|
|
|
|
2023-12-08 16:33:22 +03:00
|
|
|
return (
|
2024-03-02 03:43:02 +03:00
|
|
|
<LiveDashboardView
|
|
|
|
|
cameras={cameras}
|
2024-05-07 17:28:10 +03:00
|
|
|
cameraGroup={cameraGroup}
|
2024-03-12 22:53:01 +03:00
|
|
|
includeBirdseye={includesBirdseye}
|
2024-03-02 03:43:02 +03:00
|
|
|
onSelectCamera={setSelectedCameraName}
|
|
|
|
|
/>
|
2023-12-08 16:33:22 +03:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default Live;
|