UNPKG

@biopassid/face-sdk-react-native

Version:
52 lines (51 loc) 2.25 kB
"use strict"; // NOTE — LOCAL DEVELOPMENT VS PRODUCTION // // When developing this library locally, the example app and the library // use separate node_modules, creating two distinct instances of // `react-native`. In this scenario, NativeEventEmitter events emitted by // the library will not reach the example app. // // For LOCAL TESTING, uncomment the line below to ensure both the library // and the demo app use the same React Native instance: // import { NativeEventEmitter, NativeModules, Platform } from '../example/node_modules/react-native'; // // ⚠️ Do NOT commit or publish the library using that import. // // For PRODUCTION, always use the standard import: import { NativeEventEmitter, NativeModules, Platform } from 'react-native'; import { mergeConfigs } from "./utils/Utils.js"; 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