Skip to content

Commit

Permalink
updated with requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanuj1718 committed Feb 17, 2025
1 parent ffdbb95 commit 4db802e
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions src/components/Common/AvatarEditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ const AvatarEditModal = ({
const [selectedFile, setSelectedFile] = useState<File>();
const [preview, setPreview] = useState<string>();
const [isCameraOpen, setIsCameraOpen] = useState<boolean>(false);
const webRef = useRef<any>(null);
const [previewImage, setPreviewImage] = useState(null);
const webRef = useRef<Webcam>(null);
const [previewImage, setPreviewImage] = useState<string | null>(null);
const [isCaptureImgBeingUploaded, setIsCaptureImgBeingUploaded] =
useState(false);
const [constraint, setConstraint] = useState<IVideoConstraint>(
Expand All @@ -81,21 +81,34 @@ const AvatarEditModal = ({
}, []);

const captureImage = () => {
setPreviewImage(webRef.current.getScreenshot());
const canvas = webRef.current.getCanvas();
canvas?.toBlob((blob: Blob) => {
const myFile = new File([blob], "image.png", {
type: blob.type,
});
setSelectedFile(myFile);
if (webRef.current) {
setPreviewImage(webRef.current.getScreenshot());
}
const canvas = webRef.current?.getCanvas();
canvas?.toBlob((blob) => {
if (blob) {
const myFile = new File([blob], "image.png", {
type: blob.type,
});
setSelectedFile(myFile);
} else {
toast.error(t("failed_to_capture_image"));
}
});
};
const stopCamera = useCallback(() => {
const openCamera = webRef.current?.photo?.srcObject as MediaStream;
if (openCamera) {
openCamera.getTracks().forEach((track) => track.stop());
try {
if (webRef.current) {
const openCamera = webRef.current?.video?.srcObject as MediaStream;
if (openCamera) {
openCamera.getTracks().forEach((track) => track.stop());
}
}
} catch (error: any) {
toast.error("Failed to stop camera: ", error);
} finally {
setIsCameraOpen(false);
}
setIsCameraOpen(false);
}, []);
const closeModal = () => {
setPreview(undefined);
Expand Down

0 comments on commit 4db802e

Please sign in to comment.