2025-11-21 10:12:42 +00:00
|
|
|
import { useEffect, useRef } from "react";
|
|
|
|
|
import { useGetVideoFeed } from "./useGetVideoFeed";
|
2025-11-27 10:43:56 +00:00
|
|
|
import { useCameraFeedContext } from "../../../app/context/CameraFeedContext";
|
2025-11-21 10:12:42 +00:00
|
|
|
|
|
|
|
|
export const useCreateVideoSnapshot = () => {
|
2025-11-27 10:43:56 +00:00
|
|
|
const { state } = useCameraFeedContext();
|
|
|
|
|
const cameraFeedID = state?.cameraFeedID;
|
2025-11-21 10:12:42 +00:00
|
|
|
const latestBitmapRef = useRef<ImageBitmap | null>(null);
|
2025-11-27 10:43:56 +00:00
|
|
|
const { videoQuery } = useGetVideoFeed(cameraFeedID);
|
2025-11-21 10:12:42 +00:00
|
|
|
|
|
|
|
|
const snapShot = videoQuery?.data;
|
2025-11-24 12:19:51 +00:00
|
|
|
const isloading = videoQuery.isPending;
|
2025-11-21 10:12:42 +00:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
async function createBitmap() {
|
|
|
|
|
if (!snapShot) return;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const bitmap = await createImageBitmap(snapShot);
|
2025-11-21 16:01:34 +00:00
|
|
|
if (!bitmap) return;
|
2025-11-21 10:12:42 +00:00
|
|
|
latestBitmapRef.current = bitmap;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log(error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
createBitmap();
|
|
|
|
|
}, [snapShot]);
|
|
|
|
|
|
2025-11-24 12:19:51 +00:00
|
|
|
return { latestBitmapRef, isloading };
|
2025-11-21 10:12:42 +00:00
|
|
|
};
|