import {useRef, useState, useCallback} from 'react'; import Webcam from "react-webcam"; import {Button} from '@mui/material'; import { fileMessage } from '../../../../reducers/messageReducer'; import { useDispatch } from 'react-redux'; import { getUserAvatar } from '../../../../reducers/userDataReducer'; const WebcamCapture = () => { const dispatch = useDispatch(); const webcamRef = useRef(null); const [imgSrc, setImgSrc] = useState(null); const sendPhotoToChat = async (imageStream) => { const blob = await fetch(imageStream).then((res) => res.blob()); dispatch(fileMessage(blob)) } const savePhotoToAvatar = async (imageStream) => { const blob = await fetch(imageStream).then((res) => res.blob()); dispatch(getUserAvatar(blob)) } const capture = useCallback(async () => { const imageSrc = webcamRef.current.getScreenshot(); setImgSrc(imageSrc); }, [webcamRef, setImgSrc]); return (
{imgSrc && ( <> )}
); }; export default WebcamCapture;