- added Konvas lib
- added feed from proof of concept
This commit is contained in:
22
src/features/cameras/hooks/useGetVideoFeed.ts
Normal file
22
src/features/cameras/hooks/useGetVideoFeed.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
const getfeed = async () => {
|
||||
const response = await fetch(`http://100.115.148.59/TargetDetectionColour-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 = () => {
|
||||
const videoQuery = useQuery({
|
||||
queryKey: ["getfeed"],
|
||||
queryFn: getfeed,
|
||||
refetchInterval: 500,
|
||||
});
|
||||
|
||||
return { videoQuery };
|
||||
};
|
||||
25
src/features/cameras/hooks/useGetvideoSnapshots.ts
Normal file
25
src/features/cameras/hooks/useGetvideoSnapshots.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
import { useGetVideoFeed } from "./useGetVideoFeed";
|
||||
|
||||
export const useCreateVideoSnapshot = () => {
|
||||
const latestBitmapRef = useRef<ImageBitmap | null>(null);
|
||||
const { videoQuery } = useGetVideoFeed();
|
||||
|
||||
const snapShot = videoQuery?.data;
|
||||
|
||||
useEffect(() => {
|
||||
async function createBitmap() {
|
||||
if (!snapShot) return;
|
||||
|
||||
try {
|
||||
const bitmap = await createImageBitmap(snapShot);
|
||||
latestBitmapRef.current = bitmap;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
createBitmap();
|
||||
}, [snapShot]);
|
||||
|
||||
return { latestBitmapRef };
|
||||
};
|
||||
Reference in New Issue
Block a user