2023-12-20 15:34:27 +01:00
|
|
|
import BirdseyeLivePlayer from "@/components/player/BirdseyeLivePlayer";
|
2023-12-16 00:24:50 +01:00
|
|
|
import LivePlayer from "@/components/player/LivePlayer";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
import {
|
|
|
|
DropdownMenu,
|
|
|
|
DropdownMenuContent,
|
|
|
|
DropdownMenuLabel,
|
|
|
|
DropdownMenuRadioGroup,
|
|
|
|
DropdownMenuRadioItem,
|
|
|
|
DropdownMenuSeparator,
|
|
|
|
DropdownMenuTrigger,
|
|
|
|
} from "@/components/ui/dropdown-menu";
|
2023-12-08 14:33:22 +01:00
|
|
|
import Heading from "@/components/ui/heading";
|
2023-12-16 00:24:50 +01:00
|
|
|
import { usePersistence } from "@/hooks/use-persistence";
|
|
|
|
import { FrigateConfig } from "@/types/frigateConfig";
|
|
|
|
import { useMemo, useState } from "react";
|
2023-12-16 15:40:00 +01:00
|
|
|
import { useParams } from "react-router-dom";
|
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");
|
2023-12-16 15:40:00 +01:00
|
|
|
const { camera: openedCamera } = useParams();
|
2023-12-16 00:24:50 +01:00
|
|
|
|
2023-12-16 15:40:00 +01:00
|
|
|
const [camera, setCamera] = useState<string>(
|
2023-12-20 15:34:27 +01:00
|
|
|
openedCamera ?? (config?.birdseye.enabled ? "birdseye" : "Select A Camera")
|
2023-12-16 15:40:00 +01:00
|
|
|
);
|
2023-12-16 00:24:50 +01:00
|
|
|
const cameraConfig = useMemo(() => {
|
2023-12-20 15:34:27 +01:00
|
|
|
return camera == "birdseye" ? undefined : config?.cameras[camera];
|
2023-12-16 00:24:50 +01:00
|
|
|
}, [camera, config]);
|
2023-12-16 15:40:00 +01:00
|
|
|
const sortedCameras = useMemo(() => {
|
|
|
|
if (!config) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2023-12-20 15:34:27 +01:00
|
|
|
return Object.values(config.cameras).sort(
|
|
|
|
(aConf, bConf) => aConf.ui.order - bConf.ui.order
|
|
|
|
);
|
2023-12-16 15:40:00 +01:00
|
|
|
}, [config]);
|
2023-12-16 00:24:50 +01:00
|
|
|
const restreamEnabled = useMemo(() => {
|
|
|
|
return (
|
|
|
|
config &&
|
|
|
|
cameraConfig &&
|
|
|
|
Object.keys(config.go2rtc.streams || {}).includes(
|
|
|
|
cameraConfig.live.stream_name
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}, [config, cameraConfig]);
|
|
|
|
const defaultLiveMode = useMemo(() => {
|
|
|
|
if (cameraConfig) {
|
|
|
|
if (restreamEnabled) {
|
2024-01-31 13:29:18 +01:00
|
|
|
return cameraConfig.ui.live_mode || config?.ui.live_mode;
|
2023-12-16 00:24:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return "jsmpeg";
|
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
}, [cameraConfig, restreamEnabled]);
|
|
|
|
const [viewSource, setViewSource, sourceIsLoaded] = usePersistence(
|
|
|
|
`${camera}-source`,
|
2023-12-20 15:34:27 +01:00
|
|
|
camera == "birdseye" ? "jsmpeg" : defaultLiveMode
|
2023-12-16 00:24:50 +01:00
|
|
|
);
|
|
|
|
|
2023-12-08 14:33:22 +01:00
|
|
|
return (
|
2023-12-16 00:24:50 +01:00
|
|
|
<div className=" w-full">
|
|
|
|
<div className="flex justify-between">
|
|
|
|
<Heading as="h2">Live</Heading>
|
2024-01-31 13:29:18 +01:00
|
|
|
<div className="flex">
|
|
|
|
<div className="mx-1">
|
|
|
|
<DropdownMenu>
|
|
|
|
<DropdownMenuTrigger asChild>
|
|
|
|
<Button className="capitalize" variant="outline">
|
|
|
|
{camera?.replaceAll("_", " ") || "Select A Camera"}
|
|
|
|
</Button>
|
|
|
|
</DropdownMenuTrigger>
|
|
|
|
<DropdownMenuContent>
|
|
|
|
<DropdownMenuLabel>Select A Camera</DropdownMenuLabel>
|
|
|
|
<DropdownMenuSeparator />
|
|
|
|
<DropdownMenuRadioGroup
|
|
|
|
value={camera}
|
|
|
|
onValueChange={setCamera}
|
|
|
|
>
|
|
|
|
{config?.birdseye.enabled && (
|
|
|
|
<DropdownMenuRadioItem value="birdseye">
|
|
|
|
Birdseye
|
|
|
|
</DropdownMenuRadioItem>
|
|
|
|
)}
|
|
|
|
{sortedCameras.map((item) => (
|
|
|
|
<DropdownMenuRadioItem
|
|
|
|
className="capitalize"
|
|
|
|
key={item.name}
|
|
|
|
value={item.name}
|
|
|
|
>
|
|
|
|
{item.name.replaceAll("_", " ")}
|
|
|
|
</DropdownMenuRadioItem>
|
|
|
|
))}
|
|
|
|
</DropdownMenuRadioGroup>
|
|
|
|
</DropdownMenuContent>
|
|
|
|
</DropdownMenu>
|
|
|
|
</div>
|
|
|
|
<div className="mx-1">
|
|
|
|
<DropdownMenu>
|
|
|
|
<DropdownMenuTrigger asChild>
|
|
|
|
<Button className="capitalize" variant="outline">
|
|
|
|
{viewSource || defaultLiveMode || "Select A Live Mode"}
|
|
|
|
</Button>
|
|
|
|
</DropdownMenuTrigger>
|
|
|
|
<DropdownMenuContent>
|
|
|
|
<DropdownMenuLabel>Select A Live Mode</DropdownMenuLabel>
|
|
|
|
<DropdownMenuSeparator />
|
|
|
|
<DropdownMenuRadioGroup
|
|
|
|
value={`${viewSource}`}
|
|
|
|
onValueChange={setViewSource}
|
|
|
|
>
|
|
|
|
{restreamEnabled && (
|
|
|
|
<DropdownMenuRadioItem value="webrtc">
|
|
|
|
Webrtc
|
|
|
|
</DropdownMenuRadioItem>
|
|
|
|
)}
|
|
|
|
{restreamEnabled && (
|
|
|
|
<DropdownMenuRadioItem value="mse">
|
|
|
|
MSE
|
|
|
|
</DropdownMenuRadioItem>
|
|
|
|
)}
|
|
|
|
<DropdownMenuRadioItem value="jsmpeg">
|
|
|
|
Jsmpeg
|
2023-12-16 00:24:50 +01:00
|
|
|
</DropdownMenuRadioItem>
|
2024-01-31 13:29:18 +01:00
|
|
|
{camera != "birdseye" && (
|
|
|
|
<DropdownMenuRadioItem value="debug">
|
|
|
|
Debug
|
|
|
|
</DropdownMenuRadioItem>
|
|
|
|
)}
|
|
|
|
</DropdownMenuRadioGroup>
|
|
|
|
</DropdownMenuContent>
|
|
|
|
</DropdownMenu>
|
|
|
|
</div>
|
2023-12-16 00:24:50 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-12-20 15:34:27 +01:00
|
|
|
{config && camera == "birdseye" && sourceIsLoaded && (
|
|
|
|
<BirdseyeLivePlayer
|
|
|
|
birdseyeConfig={config?.birdseye}
|
|
|
|
liveMode={`${viewSource ?? defaultLiveMode}`}
|
|
|
|
/>
|
|
|
|
)}
|
2023-12-16 00:24:50 +01:00
|
|
|
{cameraConfig && sourceIsLoaded && (
|
|
|
|
<LivePlayer
|
|
|
|
liveMode={`${viewSource ?? defaultLiveMode}`}
|
|
|
|
cameraConfig={cameraConfig}
|
|
|
|
/>
|
|
|
|
)}
|
2023-12-08 14:33:22 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Live;
|