|
| 1 | +import "./styles.css"; |
| 2 | +import sessionMock from './session-mock.js'; |
| 3 | +let incode; |
| 4 | +let session; |
| 5 | + |
| 6 | +const container = document.querySelector("#incode-container"); |
| 7 | + |
| 8 | +function initializeIncodeSDK() { |
| 9 | + return window.OnBoarding.create({ |
| 10 | + apiURL: import.meta.env.VITE_SDK_ENDPOINT, |
| 11 | + }); |
| 12 | +} |
| 13 | + |
| 14 | +function createIncodeSession() { |
| 15 | + //emulate backend request |
| 16 | + return sessionMock; |
| 17 | +} |
| 18 | + |
| 19 | +function captureIdFrontSide() { |
| 20 | + incode.renderCamera("front", container, { |
| 21 | + onSuccess: captureIdBackSide, |
| 22 | + onError: console.log, |
| 23 | + token: session, |
| 24 | + numberOfTries: 3, |
| 25 | + showTutorial: true, |
| 26 | + showCustomCameraPermissionScreen: true, |
| 27 | + }); |
| 28 | +} |
| 29 | + |
| 30 | +function captureIdBackSide() { |
| 31 | + incode.renderCamera("back", container, { |
| 32 | + onSuccess: processId, |
| 33 | + onError: console.log, |
| 34 | + token: session, |
| 35 | + numberOfTries: 3, |
| 36 | + showTutorial: true, |
| 37 | + showCustomCameraPermissionScreen: true, |
| 38 | + }); |
| 39 | +} |
| 40 | + |
| 41 | +function processId() { |
| 42 | + return incode |
| 43 | + .processId({ token: session.token }) |
| 44 | + .then(() => { |
| 45 | + captureSelfie(); |
| 46 | + }) |
| 47 | + .catch((error) => { |
| 48 | + console.log(error); |
| 49 | + }); |
| 50 | +} |
| 51 | + |
| 52 | +function captureSelfie() { |
| 53 | + incode.renderCamera("selfie", container, { |
| 54 | + onSuccess: finishOnboarding, |
| 55 | + onError: console.log, |
| 56 | + token: session, |
| 57 | + numberOfTries: 3, |
| 58 | + showCustomCameraPermissionScreen: true, |
| 59 | + }); |
| 60 | +} |
| 61 | + |
| 62 | +//add then & catch |
| 63 | +function finishOnboarding() { |
| 64 | + incode |
| 65 | + .getFinishStatus(null, { token: session.token }) |
| 66 | + .then((response) => { |
| 67 | + console.log(response); |
| 68 | + }) |
| 69 | + .catch((error) => { |
| 70 | + console.log(error); |
| 71 | + }); |
| 72 | +} |
| 73 | + |
| 74 | +async function app() { |
| 75 | + incode = initializeIncodeSDK(); |
| 76 | + session = await createIncodeSession(); |
| 77 | + await incode.sendGeolocation({ token: session.token }).catch((error) => { |
| 78 | + console.log(error); |
| 79 | + }); |
| 80 | + |
| 81 | + captureIdFrontSide(); |
| 82 | +} |
| 83 | + |
| 84 | +document.addEventListener("DOMContentLoaded", app); |
0 commit comments