import { NativeEventEmitter } from 'react-native'; import { AnalyticsEvent, AnalyticsSubscriber, DeepPartial, LicenseInfo, OcrConfigsResult, SdkConfiguration, withSBErrorHandling, } from '../types'; import { ScanbotSDKNativeModule } from './ScanbotSDKModule'; /** * @internal * @hidden */ export const ScanbotSdkImpl = { async initialize(config: SdkConfiguration): Promise { return withSBErrorHandling( async () => new LicenseInfo(await ScanbotSDKNativeModule.initialize(config)) ); }, async getLicenseInfo(): Promise { return withSBErrorHandling( async () => new LicenseInfo(await ScanbotSDKNativeModule.getLicenseInfo()) ); }, async getOcrConfigs(): Promise { return withSBErrorHandling( async () => new OcrConfigsResult(await ScanbotSDKNativeModule.getOcrConfigs()) ); }, async cleanupStorage(): Promise { return withSBErrorHandling(ScanbotSDKNativeModule.cleanupStorage); }, async setAnalyticsSubscriber(subscriber: AnalyticsSubscriber | null): Promise { const eventEmitter = new NativeEventEmitter(ScanbotSDKNativeModule); if (subscriber === null) { eventEmitter.removeAllListeners('analyticsEvent'); return ScanbotSDKNativeModule.removeAnalyticsServiceCallback(); } else { eventEmitter.removeAllListeners('analyticsEvent'); eventEmitter.addListener('analyticsEvent', (event: DeepPartial) => { if (event) { subscriber(new AnalyticsEvent(event)); } }); return ScanbotSDKNativeModule.setAnalyticsServiceCallback(); } }, async mockCamera(params: { imageFileUri: string; captureFileUri?: string; refreshOnEachFrame?: boolean; }): Promise { return withSBErrorHandling(() => ScanbotSDKNativeModule.mockCamera(params)); }, };