@biopassid/face-sdk-react-native
Version:
BioPass ID Face React Native module.
42 lines (41 loc) • 1.69 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.takeFace = takeFace;
var _reactNative = require("react-native");
var _Utils = require("./utils/Utils");
const LINKING_ERROR = `The package '@biopassid/face-sdk-react-native' doesn't seem to be linked. Make sure: \n\n` + _reactNative.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 = _reactNative.NativeModules.FaceSdkReactNative ? _reactNative.NativeModules.FaceSdkReactNative : new Proxy({}, {
get() {
throw new Error(LINKING_ERROR);
}
});
const eventEmitter = new _reactNative.NativeEventEmitter(FaceSdkReactNative);
const supportedEvents = ['face-sdk-react-native/onFaceCapture', 'face-sdk-react-native/onFaceDetected'];
async function takeFace(options) {
try {
const newConfig = (0, _Utils.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