- updated websocket context and add heatmap support; refactor CameraSettingFields and SightingWidget components

This commit is contained in:
2025-12-16 12:17:31 +00:00
parent 555330991d
commit 29e9086d5a
6 changed files with 12 additions and 6 deletions

View File

@@ -44,7 +44,7 @@ const CameraSettingFields = ({
userName: parsed?.username ?? "", userName: parsed?.username ?? "",
password: parsed?.password ?? "", password: parsed?.password ?? "",
id: initialData?.id, id: initialData?.id,
mode: cameraMode ?? "day", mode: cameraMode ?? "",
zoom: apiZoom, zoom: apiZoom,
}), }),

View File

@@ -186,7 +186,6 @@ export default function SightingHistoryWidget({ className, title }: SightingHist
const isNPEDHitC = cat === "C"; const isNPEDHitC = cat === "C";
const isNPEDHitD = cat === "D"; const isNPEDHitD = cat === "D";
if (isNPEDHitA || isNPEDHitB || isNPEDHitC || isNPEDHitD) { if (isNPEDHitA || isNPEDHitB || isNPEDHitC || isNPEDHitD) {
console.log("first");
dispatch({ dispatch({
type: "ADD", type: "ADD",
payload: obj, payload: obj,

View File

@@ -13,11 +13,8 @@ import {
import { useState } from "react"; import { useState } from "react";
import SoundBtn from "./SoundBtn"; import SoundBtn from "./SoundBtn";
import { useIntegrationsContext } from "../../context/IntegrationsContext"; import { useIntegrationsContext } from "../../context/IntegrationsContext";
import { useInfoBarSocket } from "../../context/WebsocketContext";
export default function Header() { export default function Header() {
const { data: stats } = useInfoBarSocket();
console.log(stats);
const [isFullscreen, setIsFullscreen] = useState(false); const [isFullscreen, setIsFullscreen] = useState(false);
const [isMenuOpen, setIsMenuOpen] = useState(false); const [isMenuOpen, setIsMenuOpen] = useState(false);
const { state } = useIntegrationsContext(); const { state } = useIntegrationsContext();

View File

@@ -9,8 +9,16 @@ type InfoSocketState = {
send?: (msg: string) => void; send?: (msg: string) => void;
}; };
type heatmapSocketState = {
data: null;
readyState: ReadyState;
sendJson: (msg: unknown) => void;
send?: (msg: string) => void;
};
export type WebsocketContextValue = { export type WebsocketContextValue = {
info: InfoSocketState; info: InfoSocketState;
heatmap?: heatmapSocketState;
}; };
export const WebsocketContext = createContext<WebsocketContextValue | null>(null); export const WebsocketContext = createContext<WebsocketContextValue | null>(null);
@@ -22,3 +30,4 @@ const useWebSocketContext = () => {
}; };
export const useInfoBarSocket = () => useWebSocketContext().info; export const useInfoBarSocket = () => useWebSocketContext().info;
export const useHeatmapSocket = () => useWebSocketContext().heatmap;

View File

@@ -32,7 +32,7 @@ const WebSocketProvider = ({ children }: WebSocketProviderProps) => {
sendJson: infoSocket.sendJsonMessage, sendJson: infoSocket.sendJsonMessage,
}, },
}), }),
[infoSocket.readyState, infoSocket.sendJsonMessage, systemData] [systemData, infoSocket.readyState, infoSocket.sendJsonMessage]
); );
return <WebsocketContext.Provider value={value}>{children}</WebsocketContext.Provider>; return <WebsocketContext.Provider value={value}>{children}</WebsocketContext.Provider>;
}; };

View File

@@ -2,4 +2,5 @@ import { CAM_BASE } from "./config";
export const ws_config = { export const ws_config = {
infoBar: `${CAM_BASE.replace("http", "ws")}/websocket-infobar`, infoBar: `${CAM_BASE.replace("http", "ws")}/websocket-infobar`,
heatmap: `${CAM_BASE.replace("http", "ws")}/websocket-SystemConfig`,
}; };