SDK methods

This section provides detailed documentation for each SDK method. Scroll down to learn more about how to use each method, including their parameters, usage examples, and important notes.

initPermissions

The initPermissions method initializes the permissions required to use the SDK. This method requests the necessary permissions from the user, such as access to the camera. It returns a promise that resolves to true when the user allows the camera or if the camera is already allowed.

Important

  • It is crucial to call this method before initializing the SDK to ensure that all required permissions are granted.

  • A good practice is to provide feedback to the user that the camera is being requested or that the camera is already allowed.

Example

const result: boolean = sdk.initPermissions();

Go back to the top

initialize

The initialize method is used to initialize the SDK. This method sets up internal variables and downloads the necessary resources for the SDK to function.

Important

  • You must call this method after the initPermissions method and before any other method in the SDK.

  • The initialization process can take a few seconds. It is recommended to call this function as early as possible in your flow to ensure a smooth user experience.

Example

await sdk.initialize();

Go back to the top

capture

The capture method is used to load the SDK onto the screen and perform document capture. It initializes the video stream (requesting permissions if needed) and loads it into the container.

For more information on input parameters and output results, refer to the lists below:

Input

The capture method takes one parameter:

const captureResult = await documentDetector.capture(options);

This parameter is an object containing the capture options. The following table lists the available capture options:

Parameter

Type

Required?

Default Value

expectedDocument

Type and side of the document expected to be detected by the SDK. If value is "any" then any type of document will be accepted.

"rg_front" | "rg_back" | "rg_full" | "cnh_front" | "cnh_back" | "cnh_full" | "crlv" | "rne_front" | "rne_back" | "passport" | "ctps_front" | "ctps_back" | "any"

Yes.

-

mode

The capture mode. Can be "automatic", "manual" or "upload".

"automatic" | "manual" | "upload"

Yes.

-

automaticCaptureMaxDuration

The maximum duration in seconds for the automatic capture. If the duration is exceeded, the manual capture will be triggered.

number

No.

60

uploadFileType

Enables the security enhancement responsible for closing the SDK when the user switches browser tabs.

"IMAGE" | "PDF"

No.

Any file type is accepted.

personID

The ID of the person (used for tracking purposes).

string

No.

undefined

forceEndWhenInvalid

Determines whether the capture should be forcefully finished when it is invalid.

boolean

No.

false

Output

The output parameters are returned as an object containing the following fields:

Parameter

Type

Example

image.url

string

"image-url-here"

image.blob

Blob

image-blob-here

image.storageInfo.key

string

"s3-bucket-key-here"

image.storageInfo.bucket

string

"s3-bucket-here"

detectedDocument.type

"blank" | "rg" | "rg_new" | "cnh" | "cnh_new" | "cin" | "rne" | "rnm" | "ctps" | "passport" | "crlv" | "generic"

"passport"

detectedDocument.side

"front" | "back" | "both" | "not_applicable"

"front"

isCaptureValid

boolean

true

Example

// Load the SDK onto the screen and perform document capture.
const result = await documentDetector.capture({
  expectedDocument: "cnh_front",
  mode: "automatic",
  automaticCaptureMaxDuration: 30,
  personID: "my-person-id",
});
// Destructure fields from the SDK result
const {
  image, // example: { url: "image-url-here", blob: image-blob-here, storageInfo: { key: "s3-bucket-key-here", bucket: "s3-bucket-here" } }
  detectedDocument, // example: { type: "cnh", side: "front" }
  isCaptureValid, // example: true
} = result;
// Example usage of the destructured fields
console.log("Captured Image URL:", image.url);
console.log("Detected Document Type:", detectedDocument.type);
console.log("Is Capture Valid:", isCaptureValid);

Go back to the top

close

The close method is used to remove the SDK from the screen, removing its visual elements from the DOM.

Example

await sdk.close();

Go back to the top

dispose

The dispose method is used to de-initialize the SDK. It stops the video stream and clears the SDK's internal variables.

Example

await sdk.dispose();

Go back to the top

isSupported

The isSupported method checks if the browser supports the SDK.

Example

const isSupported: boolean = sdk.isSupported();

Go back to the top

getIsInitialized

The getIsInitialized method checks if the SDK is initialized.

Example

const isInitialized: boolean = sdk.getIsInitialized();

Go back to the top

loadAiModel

The loadAiModel method is optional, but it can greatly enhance the SDK's loading performance. For optimal results, we recommend invoking it as early as possible in your workflow, ideally before reaching the SDK's loading screen. However, if this is not feasible or does not align with the specific requirements of your integration, the initialize method will automatically handle all necessary initialization tasks to ensure the SDK operates correctly.

Example

await documentDetector.loadAiModel();

Go back to the top

Last updated

Logo

2023 © Caf. - All rights reserved