Merge branch 'develop' into feature/digitalZoom
This commit is contained in:
48
src/features/cameras/hooks/useCameraZoom.ts
Normal file
48
src/features/cameras/hooks/useCameraZoom.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { useQuery, useMutation } from "@tanstack/react-query";
|
||||
import { CAMBASE } from "../../../utils/config";
|
||||
import type { CameraZoomConfig } from "../../../types/types";
|
||||
|
||||
const fetchZoomLevel = async (cameraFeedID: string) => {
|
||||
const response = await fetch(`${CAMBASE}/api/fetch-config?id=Camera${cameraFeedID}-onvif-controller`);
|
||||
if (!response.ok) {
|
||||
throw new Error("Network response was not ok");
|
||||
}
|
||||
return response.json();
|
||||
};
|
||||
|
||||
const postZoomLevel = async (zoomConfig: CameraZoomConfig) => {
|
||||
const fields = [
|
||||
{ property: "propPhysCurrent", value: zoomConfig.zoomLevel },
|
||||
{ property: "propCameraHost", value: "192.168.0.101" },
|
||||
{ property: "propCameraPort", value: 80 },
|
||||
{ property: "propCameraUsername", value: "administrator" },
|
||||
{ property: "propCameraPassword", value: "MAV12345" },
|
||||
];
|
||||
const zoomPayload = {
|
||||
id: `Camera${zoomConfig.cameraFeedID}-onvif-controller`,
|
||||
fields,
|
||||
};
|
||||
console.log(zoomPayload);
|
||||
const response = await fetch(`${CAMBASE}/api/update-config`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(zoomPayload),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("Network response was not ok");
|
||||
}
|
||||
return response.json();
|
||||
};
|
||||
|
||||
export const useCameraZoom = (cameraFeedID: "A" | "B" | "C") => {
|
||||
const cameraZoomQuery = useQuery({
|
||||
queryKey: ["cameraZoom", cameraFeedID],
|
||||
queryFn: () => fetchZoomLevel(cameraFeedID),
|
||||
});
|
||||
|
||||
const cameraZoomMutation = useMutation({
|
||||
mutationKey: ["postCameraZoom"],
|
||||
mutationFn: (zoomConfig: CameraZoomConfig) => postZoomLevel(zoomConfig),
|
||||
});
|
||||
return { cameraZoomQuery, cameraZoomMutation };
|
||||
};
|
||||
Reference in New Issue
Block a user