()
| 36 | `; |
| 37 | |
| 38 | export default function Viewer() { |
| 39 | const webcamRef = useRef(null); |
| 40 | const [status, setStatus] = useState("Status"); |
| 41 | |
| 42 | const videoConstraints = { |
| 43 | width: 1280, |
| 44 | height: 720, |
| 45 | facingMode: "environment", // Can be "environment" or "user" |
| 46 | screenshotQuality: 1, |
| 47 | }; |
| 48 | |
| 49 | const [createMessage] = useMutation(CREATE_MESSAGE, { |
| 50 | onError: (err) => console.error(err), |
| 51 | onCompleted: () => setStatus("Request sent") |
| 52 | }); |
| 53 | |
| 54 | const capture = useCallback(() => { |
| 55 | const capturedImg = webcamRef.current.getScreenshot(); |
| 56 | createMessage({ variables: { clientId: clientId, content: capturedImg } }); |
| 57 | }, [webcamRef, createMessage]); |
| 58 | |
| 59 | |
| 60 | const [registerClient] = useMutation(REGISTER_CLIENT, { |
| 61 | onError: (err) => console.error(err), |
| 62 | onCompleted: (result) => setStatus(`Registered with ${result.createClient.client.clientId}`) |
| 63 | }); |
| 64 | useEffect(() => { |
| 65 | registerClient({ variables: { clientId: clientId } }); |
| 66 | }, [registerClient]); |
| 67 | |
| 68 | return ( |
| 69 | <Wrapper> |
| 70 | <Webcam |
| 71 | audio={false} |
| 72 | ref={webcamRef} |
| 73 | screenshotFormat="image/jpeg" |
| 74 | width="50%" |
| 75 | videoConstraints={videoConstraints} |
| 76 | /> |
| 77 | |
| 78 | <h3>{status}</h3> |
| 79 | <p> |
| 80 | <button onClick={capture}>Capture photo</button> |
| 81 | </p> |
| 82 | <ImageViewer clientId={clientId} /> |
| 83 | </Wrapper> |
| 84 | ); |
| 85 | } |
nothing calls this directly
no outgoing calls
no test coverage detected