2024-03-02 03:43:02 +03:00
|
|
|
import { useFrigateReviews } from "@/api/ws";
|
|
|
|
|
import Logo from "@/components/Logo";
|
2024-03-05 02:18:30 +03:00
|
|
|
import { CameraGroupSelector } from "@/components/filter/CameraGroupSelector";
|
2024-03-21 04:46:45 +03:00
|
|
|
import { LiveGridIcon, LiveListIcon } from "@/components/icons/LiveIcons";
|
2024-03-27 00:03:58 +03:00
|
|
|
import { AnimatedEventCard } from "@/components/card/AnimatedEventCard";
|
2024-03-12 22:53:01 +03:00
|
|
|
import BirdseyeLivePlayer from "@/components/player/BirdseyeLivePlayer";
|
2024-03-02 03:43:02 +03:00
|
|
|
import LivePlayer from "@/components/player/LivePlayer";
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
|
2024-07-01 22:00:53 +03:00
|
|
|
import {
|
|
|
|
|
Tooltip,
|
|
|
|
|
TooltipContent,
|
|
|
|
|
TooltipProvider,
|
|
|
|
|
TooltipTrigger,
|
|
|
|
|
} from "@/components/ui/tooltip";
|
2024-03-02 03:43:02 +03:00
|
|
|
import { usePersistence } from "@/hooks/use-persistence";
|
2025-02-12 02:49:22 +03:00
|
|
|
import {
|
|
|
|
|
AllGroupsStreamingSettings,
|
|
|
|
|
CameraConfig,
|
|
|
|
|
FrigateConfig,
|
|
|
|
|
} from "@/types/frigateConfig";
|
2024-03-02 03:43:02 +03:00
|
|
|
import { ReviewSegment } from "@/types/review";
|
2025-11-21 02:50:17 +03:00
|
|
|
import {
|
|
|
|
|
useCallback,
|
|
|
|
|
useContext,
|
|
|
|
|
useEffect,
|
|
|
|
|
useMemo,
|
|
|
|
|
useRef,
|
|
|
|
|
useState,
|
|
|
|
|
} from "react";
|
2024-05-07 17:28:10 +03:00
|
|
|
import {
|
|
|
|
|
isDesktop,
|
|
|
|
|
isMobile,
|
|
|
|
|
isMobileOnly,
|
2024-05-08 15:53:22 +03:00
|
|
|
isTablet,
|
2024-05-07 17:28:10 +03:00
|
|
|
} from "react-device-detect";
|
2024-03-02 03:43:02 +03:00
|
|
|
import useSWR from "swr";
|
2024-05-07 17:28:10 +03:00
|
|
|
import DraggableGridLayout from "./DraggableGridLayout";
|
2024-05-08 15:53:22 +03:00
|
|
|
import { IoClose } from "react-icons/io5";
|
2024-05-10 19:54:37 +03:00
|
|
|
import { LuLayoutDashboard } from "react-icons/lu";
|
|
|
|
|
import { cn } from "@/lib/utils";
|
2025-02-10 19:42:35 +03:00
|
|
|
import {
|
|
|
|
|
AudioState,
|
|
|
|
|
LivePlayerError,
|
|
|
|
|
StatsState,
|
|
|
|
|
VolumeState,
|
|
|
|
|
} from "@/types/live";
|
2024-07-01 22:00:53 +03:00
|
|
|
import { FaCompress, FaExpand } from "react-icons/fa";
|
2024-08-17 21:16:48 +03:00
|
|
|
import useCameraLiveMode from "@/hooks/use-camera-live-mode";
|
2024-07-01 22:00:53 +03:00
|
|
|
import { useResizeObserver } from "@/hooks/resize-observer";
|
2025-02-10 19:42:35 +03:00
|
|
|
import LiveContextMenu from "@/components/menu/LiveContextMenu";
|
2025-02-12 02:49:22 +03:00
|
|
|
import { useStreamingSettings } from "@/context/streaming-settings-provider";
|
2025-03-16 18:36:20 +03:00
|
|
|
import { useTranslation } from "react-i18next";
|
2025-10-12 00:40:39 +03:00
|
|
|
import { EmptyCard } from "@/components/card/EmptyCard";
|
|
|
|
|
import { BsFillCameraVideoOffFill } from "react-icons/bs";
|
2025-11-21 02:50:17 +03:00
|
|
|
import { AuthContext } from "@/context/auth-context";
|
2025-11-27 16:58:35 +03:00
|
|
|
import { useIsAdmin } from "@/hooks/use-is-admin";
|
2024-03-02 03:43:02 +03:00
|
|
|
|
|
|
|
|
type LiveDashboardViewProps = {
|
|
|
|
|
cameras: CameraConfig[];
|
2024-07-15 18:34:41 +03:00
|
|
|
cameraGroup: string;
|
2024-03-12 22:53:01 +03:00
|
|
|
includeBirdseye: boolean;
|
2024-03-02 03:43:02 +03:00
|
|
|
onSelectCamera: (camera: string) => void;
|
2024-05-31 15:58:33 +03:00
|
|
|
fullscreen: boolean;
|
|
|
|
|
toggleFullscreen: () => void;
|
2024-03-02 03:43:02 +03:00
|
|
|
};
|
|
|
|
|
export default function LiveDashboardView({
|
|
|
|
|
cameras,
|
2024-05-07 17:28:10 +03:00
|
|
|
cameraGroup,
|
2024-03-12 22:53:01 +03:00
|
|
|
includeBirdseye,
|
2024-03-02 03:43:02 +03:00
|
|
|
onSelectCamera,
|
2024-05-31 15:58:33 +03:00
|
|
|
fullscreen,
|
|
|
|
|
toggleFullscreen,
|
2024-03-02 03:43:02 +03:00
|
|
|
}: LiveDashboardViewProps) {
|
2025-03-16 18:36:20 +03:00
|
|
|
const { t } = useTranslation(["views/live"]);
|
|
|
|
|
|
2024-03-12 22:53:01 +03:00
|
|
|
const { data: config } = useSWR<FrigateConfig>("config");
|
|
|
|
|
|
2024-03-02 03:43:02 +03:00
|
|
|
// layout
|
|
|
|
|
|
2024-05-07 17:28:10 +03:00
|
|
|
const [mobileLayout, setMobileLayout] = usePersistence<"grid" | "list">(
|
2024-03-02 03:43:02 +03:00
|
|
|
"live-layout",
|
|
|
|
|
isDesktop ? "grid" : "list",
|
|
|
|
|
);
|
|
|
|
|
|
2024-05-08 15:53:22 +03:00
|
|
|
const [isEditMode, setIsEditMode] = useState<boolean>(false);
|
|
|
|
|
const containerRef = useRef<HTMLDivElement>(null);
|
2024-06-02 06:13:37 +03:00
|
|
|
const birdseyeContainerRef = useRef<HTMLDivElement>(null);
|
2024-05-08 15:53:22 +03:00
|
|
|
|
2024-03-02 03:43:02 +03:00
|
|
|
// recent events
|
2024-05-29 17:01:39 +03:00
|
|
|
|
2024-07-11 18:25:33 +03:00
|
|
|
const eventUpdate = useFrigateReviews();
|
2024-07-15 18:34:41 +03:00
|
|
|
|
|
|
|
|
const alertCameras = useMemo(() => {
|
|
|
|
|
if (!config || cameraGroup == "default") {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (includeBirdseye && cameras.length == 0) {
|
|
|
|
|
return Object.values(config.cameras)
|
|
|
|
|
.filter((cam) => cam.birdseye.enabled)
|
|
|
|
|
.map((cam) => cam.name)
|
|
|
|
|
.join(",");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return cameras
|
|
|
|
|
.map((cam) => cam.name)
|
2024-07-16 14:50:58 +03:00
|
|
|
.filter((cam) => config.camera_groups[cameraGroup]?.cameras.includes(cam))
|
2024-07-15 18:34:41 +03:00
|
|
|
.join(",");
|
|
|
|
|
}, [cameras, cameraGroup, config, includeBirdseye]);
|
|
|
|
|
|
2024-03-02 03:43:02 +03:00
|
|
|
const { data: allEvents, mutate: updateEvents } = useSWR<ReviewSegment[]>([
|
|
|
|
|
"review",
|
2024-07-15 15:35:41 +03:00
|
|
|
{
|
|
|
|
|
limit: 10,
|
|
|
|
|
severity: "alert",
|
2024-07-15 18:34:41 +03:00
|
|
|
cameras: alertCameras,
|
2024-07-15 15:35:41 +03:00
|
|
|
},
|
2024-03-02 03:43:02 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (!eventUpdate) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if event is ended and was saved, update events list
|
2024-04-23 05:20:30 +03:00
|
|
|
if (eventUpdate.after.severity == "alert") {
|
2025-10-09 17:49:42 +03:00
|
|
|
if (
|
|
|
|
|
eventUpdate.type == "end" ||
|
|
|
|
|
eventUpdate.type == "new" ||
|
|
|
|
|
eventUpdate.type == "genai"
|
|
|
|
|
) {
|
2024-04-23 05:20:30 +03:00
|
|
|
setTimeout(
|
|
|
|
|
() => updateEvents(),
|
|
|
|
|
eventUpdate.type == "end" ? 1000 : 6000,
|
|
|
|
|
);
|
|
|
|
|
} else if (
|
|
|
|
|
eventUpdate.before.data.objects.length <
|
|
|
|
|
eventUpdate.after.data.objects.length
|
|
|
|
|
) {
|
|
|
|
|
setTimeout(() => updateEvents(), 5000);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-02 03:43:02 +03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}, [eventUpdate, updateEvents]);
|
|
|
|
|
|
|
|
|
|
const events = useMemo(() => {
|
|
|
|
|
if (!allEvents) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const date = new Date();
|
|
|
|
|
date.setHours(date.getHours() - 1);
|
|
|
|
|
const cutoff = date.getTime() / 1000;
|
|
|
|
|
return allEvents.filter((event) => event.start_time > cutoff);
|
|
|
|
|
}, [allEvents]);
|
|
|
|
|
|
|
|
|
|
// camera live views
|
|
|
|
|
|
2024-07-01 22:00:53 +03:00
|
|
|
const [{ height: containerHeight }] = useResizeObserver(containerRef);
|
|
|
|
|
|
|
|
|
|
const hasScrollbar = useMemo(() => {
|
|
|
|
|
if (containerHeight && containerRef.current) {
|
|
|
|
|
return (
|
|
|
|
|
containerRef.current.offsetHeight < containerRef.current.scrollHeight
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}, [containerRef, containerHeight]);
|
|
|
|
|
|
2024-03-02 03:43:02 +03:00
|
|
|
const [windowVisible, setWindowVisible] = useState(true);
|
|
|
|
|
const visibilityListener = useCallback(() => {
|
|
|
|
|
setWindowVisible(document.visibilityState == "visible");
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
addEventListener("visibilitychange", visibilityListener);
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
removeEventListener("visibilitychange", visibilityListener);
|
|
|
|
|
};
|
|
|
|
|
}, [visibilityListener]);
|
|
|
|
|
|
2024-03-25 23:56:13 +03:00
|
|
|
const [visibleCameras, setVisibleCameras] = useState<string[]>([]);
|
|
|
|
|
const visibleCameraObserver = useRef<IntersectionObserver | null>(null);
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const visibleCameras = new Set<string>();
|
|
|
|
|
visibleCameraObserver.current = new IntersectionObserver(
|
|
|
|
|
(entries) => {
|
|
|
|
|
entries.forEach((entry) => {
|
|
|
|
|
const camera = (entry.target as HTMLElement).dataset.camera;
|
|
|
|
|
|
|
|
|
|
if (!camera) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (entry.isIntersecting) {
|
|
|
|
|
visibleCameras.add(camera);
|
|
|
|
|
} else {
|
|
|
|
|
visibleCameras.delete(camera);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setVisibleCameras([...visibleCameras]);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
{ threshold: 0.5 },
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
visibleCameraObserver.current?.disconnect();
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
|
|
|
|
|
2025-02-12 02:49:22 +03:00
|
|
|
const [globalAutoLive] = usePersistence("autoLiveView", true);
|
2025-10-29 17:20:11 +03:00
|
|
|
const [displayCameraNames] = usePersistence("displayCameraNames", false);
|
2025-02-12 02:49:22 +03:00
|
|
|
|
|
|
|
|
const { allGroupsStreamingSettings, setAllGroupsStreamingSettings } =
|
|
|
|
|
useStreamingSettings();
|
|
|
|
|
|
|
|
|
|
const currentGroupStreamingSettings = useMemo(() => {
|
|
|
|
|
if (cameraGroup && cameraGroup != "default" && allGroupsStreamingSettings) {
|
|
|
|
|
return allGroupsStreamingSettings[cameraGroup];
|
|
|
|
|
}
|
|
|
|
|
}, [allGroupsStreamingSettings, cameraGroup]);
|
|
|
|
|
|
2024-03-25 23:56:13 +03:00
|
|
|
const cameraRef = useCallback(
|
|
|
|
|
(node: HTMLElement | null) => {
|
|
|
|
|
if (!visibleCameraObserver.current) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (node) visibleCameraObserver.current.observe(node);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
// no op
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// we need to listen on the value of the ref
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
[visibleCameraObserver.current],
|
|
|
|
|
);
|
|
|
|
|
|
2025-11-12 02:00:54 +03:00
|
|
|
const activeStreams = useMemo(() => {
|
|
|
|
|
const streams: { [cameraName: string]: string } = {};
|
|
|
|
|
cameras.forEach((camera) => {
|
|
|
|
|
const availableStreams = camera.live.streams || {};
|
|
|
|
|
const streamNameFromSettings =
|
|
|
|
|
currentGroupStreamingSettings?.[camera.name]?.streamName || "";
|
|
|
|
|
const streamExists =
|
|
|
|
|
streamNameFromSettings &&
|
|
|
|
|
Object.values(availableStreams).includes(streamNameFromSettings);
|
|
|
|
|
|
|
|
|
|
const streamName = streamExists
|
|
|
|
|
? streamNameFromSettings
|
|
|
|
|
: Object.values(availableStreams)[0] || "";
|
|
|
|
|
|
|
|
|
|
streams[camera.name] = streamName;
|
|
|
|
|
});
|
|
|
|
|
return streams;
|
|
|
|
|
}, [cameras, currentGroupStreamingSettings]);
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
preferredLiveModes,
|
|
|
|
|
setPreferredLiveModes,
|
|
|
|
|
resetPreferredLiveMode,
|
|
|
|
|
isRestreamedStates,
|
|
|
|
|
supportsAudioOutputStates,
|
|
|
|
|
} = useCameraLiveMode(cameras, windowVisible, activeStreams);
|
|
|
|
|
|
2024-03-12 22:53:01 +03:00
|
|
|
const birdseyeConfig = useMemo(() => config?.birdseye, [config]);
|
|
|
|
|
|
2024-06-30 15:04:45 +03:00
|
|
|
const handleError = useCallback(
|
|
|
|
|
(cameraName: string, error: LivePlayerError) => {
|
|
|
|
|
setPreferredLiveModes((prevModes) => {
|
|
|
|
|
const newModes = { ...prevModes };
|
|
|
|
|
if (error === "mse-decode") {
|
|
|
|
|
newModes[cameraName] = "webrtc";
|
|
|
|
|
} else {
|
|
|
|
|
newModes[cameraName] = "jsmpeg";
|
|
|
|
|
}
|
|
|
|
|
return newModes;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
[setPreferredLiveModes],
|
|
|
|
|
);
|
|
|
|
|
|
2025-02-10 19:42:35 +03:00
|
|
|
// audio states
|
|
|
|
|
|
|
|
|
|
const [audioStates, setAudioStates] = useState<AudioState>({});
|
|
|
|
|
const [volumeStates, setVolumeStates] = useState<VolumeState>({});
|
|
|
|
|
const [statsStates, setStatsStates] = useState<StatsState>({});
|
|
|
|
|
|
|
|
|
|
const toggleStats = (cameraName: string): void => {
|
|
|
|
|
setStatsStates((prev) => ({
|
|
|
|
|
...prev,
|
|
|
|
|
[cameraName]: !prev[cameraName],
|
|
|
|
|
}));
|
|
|
|
|
};
|
|
|
|
|
|
2025-02-12 02:49:22 +03:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (!allGroupsStreamingSettings) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const initialAudioStates: AudioState = {};
|
|
|
|
|
const initialVolumeStates: VolumeState = {};
|
|
|
|
|
|
|
|
|
|
Object.entries(allGroupsStreamingSettings).forEach(([_, groupSettings]) => {
|
2025-03-04 00:05:49 +03:00
|
|
|
if (groupSettings) {
|
|
|
|
|
Object.entries(groupSettings).forEach(([camera, cameraSettings]) => {
|
|
|
|
|
initialAudioStates[camera] = cameraSettings.playAudio ?? false;
|
|
|
|
|
initialVolumeStates[camera] = cameraSettings.volume ?? 1;
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-02-12 02:49:22 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
setAudioStates(initialAudioStates);
|
|
|
|
|
setVolumeStates(initialVolumeStates);
|
|
|
|
|
}, [allGroupsStreamingSettings]);
|
|
|
|
|
|
2025-02-10 19:42:35 +03:00
|
|
|
const toggleAudio = (cameraName: string): void => {
|
|
|
|
|
setAudioStates((prev) => ({
|
|
|
|
|
...prev,
|
|
|
|
|
[cameraName]: !prev[cameraName],
|
|
|
|
|
}));
|
|
|
|
|
};
|
|
|
|
|
|
2025-02-12 02:49:22 +03:00
|
|
|
const onSaveMuting = useCallback(
|
|
|
|
|
(playAudio: boolean) => {
|
|
|
|
|
if (
|
|
|
|
|
!cameraGroup ||
|
|
|
|
|
!allGroupsStreamingSettings ||
|
|
|
|
|
cameraGroup == "default"
|
|
|
|
|
) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const existingGroupSettings =
|
|
|
|
|
allGroupsStreamingSettings[cameraGroup] || {};
|
|
|
|
|
|
|
|
|
|
const updatedSettings: AllGroupsStreamingSettings = {
|
|
|
|
|
...Object.fromEntries(
|
|
|
|
|
Object.entries(allGroupsStreamingSettings || {}).filter(
|
|
|
|
|
([key]) => key !== cameraGroup,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
[cameraGroup]: {
|
|
|
|
|
...existingGroupSettings,
|
|
|
|
|
...Object.fromEntries(
|
|
|
|
|
Object.entries(existingGroupSettings).map(
|
|
|
|
|
([cameraName, settings]) => [
|
|
|
|
|
cameraName,
|
|
|
|
|
{
|
|
|
|
|
...settings,
|
|
|
|
|
playAudio: playAudio,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
setAllGroupsStreamingSettings?.(updatedSettings);
|
|
|
|
|
},
|
|
|
|
|
[cameraGroup, allGroupsStreamingSettings, setAllGroupsStreamingSettings],
|
|
|
|
|
);
|
|
|
|
|
|
2025-02-10 19:42:35 +03:00
|
|
|
const muteAll = (): void => {
|
|
|
|
|
const updatedStates: Record<string, boolean> = {};
|
|
|
|
|
visibleCameras.forEach((cameraName) => {
|
|
|
|
|
updatedStates[cameraName] = false;
|
|
|
|
|
});
|
|
|
|
|
setAudioStates(updatedStates);
|
2025-02-12 02:49:22 +03:00
|
|
|
onSaveMuting(false);
|
2025-02-10 19:42:35 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const unmuteAll = (): void => {
|
|
|
|
|
const updatedStates: Record<string, boolean> = {};
|
|
|
|
|
visibleCameras.forEach((cameraName) => {
|
|
|
|
|
updatedStates[cameraName] = true;
|
|
|
|
|
});
|
|
|
|
|
setAudioStates(updatedStates);
|
2025-02-12 02:49:22 +03:00
|
|
|
onSaveMuting(true);
|
2025-02-10 19:42:35 +03:00
|
|
|
};
|
|
|
|
|
|
2024-03-02 03:43:02 +03:00
|
|
|
return (
|
2024-05-16 19:51:57 +03:00
|
|
|
<div
|
2025-02-10 19:42:35 +03:00
|
|
|
className="scrollbar-container size-full select-none overflow-y-auto px-1 pt-2 md:p-2"
|
2024-05-16 19:51:57 +03:00
|
|
|
ref={containerRef}
|
|
|
|
|
>
|
2024-03-02 03:43:02 +03:00
|
|
|
{isMobile && (
|
2024-05-14 18:06:44 +03:00
|
|
|
<div className="relative flex h-11 items-center justify-between">
|
|
|
|
|
<Logo className="absolute inset-x-1/2 h-8 -translate-x-1/2" />
|
2024-04-26 02:19:31 +03:00
|
|
|
<div className="max-w-[45%]">
|
|
|
|
|
<CameraGroupSelector />
|
|
|
|
|
</div>
|
2024-05-08 15:53:22 +03:00
|
|
|
{(!cameraGroup || cameraGroup == "default" || isMobileOnly) && (
|
|
|
|
|
<div className="flex items-center gap-1">
|
|
|
|
|
<Button
|
|
|
|
|
className={`p-1 ${
|
|
|
|
|
mobileLayout == "grid"
|
2024-05-14 18:06:44 +03:00
|
|
|
? "bg-blue-900 bg-opacity-60 focus:bg-blue-900 focus:bg-opacity-60"
|
2024-05-08 15:53:22 +03:00
|
|
|
: "bg-secondary"
|
|
|
|
|
}`}
|
2024-10-23 01:07:42 +03:00
|
|
|
aria-label="Use mobile grid layout"
|
2024-05-08 15:53:22 +03:00
|
|
|
size="xs"
|
|
|
|
|
onClick={() => setMobileLayout("grid")}
|
|
|
|
|
>
|
|
|
|
|
<LiveGridIcon layout={mobileLayout} />
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
className={`p-1 ${
|
|
|
|
|
mobileLayout == "list"
|
2024-05-14 18:06:44 +03:00
|
|
|
? "bg-blue-900 bg-opacity-60 focus:bg-blue-900 focus:bg-opacity-60"
|
2024-05-08 15:53:22 +03:00
|
|
|
: "bg-secondary"
|
|
|
|
|
}`}
|
2024-10-23 01:07:42 +03:00
|
|
|
aria-label="Use mobile list layout"
|
2024-05-08 15:53:22 +03:00
|
|
|
size="xs"
|
|
|
|
|
onClick={() => setMobileLayout("list")}
|
|
|
|
|
>
|
|
|
|
|
<LiveListIcon layout={mobileLayout} />
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{cameraGroup && cameraGroup !== "default" && isTablet && (
|
|
|
|
|
<div className="flex items-center gap-1">
|
|
|
|
|
<Button
|
2024-05-10 19:54:37 +03:00
|
|
|
className={cn(
|
|
|
|
|
"p-1",
|
|
|
|
|
isEditMode
|
2024-05-14 18:06:44 +03:00
|
|
|
? "bg-selected text-primary"
|
|
|
|
|
: "bg-secondary text-secondary-foreground",
|
2024-05-10 19:54:37 +03:00
|
|
|
)}
|
2024-10-23 01:07:42 +03:00
|
|
|
aria-label="Enter layout editing mode"
|
2024-05-08 15:53:22 +03:00
|
|
|
size="xs"
|
|
|
|
|
onClick={() =>
|
|
|
|
|
setIsEditMode((prevIsEditMode) => !prevIsEditMode)
|
|
|
|
|
}
|
|
|
|
|
>
|
2024-05-10 19:54:37 +03:00
|
|
|
{isEditMode ? <IoClose /> : <LuLayoutDashboard />}
|
2024-05-08 15:53:22 +03:00
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2024-03-02 03:43:02 +03:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
2025-11-21 02:50:17 +03:00
|
|
|
{cameras.length == 0 && !includeBirdseye ? (
|
|
|
|
|
<NoCameraView />
|
|
|
|
|
) : (
|
2024-07-01 22:00:53 +03:00
|
|
|
<>
|
2025-11-21 02:50:17 +03:00
|
|
|
{!fullscreen && events && events.length > 0 && (
|
|
|
|
|
<ScrollArea>
|
|
|
|
|
<TooltipProvider>
|
|
|
|
|
<div className="flex items-center gap-2 px-1">
|
|
|
|
|
{events.map((event) => {
|
|
|
|
|
return (
|
|
|
|
|
<AnimatedEventCard
|
|
|
|
|
key={event.id}
|
|
|
|
|
event={event}
|
|
|
|
|
selectedGroup={cameraGroup}
|
|
|
|
|
updateEvents={updateEvents}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
</TooltipProvider>
|
|
|
|
|
<ScrollBar orientation="horizontal" />
|
|
|
|
|
</ScrollArea>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{!cameraGroup || cameraGroup == "default" || isMobileOnly ? (
|
|
|
|
|
<>
|
2024-07-01 22:00:53 +03:00
|
|
|
<div
|
2025-11-21 02:50:17 +03:00
|
|
|
className={cn(
|
|
|
|
|
"mt-2 grid grid-cols-1 gap-2 px-2 md:gap-4",
|
|
|
|
|
mobileLayout == "grid" &&
|
|
|
|
|
"grid-cols-2 xl:grid-cols-3 3xl:grid-cols-4",
|
|
|
|
|
isMobile && "px-0",
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{includeBirdseye && birdseyeConfig?.enabled && (
|
|
|
|
|
<div
|
|
|
|
|
className={(() => {
|
|
|
|
|
const aspectRatio =
|
|
|
|
|
birdseyeConfig.width / birdseyeConfig.height;
|
|
|
|
|
if (aspectRatio > 2) {
|
|
|
|
|
return `${mobileLayout == "grid" && "col-span-2"} aspect-wide`;
|
|
|
|
|
} else if (aspectRatio < 1) {
|
|
|
|
|
return `${mobileLayout == "grid" && "row-span-2 h-full"} aspect-tall`;
|
|
|
|
|
} else {
|
|
|
|
|
return "aspect-video";
|
|
|
|
|
}
|
|
|
|
|
})()}
|
|
|
|
|
ref={birdseyeContainerRef}
|
|
|
|
|
>
|
|
|
|
|
<BirdseyeLivePlayer
|
|
|
|
|
birdseyeConfig={birdseyeConfig}
|
|
|
|
|
liveMode={birdseyeConfig.restream ? "mse" : "jsmpeg"}
|
|
|
|
|
onClick={() => onSelectCamera("birdseye")}
|
|
|
|
|
containerRef={birdseyeContainerRef}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{cameras.map((camera) => {
|
|
|
|
|
let grow;
|
2024-07-01 22:00:53 +03:00
|
|
|
const aspectRatio =
|
2025-11-21 02:50:17 +03:00
|
|
|
camera.detect.width / camera.detect.height;
|
2024-07-01 22:00:53 +03:00
|
|
|
if (aspectRatio > 2) {
|
2025-11-21 02:50:17 +03:00
|
|
|
grow = `${mobileLayout == "grid" && "col-span-2"} aspect-wide`;
|
2024-07-01 22:00:53 +03:00
|
|
|
} else if (aspectRatio < 1) {
|
2025-11-21 02:50:17 +03:00
|
|
|
grow = `${mobileLayout == "grid" && "row-span-2 h-full"} aspect-tall`;
|
2024-07-01 22:00:53 +03:00
|
|
|
} else {
|
2025-11-21 02:50:17 +03:00
|
|
|
grow = "aspect-video";
|
2024-07-01 22:00:53 +03:00
|
|
|
}
|
2025-11-21 02:50:17 +03:00
|
|
|
const availableStreams = camera.live.streams || {};
|
|
|
|
|
const firstStreamEntry =
|
|
|
|
|
Object.values(availableStreams)[0] || "";
|
|
|
|
|
|
|
|
|
|
const streamNameFromSettings =
|
|
|
|
|
currentGroupStreamingSettings?.[camera.name]?.streamName ||
|
|
|
|
|
"";
|
|
|
|
|
const streamExists =
|
|
|
|
|
streamNameFromSettings &&
|
|
|
|
|
Object.values(availableStreams).includes(
|
|
|
|
|
streamNameFromSettings,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const streamName = streamExists
|
|
|
|
|
? streamNameFromSettings
|
|
|
|
|
: firstStreamEntry;
|
|
|
|
|
const streamType =
|
|
|
|
|
currentGroupStreamingSettings?.[camera.name]?.streamType;
|
|
|
|
|
const autoLive =
|
|
|
|
|
streamType !== undefined
|
|
|
|
|
? streamType !== "no-streaming"
|
|
|
|
|
: undefined;
|
|
|
|
|
const showStillWithoutActivity =
|
|
|
|
|
currentGroupStreamingSettings?.[camera.name]?.streamType !==
|
|
|
|
|
"continuous";
|
|
|
|
|
const useWebGL =
|
|
|
|
|
currentGroupStreamingSettings?.[camera.name]
|
|
|
|
|
?.compatibilityMode || false;
|
|
|
|
|
return (
|
|
|
|
|
<LiveContextMenu
|
|
|
|
|
className={grow}
|
|
|
|
|
key={camera.name}
|
|
|
|
|
camera={camera.name}
|
|
|
|
|
cameraGroup={cameraGroup}
|
|
|
|
|
streamName={streamName}
|
|
|
|
|
preferredLiveMode={
|
|
|
|
|
preferredLiveModes[camera.name] ?? "mse"
|
|
|
|
|
}
|
|
|
|
|
isRestreamed={isRestreamedStates[camera.name]}
|
|
|
|
|
supportsAudio={
|
|
|
|
|
supportsAudioOutputStates[streamName]?.supportsAudio ??
|
|
|
|
|
false
|
|
|
|
|
}
|
|
|
|
|
audioState={audioStates[camera.name]}
|
|
|
|
|
toggleAudio={() => toggleAudio(camera.name)}
|
|
|
|
|
statsState={statsStates[camera.name]}
|
|
|
|
|
toggleStats={() => toggleStats(camera.name)}
|
|
|
|
|
volumeState={volumeStates[camera.name] ?? 1}
|
|
|
|
|
setVolumeState={(value) =>
|
|
|
|
|
setVolumeStates({
|
|
|
|
|
[camera.name]: value,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
muteAll={muteAll}
|
|
|
|
|
unmuteAll={unmuteAll}
|
|
|
|
|
resetPreferredLiveMode={() =>
|
|
|
|
|
resetPreferredLiveMode(camera.name)
|
|
|
|
|
}
|
|
|
|
|
config={config}
|
|
|
|
|
>
|
|
|
|
|
<LivePlayer
|
|
|
|
|
cameraRef={cameraRef}
|
|
|
|
|
key={camera.name}
|
|
|
|
|
className={`${grow} rounded-lg bg-black md:rounded-2xl`}
|
|
|
|
|
windowVisible={
|
|
|
|
|
windowVisible && visibleCameras.includes(camera.name)
|
|
|
|
|
}
|
|
|
|
|
cameraConfig={camera}
|
|
|
|
|
preferredLiveMode={
|
|
|
|
|
preferredLiveModes[camera.name] ?? "mse"
|
|
|
|
|
}
|
|
|
|
|
autoLive={autoLive ?? globalAutoLive}
|
|
|
|
|
showStillWithoutActivity={
|
|
|
|
|
showStillWithoutActivity ?? true
|
|
|
|
|
}
|
|
|
|
|
alwaysShowCameraName={displayCameraNames}
|
|
|
|
|
useWebGL={useWebGL}
|
|
|
|
|
playInBackground={false}
|
|
|
|
|
showStats={statsStates[camera.name]}
|
|
|
|
|
streamName={streamName}
|
|
|
|
|
onClick={() => onSelectCamera(camera.name)}
|
|
|
|
|
onError={(e) => handleError(camera.name, e)}
|
|
|
|
|
onResetLiveMode={() =>
|
|
|
|
|
resetPreferredLiveMode(camera.name)
|
|
|
|
|
}
|
|
|
|
|
playAudio={audioStates[camera.name] ?? false}
|
|
|
|
|
volume={volumeStates[camera.name]}
|
|
|
|
|
/>
|
|
|
|
|
</LiveContextMenu>
|
|
|
|
|
);
|
|
|
|
|
})}
|
2024-07-01 22:00:53 +03:00
|
|
|
</div>
|
2025-11-21 02:50:17 +03:00
|
|
|
{isDesktop && (
|
|
|
|
|
<div
|
|
|
|
|
className={cn(
|
|
|
|
|
"fixed",
|
|
|
|
|
isDesktop && "bottom-12 lg:bottom-9",
|
|
|
|
|
isMobile && "bottom-12 lg:bottom-16",
|
|
|
|
|
hasScrollbar && isDesktop ? "right-6" : "right-3",
|
|
|
|
|
"z-50 flex flex-row gap-2",
|
|
|
|
|
)}
|
2025-02-10 19:42:35 +03:00
|
|
|
>
|
2025-11-21 02:50:17 +03:00
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger asChild>
|
|
|
|
|
<div
|
|
|
|
|
className="cursor-pointer rounded-lg bg-secondary text-secondary-foreground opacity-60 transition-all duration-300 hover:bg-muted hover:opacity-100"
|
|
|
|
|
onClick={toggleFullscreen}
|
|
|
|
|
>
|
|
|
|
|
{fullscreen ? (
|
|
|
|
|
<FaCompress className="size-5 md:m-[6px]" />
|
|
|
|
|
) : (
|
|
|
|
|
<FaExpand className="size-5 md:m-[6px]" />
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent>
|
|
|
|
|
{fullscreen
|
|
|
|
|
? t("button.exitFullscreen", { ns: "common" })
|
|
|
|
|
: t("button.fullscreen", { ns: "common" })}
|
|
|
|
|
</TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</div>
|
2024-07-01 22:00:53 +03:00
|
|
|
)}
|
2025-11-21 02:50:17 +03:00
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<DraggableGridLayout
|
|
|
|
|
cameras={cameras}
|
|
|
|
|
cameraGroup={cameraGroup}
|
|
|
|
|
containerRef={containerRef}
|
|
|
|
|
cameraRef={cameraRef}
|
|
|
|
|
includeBirdseye={includeBirdseye}
|
|
|
|
|
onSelectCamera={onSelectCamera}
|
|
|
|
|
windowVisible={windowVisible}
|
|
|
|
|
visibleCameras={visibleCameras}
|
|
|
|
|
isEditMode={isEditMode}
|
|
|
|
|
setIsEditMode={setIsEditMode}
|
|
|
|
|
fullscreen={fullscreen}
|
|
|
|
|
toggleFullscreen={toggleFullscreen}
|
|
|
|
|
/>
|
2024-05-07 17:28:10 +03:00
|
|
|
)}
|
2024-07-01 22:00:53 +03:00
|
|
|
</>
|
2024-05-07 17:28:10 +03:00
|
|
|
)}
|
2024-03-02 03:43:02 +03:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-10-12 00:40:39 +03:00
|
|
|
|
|
|
|
|
function NoCameraView() {
|
|
|
|
|
const { t } = useTranslation(["views/live"]);
|
2025-11-21 02:50:17 +03:00
|
|
|
const { auth } = useContext(AuthContext);
|
2025-11-27 16:58:35 +03:00
|
|
|
const isAdmin = useIsAdmin();
|
2025-11-21 02:50:17 +03:00
|
|
|
|
|
|
|
|
// Check if this is a restricted user with no cameras in this group
|
2025-11-27 16:58:35 +03:00
|
|
|
const isRestricted = !isAdmin && auth.isAuthenticated;
|
2025-10-12 00:40:39 +03:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex size-full items-center justify-center">
|
|
|
|
|
<EmptyCard
|
|
|
|
|
icon={<BsFillCameraVideoOffFill className="size-8" />}
|
2025-11-21 02:50:17 +03:00
|
|
|
title={
|
|
|
|
|
isRestricted ? t("noCameras.restricted.title") : t("noCameras.title")
|
|
|
|
|
}
|
|
|
|
|
description={
|
|
|
|
|
isRestricted
|
|
|
|
|
? t("noCameras.restricted.description")
|
|
|
|
|
: t("noCameras.description")
|
|
|
|
|
}
|
|
|
|
|
buttonText={!isRestricted ? t("noCameras.buttonText") : undefined}
|
|
|
|
|
link={!isRestricted ? "/settings?page=cameraManagement" : undefined}
|
2025-10-12 00:40:39 +03:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|