2025-11-21 10:12:42 +00:00
|
|
|
import { useQuery } from "@tanstack/react-query";
|
2025-11-27 10:43:56 +00:00
|
|
|
import { CAMBASE } from "../../../utils/config";
|
2025-11-21 10:12:42 +00:00
|
|
|
|
2025-12-09 12:39:03 +00:00
|
|
|
const targetDectionFeed = async (cameraFeedID: "A" | "B" | "C" | null) => {
|
2025-12-08 09:03:04 +00:00
|
|
|
const response = await fetch(`${CAMBASE}/TargetDetectionColour${cameraFeedID}-preview`, {
|
2025-11-21 10:12:42 +00:00
|
|
|
signal: AbortSignal.timeout(300000),
|
|
|
|
|
cache: "no-store",
|
|
|
|
|
});
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
throw new Error(`Cannot reach endpoint (${response.status})`);
|
|
|
|
|
}
|
|
|
|
|
return response.blob();
|
|
|
|
|
};
|
|
|
|
|
|
2025-12-09 12:39:03 +00:00
|
|
|
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({
|
2025-11-27 10:43:56 +00:00
|
|
|
queryKey: ["getfeed", cameraFeedID],
|
2025-12-09 12:39:03 +00:00
|
|
|
queryFn: () => targetDectionFeed(cameraFeedID),
|
|
|
|
|
refetchInterval: 500,
|
|
|
|
|
enabled: mode !== "zoom",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const videoFeedQuery = useQuery({
|
|
|
|
|
queryKey: ["videoQuery", cameraFeedID, mode],
|
|
|
|
|
queryFn: () => getVideoFeed(cameraFeedID),
|
2025-11-21 10:12:42 +00:00
|
|
|
refetchInterval: 500,
|
2025-12-09 12:39:03 +00:00
|
|
|
enabled: mode === "zoom",
|
2025-11-21 10:12:42 +00:00
|
|
|
});
|
|
|
|
|
|
2025-12-09 12:39:03 +00:00
|
|
|
return { targetDetectionQuery, videoFeedQuery };
|
2025-11-21 10:12:42 +00:00
|
|
|
};
|