React Native Integration

Overview

The Face Capture SDK comes with a React Native interface for integration. This chapter will outline the requirements for React Native integration and which parts of the demo source code correspond to the integration tasks outlined in the Application Design chapter.

Integration Requirements

The Face Capture SDK requires Camera permissions.

Demo Code

This section provides details regarding the Face Capture API and how it is used to implement an application.

Create a Face Capture Object

Create a Face Capture Object
   import FaceCapture from 'react-native-face-capture'

This provides you with the singleton FaceCapture object from the library.

Create a Workflow Object

Create a Workflow Object
   workflow = await FaceCapture.createWorkflow(FaceCapture.constants.FOXTROT);

Adjust Workflow Settings

Adjust Workflow Settings
   await workflow.setStringProperty(FaceCapture.constants.WorkflowPropertyUsername, username);
   await workflow.setDoubleProperty(FaceCapture.constants.WorkflowPropertyCaptureTimeout, captureTimeout);
   await workflow.setStringProperty(FaceCapture.constants.WorkflowPropertyCaptureProfile, captureProfile);

Select a Camera

Select a camera
   cameraList = await FaceCapture.getCameraList(FaceCapture.constants.CameraPositionFront);
   camera = cameraList[0];
   await camera.setOrientation(FaceCapture.constants.CameraOrientationPortrait);

Begin a Capture Session

Begin a Capture Session
   await FaceCapture.startCaptureSession(workflow, camera);

Stop a Capture Session

Stop a Capture Session
   await FaceCapture.stopCaptureSession();

Get the capture region

Get capture region
   captureRegion = await FaceCapture.captureSessionGetCaptureRegion();

The capture region can be used to determine where on the GUI to display a graphic to guide the user to that space for a successful capture.

Get the current Capture Session State

Capture Session State
   captureState = await FaceCapture.getCaptureSessionState();

Put this function inside a loop to continually poll for new state updates until the capture ends.

Get the Capture State’s Status

Capture Session Status Changes
   captureSessionStatus = await captureState.getStatus();

Depending on the status returned, the Capture State may not contain an image nor feedback. Query this first to determine if the application should query for a frame and feedback. Please see the extended description in the API chapter for additional information.

Get the Capture State’s Image

Capture Session Images
   captureSessionFrame = await captureState.getFrame();

Get the Capture State’s Feedback

Capture Session Feedback
   captureSessionFeedback = await captureState.getFeedback();

The string returned from this function should be used to determine what localized instructions to put on screen. The feedback string itself is not intended to be displayed to end users.

Get the Server Package

Get the Server Package
   captureServerPackage = await FaceCapture.getServerPackage(workflow, FaceCapture.constants.PackageTypeBalanced);

Get the Encrypted Server Package

Get the Encrypted Server Package
   captureServerPackage = await currentFaceCapture.getEncryptedServerPackage(FaceCapture.constants.EncryptionTypeRSA_AES_256_CBC, encryptionKey, workflow, FaceCapture.constants.PackageTypeBalanced);

Enable Autocapture

Enable Autocapture
   await currentFaceCapture.captureSessionEnableAutocapture(true);

After starting the capture session, this can be set to false to stop the capture session from successfully completing until it is set back to true. This is useful for creating an intentional delay during the capture process. A slight delay at the start of capture may allow the subject to steady the device or hold still to prevent blur when capturing.