Web Capture with Custom UX/UI

This guide shows how to integrate the Trulioo DocV-Capture SDK and run a full document + selfie verification flow. For the authoritative API reference, see Trulioo’s docs: https://docs.verification.trulioo.com/sdk/getting-started/index.html.

SDK Overview

The DocV-Capture Web SDK gives organizations the flexibility to design and manage a custom user experience (UX) and user interface (UI) that reflects their brand language. The SDK provides complete control over the look and feel of the capture flow, while Trulioo powers the underlying image capture and verification technology.

This approach enables:

  • Experiences fully aligned with brand guidelines.
  • Custom UI overlays, animations, and messaging.
  • Dependable Trulioo document and selfie capture with built-in verification intelligence.

In short: the brand owns the UI/UX, and Trulioo ensures the capture and verification are accurate and secure.

For organizations that prefer a ready-made solution, Trulioo also offers out-of-the-box SDKs. These SDKs deliver a complete Trulioo-designed UI/UX along with the same trusted image capture and verification technology - ideal for rapid development with minimal customization.

Installation

npm i @trulioo/docv-capture-web
cd ios && pod install

Document Capture and Verification Flow Overview

Starting a new document verification transaction

Create an instance of TruliooCapture and call the initialize function using the shortcode obtained from the Trulioo API endpoint: /customer/handoff. This will create a new document verification transaction with a unique Transaction ID.

const shortCode = "generatedFromTruliooAPI"

const truliooCapture = new TruliooCapture()

truliooCapture.initialize(shortCode).then((transactionId) => {
    console.log(`Successfully initialized with transaction ID: ${transactionId}`)
}).catch(error => {
    console.log(`Error on initialize: ${error}`)
})

Creating and rendering a camera component

Using the same created instance of TruliooCapture, get a camera component to be rendered later by calling the getCameraComponent function. Then specify the camera detection type by providing a TruliooCameraConfig with the desired DetectionType.

// Will get a document detection type camera by default.
const documentCamera = truliooCapture.getCameraComponent()

// To get a selfie detection type camera.
const selfieCamera = truliooCapture.getCameraComponent({
  detectionType: DetectionType.BIOMETRIC_SELFIE,
})

To render the camera component on the screen, call the renderCamera function. This will render a full screen camera on the screen by attaching a video element to the parent element based on the provided element id. The renderCamera function will resolve when the camera is successfully loaded, otherwise it will reject with an error. The onCaptureRegionChangecallback function is provided, which will return the current capture frame coordinates location (the location on the camera screen where the document/face should be located to do a capture). Utilize this coordinate information to render a custom UI overlay.

const cameraProps = new CameraProps(
    (captureRegion: CaptureRegion) => {
        // Utilize the given captureRegion data to render custom UI.
    }
)

documentCamera.renderCamera("parent-element-id", cameraProps).then((_) => {
    console.log("Camera is successfully loaded")
}).catch((e: Error) => {
    console.error(`Camera is not loaded successfully: ${e.message}`)
})

To remove the current camera on the screen, call the removeCamera function.

documentCamera.removeCamera()

To resume the camera feed again after a successful auto or manual capture, call the resumeCamera function.

documentCamera.resumeCamera()


Starting the document capture flow

Once the camera component is loaded and ready, start the document capture experience by calling startFeedback using the previously created TruliooCapture instance.

To do an auto capture experience (a good document/selfie image criteria decided entirely by SDK), call startFeedback by providing the camera id that refers to the currently active/rendered camera component. The promise will only resolve when the SDK manages to capture a good image that is presented in front of the camera capture frame.

truliooCapture.startFeedback(documentCamera.id).then((result: TruliooCaptureResponse) => {
    console.log(`Successfully captured a good image with imageId: ${result.imageId}`)
})

To stop the feedback call the stopFeedback function. This will stop any ongoing feedback from the camera component.

truliooCapture.stopFeedback(documentCamera.id)

Note that if the stopFeedback function is called during an ongoing startFeedback promise, the startFeedback promise is expected to be rejected with the specific FeedbackStopped error. It is recommended to check this specific error to make sure it is not treated as an unexpected error.

import { HandledError } from '@trulioo/docv-capture-web'

truliooCapture.startFeedback(documentCamera.id).then((result: TruliooCaptureResponse) => {
    console.log(`Successfully captured a good image with imageId: ${result.imageId}`)
}).catch((error: unknown) => {
    if (error == HandledError.FeedbackStopped) {
        console.log("startFeedback was stopped.")
    } else {
        // Other error handling
    }
})

To do a manual capture instead of an automatic one, call the captureLatestFrame function. This will return a TruliooManualCaptureResponse that is similar to the TruliooCaptureResponse excluding the auto capture specific fields.

Ensure that the camera feed is currently running before triggering the manual capture. Further, use the resumeCamera function to resume the camera again and to trigger another capture after a successful auto or manual capture.

truliooCapture.captureLatestFrame(documentCamera.id).then((result: TruliooManualCaptureResponse) => {
    console.log(`Successfully captured an image manually with imageId: ${result.imageId}`)
})

The SDK also provides the onFeedbackState function that helps listen to ongoing capture state updates which are started by the startFeedback function. This allows the addition of any custom logic, or to render any necessary custom UI based on the current capture state. It is recommended to call the onFeedbackState function and start listening to the feedback state before calling the startFeedback function.

truliooCapture.onFeedbackState(
    (feedbackState: FeedbackState) => {
        switch (feedbackState) {
            case FeedbackState.NONE:
                // Nothing happened yet/no document detected at this point.
                break
            case FeedbackState.CAPTURING:
                // Currently in the middle of capturing a document.
                break
            case FeedbackState.BLUR:
                // The detected document is blurry. Show a blur UI feedback to user.
                break
            case FeedbackState.SUCCESS:
                // Managed to capture a document.
                break
            default:
                break
        }
    },
)

Note that the above flow is the same for the selfie capture type too.


Starting the document capture flow

After obtaining the resulting TruliooCaptureResponse or TruliooManualCaptureResponse image data, call the verifyImage function to get post-capture feedback that is part of the response data. This provides more information regarding the captured image which in turn helps decide if the captured image should be submitted for verification. To submit the image call the acceptImage function.

// As an example, we will submit the captured image for document verification if the post capture feedback documentVerifyResponse.documentTypeAccepted is not RESULT_CHECK_DECLINED.
// Note that the documentVerifyResponse will have more than just documentTypeAccepted, the below code is just an example of checking for documentTypeAccepted.
result.verifyImage().then((verifyFeedback: TruliooVerifyFeedback) => {
    if (verifyFeedback.documentVerifyResponse.documentTypeAccepted !== ResultCheck.RESULT_CHECK_DECLINED){
        // Note that the acceptImage can be called outside of the verifyImage function.
        result.acceptImage().then((status: boolean) => {
            console.log("Successfully submitted the image.")
        })
    } else {
        // Do something else, e.g., notify the user that the  mage is not accepted and prompt to take a new image.
    }
})


Finalize the document verification transaction

After submitting all the necessary images for the transaction, finalize the transaction by calling the submitTransaction function.

truliooCapture.submitTransaction().then((status: boolean) => {
    console.log("Transaction successfully submitted.")
})