mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-08 12:15:25 +03:00
Improving layouts and add chip component
This commit is contained in:
parent
acb148547a
commit
aefb4bf354
@ -36,7 +36,7 @@ function App() {
|
|||||||
>
|
>
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path="/" element={<Dashboard />} />
|
<Route path="/" element={<Dashboard />} />
|
||||||
<Route path="/live/:camera?" element={<Live />} />
|
<Route path="/live" element={<Live />} />
|
||||||
<Route path="/history" element={<History />} />
|
<Route path="/history" element={<History />} />
|
||||||
<Route path="/export" element={<Export />} />
|
<Route path="/export" element={<Export />} />
|
||||||
<Route path="/storage" element={<Storage />} />
|
<Route path="/storage" element={<Storage />} />
|
||||||
|
|||||||
13
web/src/components/Chip.tsx
Normal file
13
web/src/components/Chip.tsx
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { ReactNode } from "react";
|
||||||
|
|
||||||
|
type ChipProps = {
|
||||||
|
className?: string;
|
||||||
|
children?: ReactNode[];
|
||||||
|
};
|
||||||
|
export default function Chip({ className, children }: ChipProps) {
|
||||||
|
return (
|
||||||
|
<div className={`flex p-1 rounded-lg items-center ${className}`}>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -12,12 +12,15 @@ import { usePersistence } from "@/hooks/use-persistence";
|
|||||||
import MSEPlayer from "./MsePlayer";
|
import MSEPlayer from "./MsePlayer";
|
||||||
import JSMpegPlayer from "./JSMpegPlayer";
|
import JSMpegPlayer from "./JSMpegPlayer";
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
|
import { MdCircle } from "react-icons/md";
|
||||||
|
import Chip from "../Chip";
|
||||||
|
|
||||||
const emptyObject = Object.freeze({});
|
const emptyObject = Object.freeze({});
|
||||||
|
|
||||||
type LivePlayerProps = {
|
type LivePlayerProps = {
|
||||||
className?: string;
|
className?: string;
|
||||||
cameraConfig: CameraConfig;
|
cameraConfig: CameraConfig;
|
||||||
|
liveMode?: "webrtc" | "mse" | "jsmpeg" | "debug";
|
||||||
};
|
};
|
||||||
|
|
||||||
type Options = { [key: string]: boolean };
|
type Options = { [key: string]: boolean };
|
||||||
@ -25,6 +28,7 @@ type Options = { [key: string]: boolean };
|
|||||||
export default function LivePlayer({
|
export default function LivePlayer({
|
||||||
className,
|
className,
|
||||||
cameraConfig,
|
cameraConfig,
|
||||||
|
liveMode = "mse",
|
||||||
}: LivePlayerProps) {
|
}: LivePlayerProps) {
|
||||||
const { data: config } = useSWR<FrigateConfig>("config");
|
const { data: config } = useSWR<FrigateConfig>("config");
|
||||||
const [showSettings, setShowSettings] = useState(false);
|
const [showSettings, setShowSettings] = useState(false);
|
||||||
@ -34,35 +38,6 @@ export default function LivePlayer({
|
|||||||
emptyObject
|
emptyObject
|
||||||
);
|
);
|
||||||
|
|
||||||
const restreamEnabled = useMemo(() => {
|
|
||||||
if (!config) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
cameraConfig &&
|
|
||||||
Object.keys(config.go2rtc.streams || {}).includes(
|
|
||||||
cameraConfig.live.stream_name
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}, [config, cameraConfig]);
|
|
||||||
|
|
||||||
const defaultLiveMode = useMemo(() => {
|
|
||||||
if (cameraConfig) {
|
|
||||||
if (restreamEnabled) {
|
|
||||||
return cameraConfig.ui.live_mode || config?.ui.live_mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
return "jsmpeg";
|
|
||||||
}
|
|
||||||
|
|
||||||
return undefined;
|
|
||||||
}, [cameraConfig, restreamEnabled]);
|
|
||||||
const [liveMode, setLiveMode, sourceIsLoaded] = usePersistence(
|
|
||||||
`${cameraConfig.name}-source`,
|
|
||||||
defaultLiveMode
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleSetOption = useCallback(
|
const handleSetOption = useCallback(
|
||||||
(id: string, value: boolean) => {
|
(id: string, value: boolean) => {
|
||||||
const newOptions = { ...options, [id]: value };
|
const newOptions = { ...options, [id]: value };
|
||||||
@ -91,24 +66,24 @@ export default function LivePlayer({
|
|||||||
return <ActivityIndicator />;
|
return <ActivityIndicator />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let player;
|
||||||
if (liveMode == "webrtc") {
|
if (liveMode == "webrtc") {
|
||||||
return (
|
player = (
|
||||||
<div className="max-w-5xl">
|
<WebRtcPlayer
|
||||||
<WebRtcPlayer
|
className="rounded-2xl"
|
||||||
className={className}
|
camera={cameraConfig.live.stream_name}
|
||||||
camera={cameraConfig.live.stream_name}
|
/>
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
} else if (liveMode == "mse") {
|
} else if (liveMode == "mse") {
|
||||||
if ("MediaSource" in window || "ManagedMediaSource" in window) {
|
if ("MediaSource" in window || "ManagedMediaSource" in window) {
|
||||||
return (
|
player = (
|
||||||
<div className="max-w-5xl">
|
<MSEPlayer
|
||||||
<MSEPlayer camera={cameraConfig.live.stream_name} />
|
className="rounded-2xl"
|
||||||
</div>
|
camera={cameraConfig.live.stream_name}
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return (
|
player = (
|
||||||
<div className="w-5xl text-center text-sm">
|
<div className="w-5xl text-center text-sm">
|
||||||
MSE is only supported on iOS 17.1+. You'll need to update if available
|
MSE is only supported on iOS 17.1+. You'll need to update if available
|
||||||
or use jsmpeg / webRTC streams. See the docs for more info.
|
or use jsmpeg / webRTC streams. See the docs for more info.
|
||||||
@ -116,17 +91,15 @@ export default function LivePlayer({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if (liveMode == "jsmpeg") {
|
} else if (liveMode == "jsmpeg") {
|
||||||
return (
|
player = (
|
||||||
<div className={`max-w-[${cameraConfig.detect.width}px]`}>
|
<JSMpegPlayer
|
||||||
<JSMpegPlayer
|
camera={cameraConfig.name}
|
||||||
camera={cameraConfig.name}
|
width={cameraConfig.detect.width}
|
||||||
width={cameraConfig.detect.width}
|
height={cameraConfig.detect.height}
|
||||||
height={cameraConfig.detect.height}
|
/>
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
} else if (liveMode == "debug") {
|
} else if (liveMode == "debug") {
|
||||||
return (
|
player = (
|
||||||
<>
|
<>
|
||||||
<AutoUpdatingCameraImage
|
<AutoUpdatingCameraImage
|
||||||
camera={cameraConfig.name}
|
camera={cameraConfig.name}
|
||||||
@ -154,8 +127,20 @@ export default function LivePlayer({
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
<ActivityIndicator />;
|
player = <ActivityIndicator />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={`relative ${className}`}>
|
||||||
|
{player}
|
||||||
|
<Chip className="absolute right-2 top-2 bg-gray-500 bg-gradient-to-br">
|
||||||
|
<MdCircle className="w-2 h-2 text-danger" />
|
||||||
|
<div className="ml-1 capitalize text-white text-xs">
|
||||||
|
{cameraConfig.name.replaceAll("_", " ")}
|
||||||
|
</div>
|
||||||
|
</Chip>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
type DebugSettingsProps = {
|
type DebugSettingsProps = {
|
||||||
|
|||||||
@ -3,9 +3,10 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|||||||
|
|
||||||
type MSEPlayerProps = {
|
type MSEPlayerProps = {
|
||||||
camera: string;
|
camera: string;
|
||||||
|
className?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
function MSEPlayer({ camera }: MSEPlayerProps) {
|
function MSEPlayer({ camera, className }: MSEPlayerProps) {
|
||||||
let connectTS: number = 0;
|
let connectTS: number = 0;
|
||||||
|
|
||||||
const RECONNECT_TIMEOUT: number = 30000;
|
const RECONNECT_TIMEOUT: number = 30000;
|
||||||
@ -246,6 +247,7 @@ function MSEPlayer({ camera }: MSEPlayerProps) {
|
|||||||
return (
|
return (
|
||||||
<video
|
<video
|
||||||
ref={videoRef}
|
ref={videoRef}
|
||||||
|
className={className}
|
||||||
controls
|
controls
|
||||||
playsInline
|
playsInline
|
||||||
preload="auto"
|
preload="auto"
|
||||||
|
|||||||
@ -1,13 +1,11 @@
|
|||||||
import { baseUrl } from "@/api/baseUrl";
|
import { baseUrl } from "@/api/baseUrl";
|
||||||
import LivePlayer from "@/components/player/LivePlayer";
|
import LivePlayer from "@/components/player/LivePlayer";
|
||||||
import Heading from "@/components/ui/heading";
|
|
||||||
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
|
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
|
||||||
import { usePersistence } from "@/hooks/use-persistence";
|
|
||||||
import { Event as FrigateEvent } from "@/types/event";
|
import { Event as FrigateEvent } from "@/types/event";
|
||||||
import { CameraConfig, FrigateConfig } from "@/types/frigateConfig";
|
import { FrigateConfig } from "@/types/frigateConfig";
|
||||||
import { useMemo, useState } from "react";
|
import axios from "axios";
|
||||||
|
import { useCallback, useMemo } from "react";
|
||||||
import { LuStar } from "react-icons/lu";
|
import { LuStar } from "react-icons/lu";
|
||||||
import { useParams } from "react-router-dom";
|
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
|
|
||||||
function Live() {
|
function Live() {
|
||||||
@ -23,14 +21,32 @@ function Live() {
|
|||||||
{ limit: 10, after: recentTimestamp },
|
{ limit: 10, after: recentTimestamp },
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const onFavorite = useCallback(
|
||||||
|
async (e: Event, event: FrigateEvent) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
let response;
|
||||||
|
if (!event.retain_indefinitely) {
|
||||||
|
response = await axios.post(`events/${event.id}/retain`);
|
||||||
|
} else {
|
||||||
|
response = await axios.delete(`events/${event.id}/retain`);
|
||||||
|
}
|
||||||
|
if (response.status === 200) {
|
||||||
|
updateEvents();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[event]
|
||||||
|
);
|
||||||
|
|
||||||
// camera live views
|
// camera live views
|
||||||
|
|
||||||
const enabledCameras = useMemo<CameraConfig[]>(() => {
|
const cameras = useMemo(() => {
|
||||||
if (!config) {
|
if (!config) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return Object.values(config.cameras);
|
return Object.values(config.cameras)
|
||||||
|
.filter((conf) => conf.ui.dashboard && conf.enabled)
|
||||||
|
.sort((aConf, bConf) => aConf.ui.order - bConf.ui.order);
|
||||||
}, [config]);
|
}, [config]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -48,7 +64,7 @@ function Live() {
|
|||||||
>
|
>
|
||||||
<LuStar
|
<LuStar
|
||||||
className="h-6 w-6 text-yellow-300 absolute top-1 right-1 cursor-pointer"
|
className="h-6 w-6 text-yellow-300 absolute top-1 right-1 cursor-pointer"
|
||||||
//onClick={(e: Event) => onSave(e)}
|
onClick={(e: Event) => onFavorite(e, event)}
|
||||||
fill={event.retain_indefinitely ? "currentColor" : "none"}
|
fill={event.retain_indefinitely ? "currentColor" : "none"}
|
||||||
/>
|
/>
|
||||||
{event.end_time ? null : (
|
{event.end_time ? null : (
|
||||||
@ -65,13 +81,8 @@ function Live() {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="mt-4 grid grid-cols-1 md:grid-cols-2 2xl:grid-cols-3 gap-4">
|
<div className="mt-4 grid grid-cols-1 md:grid-cols-2 2xl:grid-cols-3 gap-4">
|
||||||
{enabledCameras.map((camera) => {
|
{cameras.map((camera) => {
|
||||||
return (
|
return <LivePlayer className=" rounded-2xl" cameraConfig={camera} />;
|
||||||
<LivePlayer
|
|
||||||
className=" rounded-2xl overflow-hidden"
|
|
||||||
cameraConfig={camera}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user