+
-
+
- {
- const cells = paintedCells;
- if (!cells || cells.size === 0 || !paintLayerRef.current) return;
- cells?.forEach((cell, key) => {
- const [rowStr, colStr] = key.split("-");
- const row = Number(rowStr);
- const col = Number(colStr);
+ {mode === "painter" || mode === "eraser" ? (
+ {
+ const cells = paintedCells;
+ if (!cells || cells.size === 0 || !paintLayerRef.current) return;
+ cells?.forEach((cell, key) => {
+ const [rowStr, colStr] = key.split("-");
+ const row = Number(rowStr);
+ const col = Number(colStr);
- const x = col * (size + gap);
- const y = row * (size + gap);
+ const x = col * (size + gap);
+ const y = row * (size + gap);
- ctx.beginPath();
- ctx.rect(x, y, size, size);
- ctx.fillStyle = cell.colour;
- ctx.fill();
- });
+ ctx.beginPath();
+ ctx.rect(x, y, size, size);
+ ctx.fillStyle = cell.colour;
+ ctx.fill();
+ });
- ctx.fillStrokeShape(shape);
- }}
- width={stageSize.width}
- height={stageSize.height}
- />
+ ctx.fillStrokeShape(shape);
+ }}
+ width={stageSize.width}
+ height={stageSize.height}
+ />
+ ) : null}
diff --git a/src/features/cameras/hooks/useGetVideoFeed.ts b/src/features/cameras/hooks/useGetVideoFeed.ts
index 660458a..44b2796 100644
--- a/src/features/cameras/hooks/useGetVideoFeed.ts
+++ b/src/features/cameras/hooks/useGetVideoFeed.ts
@@ -1,7 +1,7 @@
import { useQuery } from "@tanstack/react-query";
import { CAMBASE } from "../../../utils/config";
-const getfeed = async (cameraFeedID: "A" | "B" | "C" | null) => {
+const targetDectionFeed = async (cameraFeedID: "A" | "B" | "C" | null) => {
const response = await fetch(`${CAMBASE}/TargetDetectionColour${cameraFeedID}-preview`, {
signal: AbortSignal.timeout(300000),
cache: "no-store",
@@ -12,12 +12,31 @@ const getfeed = async (cameraFeedID: "A" | "B" | "C" | null) => {
return response.blob();
};
-export const useGetVideoFeed = (cameraFeedID: "A" | "B" | "C" | null) => {
- const videoQuery = useQuery({
+const getVideoFeed = async (cameraFeedID: "A" | "B" | "C" | null) => {
+ const response = await fetch(`${CAMBASE}/Camera${cameraFeedID}-preview`, {
+ signal: AbortSignal.timeout(300000),
+ cache: "no-store",
+ });
+ if (!response.ok) {
+ throw new Error(`Cannot reach endpoint (${response.status})`);
+ }
+ return response.blob();
+};
+
+export const useGetVideoFeed = (cameraFeedID: "A" | "B" | "C" | null, mode: string) => {
+ const targetDetectionQuery = useQuery({
queryKey: ["getfeed", cameraFeedID],
- queryFn: () => getfeed(cameraFeedID),
+ queryFn: () => targetDectionFeed(cameraFeedID),
refetchInterval: 500,
+ enabled: mode !== "zoom",
});
- return { videoQuery };
+ const videoFeedQuery = useQuery({
+ queryKey: ["videoQuery", cameraFeedID, mode],
+ queryFn: () => getVideoFeed(cameraFeedID),
+ refetchInterval: 500,
+ enabled: mode === "zoom",
+ });
+
+ return { targetDetectionQuery, videoFeedQuery };
};
diff --git a/src/features/cameras/hooks/useGetvideoSnapshots.ts b/src/features/cameras/hooks/useGetvideoSnapshots.ts
index 9bf941d..da70292 100644
--- a/src/features/cameras/hooks/useGetvideoSnapshots.ts
+++ b/src/features/cameras/hooks/useGetvideoSnapshots.ts
@@ -5,11 +5,19 @@ import { useCameraFeedContext } from "../../../app/context/CameraFeedContext";
export const useCreateVideoSnapshot = () => {
const { state } = useCameraFeedContext();
const cameraFeedID = state?.cameraFeedID;
+ const mode = state.modeByCamera[cameraFeedID];
const latestBitmapRef = useRef
(null);
- const { videoQuery } = useGetVideoFeed(cameraFeedID);
+ const { targetDetectionQuery, videoFeedQuery } = useGetVideoFeed(cameraFeedID, mode);
- const snapShot = videoQuery?.data;
- const isloading = videoQuery.isPending;
+ let snapShot = targetDetectionQuery?.data;
+ const isloading = targetDetectionQuery.isPending;
+
+ const videoSnapShot = videoFeedQuery?.data;
+ const isVideoLoading = videoFeedQuery.isPending;
+
+ if (isVideoLoading === false && videoSnapShot && mode === "zoom") {
+ snapShot = videoSnapShot;
+ }
useEffect(() => {
async function createBitmap() {