-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
120 lines (104 loc) · 2.85 KB
/
main.js
File metadata and controls
120 lines (104 loc) · 2.85 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
120
import { startOnboardingSession, finishOnboardingSession } from './session'
// Lets put all the variables needed for all modules in the global scope
const localServerUrl= import.meta.env.VITE_LOCAL_SERVER_URL;
let incode;
let session;
const container = document.getElementById("camera-container");
function showError(e=null) {
container.innerHTML = "<h1>There was an error</h1>";
console.log(e.message)
}
function renderRedirectToMobile(){
if (incode.isDesktop()) {
incode.renderRedirectToMobile(container, {
onSuccess: () => {
showFinishScreen();
},
session: session,
url: `${localServerUrl}?uniqueId=${session.uniqueId}`,
// showSms: false, //uncomment if you want to remove the SMS feature
});
} else {
saveDeviceData();
showUserConsent();
}
}
function saveDeviceData() {
incode.sendGeolocation({ token: session.token });
incode.sendFingerprint({ token: session.token });
}
function showUserConsent(){
incode.renderUserConsent(container, {
session: session,
onSuccess: captureIdFrontSide,
});
}
function captureIdFrontSide() {
incode.renderCamera("front", container, {
onSuccess: captureIdBackSide,
onError: showError,
token: session,
numberOfTries: -1,
noWait: true
});
}
function captureIdBackSide() {
incode.renderCamera("back", container, {
onSuccess: processID,
onError: showError,
token: session,
numberOfTries: -1,
noWait: true
});
}
async function processID() {
const results = await incode.processId({
token: session.token,
});
console.log("processId results", results);
captureSelfie();
}
function captureSelfie() {
incode.renderCamera("selfie", container, {
onSuccess: finishOnboarding,
onError: showError,
token: session,
numberOfTries: -1,
noWait: true
});
}
function finishOnboarding() {
// Finishing the session works along with the configuration in the flow
// webhooks and business rules are ran here.
const response = finishOnboardingSession(session.token);
showFinishScreen();
}
function showFinishScreen(){
const container = document.getElementById("finish-container");
container.innerHTML = "<h1>Finished</h1>";
}
async function app() {
try {
// Create the instance of incode linked to a client
const apiURL = import.meta.env.VITE_API_URL;
incode = window.OnBoarding.create({
apiURL: apiURL
});
// Create the single session
container.innerHTML = "<h1>Creating session...</h1>";
try {
session = await startOnboardingSession();
} catch(e) {
showError(e);
return;
}
// Empty the container and starting the flow
container.innerHTML = "";
renderRedirectToMobile();
} catch (e) {
console.dir(e);
container.innerHTML = "<h1>Something Went Wrong</h1>";
throw e;
}
}
document.addEventListener("DOMContentLoaded", app);