-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.js
More file actions
119 lines (106 loc) · 3.23 KB
/
main.js
File metadata and controls
119 lines (106 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import { fakeBackendStart, fakeBackendFinish } from './fake_backend'
let incode;
let incodeSession;
let showTutorialsFlag=false;
const cameraContainer = document.getElementById("camera-container");
function showError(e=null) {
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() {
incode.sendGeolocation({ token: incodeSession.token });
incode.sendFingerprint({ token: incodeSession.token });
captureIdFrontSide();
}
function captureIdFrontSide() {
incode.renderCamera("front", cameraContainer, {
onSuccess: captureIdBackSide,
onError: showError,
token: incodeSession,
numberOfTries: 3,
showTutorial: showTutorialsFlag
});
}
function captureIdBackSide(response) {
incode.renderCamera("back", cameraContainer, {
onSuccess: processId,
onError: showError,
token: incodeSession,
numberOfTries: 3,
showTutorial: showTutorialsFlag
});
}
async function processId() {
const results = await incode.processId({
token: incodeSession.token,
});
console.log("processId results", results);
captureSelfie();
}
function captureSelfie() {
incode.renderCamera("selfie", cameraContainer, {
onSuccess: captureVideoSelfie, // change this for captureVideoSelfie if you want to enable it
onError: showError,
token: incodeSession,
numberOfTries: 3,
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((e) => {
showError(e);
});
}
async function app() {
try {
const apiURL = import.meta.env.VITE_API_URL;
incode = window.OnBoarding.create({
apiURL: apiURL
});
// Create the single session
cameraContainer.innerHTML = "<h1>Creating session...</h1>";
incodeSession = await fakeBackendStart();
// Empty the container and start the flow
cameraContainer.innerHTML = "";
saveDeviceData();
} catch (e) {
showError(e);
}
}
document.addEventListener("DOMContentLoaded", app);