Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
VITE_API_URL=https://demo-api.incodesmile.com/0
VITE_SDK_URL=https://sdk.incode.com/sdk/onBoarding-1.71.1.js
VITE_SDK_URL=https://sdk.incode.com/sdk/onBoarding-1.73.1.js

# HERE ONLY FOR DEMO PURPOSES, THE APIKEY AND THE FLOW_ID SHOULD NEVER BE IN THE FRONTEND.
VITE_FAKE_BACKEND_APIURL=https://demo-api.incodesmile.com
Expand Down
83 changes: 53 additions & 30 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ import { fakeBackendStart, fakeBackendFinish } from './fake_backend'

let incode;
let incodeSession;
const container = document.getElementById("camera-container");
let showTutorialsFlag=false;
const cameraContainer = document.getElementById("camera-container");

function showError(e=null) {
container.innerHTML = "<h1>There was an error</h1>";
console.log(e.message)
const finishContainer = document.getElementById("finish-container");
if (e?.message) {
finishContainer.innerHTML = `<h1>Error: ${e.message}</h1>`;
} else {
finishContainer.innerHTML = "<h1>There was an error</h1>";
console.log(e);
}
}

function saveDeviceData() {
Expand All @@ -16,22 +22,22 @@ function saveDeviceData() {
}

function captureIdFrontSide() {
incode.renderCamera("front", container, {
incode.renderCamera("front", cameraContainer, {
onSuccess: captureIdBackSide,
onError: showError,
token: incodeSession,
numberOfTries: 3,
showTutorial: true
showTutorial: showTutorialsFlag
});
}

function captureIdBackSide(response) {
incode.renderCamera("back", container, {
incode.renderCamera("back", cameraContainer, {
onSuccess: processId,
onError: showError,
token: incodeSession,
numberOfTries: 3,
showTutorial: true
showTutorial: showTutorialsFlag
});
}

Expand All @@ -44,27 +50,52 @@ async function processId() {
}

function captureSelfie() {
incode.renderCamera("selfie", container, {
onSuccess: finishOnboarding,
incode.renderCamera("selfie", cameraContainer, {
onSuccess: captureVideoSelfie, // change this for captureVideoSelfie if you want to enable it
onError: showError,
token: incodeSession,
numberOfTries: 3,
showTutorial: true
showTutorial: showTutorialsFlag
});
}

function captureVideoSelfie(){
incode.renderVideoSelfie( cameraContainer, {
token: incodeSession,
showTutorial: showTutorialsFlag,
modules: ["front", "back", "selfie", "speech"], // you can add 'poa' and 'questions'
speechToTextCheck: true, // this is the check for the speech
},
{
onSuccess: finishOnboarding,
onError: showVideoSelfieError,
numberOfTries: 1, // Only works for text-to-speech
}
);
}

function showVideoSelfieError(errors=[]) {
let error_string="<h1>There was some errors</h1>\n<ul>\n";
for (let i=0; i<errors.length;i++){
error_string +=` <li>${errors[i]}</li>\n`
}
error_string+="</ul>"
const finishContainer = document.getElementById("finish-container");
finishContainer.innerHTML = error_string;
}

function finishOnboarding() {
// Finishing the session works along with the configuration in the flow
// webhooks and business rules are ran here.
fakeBackendFinish(incodeSession.token)
.then((response) => {
console.log(response);
const container = document.getElementById("finish-container");
container.innerHTML = "<h1>Onboarding Finished.</h1>";
})
.catch((error) => {
showError(error);
});
.then((response) => {
console.log(response);
const container = document.getElementById("finish-container");
container.innerHTML = "<h1>Onboarding Finished.</h1>";
})
.catch((e) => {
showError(e);
});
}

async function app() {
Expand All @@ -75,21 +106,13 @@ async function app() {
});

// Create the single session
container.innerHTML = "<h1>Creating session...</h1>";
try {
incodeSession = await fakeBackendStart();
} catch(e) {
showError(e);
return;
}

cameraContainer.innerHTML = "<h1>Creating session...</h1>";
incodeSession = await fakeBackendStart();
// Empty the container and start the flow
container.innerHTML = "";
cameraContainer.innerHTML = "";
saveDeviceData();
} catch (e) {
console.dir(e);
container.innerHTML = "<h1>Something Went Wrong</h1>";
throw e;
showError(e);
}
}

Expand Down