Event listeners

The SDK provides various event listeners to handle different events during the document capture process. These listeners allow you to execute custom logic when specific events occur.

addEventListener

The addEventListener method is used to listen to events of the specified type.

documentDetector.addEventListener(type, listener, options);

Parameters

  • type (EventType): The type of event to listen for (check EventType for details).

  • listener (function): The function to be executed when the event is triggered.

  • options (object, optional): Additional options for the event listener

removeEventListener

The removeEventListener method is used to lto remove an event listener of the specified type.

documentDetector.removeEventListener(type, callback, options);

Parameters

  • type (EventType): The type of event to listen for (check EventType for details).

  • callback (function): The function to be removed.

  • options (object, optional): Additional options for the event listener

EventType

Type

Description

"front_capture_started"

Triggered when the capture of the front of the document has started.

"back_capture_started"

Triggered when the capture of the back of the document has started.

"capture_invalid"

Triggered when an error occurs in some validation performed by the SDK.

"capture_failed"

Triggered when an error occurs that is not handled by the SDK.

Example

// Listen for the event when the capture of the front of the document starts
documentDetector.addEventListener('front_capture_started', () => {
    console.debug('Document front capture event fired');
});

// Listen for the event when the capture of the back of the document starts
documentDetector.addEventListener('back_capture_started', () => {
    console.debug('Document back capture event fired');
});

Last updated

Logo

2023 © Caf. - All rights reserved