Nutech RN - ADVACE AI Liveness

startLiveness function to return any responses
 avatar
user_9601788
tsx
10 months ago
2.1 kB
25
Indexable
NativeModules.LivenessModule.initSDKByLicense('Indonesia', false);
  const checkLicence = async () => {
    const licences: any = await getData('license');
    if (!licences) {
      Alert.alert('Error', 'Licence not found. Please get a licence first.');
      return;
    }
    setLicence(licences.data.license);
  };

  const memoCheckLicence = useCallback(checkLicence, []);

  NativeModules.LivenessModule.set3DLivenessTimeoutMills(50000);
  NativeModules.LivenessModule.setAuditImageConfig(true, 400, 10, 400, 30);
  NativeModules.LivenessModule.setResultPictureSize(600);
  NativeModules.LivenessModule.setVideoRecorderConfig(true, 60);
  NativeModules.LivenessModule.isDetectOcclusion(true);

  const startLivenessActivity = () => {
    console.log('Liveness Activity screen starting');
    NativeModules.LivenessModule?.startLiveness(handleSuccess, handleError);
  };

  const handleSuccess = async (successJsonData: any) => {
    console.log('Liveness Activity success', successJsonData);
    // try {
    //   const result = await fetchDetectionResult(successJsonData.livenessId);
    //   console.log('fetchDetectionResult Success : ', result);
    // } catch (err) {
    //   console.log('fetchDetectionResult error: ', err);
    // }
  };
  const handleError = () => (failedJsonData: any) => {
    console.log('Liveness Activity error', failedJsonData);
    setError(failedJsonData);
    setVisible(true);
  };

  const mainLiveness = useCallback(startLivenessActivity, []);

  useEffect(() => {
    memoCheckLicence();
  }, [memoCheckLicence]);

  useEffect(() => {
    if (licence) {
      NativeModules.LivenessModule.setLicenseAndCheck(
        licence,
        (successCode: any) => {
          console.log('Check License : ', successCode);
          setLicenceStatus(successCode);
        },
        (errorCode: any) => {
          console.log('Check License : ', errorCode);
          setLicenceStatus(errorCode);
        },
      );
    }
  }, [licence]);

  useEffect(() => {
    if (licence && licenceStatus === 'SUCCESS') {
      mainLiveness();
    }
  }, [licence, licenceStatus, mainLiveness]);
Editor is loading...
Leave a Comment