2024-02-07 00:30:41 +03:00
|
|
|
import { baseUrl } from "@/api/baseUrl";
|
2023-12-16 02:24:50 +03:00
|
|
|
import LivePlayer from "@/components/player/LivePlayer";
|
2023-12-08 16:33:22 +03:00
|
|
|
import Heading from "@/components/ui/heading";
|
2024-02-07 00:30:41 +03:00
|
|
|
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
|
2023-12-16 02:24:50 +03:00
|
|
|
import { usePersistence } from "@/hooks/use-persistence";
|
2024-02-07 00:30:41 +03:00
|
|
|
import { Event as FrigateEvent } from "@/types/event";
|
|
|
|
|
import { CameraConfig, FrigateConfig } from "@/types/frigateConfig";
|
2023-12-16 02:24:50 +03:00
|
|
|
import { useMemo, useState } from "react";
|
2024-02-07 00:30:41 +03:00
|
|
|
import { LuStar } from "react-icons/lu";
|
2023-12-16 17:40:00 +03:00
|
|
|
import { useParams } from "react-router-dom";
|
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-02-07 00:30:41 +03:00
|
|
|
// recent events
|
2023-12-16 17:40:00 +03:00
|
|
|
|
2024-02-07 00:30:41 +03:00
|
|
|
const now = new Date();
|
|
|
|
|
now.setHours(now.getHours() - 4, 0, 0, 0);
|
|
|
|
|
const recentTimestamp = now.getTime() / 1000;
|
|
|
|
|
const { data: events, mutate: updateEvents } = useSWR<FrigateEvent[]>([
|
|
|
|
|
"events",
|
|
|
|
|
{ limit: 10, after: recentTimestamp },
|
|
|
|
|
]);
|
2024-02-01 15:44:10 +03:00
|
|
|
|
2024-02-07 00:30:41 +03:00
|
|
|
// camera live views
|
2023-12-16 02:24:50 +03:00
|
|
|
|
2024-02-07 00:30:41 +03:00
|
|
|
const enabledCameras = useMemo<CameraConfig[]>(() => {
|
|
|
|
|
if (!config) {
|
|
|
|
|
return [];
|
2023-12-16 02:24:50 +03:00
|
|
|
}
|
|
|
|
|
|
2024-02-07 00:30:41 +03:00
|
|
|
return Object.values(config.cameras);
|
|
|
|
|
}, [config]);
|
2023-12-16 02:24:50 +03:00
|
|
|
|
2023-12-08 16:33:22 +03:00
|
|
|
return (
|
2024-02-07 00:30:41 +03:00
|
|
|
<>
|
|
|
|
|
{events && events.length > 0 && (
|
|
|
|
|
<ScrollArea>
|
|
|
|
|
<div className="flex">
|
|
|
|
|
{events.map((event) => {
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
className="relative rounded min-w-[125px] h-[125px] bg-contain bg-no-repeat bg-center mr-4"
|
|
|
|
|
style={{
|
|
|
|
|
backgroundImage: `url(${baseUrl}api/events/${event.id}/thumbnail.jpg)`,
|
|
|
|
|
}}
|
2024-01-31 15:29:18 +03:00
|
|
|
>
|
2024-02-07 00:30:41 +03:00
|
|
|
<LuStar
|
|
|
|
|
className="h-6 w-6 text-yellow-300 absolute top-1 right-1 cursor-pointer"
|
|
|
|
|
//onClick={(e: Event) => onSave(e)}
|
|
|
|
|
fill={event.retain_indefinitely ? "currentColor" : "none"}
|
|
|
|
|
/>
|
|
|
|
|
{event.end_time ? null : (
|
|
|
|
|
<div className="bg-slate-300 dark:bg-slate-700 absolute bottom-0 text-center w-full uppercase text-sm rounded-bl">
|
|
|
|
|
In progress
|
|
|
|
|
</div>
|
2024-01-31 15:29:18 +03:00
|
|
|
)}
|
2024-02-07 00:30:41 +03:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
})}
|
2024-01-31 15:29:18 +03:00
|
|
|
</div>
|
2024-02-07 00:30:41 +03:00
|
|
|
<ScrollBar orientation="horizontal" />
|
|
|
|
|
</ScrollArea>
|
2023-12-16 02:24:50 +03:00
|
|
|
)}
|
2024-02-07 00:30:41 +03:00
|
|
|
|
|
|
|
|
<div className="mt-4 grid grid-cols-1 md:grid-cols-2 2xl:grid-cols-3 gap-4">
|
|
|
|
|
{enabledCameras.map((camera) => {
|
|
|
|
|
return (
|
|
|
|
|
<LivePlayer
|
|
|
|
|
className=" rounded-2xl overflow-hidden"
|
|
|
|
|
cameraConfig={camera}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
2023-12-08 16:33:22 +03:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default Live;
|