import React from 'react'; import { LivenessError } from '../types/sdkTypes'; import type { InitialiseLivenessScanProps, InitialiseLivenessScanResult, LivenessScanHandle, } from '../types/sdkTypes'; import Logger from '../utils/logger'; import type { GetIdSdk } from '@get-id/react-native-sdk'; import LivenessScan from '../components/LivenessScan'; async function initialiseLivenessScan( { onUserHintChange, onServerValidationStarted, onCameraReady, }: InitialiseLivenessScanProps, sdk: GetIdSdk ): Promise { Logger.log('Initialise Liveness Scan'); if (!sdk.config.stepsConfigs.liveness) { throw new Error('Liveness step not found in the flow'); } const LivenessScanRef = React.createRef(); const component = React.createElement(LivenessScan, { ref: LivenessScanRef, sdk, onUserHintChange, onCameraReady, onServerValidationStarted, }); const capture = async (): Promise => { if (LivenessScanRef.current?.capture) { return LivenessScanRef.current.capture(); } else { return Promise.reject(new LivenessError('capture is not available')); } }; const stopCapture = () => { LivenessScanRef.current?.stopCapture?.(); }; return { component, capture, stopCapture, }; } export default initialiseLivenessScan;