UNPKG

@biopassid/face-sdk-react-native

Version:
36 lines 1.56 kB
import { NativeModules, Platform, NativeEventEmitter } from 'react-native'; import { mergeConfigs } from './utils/Utils'; const LINKING_ERROR = `The package '@biopassid/face-sdk-react-native' doesn't seem to be linked. Make sure: \n\n` + Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n'; const FaceSdkReactNative = NativeModules.FaceSdkReactNative ? NativeModules.FaceSdkReactNative : new Proxy({}, { get() { throw new Error(LINKING_ERROR); } }); const eventEmitter = new NativeEventEmitter(FaceSdkReactNative); const supportedEvents = ['face-sdk-react-native/onFaceCapture', 'face-sdk-react-native/onFaceDetected']; export async function takeFace(options) { try { const newConfig = mergeConfigs(options.config); supportedEvents.map(eventName => { eventEmitter.removeAllListeners(eventName); if (eventName === 'face-sdk-react-native/onFaceCapture') { eventEmitter.addListener(eventName, event => { options.onFaceCapture(event.image, event.faceAttributes); }); } else if (eventName === 'face-sdk-react-native/onFaceDetected') { eventEmitter.addListener(eventName, event => { if (options.onFaceDetected != null) { options.onFaceDetected(event.faceAttributes); } }); } }); await FaceSdkReactNative.takeFace(newConfig); } catch (error) { console.error(`Unknown error: ${error}`); } } //# sourceMappingURL=Face.js.map