UNPKG

@seontechnologies/seon-id-verification

Version:

An advanced SDK featuring web components for natural person identification through document scanning, facial recognition, hand gesture, and face turning detection, designed for secure and efficient user verification.

212 lines (211 loc) 7.05 kB
import { D as Z, y as b, t as V, l as n, z as $, A as F, C as D, j as x } from "./index-oGnhSncZ.mjs"; import { I as B, U as ee, k as te } from "./UploadLivenessVideo-ia7J-Ak0.mjs"; import { useRef as f, useState as H, useMemo as M, useCallback as k, useEffect as J } from "react"; import { S as re } from "./SelectInput-D_egVIuA.mjs"; let h; const I = []; let t, U = () => { }, j = () => { }; const oe = ({ videoRef: r, initializeDetector: O, handleIsUploading: L, videoDurationS: l, minFaceCapturedInRow: i, onNext: z, detectionLoop: d, handleAnimationSteps: K, resetStates: R, detectorRef: P }) => { const Q = f(24), m = f(null), w = f(!1), g = f(0), u = f(null), [C, W] = H([]), [X, v] = H(!1), A = M(() => [ "video/mp4", "video/webm", "video/webm;codecs=vp8", "video/webm;codecs=daala", "video/webm;codecs=h264" ], []), E = M(() => A.find((e) => MediaRecorder.isTypeSupported(e)) || "video/webm", [A]), S = M(() => async () => { const a = (await Z()).map((c) => ({ value: c.deviceId, text: c.label })); W(a); }, []), p = k(async (e, a = []) => { L(!0); const c = new B(a); c.getUploadUrl().then(() => { c.getUploadUrlResponse().then(async (s) => { if (!(s != null && s.ok)) throw new Error("Error getting video upload url"); let _ = (e == null ? void 0 : e.size) || 0; for (; _ === 0; ) _ = (e == null ? void 0 : e.size) || 0; const y = new ee({ url: s.videoUploadUrl, video: e || null, mimeType: E }); await y.startUploadLivenessVideo(), y.getUploadLivenessVideoResponse().then((o) => { if (o.ok === !1) throw new Error("Error uploading video"); return o; }).then((o) => { b(), z(); }).catch((o) => { b(), V({ title: n.error_liveness_upload_title, description: n.error_liveness_upload_description, btnText: n.restart_button, ERROR: o }); }); }).catch((s) => { b(), V({ title: n.error_liveness_upload_title, description: n.error_liveness_upload_description, btnText: n.restart_button, ERROR: s }); }); }).catch((s) => { b(), V({ title: n.error_liveness_upload_title, description: n.error_liveness_upload_description, btnText: n.restart_button, ERROR: s }); }); }, [L, E, z]), q = k(() => { !h || (t == null ? void 0 : t.state) === "recording" || (t = new MediaRecorder(h, { mimeType: E || "video/webm" }), t.ondataavailable = (e) => { e.data.size > 0 && I.push(e.data); }, t.onstop = async () => { const e = new Blob(I, { type: E || "video/webm" }); u.current = e, I.length = 0; }, t.start()); }, [E]), T = k(async (e = "") => { var c, s; if (P.current instanceof te && e.length === 0) { d({ capturedInRow: g, videoDetectedChunkStartingTime: m, isDurationCompleted: w, mediaRecorder: t, capturedVideo: u, minFaceCapturedInRow: i, videoDurationS: l, setIsRecordingStopped: v, uploadVideo: p }), U = () => { d({ capturedInRow: g, videoDetectedChunkStartingTime: m, isDurationCompleted: w, mediaRecorder: t, capturedVideo: u, minFaceCapturedInRow: i, videoDurationS: l, setIsRecordingStopped: v, uploadVideo: p }); }, (c = r.current) == null || c.addEventListener("change", U), j = () => { d({ capturedInRow: g, videoDetectedChunkStartingTime: m, isDurationCompleted: w, mediaRecorder: t, capturedVideo: u, minFaceCapturedInRow: i, videoDurationS: l, setIsRecordingStopped: v, uploadVideo: p }); }, (s = r.current) == null || s.addEventListener("loadeddata", j); return; } $() || V({ ERROR: "Camera access denied" }); const a = { video: { deviceId: { exact: e.length > 0 ? e : (await F()).deviceId } } }; navigator.mediaDevices.getUserMedia(a).then(async (_) => { var y, o, N; if (r.current) { if (!((y = r.current) != null && y.srcObject) || e.length > 0) { const G = await D(_); h = G.stream, r.current.srcObject = h, Q.current = G.frameRate; } else d({ capturedInRow: g, videoDetectedChunkStartingTime: m, isDurationCompleted: w, mediaRecorder: t, capturedVideo: u, minFaceCapturedInRow: i, videoDurationS: l, setIsRecordingStopped: v, uploadVideo: p }); U = () => { d({ capturedInRow: g, videoDetectedChunkStartingTime: m, isDurationCompleted: w, mediaRecorder: t, capturedVideo: u, minFaceCapturedInRow: i, videoDurationS: l, setIsRecordingStopped: v, uploadVideo: p }); }, (o = r.current) == null || o.addEventListener("change", U), j = () => { d({ capturedInRow: g, videoDetectedChunkStartingTime: m, isDurationCompleted: w, mediaRecorder: t, capturedVideo: u, minFaceCapturedInRow: i, videoDurationS: l, setIsRecordingStopped: v, uploadVideo: p }); }, (N = r.current) == null || N.addEventListener("loadeddata", j); } }).then(() => { q(); }).catch((_) => { console.error(_); }); }, [ d, P, i, q, p, l, r ]); J(() => (O().then(() => { T().then(() => { S().catch((e) => { }); }).catch((e) => { }); }).catch((e) => { }), () => { var e, a; (e = r.current) == null || e.removeEventListener("change", U), (a = r.current) == null || a.removeEventListener("loadeddata", j); }), [S, T, O, r]), J(() => () => { h == null || h.getTracks().forEach((e) => { e.stop(); }), t = null, b(); }, []); const Y = k((e) => { r.current && (t.stop(), b(), R && R(), O().then(() => { T(e.value); })); }, [T, O, R, r]); return K({ isRecordingStopped: X }), x.jsxs(x.Fragment, { children: [C.length <= 1 ? null : x.jsx("div", { className: "tw-absolute tw-z-[9999] tw-top-[-36px] hover:tw-top-1 tw-opacity-100 hover:tw-opacity-75 tw-transition-all tw-duration-300", children: x.jsx(re, { idPrefix: "liveness-camera", onChange: Y, options: C, placeholder: C[0], chevronPosition: "bottom" }) }), x.jsx("video", { id: "liveness-webcam", ref: r, className: "tw-bg-black tw-object-cover tw-object-center tw-max-w-none tw-w-full tw-h-full sm:tw-h-auto", autoPlay: !0, playsInline: !0 })] }); }; export { oe as M };