Skip to main content

Method Signature

FAD_SDK.startLivenessToc(
  credentials: LivenessTocCredentials,
  configuration?: Configuration
): Promise<LivenessTocResponse>

Description

The startLivenessToc() method initiates the TOC (Touch On Camera) liveness detection module. This technology provides passive liveness detection to ensure a live person is present during face capture.

Parameters

credentials
LivenessTocCredentials
required
TOC liveness service credentials
configuration
Configuration
Optional configuration object for customizing the module’s behavior and appearance

Returns

LivenessTocResponse
Promise<object>
A promise that resolves with the TOC liveness module response

Code Example

import FadSDK from '@fad-producto/fad-sdk';

const CREDENTIALS = {
  app: 'YOUR_TOC_APP_ID',
};

const TOKEN = 'YOUR_FAD_TOKEN';

const CONFIGURATION = {
  views: {
    instructions: true,
  },
  livenessDetection: {
    mode: 0, // Passive liveness detection
  },
  customization: {
    fadCustomization: {
      colors: {
        primary: '#0066CC',
      },
      buttons: {
        primary: {
          backgroundColor: '#0066CC',
          labelColor: '#ffffff',
        },
      },
    },
    moduleCustomization: {
      legends: {
        locale: 'en',
      },
      legendsInstructions: {
        title: 'Liveness Check',
        subtitle: 'Position your face in the guide',
        buttonNext: 'Continue',
      },
    },
  },
};

async function performLivenessToc() {
  const options = {
    environment: FadSDK.getFadEnvironments().UATHA
  };

  const FAD_SDK = new FadSDK(TOKEN, options);
  
  try {
    const moduleResponse = await FAD_SDK.startLivenessToc(
      CREDENTIALS,
      CONFIGURATION
    );

    if (moduleResponse.event === FadSDK.Constants.EventModule.MODULE_CLOSED) {
      console.log('Module closed by user');
      return;
    }

    // Process the results
    console.log('Liveness check completed successfully');
    
    const faceImage = moduleResponse.data.faceScan;
    console.log('Face image:', faceImage);

    // Display in HTML element
    // document.getElementById('image-id').src = faceImage;

  } catch (error) {
    if (error.code === FadSDK.Errors.LivenessToc.SERVICE_ERROR) {
      console.error('Service error occurred');
    } else if (error.code === FadSDK.Errors.LivenessToc.TIMEOUT_EXCEEDED) {
      console.error('Timeout exceeded');
    } else if (error.code === FadSDK.Errors.LivenessToc.FACE_BLURRY) {
      console.error('Face image is too blurry');
    } else {
      console.error('Error:', error);
    }
  } finally {
    FAD_SDK.end();
  }
}

Error Handling

The method may throw errors that can be identified using FadSDK.Errors.LivenessToc:
  • SERVICE_ERROR - Service error occurred
  • TIMEOUT_EXCEEDED - Detection timeout was exceeded
  • FACE_BLURRY - Captured face image is too blurry
TOC liveness detection provides passive liveness checking, which means the user doesn’t need to perform specific actions like nodding or smiling.
Always call FAD_SDK.end() in a finally block to properly clean up resources after the module completes or fails.

Build docs developers (and LLMs) love