diff --git a/.env.example b/.env.example
index 86056bc..bc3d917 100644
--- a/.env.example
+++ b/.env.example
@@ -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
diff --git a/main.js b/main.js
index bc6c56f..f74c21b 100644
--- a/main.js
+++ b/main.js
@@ -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 = "
There was an error
";
- console.log(e.message)
+ const finishContainer = document.getElementById("finish-container");
+ if (e?.message) {
+ finishContainer.innerHTML = `Error: ${e.message}
`;
+ } else {
+ finishContainer.innerHTML = "There was an error
";
+ console.log(e);
+ }
}
function saveDeviceData() {
@@ -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
});
}
@@ -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="There was some errors
\n\n";
+ for (let i=0; i${errors[i]}\n`
+ }
+ error_string+="
"
+ 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 = "Onboarding Finished.
";
- })
- .catch((error) => {
- showError(error);
- });
+ .then((response) => {
+ console.log(response);
+ const container = document.getElementById("finish-container");
+ container.innerHTML = "Onboarding Finished.
";
+ })
+ .catch((e) => {
+ showError(e);
+ });
}
async function app() {
@@ -75,21 +106,13 @@ async function app() {
});
// Create the single session
- container.innerHTML = "Creating session...
";
- try {
- incodeSession = await fakeBackendStart();
- } catch(e) {
- showError(e);
- return;
- }
-
+ cameraContainer.innerHTML = "Creating session...
";
+ incodeSession = await fakeBackendStart();
// Empty the container and start the flow
- container.innerHTML = "";
+ cameraContainer.innerHTML = "";
saveDeviceData();
} catch (e) {
- console.dir(e);
- container.innerHTML = "Something Went Wrong
";
- throw e;
+ showError(e);
}
}