23 lines
609 B
TypeScript
23 lines
609 B
TypeScript
|
|
import { useMutation } from "@tanstack/react-query";
|
||
|
|
import { CAM_BASE } from "../utils/config";
|
||
|
|
import type { ZoomInOptions } from "../types/types";
|
||
|
|
|
||
|
|
async function zoomIn(options: ZoomInOptions) {
|
||
|
|
const response = await fetch(
|
||
|
|
`${CAM_BASE}/Ip${options.camera}-command?magnification=${options.multiplier}x`
|
||
|
|
);
|
||
|
|
if (!response.ok) {
|
||
|
|
throw new Error("Cannot reach camera zoom endpoint");
|
||
|
|
}
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
export const useCameraZoom = () => {
|
||
|
|
const mutation = useMutation({
|
||
|
|
mutationKey: ["zoomIn"],
|
||
|
|
mutationFn: (options: ZoomInOptions) => zoomIn(options),
|
||
|
|
});
|
||
|
|
|
||
|
|
return { mutation };
|
||
|
|
};
|