import React from 'react'; import { SelfieError, type InitialiseSelfieProps, type InitialiseSelfieScanResult, type SelfieScanHandle, } from '../types/sdkTypes'; import Logger from '../utils/logger'; import SelfieScan from '../components/SelfieScan'; import type { GetIdSdk } from '..'; async function initialiseSelfieScan( { onUserHintChange, onCameraReady, onServerValidationStarted, useAutoCapture, }: InitialiseSelfieProps, sdk: GetIdSdk ): Promise { Logger.log('Initialise Selfie Scan'); if (!sdk.config.stepsConfigs.selfie) { throw new Error('Selfie step not found in the flow'); } const SelfieScanRef = React.createRef(); const component = React.createElement(SelfieScan, { ref: SelfieScanRef, sdk, onUserHintChange, onCameraReady, onServerValidationStarted, useAutoCapture, }); const takePicture = async () => { return SelfieScanRef.current?.takePicture?.(); }; const capture = async (): Promise => { if (SelfieScanRef.current?.capture) { return SelfieScanRef.current.capture(); } else { return Promise.reject(new SelfieError('capture is not available')); } }; const stopCapture = () => { SelfieScanRef.current?.stopCapture?.(); }; return { component, takePicture, capture, stopCapture, }; } export default initialiseSelfieScan;