enhancement/dynamiccameraFeed #26
12
src/app/config/cameraConfig.ts
Normal file
12
src/app/config/cameraConfig.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
// Camera configuration - add more cameras here as needed
|
||||
export const CAMERA_IDS = ["A", "B", "C"] as const;
|
||||
|
||||
export type CameraID = (typeof CAMERA_IDS)[number];
|
||||
|
||||
export const DEFAULT_REGIONS = [
|
||||
{ name: "Bay 1", brushColour: "#ff0000" },
|
||||
{ name: "Bay 2", brushColour: "#00ff00" },
|
||||
{ name: "Bay 3", brushColour: "#0400ff" },
|
||||
{ name: "Bay 4", brushColour: "#ffff00" },
|
||||
{ name: "Bay 5", brushColour: "#fc35db" },
|
||||
];
|
||||
@@ -17,9 +17,7 @@ type CameraSocketState = {
|
||||
|
||||
export type WebSocketConextValue = {
|
||||
info: InfoSocketState;
|
||||
cameraFeedA: CameraSocketState;
|
||||
cameraFeedB: CameraSocketState;
|
||||
cameraFeedC: CameraSocketState;
|
||||
cameraFeed: CameraSocketState;
|
||||
};
|
||||
|
||||
export const WebsocketContext = createContext<WebSocketConextValue | null>(null);
|
||||
@@ -31,6 +29,4 @@ const useWebSocketContext = () => {
|
||||
};
|
||||
|
||||
export const useInfoSocket = () => useWebSocketContext().info;
|
||||
export const useCameraFeedASocket = () => useWebSocketContext().cameraFeedA;
|
||||
export const useCameraFeedBSocket = () => useWebSocketContext().cameraFeedB;
|
||||
export const useCameraFeedCSocket = () => useWebSocketContext().cameraFeedC;
|
||||
export const useCameraFeedSocket = () => useWebSocketContext().cameraFeed;
|
||||
|
||||
@@ -3,13 +3,12 @@ import { CameraFeedContext } from "../context/CameraFeedContext";
|
||||
import { initialState, reducer } from "../reducers/cameraFeedReducer";
|
||||
import { useBlackBoard } from "../../hooks/useBlackBoard";
|
||||
import type { CameraFeedState } from "../../types/types";
|
||||
import { useCameraZoom } from "../../features/cameras/hooks/useCameraZoom";
|
||||
|
||||
import { CAMERA_IDS } from "../config/cameraConfig";
|
||||
import CameraZoomFetcher from "./CameraZoomFetcher";
|
||||
|
||||
export const CameraFeedProvider = ({ children }: { children: ReactNode }) => {
|
||||
const { blackboardMutation } = useBlackBoard();
|
||||
const { cameraZoomQuery: cameraZoomQueryA } = useCameraZoom("A");
|
||||
const { cameraZoomQuery: cameraZoomQueryB } = useCameraZoom("B");
|
||||
const { cameraZoomQuery: cameraZoomQueryC } = useCameraZoom("C");
|
||||
|
||||
const [state, dispatch] = useReducer(reducer, initialState);
|
||||
|
||||
@@ -23,52 +22,25 @@ export const CameraFeedProvider = ({ children }: { children: ReactNode }) => {
|
||||
const cameraFeedData: CameraFeedState = result.result;
|
||||
const recontructedState = {
|
||||
...cameraFeedData,
|
||||
paintedCells: {
|
||||
A: new Map(cameraFeedData.paintedCells.A),
|
||||
B: new Map(cameraFeedData.paintedCells.B),
|
||||
C: new Map(cameraFeedData.paintedCells.C),
|
||||
},
|
||||
paintedCells: CAMERA_IDS.reduce(
|
||||
(acc, id) => {
|
||||
acc[id] = new Map(cameraFeedData.paintedCells[id]);
|
||||
return acc;
|
||||
},
|
||||
{} as typeof cameraFeedData.paintedCells,
|
||||
),
|
||||
};
|
||||
dispatch({ type: "SET_CAMERA_FEED_DATA", cameraState: recontructedState });
|
||||
};
|
||||
fetchBlackBoardData();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchZoomLevels = async () => {
|
||||
const [resultA, resultB, resultC] = await Promise.all([
|
||||
cameraZoomQueryA.refetch(),
|
||||
cameraZoomQueryB.refetch(),
|
||||
cameraZoomQueryC.refetch(),
|
||||
]);
|
||||
|
||||
const zoomLevelAnumber = parseFloat(resultA.data?.propPhysCurrent?.value);
|
||||
const zoomLevelBnumber = parseFloat(resultB.data?.propPhysCurrent?.value);
|
||||
const zoomLevelCnumber = parseFloat(resultC.data?.propPhysCurrent?.value);
|
||||
|
||||
if (resultA.data) {
|
||||
dispatch({
|
||||
type: "SET_ZOOM_LEVEL",
|
||||
payload: { cameraFeedID: "A", zoomLevel: zoomLevelAnumber },
|
||||
});
|
||||
}
|
||||
|
||||
if (resultB.data) {
|
||||
dispatch({
|
||||
type: "SET_ZOOM_LEVEL",
|
||||
payload: { cameraFeedID: "B", zoomLevel: zoomLevelBnumber },
|
||||
});
|
||||
}
|
||||
|
||||
if (resultC.data) {
|
||||
dispatch({
|
||||
type: "SET_ZOOM_LEVEL",
|
||||
payload: { cameraFeedID: "C", zoomLevel: zoomLevelCnumber },
|
||||
});
|
||||
}
|
||||
};
|
||||
fetchZoomLevels();
|
||||
}, []);
|
||||
|
||||
return <CameraFeedContext.Provider value={{ state, dispatch }}>{children}</CameraFeedContext.Provider>;
|
||||
return (
|
||||
<CameraFeedContext.Provider value={{ state, dispatch }}>
|
||||
{CAMERA_IDS.map((cameraId) => (
|
||||
<CameraZoomFetcher key={cameraId} cameraId={cameraId} dispatch={dispatch} />
|
||||
))}
|
||||
{children}
|
||||
</CameraFeedContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
31
src/app/providers/CameraZoomFetcher.tsx
Normal file
31
src/app/providers/CameraZoomFetcher.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import { useEffect } from "react";
|
||||
import { useCameraZoom } from "../../features/cameras/hooks/useCameraZoom";
|
||||
import type { CameraFeedAction } from "../../types/types";
|
||||
import type { CameraID } from "../config/cameraConfig";
|
||||
|
||||
type CameraZoomFetcherProps = {
|
||||
cameraId: CameraID;
|
||||
dispatch: (action: CameraFeedAction) => void;
|
||||
};
|
||||
|
||||
const CameraZoomFetcher = ({ cameraId, dispatch }: CameraZoomFetcherProps) => {
|
||||
const { cameraZoomQuery } = useCameraZoom(cameraId);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchZoomLevel = async () => {
|
||||
const result = await cameraZoomQuery.refetch();
|
||||
if (result.data && typeof result.data.zoomLevel === "number") {
|
||||
dispatch({
|
||||
type: "SET_ZOOM_LEVEL",
|
||||
payload: { cameraFeedID: cameraId, zoomLevel: result.data.zoomLevel },
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
fetchZoomLevel();
|
||||
}, [cameraId, cameraZoomQuery, dispatch]);
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
export default CameraZoomFetcher;
|
||||
@@ -3,18 +3,28 @@ import { WebsocketContext, type WebSocketConextValue } from "../context/WebSocke
|
||||
import useWebSocket from "react-use-websocket";
|
||||
import { wsConfig } from "../config/wsconfig";
|
||||
import type { CameraZoomData, InfoBarData } from "../../types/types";
|
||||
import { CAMERA_IDS } from "../config/cameraConfig";
|
||||
import { CAMBASE_WS } from "../../utils/config";
|
||||
import { useCameraFeedContext } from "../context/CameraFeedContext";
|
||||
|
||||
type WebSocketProviderProps = {
|
||||
children: ReactNode;
|
||||
};
|
||||
|
||||
export const WebSocketProvider = ({ children }: WebSocketProviderProps) => {
|
||||
const { state } = useCameraFeedContext();
|
||||
const [systemData, setSystemData] = useState<InfoBarData | null>(null);
|
||||
const [socketData, setSocketData] = useState<CameraZoomData | null>(null);
|
||||
const infoSocket = useWebSocket(wsConfig.infoBar, { share: true, shouldReconnect: () => true });
|
||||
const cameraFeedASocket = useWebSocket(wsConfig.cameraFeedA, { share: true, shouldReconnect: () => true });
|
||||
const cameraFeedBSocket = useWebSocket(wsConfig.cameraFeedB, { share: true, shouldReconnect: () => true });
|
||||
const cameraFeedCSocket = useWebSocket(wsConfig.cameraFeedC, { share: true, shouldReconnect: () => true });
|
||||
const sockets = CAMERA_IDS.reduce(
|
||||
(acc, id) => {
|
||||
acc[id] = `${CAMBASE_WS}/websocket-Camera${id}-live-video`;
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, string>,
|
||||
);
|
||||
const cameraFeedID = state.cameraFeedID;
|
||||
const cameraFeed = useWebSocket(sockets[cameraFeedID], { share: true, shouldReconnect: () => true });
|
||||
|
||||
useEffect(() => {
|
||||
async function parseData() {
|
||||
@@ -23,20 +33,15 @@ export const WebSocketProvider = ({ children }: WebSocketProviderProps) => {
|
||||
const data = JSON.parse(text);
|
||||
setSystemData(data);
|
||||
}
|
||||
if (cameraFeedASocket.lastMessage || cameraFeedBSocket.lastMessage || cameraFeedCSocket.lastMessage) {
|
||||
const message = cameraFeedASocket.lastMessage || cameraFeedBSocket.lastMessage || cameraFeedCSocket.lastMessage;
|
||||
if (cameraFeed.lastMessage) {
|
||||
const message = cameraFeed.lastMessage;
|
||||
const data = await message?.data.text();
|
||||
const parsedData: CameraZoomData = JSON.parse(data || "");
|
||||
setSocketData(parsedData);
|
||||
}
|
||||
}
|
||||
parseData();
|
||||
}, [
|
||||
cameraFeedASocket.lastMessage,
|
||||
cameraFeedBSocket.lastMessage,
|
||||
cameraFeedCSocket.lastMessage,
|
||||
infoSocket.lastMessage,
|
||||
]);
|
||||
}, [cameraFeed.lastMessage, infoSocket.lastMessage]);
|
||||
|
||||
const value = useMemo<WebSocketConextValue>(
|
||||
() => ({
|
||||
@@ -45,32 +50,16 @@ export const WebSocketProvider = ({ children }: WebSocketProviderProps) => {
|
||||
readyState: infoSocket.readyState,
|
||||
sendJson: infoSocket.sendJsonMessage,
|
||||
},
|
||||
cameraFeedA: {
|
||||
cameraFeed: {
|
||||
data: socketData,
|
||||
readyState: cameraFeedASocket.readyState,
|
||||
readyState: cameraFeed.readyState,
|
||||
|
||||
send: cameraFeedASocket.sendMessage,
|
||||
},
|
||||
cameraFeedB: {
|
||||
data: socketData,
|
||||
readyState: cameraFeedBSocket.readyState,
|
||||
|
||||
send: cameraFeedBSocket.sendMessage,
|
||||
},
|
||||
cameraFeedC: {
|
||||
data: socketData,
|
||||
readyState: cameraFeedCSocket.readyState,
|
||||
|
||||
send: cameraFeedCSocket.sendMessage,
|
||||
send: cameraFeed.sendMessage,
|
||||
},
|
||||
}),
|
||||
[
|
||||
cameraFeedASocket.readyState,
|
||||
cameraFeedASocket.sendMessage,
|
||||
cameraFeedBSocket.readyState,
|
||||
cameraFeedBSocket.sendMessage,
|
||||
cameraFeedCSocket.readyState,
|
||||
cameraFeedCSocket.sendMessage,
|
||||
cameraFeed.readyState,
|
||||
cameraFeed.sendMessage,
|
||||
infoSocket.readyState,
|
||||
infoSocket.sendJsonMessage,
|
||||
socketData,
|
||||
|
||||
@@ -1,47 +1,38 @@
|
||||
import type { CameraFeedAction, CameraFeedState, PaintedCell } from "../../types/types";
|
||||
import { CAMERA_IDS, DEFAULT_REGIONS, type CameraID } from "../config/cameraConfig";
|
||||
|
||||
export const initialState: CameraFeedState = {
|
||||
cameraFeedID: "A",
|
||||
paintedCells: {
|
||||
A: new Map<string, PaintedCell>(),
|
||||
B: new Map<string, PaintedCell>(),
|
||||
C: new Map<string, PaintedCell>(),
|
||||
},
|
||||
regionsByCamera: {
|
||||
A: [
|
||||
{ name: "Bay 1", brushColour: "#ff0000" },
|
||||
{ name: "Bay 2", brushColour: "#00ff00" },
|
||||
{ name: "Bay 3", brushColour: "#0400ff" },
|
||||
{ name: "Bay 4", brushColour: "#ffff00" },
|
||||
{ name: "Bay 5", brushColour: "#fc35db" },
|
||||
],
|
||||
B: [
|
||||
{ name: "Bay 1", brushColour: "#ff0000" },
|
||||
{ name: "Bay 2", brushColour: "#00ff00" },
|
||||
{ name: "Bay 3", brushColour: "#0400ff" },
|
||||
{ name: "Bay 4", brushColour: "#ffff00" },
|
||||
{ name: "Bay 5", brushColour: "#fc35db" },
|
||||
],
|
||||
C: [
|
||||
{ name: "Bay 1", brushColour: "#ff0000" },
|
||||
{ name: "Bay 2", brushColour: "#00ff00" },
|
||||
{ name: "Bay 3", brushColour: "#0400ff" },
|
||||
{ name: "Bay 4", brushColour: "#ffff00" },
|
||||
{ name: "Bay 5", brushColour: "#fc35db" },
|
||||
],
|
||||
},
|
||||
cameraFeedID: CAMERA_IDS[0],
|
||||
paintedCells: CAMERA_IDS.reduce(
|
||||
(acc, id) => {
|
||||
acc[id] = new Map<string, PaintedCell>();
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, Map<string, PaintedCell>>,
|
||||
),
|
||||
regionsByCamera: CAMERA_IDS.reduce(
|
||||
(acc, id) => {
|
||||
acc[id] = DEFAULT_REGIONS;
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, { name: string; brushColour: string }[]>,
|
||||
),
|
||||
|
||||
selectedRegionIndex: 0,
|
||||
modeByCamera: {
|
||||
A: "painter",
|
||||
B: "painter",
|
||||
C: "painter",
|
||||
},
|
||||
zoomLevel: {
|
||||
A: 1,
|
||||
B: 1,
|
||||
C: 1,
|
||||
},
|
||||
modeByCamera: CAMERA_IDS.reduce(
|
||||
(acc, id) => {
|
||||
acc[id] = "painter";
|
||||
return acc;
|
||||
},
|
||||
{} as Record<CameraID, string>,
|
||||
),
|
||||
zoomLevel: CAMERA_IDS.reduce(
|
||||
(acc, id) => {
|
||||
acc[id] = 1;
|
||||
return acc;
|
||||
},
|
||||
{} as Record<CameraID, number>,
|
||||
),
|
||||
};
|
||||
|
||||
export function reducer(state: CameraFeedState, action: CameraFeedAction) {
|
||||
|
||||
@@ -28,6 +28,7 @@ const CameraPanel = ({ tabIndex, isResetAllModalOpen, handleClose, setIsResetMod
|
||||
return "B";
|
||||
case 2:
|
||||
return "C";
|
||||
//Add more cases if more cameras are added
|
||||
default:
|
||||
return "A";
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import Card from "../../../../ui/Card";
|
||||
import { Tab, Tabs, TabList, TabPanel } from "react-tabs";
|
||||
import "react-tabs/style/react-tabs.css";
|
||||
import CameraPanel from "./CameraPanel";
|
||||
import { CAMERA_IDS } from "../../../../app/config/cameraConfig";
|
||||
|
||||
type CameraSettingsProps = {
|
||||
setTabIndex: (tabIndex: number) => void;
|
||||
@@ -12,7 +13,6 @@ type CameraSettingsProps = {
|
||||
};
|
||||
|
||||
const CameraSettings = ({
|
||||
tabIndex,
|
||||
setTabIndex,
|
||||
isResetAllModalOpen,
|
||||
handleClose,
|
||||
@@ -26,34 +26,20 @@ const CameraSettings = ({
|
||||
onSelect={(index) => setTabIndex(index)}
|
||||
>
|
||||
<TabList>
|
||||
<Tab>Camera A</Tab>
|
||||
<Tab>Camera B</Tab>
|
||||
<Tab>Camera C</Tab>
|
||||
{CAMERA_IDS.map((id) => (
|
||||
<Tab key={id}>Camera {id}</Tab>
|
||||
))}
|
||||
</TabList>
|
||||
<TabPanel>
|
||||
<CameraPanel
|
||||
tabIndex={tabIndex}
|
||||
isResetAllModalOpen={isResetAllModalOpen}
|
||||
handleClose={handleClose}
|
||||
setIsResetModalOpen={setIsResetModalOpen}
|
||||
/>
|
||||
</TabPanel>
|
||||
<TabPanel>
|
||||
<CameraPanel
|
||||
tabIndex={tabIndex}
|
||||
isResetAllModalOpen={isResetAllModalOpen}
|
||||
handleClose={handleClose}
|
||||
setIsResetModalOpen={setIsResetModalOpen}
|
||||
/>
|
||||
</TabPanel>
|
||||
<TabPanel>
|
||||
<CameraPanel
|
||||
tabIndex={tabIndex}
|
||||
isResetAllModalOpen={isResetAllModalOpen}
|
||||
handleClose={handleClose}
|
||||
setIsResetModalOpen={setIsResetModalOpen}
|
||||
/>
|
||||
</TabPanel>
|
||||
{CAMERA_IDS.map((id, index) => (
|
||||
<TabPanel key={id}>
|
||||
<CameraPanel
|
||||
tabIndex={index}
|
||||
isResetAllModalOpen={isResetAllModalOpen}
|
||||
handleClose={handleClose}
|
||||
setIsResetModalOpen={setIsResetModalOpen}
|
||||
/>
|
||||
</TabPanel>
|
||||
))}
|
||||
</Tabs>
|
||||
</Card>
|
||||
);
|
||||
|
||||
@@ -4,17 +4,14 @@ import { useCameraFeedContext } from "../../../../app/context/CameraFeedContext"
|
||||
import { useColourDectection } from "../../hooks/useColourDetection";
|
||||
import { useBlackBoard } from "../../../../hooks/useBlackBoard";
|
||||
import { toast } from "sonner";
|
||||
import {
|
||||
useCameraFeedASocket,
|
||||
useCameraFeedBSocket,
|
||||
useCameraFeedCSocket,
|
||||
} from "../../../../app/context/WebSocketContext";
|
||||
import { useCameraFeedSocket } from "../../../../app/context/WebSocketContext";
|
||||
import type { CameraID } from "../../../../app/config/cameraConfig";
|
||||
|
||||
type RegionSelectorProps = {
|
||||
regions: Region[];
|
||||
selectedRegionIndex: number;
|
||||
mode: string;
|
||||
cameraFeedID: "A" | "B" | "C";
|
||||
cameraFeedID: CameraID;
|
||||
isResetAllModalOpen: boolean;
|
||||
handleClose: () => void;
|
||||
setIsResetModalOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
@@ -33,26 +30,24 @@ const RegionSelector = ({
|
||||
const { state, dispatch } = useCameraFeedContext();
|
||||
const { blackboardMutation } = useBlackBoard();
|
||||
const paintedCells = state.paintedCells[cameraFeedID];
|
||||
const cameraASocket = useCameraFeedASocket();
|
||||
const cameraBSocket = useCameraFeedBSocket();
|
||||
const cameraCSocket = useCameraFeedCSocket();
|
||||
const cameraSocket = useCameraFeedSocket();
|
||||
|
||||
const getCurrentSocket = () => {
|
||||
switch (cameraFeedID) {
|
||||
case "A":
|
||||
return cameraASocket;
|
||||
return cameraSocket;
|
||||
case "B":
|
||||
return cameraBSocket;
|
||||
return cameraSocket;
|
||||
case "C":
|
||||
return cameraCSocket;
|
||||
return cameraSocket;
|
||||
}
|
||||
};
|
||||
|
||||
const socket = getCurrentSocket();
|
||||
|
||||
const getMagnificationLevel = () => {
|
||||
const test = socket.data;
|
||||
if (!socket.data) return null;
|
||||
const test = socket?.data;
|
||||
if (!socket?.data) return null;
|
||||
console.log(test);
|
||||
if (!test || !test.magnificationLevel) return "1x";
|
||||
return test?.magnificationLevel;
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import type { CameraID } from "../../../../../app/config/cameraConfig";
|
||||
import { useCameraFeedContext } from "../../../../../app/context/CameraFeedContext";
|
||||
import SliderComponent from "../../../../../ui/SliderComponent";
|
||||
import { useCameraZoom } from "../../../hooks/useCameraZoom";
|
||||
import { useDebouncedCallback } from "use-debounce";
|
||||
|
||||
type CameraControlsProps = {
|
||||
cameraFeedID: "A" | "B" | "C";
|
||||
cameraFeedID: CameraID;
|
||||
};
|
||||
|
||||
const CameraControls = ({ cameraFeedID }: CameraControlsProps) => {
|
||||
|
||||
@@ -3,13 +3,10 @@ import { Stage, Layer, Image, Shape } from "react-konva";
|
||||
import type { KonvaEventObject } from "konva/lib/Node";
|
||||
import { useCreateVideoSnapshot } from "../../hooks/useGetvideoSnapshots";
|
||||
import { useCameraFeedContext } from "../../../../app/context/CameraFeedContext";
|
||||
import {
|
||||
useCameraFeedASocket,
|
||||
useCameraFeedBSocket,
|
||||
useCameraFeedCSocket,
|
||||
} from "../../../../app/context/WebSocketContext";
|
||||
import { useCameraFeedSocket } from "../../../../app/context/WebSocketContext";
|
||||
import { ReadyState } from "react-use-websocket";
|
||||
import { toast } from "sonner";
|
||||
import type { CameraID } from "../../../../app/config/cameraConfig";
|
||||
|
||||
const BACKEND_WIDTH = 640;
|
||||
const BACKEND_HEIGHT = 360;
|
||||
@@ -41,22 +38,20 @@ const VideoFeedGridPainter = () => {
|
||||
const currentScale = stageSize.width / BACKEND_WIDTH;
|
||||
const size = BACKEND_CELL_SIZE * currentScale;
|
||||
|
||||
const cameraASocket = useCameraFeedASocket();
|
||||
const cameraBSocket = useCameraFeedBSocket();
|
||||
const cameraCSocket = useCameraFeedCSocket();
|
||||
const cameraSocket = useCameraFeedSocket();
|
||||
|
||||
const getCurrentSocket = () => {
|
||||
switch (cameraFeedID) {
|
||||
case "A":
|
||||
return cameraASocket;
|
||||
return cameraSocket;
|
||||
case "B":
|
||||
return cameraBSocket;
|
||||
return cameraSocket;
|
||||
case "C":
|
||||
return cameraCSocket;
|
||||
return cameraSocket;
|
||||
}
|
||||
};
|
||||
|
||||
const handleZoomClick = (e: KonvaEventObject<MouseEvent>, cameraFeedID: "A" | "B" | "C") => {
|
||||
const handleZoomClick = (e: KonvaEventObject<MouseEvent>, cameraFeedID: CameraID) => {
|
||||
if (mode !== "zoom") return;
|
||||
const socket = getCurrentSocket();
|
||||
const stage = e.target.getStage();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useQuery, useMutation } from "@tanstack/react-query";
|
||||
import { CAMBASE } from "../../../utils/config";
|
||||
import type { CameraZoomConfig } from "../../../types/types";
|
||||
import type { CameraID } from "../../../app/config/cameraConfig";
|
||||
|
||||
const fetchZoomLevel = async (cameraFeedID: string) => {
|
||||
const response = await fetch(`${CAMBASE}/api/fetch-config?id=Camera${cameraFeedID}-onvif-controller`);
|
||||
@@ -34,7 +35,7 @@ const postZoomLevel = async (zoomConfig: CameraZoomConfig) => {
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const useCameraZoom = (cameraFeedID: "A" | "B" | "C") => {
|
||||
export const useCameraZoom = (cameraFeedID: CameraID) => {
|
||||
const cameraZoomQuery = useQuery({
|
||||
queryKey: ["cameraZoom", cameraFeedID],
|
||||
queryFn: () => fetchZoomLevel(cameraFeedID),
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { CAMBASE } from "../../../utils/config";
|
||||
import type { CameraID } from "../../../app/config/cameraConfig";
|
||||
|
||||
const targetDectionFeed = async (cameraFeedID: "A" | "B" | "C" | null) => {
|
||||
const targetDectionFeed = async (cameraFeedID: CameraID | null) => {
|
||||
const response = await fetch(`${CAMBASE}/TargetDetectionColour${cameraFeedID}-preview`, {
|
||||
signal: AbortSignal.timeout(300000),
|
||||
cache: "no-store",
|
||||
@@ -12,7 +13,7 @@ const targetDectionFeed = async (cameraFeedID: "A" | "B" | "C" | null) => {
|
||||
return response.blob();
|
||||
};
|
||||
|
||||
const getVideoFeed = async (cameraFeedID: "A" | "B" | "C" | null) => {
|
||||
const getVideoFeed = async (cameraFeedID: CameraID | null) => {
|
||||
const response = await fetch(`${CAMBASE}/Camera${cameraFeedID}-preview`, {
|
||||
signal: AbortSignal.timeout(300000),
|
||||
cache: "no-store",
|
||||
@@ -23,7 +24,7 @@ const getVideoFeed = async (cameraFeedID: "A" | "B" | "C" | null) => {
|
||||
return response.blob();
|
||||
};
|
||||
|
||||
export const useGetVideoFeed = (cameraFeedID: "A" | "B" | "C" | null, mode: string) => {
|
||||
export const useGetVideoFeed = (cameraFeedID: CameraID | null, mode: string) => {
|
||||
const targetDetectionQuery = useQuery({
|
||||
queryKey: ["getfeed", cameraFeedID],
|
||||
queryFn: () => targetDectionFeed(cameraFeedID),
|
||||
|
||||
@@ -3,6 +3,7 @@ import { useGetSystemHealth } from "../hooks/useGetSystemHealth";
|
||||
import CameraStatus from "./cameraStatus/CameraStatus";
|
||||
import SystemHealthCard from "./systemHealth/SystemHealthCard";
|
||||
import SystemStatusCard from "./systemStatus/SystemStatusCard";
|
||||
import { CAMERA_IDS } from "../../../app/config/cameraConfig";
|
||||
|
||||
const DashboardGrid = () => {
|
||||
const { query } = useGetSystemHealth();
|
||||
@@ -26,30 +27,35 @@ const DashboardGrid = () => {
|
||||
channelA: [],
|
||||
channelB: [],
|
||||
channelC: [],
|
||||
// todo: check if more cameras will be added later
|
||||
default: [],
|
||||
},
|
||||
);
|
||||
|
||||
const categoryA = statusCategories?.channelA ?? [];
|
||||
const categoryB = statusCategories?.channelB ?? [];
|
||||
const categoryC = statusCategories?.channelC ?? [];
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-1 md:grid-rows-2 md:grid-cols-2 gap-4">
|
||||
<SystemStatusCard />
|
||||
<SystemHealthCard
|
||||
startTime={startTime}
|
||||
uptime={uptime}
|
||||
statuses={statuses}
|
||||
isLoading={isLoading}
|
||||
isError={isError}
|
||||
dateUpdatedAt={dateUpdatedAt}
|
||||
refetch={refetch}
|
||||
/>
|
||||
<div className="grid grid-cols-1 md:col-span-2 md:grid-cols-3 gap-x-4">
|
||||
<CameraStatus title="Camera A" category={categoryA} isError={isError} />
|
||||
<CameraStatus title="Camera B" category={categoryB} isError={isError} />
|
||||
<CameraStatus title="Camera C" category={categoryC} isError={isError} />
|
||||
<div className="grid grid-cols-1 md:grid-rows-0 md:grid-cols-2 gap-4 md:col-span-2">
|
||||
<SystemStatusCard />
|
||||
<SystemHealthCard
|
||||
startTime={startTime}
|
||||
uptime={uptime}
|
||||
statuses={statuses}
|
||||
isLoading={isLoading}
|
||||
isError={isError}
|
||||
dateUpdatedAt={dateUpdatedAt}
|
||||
refetch={refetch}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:col-span-2 md:grid-cols-[repeat(3,1fr)] gap-x-4">
|
||||
{CAMERA_IDS.map((cameraID) => (
|
||||
<CameraStatus
|
||||
key={cameraID}
|
||||
title={`Camera ${cameraID}`}
|
||||
category={statusCategories?.[`channel${cameraID}`] ?? []}
|
||||
isError={isError}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { useState } from "react";
|
||||
import type { SystemHealthStatus } from "../../../../types/types";
|
||||
import { capitalize } from "../../../../utils/utils";
|
||||
|
||||
import SystemHealthModal from "../systemHealth/systemHealthModal/SystemHealthModal";
|
||||
import Badge from "../../../../ui/Badge";
|
||||
|
||||
type CameraStatusGridItemProps = {
|
||||
title: string;
|
||||
@@ -15,6 +16,10 @@ const CameraStatusGridItem = ({ title, statusCategory }: CameraStatusGridItemPro
|
||||
return status.tags.every((tag) => allowedTags.includes(tag));
|
||||
});
|
||||
|
||||
const downItems = statusCategory?.filter((status) => {
|
||||
return status.tags.some((tag) => tag !== "RUNNING" && tag !== "VIDEO-PLAYING");
|
||||
});
|
||||
|
||||
const handleClick = () => {
|
||||
setIsOpen(false);
|
||||
};
|
||||
@@ -24,8 +29,21 @@ const CameraStatusGridItem = ({ title, statusCategory }: CameraStatusGridItemPro
|
||||
className="flex flex-col border border-gray-600 p-4 rounded-lg mr-4 hover:bg-[#233241] hover:cursor-pointer m-2 h-70"
|
||||
onClick={() => setIsOpen(true)}
|
||||
>
|
||||
<h3 className="text-lg flex flex-row items-center">{capitalize(title)}</h3>
|
||||
<p className="text-sm text-slate-300">{isAllGood ? "Click to view module status" : "Some systems down"}</p>
|
||||
<p className="text-sm text-slate-300">
|
||||
{isAllGood ? (
|
||||
"Click to view module status"
|
||||
) : (
|
||||
<>
|
||||
<ul>
|
||||
{downItems.map((item) => (
|
||||
<li key={item.id} className="flex justify-between mb-2">
|
||||
<span>{item.id}</span> <Badge text={item.tags[0]} />
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</>
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
<SystemHealthModal
|
||||
isSystemHealthModalOpen={isOpen}
|
||||
|
||||
@@ -25,7 +25,7 @@ const SystemHealthCard = ({
|
||||
refetch,
|
||||
}: SystemOverviewProps) => {
|
||||
return (
|
||||
<Card className="p-4">
|
||||
<Card className="p-4 ">
|
||||
<CardHeader title="System Health" refetch={refetch} icon={faArrowsRotate} />
|
||||
<SystemHealth
|
||||
startTime={startTime}
|
||||
|
||||
@@ -29,7 +29,7 @@ const SystemStatusCard = () => {
|
||||
);
|
||||
}
|
||||
return (
|
||||
<Card className="p-4">
|
||||
<Card className="p-4 ">
|
||||
<CardHeader title="System Status" />
|
||||
{stats ? (
|
||||
<div className="grid grid-cols-2 grid-rows-2 gap-4 col-span-2">
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
import { Route as rootRouteImport } from './routes/__root'
|
||||
import { Route as SettingsRouteImport } from './routes/settings'
|
||||
import { Route as OutputRouteImport } from './routes/output'
|
||||
import { Route as BaywatchRouteImport } from './routes/baywatch'
|
||||
import { Route as CamerasRouteImport } from './routes/cameras'
|
||||
import { Route as AboutRouteImport } from './routes/about'
|
||||
import { Route as IndexRouteImport } from './routes/index'
|
||||
|
||||
@@ -25,9 +25,9 @@ const OutputRoute = OutputRouteImport.update({
|
||||
path: '/output',
|
||||
getParentRoute: () => rootRouteImport,
|
||||
} as any)
|
||||
const BaywatchRoute = BaywatchRouteImport.update({
|
||||
id: '/baywatch',
|
||||
path: '/baywatch',
|
||||
const CamerasRoute = CamerasRouteImport.update({
|
||||
id: '/cameras',
|
||||
path: '/cameras',
|
||||
getParentRoute: () => rootRouteImport,
|
||||
} as any)
|
||||
const AboutRoute = AboutRouteImport.update({
|
||||
@@ -44,14 +44,14 @@ const IndexRoute = IndexRouteImport.update({
|
||||
export interface FileRoutesByFullPath {
|
||||
'/': typeof IndexRoute
|
||||
'/about': typeof AboutRoute
|
||||
'/baywatch': typeof BaywatchRoute
|
||||
'/cameras': typeof CamerasRoute
|
||||
'/output': typeof OutputRoute
|
||||
'/settings': typeof SettingsRoute
|
||||
}
|
||||
export interface FileRoutesByTo {
|
||||
'/': typeof IndexRoute
|
||||
'/about': typeof AboutRoute
|
||||
'/baywatch': typeof BaywatchRoute
|
||||
'/cameras': typeof CamerasRoute
|
||||
'/output': typeof OutputRoute
|
||||
'/settings': typeof SettingsRoute
|
||||
}
|
||||
@@ -59,22 +59,22 @@ export interface FileRoutesById {
|
||||
__root__: typeof rootRouteImport
|
||||
'/': typeof IndexRoute
|
||||
'/about': typeof AboutRoute
|
||||
'/baywatch': typeof BaywatchRoute
|
||||
'/cameras': typeof CamerasRoute
|
||||
'/output': typeof OutputRoute
|
||||
'/settings': typeof SettingsRoute
|
||||
}
|
||||
export interface FileRouteTypes {
|
||||
fileRoutesByFullPath: FileRoutesByFullPath
|
||||
fullPaths: '/' | '/about' | '/baywatch' | '/output' | '/settings'
|
||||
fullPaths: '/' | '/about' | '/cameras' | '/output' | '/settings'
|
||||
fileRoutesByTo: FileRoutesByTo
|
||||
to: '/' | '/about' | '/baywatch' | '/output' | '/settings'
|
||||
id: '__root__' | '/' | '/about' | '/baywatch' | '/output' | '/settings'
|
||||
to: '/' | '/about' | '/cameras' | '/output' | '/settings'
|
||||
id: '__root__' | '/' | '/about' | '/cameras' | '/output' | '/settings'
|
||||
fileRoutesById: FileRoutesById
|
||||
}
|
||||
export interface RootRouteChildren {
|
||||
IndexRoute: typeof IndexRoute
|
||||
AboutRoute: typeof AboutRoute
|
||||
BaywatchRoute: typeof BaywatchRoute
|
||||
CamerasRoute: typeof CamerasRoute
|
||||
OutputRoute: typeof OutputRoute
|
||||
SettingsRoute: typeof SettingsRoute
|
||||
}
|
||||
@@ -95,11 +95,11 @@ declare module '@tanstack/react-router' {
|
||||
preLoaderRoute: typeof OutputRouteImport
|
||||
parentRoute: typeof rootRouteImport
|
||||
}
|
||||
'/baywatch': {
|
||||
id: '/baywatch'
|
||||
path: '/baywatch'
|
||||
fullPath: '/baywatch'
|
||||
preLoaderRoute: typeof BaywatchRouteImport
|
||||
'/cameras': {
|
||||
id: '/cameras'
|
||||
path: '/cameras'
|
||||
fullPath: '/cameras'
|
||||
preLoaderRoute: typeof CamerasRouteImport
|
||||
parentRoute: typeof rootRouteImport
|
||||
}
|
||||
'/about': {
|
||||
@@ -122,7 +122,7 @@ declare module '@tanstack/react-router' {
|
||||
const rootRouteChildren: RootRouteChildren = {
|
||||
IndexRoute: IndexRoute,
|
||||
AboutRoute: AboutRoute,
|
||||
BaywatchRoute: BaywatchRoute,
|
||||
CamerasRoute: CamerasRoute,
|
||||
OutputRoute: OutputRoute,
|
||||
SettingsRoute: SettingsRoute,
|
||||
}
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
import { createFileRoute } from "@tanstack/react-router";
|
||||
import CameraGrid from "../features/cameras/components/CameraGrid";
|
||||
|
||||
export const Route = createFileRoute("/baywatch")({
|
||||
export const Route = createFileRoute("/cameras")({
|
||||
component: RouteComponent,
|
||||
});
|
||||
|
||||
function RouteComponent() {
|
||||
return (
|
||||
<div>
|
||||
<CameraGrid />
|
||||
</div>
|
||||
);
|
||||
return <CameraGrid />;
|
||||
}
|
||||
@@ -6,9 +6,5 @@ export const Route = createFileRoute("/output")({
|
||||
});
|
||||
|
||||
function RouteComponent() {
|
||||
return (
|
||||
<div>
|
||||
<OutputForms />
|
||||
</div>
|
||||
);
|
||||
return <OutputForms />;
|
||||
}
|
||||
|
||||
@@ -6,9 +6,5 @@ export const Route = createFileRoute("/settings")({
|
||||
});
|
||||
|
||||
function RouteComponent() {
|
||||
return (
|
||||
<div>
|
||||
<Settings />
|
||||
</div>
|
||||
);
|
||||
return <Settings />;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import type { CameraID } from "../app/config/cameraConfig";
|
||||
|
||||
export type WebSocketContextValue = {
|
||||
connected: boolean;
|
||||
send?: (msg: unknown) => void;
|
||||
@@ -128,57 +130,42 @@ export type OptionalBOF2LaneIDs = {
|
||||
};
|
||||
|
||||
export type CameraFeedState = {
|
||||
cameraFeedID: "A" | "B" | "C";
|
||||
paintedCells: {
|
||||
A: Map<string, PaintedCell>;
|
||||
B: Map<string, PaintedCell>;
|
||||
C: Map<string, PaintedCell>;
|
||||
};
|
||||
regionsByCamera: {
|
||||
A: Region[];
|
||||
B: Region[];
|
||||
C: Region[];
|
||||
};
|
||||
cameraFeedID: CameraID;
|
||||
paintedCells: Record<CameraID, Map<string, PaintedCell>>;
|
||||
|
||||
regionsByCamera: Record<CameraID, Region[]>;
|
||||
selectedRegionIndex: number;
|
||||
modeByCamera: {
|
||||
A: string;
|
||||
B: string;
|
||||
C: string;
|
||||
};
|
||||
modeByCamera: Record<CameraID, string>;
|
||||
|
||||
tabIndex?: number;
|
||||
zoomLevel: {
|
||||
A: number;
|
||||
B: number;
|
||||
C: number;
|
||||
};
|
||||
zoomLevel: Record<CameraID, number>;
|
||||
};
|
||||
|
||||
export type CameraFeedAction =
|
||||
| {
|
||||
type: "SET_CAMERA_FEED";
|
||||
payload: "A" | "B" | "C";
|
||||
payload: CameraID;
|
||||
}
|
||||
| {
|
||||
type: "CHANGE_MODE";
|
||||
payload: { cameraFeedID: "A" | "B" | "C"; mode: string };
|
||||
payload: { cameraFeedID: CameraID; mode: string };
|
||||
}
|
||||
| { type: "SET_SELECTED_REGION_INDEX"; payload: number }
|
||||
| {
|
||||
type: "SET_SELECTED_REGION_COLOUR";
|
||||
payload: { cameraFeedID: "A" | "B" | "C"; regionName: string; newColour: string };
|
||||
payload: { cameraFeedID: CameraID; regionName: string; newColour: string };
|
||||
}
|
||||
| {
|
||||
type: "ADD_NEW_REGION";
|
||||
payload: { cameraFeedID: "A" | "B" | "C"; regionName: string; brushColour: string };
|
||||
payload: { cameraFeedID: CameraID; regionName: string; brushColour: string };
|
||||
}
|
||||
| {
|
||||
type: "REMOVE_REGION";
|
||||
payload: { cameraFeedID: "A" | "B" | "C"; regionName: string };
|
||||
payload: { cameraFeedID: CameraID; regionName: string };
|
||||
}
|
||||
| {
|
||||
type: "RESET_PAINTED_CELLS";
|
||||
payload: { cameraFeedID: "A" | "B" | "C"; paintedCells: Map<string, PaintedCell> };
|
||||
payload: { cameraFeedID: CameraID; paintedCells: Map<string, PaintedCell> };
|
||||
}
|
||||
| {
|
||||
type: "SET_CAMERA_FEED_DATA";
|
||||
@@ -189,7 +176,7 @@ export type CameraFeedAction =
|
||||
}
|
||||
| {
|
||||
type: "SET_ZOOM_LEVEL";
|
||||
payload: { cameraFeedID: "A" | "B" | "C"; zoomLevel: number };
|
||||
payload: { cameraFeedID: CameraID; zoomLevel: number };
|
||||
};
|
||||
|
||||
export type DecodeReading = {
|
||||
@@ -211,7 +198,7 @@ export type ColourData = {
|
||||
};
|
||||
|
||||
export type ColourDetectionPayload = {
|
||||
cameraFeedID: "A" | "B" | "C";
|
||||
cameraFeedID: CameraID;
|
||||
regions: ColourData[];
|
||||
};
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ const Header = () => {
|
||||
</Link>
|
||||
|
||||
<Link
|
||||
to="/baywatch"
|
||||
to="/cameras"
|
||||
className="[&.active]:font-bold [&.active]:bg-gray-700 p-2 rounded-lg flex items-center gap-2 hover:bg-gray-700"
|
||||
>
|
||||
Cameras
|
||||
@@ -58,7 +58,7 @@ const Header = () => {
|
||||
{/* <FontAwesomeIcon icon={faGaugeHigh} /> */}
|
||||
Dashboard
|
||||
</Link>
|
||||
<Link to="/baywatch" className="" onClick={toggleMenu}>
|
||||
<Link to="/cameras" className="" onClick={toggleMenu}>
|
||||
{/* <FontAwesomeIcon icon={faGaugeHigh} /> */}
|
||||
Cameras
|
||||
</Link>
|
||||
|
||||
Reference in New Issue
Block a user