PassiveFaceLiveness (Deprecated)

Importing SDK

To use PassiveFaceLiveness, you can either remotely import the .js file or download it locally.

Remotely

Include the .js file directly from the CDN:

<script
  src="https://repo.combateafraude.com/javascript/release/passive-face-liveness/<VERSION>.umd.js"
  type="text/javascript"
></script>

You can retrieve the class from the SDK using the following code:

const { PassiveFaceLivenessSdk } =
  window["@combateafraude/passive-face-liveness"];

Locally

Download the .js file and import it as an ES6 module:

import { PassiveFaceLivenessSdk } from "../assets/js/passive-face-liveness-<VERSION>.js";

Construction

In the builder, the SDK receives a single parameter with the settings:

const sdk = new PassiveFaceLivenessSdk(options);

Supported Parameters

ParameterRequired?

token

Authentication token for consuming the SDK.

Yes.

language

Default message language, valid values: en_US, en_BR, es_MX.

No. The default is pt_BR

environmentSettings.disableDesktopExecution

Flag indicating whether execution on desktops should be blocked.

No. The default is false

environmentSettings.disableVisibilityChangeSecurity

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

No. The default is false

environmentSettings.disableFaceDetectionSecurity

Disables the security enhancement responsible for closing the SDK when the user moves the face away from the mask in automatic capture.

No. The default is false

capturerSettings.disableAdvancedCapturing

Flag indicating whether advanced capture should be disabled*.

No. The default is false

capturerSettings.disableVideoCapturing

Flag indicating whether video capture should be disabled*.

No. The default is false

appearenceSettings.hideSwitchCameraButton

hide the switch camera button.

No

appearenceSettings.captureButtonIcon

Customization of the capture icon accepts values such as image URL or base64 of SVGs.

No

appearenceSettings.captureIconSize

Customization of the icon size for the captureButtonIcon field

No

appearenceSettings.captureButtonColor

Customization of the default image capture button color.

No

appearenceSettings.switchButtonIcon

Customization of the camera switch icon accepts values such as image URL or base64 from SVGs.

No

appearenceSettings.switchIconSize

Customization of the icon size for the switchButtonIcon field.

No

appearenceSettings.switchIconColor

Customization of the color of the default camera switching icon.

No

appearenceSettings.fontFamily

Changes the font for all elements contained in the SDK.

No. The pattern is inherited from the page

textSettings.messages.processMessage

Customization of the image processing message.

No. The default is "Processando sua foto, aguarde um momento"

textSettings.messages.isNotAliveMessage

Customization of the message when the isAlive parameter returns as false.

No. The default is "Não conseguimos capturar seu rosto :( Por favor, tente novamente."

textSettings.messages.captureFailedMessage

Customization of the capture failure message.

No. The default is "Ops! Tivemos um problema ao processar sua imagem."

* Advanced capture consists of using more complex and not-so-stable APIs in browsers that support them (e.g. ImageCapture)

Example

const sdk = new PassiveFaceLivenessSdk({
  token: `my-sdk-token`,

  analyticsSettings: {
    disableAnalytics: false,
    trackingId: "",
    trackingInfo: "",
  },

  environmentSettings: {
    disableDesktopExecution: false,
    disableVisibilityChangeSecurity: true,
    disableFaceDetectionSecurity: true,
  },

  capturerSettings: {
    disableAdvancedCapturing: true,
    disableVideoCapturing: true,
  },

  appearenceSettings: {
    captureButtonIcon: "",
    captureIconSize: "",
    captureButtonColor: "",
    switchButtonIcon: "",
    switchIconSize: "",
    switchIconColor: "",
    fontFamily: "",
  },

  textSettings: {
    title: "",
    messages: {
      processMessage: "",
      isNotAliveMessage: "",
      captureFailedMessage: "",
    },
  },
});

CaptureStage

CaptureStage allows the client to configure the stages. To do this, we offer the CaptureStage object, where you can set the following parameters:

Parameter

mode

Desired capture mode. It can be used manually or automatically. In the manual capture, a button will be enabled for the user to perform the capture.

attempts

The number of attempts of the current stage. If it is the only stage, the value 0 must be passed.

duration

Duration time of the current stage. If more than one stage is set, the total time for each stage can be set, and when the total time is reached, the stage will move on to the next one. Set it to 0 if you don't want to set a time for the stage.

Example CaptureStage

const stages = [
  { mode: "automatic", attempts: 3, duration: 60 },
  { mode: "manual", attempts: 0, duration: 0 },
];

Objects are defined for each stage, according to an example, the SDK will start with the automatic capture, where there will be 3 capture attempts or a time limit of 60 seconds for each attempt, after exceeding the time or attempts, the SDK will automatically move on to the next stage, where the manual capture will be performed without time or attempt limits, so the user can perform as many attempts as he/she wants without time limits.

Limit SDK attempts

Through the totalAttempts parameter you can set the total number of attempts to run the SDK, after reaching the limit value the SDK will automatically terminate.

Example totalAttempts

await sdk.capture(sdkContainer, stages, { personData, totalAttempts: 3 });

Initialization

initialize(): Promise<void>

The SDK has an isolated initialization method, to allow greater control over when it occurs.

During this process, the SDK will initialize its internal variables and download the resources it needs to run.

[!]You must call this method before using other SDK methods.

[!]Initializing the SDK can take a few seconds. We recommend that you call this function as early as possible in your flow so that opening the SDK is smooth for the user.

Example

await sdk.initialize();

Utilization

Opening and taking selfies

capture(container: HTMLElement, stages, {personData?: LivenessPersonData, totalAttempts?: Number}): Promise<Result>

The method used to load the SDK onto the screen and perform selfie capture.

It will initialize the video stream (requesting permissions if needed) and load it into the container.

Parameters

Parameter

Type

personData.cpf

This variable has been deprecated, use personId

string

personData.name

Name of the user doing the authentication (optional).

string

personData.personId

Document number used as a unique identifier for each user (optional).

string

¹ If not specified, automatic capture is used.

² If not specified, a default value of 30 seconds is used.

Example

// div or another element on DOM
const sdkContainer = document.getElementById("sdk-displayer");
const personData = { personId: "user-identifier", name: "user-name" };
await sdk.capture(sdkContainer, stages, { personData, totalAttempts });

Return

The return consists of an object with the following fields:

Field

Type

Description

imageUrl

string

Temporary link to the image, generated by our API

imageKey

string

Object key

blob

Blob

Blob of the captured image

Example

const result = await sdk.capture(sdkContainer, stages, {
  personData,
  totalAttempts,
});
// { imageUrl: '[link da imagem]', imageKey: '[key da imagem]', blob: Blob

Close SDK

close(): Promise<void>

The method used to remove the SDK on the canvas, removing the SDK's visual elements from the DOM.

De-initialize the SDK

dispose(): Promise<void>

The method used to remove the SDK on the screen.

Will de-initialize the video stream and clear the SDK's internal variables

Complete Example

Soon.

Last updated

Logo

2023 © Caf. - All rights reserved