mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-15 11:32:09 +03:00
limit cameras in live view
This commit is contained in:
parent
8976b061a4
commit
fa863bad63
@ -11,12 +11,15 @@ import LiveCameraView from "@/views/live/LiveCameraView";
|
|||||||
import LiveDashboardView from "@/views/live/LiveDashboardView";
|
import LiveDashboardView from "@/views/live/LiveDashboardView";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
import { useEffect, useMemo, useRef } from "react";
|
import { useContext, useEffect, useMemo, useRef } from "react";
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
|
import { useAllowedCameras } from "@/hooks/use-allowed-cameras";
|
||||||
|
import { AuthContext } from "@/context/auth-context";
|
||||||
|
|
||||||
function Live() {
|
function Live() {
|
||||||
const { t } = useTranslation(["views/live"]);
|
const { t } = useTranslation(["views/live"]);
|
||||||
const { data: config } = useSWR<FrigateConfig>("config");
|
const { data: config } = useSWR<FrigateConfig>("config");
|
||||||
|
const { auth } = useContext(AuthContext);
|
||||||
|
|
||||||
// selection
|
// selection
|
||||||
|
|
||||||
@ -81,19 +84,25 @@ function Live() {
|
|||||||
|
|
||||||
// settings
|
// settings
|
||||||
|
|
||||||
|
const allowedCameras = useAllowedCameras();
|
||||||
|
|
||||||
const includesBirdseye = useMemo(() => {
|
const includesBirdseye = useMemo(() => {
|
||||||
if (
|
if (
|
||||||
config &&
|
config &&
|
||||||
Object.keys(config.camera_groups).length &&
|
Object.keys(config.camera_groups).length &&
|
||||||
cameraGroup &&
|
cameraGroup &&
|
||||||
config.camera_groups[cameraGroup] &&
|
config.camera_groups[cameraGroup] &&
|
||||||
cameraGroup != "default"
|
cameraGroup != "default" &&
|
||||||
|
(auth.user?.role === "admin" ||
|
||||||
|
auth.user?.role == "viewer" ||
|
||||||
|
!auth.isAuthenticated ||
|
||||||
|
"birdseye" in allowedCameras)
|
||||||
) {
|
) {
|
||||||
return config.camera_groups[cameraGroup].cameras.includes("birdseye");
|
return config.camera_groups[cameraGroup].cameras.includes("birdseye");
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}, [config, cameraGroup]);
|
}, [config, cameraGroup, allowedCameras, auth]);
|
||||||
|
|
||||||
const cameras = useMemo(() => {
|
const cameras = useMemo(() => {
|
||||||
if (!config) {
|
if (!config) {
|
||||||
@ -111,13 +120,15 @@ function Live() {
|
|||||||
.filter(
|
.filter(
|
||||||
(conf) => conf.enabled_in_config && group.cameras.includes(conf.name),
|
(conf) => conf.enabled_in_config && group.cameras.includes(conf.name),
|
||||||
)
|
)
|
||||||
|
.filter((cam) => allowedCameras.includes(cam.name))
|
||||||
.sort((aConf, bConf) => aConf.ui.order - bConf.ui.order);
|
.sort((aConf, bConf) => aConf.ui.order - bConf.ui.order);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Object.values(config.cameras)
|
return Object.values(config.cameras)
|
||||||
.filter((conf) => conf.ui.dashboard && conf.enabled_in_config)
|
.filter((conf) => conf.ui.dashboard && conf.enabled_in_config)
|
||||||
|
.filter((cam) => allowedCameras.includes(cam.name))
|
||||||
.sort((aConf, bConf) => aConf.ui.order - bConf.ui.order);
|
.sort((aConf, bConf) => aConf.ui.order - bConf.ui.order);
|
||||||
}, [config, cameraGroup]);
|
}, [config, cameraGroup, allowedCameras]);
|
||||||
|
|
||||||
const selectedCamera = useMemo(
|
const selectedCamera = useMemo(
|
||||||
() => cameras.find((cam) => cam.name == selectedCameraName),
|
() => cameras.find((cam) => cam.name == selectedCameraName),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user