import FadSDK from '@fad-producto/fad-sdk';
const TOKEN = 'YOUR_FAD_TOKEN';
const CONFIGURATION = {
allowClose: true,
views: {
instructions: true,
preview: true,
},
selfie: {
captureSelfie: false,
imageType: 'image/png',
imageQuality: 1,
},
timer: {
recording: { min: 2, max: 15 },
faceUndetected: 5,
},
customization: {
fadCustomization: {
colors: {
succesful: '#5A9A92',
},
buttons: {
primary: {
backgroundColor: '#0066CC',
labelColor: '#ffffff',
},
},
},
moduleCustomization: {
legends: {
tapInstruction: 'Tap the box to start signing',
buttonFinish: 'Finish',
recording: 'Recording',
focusFace: 'Frame your face within the guide',
signNowHere: 'Sign here now',
},
legendsInstructions: {
title: 'Video Signature',
subtitle: 'Frame your face within the guide and sign in the box',
buttonNext: 'Continue',
},
legendsPreview: {
title: 'Signature',
buttonRetry: 'Sign again',
buttonNext: 'Confirm signature',
},
},
},
};
async function captureSignature() {
const options = {
environment: FadSDK.getFadEnvironments().UATHA
};
const FAD_SDK = new FadSDK(TOKEN, options);
try {
const signatureResponse = await FAD_SDK.startSignature(CONFIGURATION);
if (signatureResponse.event === FadSDK.Constants.EventModule.MODULE_CLOSED) {
console.log('Module closed by the user');
return;
}
// Process the results
console.log('Signature captured successfully');
// Create URLs for the video blobs
const faceVideoUrl = URL.createObjectURL(signatureResponse.data.videoFace);
const signatureVideoUrl = URL.createObjectURL(signatureResponse.data.videoSignature);
console.log('Face video URL:', faceVideoUrl);
console.log('Signature video URL:', signatureVideoUrl);
console.log('Signature image:', signatureResponse.data.imageSignature);
// Display in HTML elements
// document.getElementById('face-video').src = faceVideoUrl;
// document.getElementById('signature-video').src = signatureVideoUrl;
// document.getElementById('signature-img').src = signatureResponse.data.imageSignature;
} catch (error) {
if (error.code === FadSDK.Errors.Signature.NOT_ACCEPT_CAMERA_PERMISSION) {
console.error('Camera permission not granted');
} else {
console.error('Error:', error);
}
} finally {
FAD_SDK.end();
}
}