@tsocial/tvweb-sdk.tcb 5.11.3 → 5.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,438 +1,452 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="en">
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
6
- <meta name="description" content="Vanilla JS demo" />
7
- <link rel="preconnect" href="https://fonts.googleapis.com">
8
- <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
9
- <link href="https://fonts.googleapis.com/css2?family=Nunito:ital,wght@0,200;0,300;0,400;0,600;0,700;0,800;0,900;1,200;1,300;1,400;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">
10
-
11
- <link rel="stylesheet" href="./style.css" />
12
- </head>
13
- <body>
14
- <noscript>You need to enable JavaScript to run this app.</noscript>
15
- <h2>Extract ID Info & Liveness detection</h2>
16
- <div id="container"></div>
17
-
18
- <div style="margin-bottom: 10px">
19
- <label>
20
- Keys:
21
- <select id="select-api-key" onchange="onSelectKey()">
22
- <option value="0" selected>Web face tracking (..a31)</option>
23
- <option value="1">QA (..217)</option>
24
- <option value="2">Labeller test real data (..3b2)</option>
25
- <option value="3">Labeller test fake data (..ac4)</option>
26
- </select>
27
- </label>
28
- </div>
29
- <div style="margin-bottom: 10px">
30
- <label>
31
- Access key
32
- <input id="access-key" style="width: 500px" />
33
- </label>
34
- </div>
35
- <div style="margin-bottom: 10px">
36
- <label>
37
- Secret key
38
- <input id="secret-key" style="width: 500px" />
39
- </label>
40
- </div>
41
- <div style="margin-bottom: 10px">
42
- <label>
43
- API URL
44
- <input id="api-url" style="width: 500px" />
45
- </label>
46
- </div>
47
- <div>
48
- Api check
49
- <select id="select-api-check">
50
- <option value="false">false</option>
51
- <option value="true" selected>true</option>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
6
+ <meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-eval' 'unsafe-inline' https: data:; worker-src blob:">
7
+ <meta name="description" content="Vanilla JS demo" />
8
+ <link rel="preconnect" href="https://fonts.googleapis.com">
9
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
10
+ <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
11
+ <link rel="stylesheet" href="./style.css" />
12
+ </head>
13
+ <body>
14
+ <noscript>You need to enable JavaScript to run this app.</noscript>
15
+ <h2>Extract ID Info & Liveness detection</h2>
16
+ <div id="container"></div>
17
+
18
+ <div id="content">
19
+ <div style="margin-bottom: 10px">
20
+ Language
21
+ <select id="select-lang" onchange="onSelectLang()">
22
+ <option value="vi" selected>vi</option>
23
+ <option value="en">en</option>
24
+ </select>
25
+ </div>
26
+ <div style="margin-bottom: 10px">
27
+ <label>
28
+ Keys:
29
+ <select id="select-api-key" onchange="onSelectKey()">
30
+ <option value="0" selected>Web face tracking (..a31)</option>
31
+ <option value="1">QA (..217)</option>
32
+ <option value="2">Labeller test real data (..3b2)</option>
33
+ <option value="3">Labeller test fake data (..ac4)</option>
52
34
  </select>
53
- </div>
54
-
55
- <div style="margin-top: 10px;">
56
- <label>
57
- Cached User ID
58
- <input id="user-id" readonly style="width: 300px" />
59
- </label>
60
- <button onclick="clearUserId()">Clear user id (x-request-id)</button>
61
- </div>
62
-
63
- <div style="display: inline-block; margin-top: 10px;">
64
- <div>
65
- Tracking config
66
- <select id="select-tracking-config-template" onchange="onSelectTrackingConfigTemplate()">
67
- <option value="0" selected>default</option>
68
- <option value="1">Engineering test (...9fe5)</option>
69
- </select>
70
- </div>
71
- <textarea cols="55" rows="8" id="tracking-config"></textarea>
72
- </div>
73
-
74
- <div style="margin-top: 10px;">
75
- <div>
76
- Encryption config
77
- </div>
78
- <textarea cols="55" rows="4" id="encryption-config"></textarea>
79
- </div>
80
-
81
- <hr />
82
- <h4>Extract ID Info</h4>
83
- <div style="display: inline-block; margin-right: 20px;">
84
- <div>Settings (notice that if <strong>Api check: true</strong>, settings from api will overwrite these settings)</div>
85
- <textarea cols="55" rows="15" id="id-card-settings"></textarea>
86
- </div>
87
- <div style="display: inline-block">
88
- <div>Steps</div>
89
- <textarea cols="55" rows="15" id="id-card-steps"></textarea>
90
- </div>
91
- <div style="margin-bottom: 10px">
92
- <button onclick="runWarmUpReadIDCard()">Warm up</button>
93
- <span id="status-warmup-read-id-card"></span>
94
- </div>
95
- <button onclick="startExtractIDInfo()">Start</button>
96
- <pre id="result-extract-id-info"></pre>
97
- <div id="read-id-card-loading" style="margin-top: 10px; display: none;">
98
- Api checking
99
- <div class="dot-windmill"></div>
100
- </div>
101
-
102
- <hr />
103
-
104
- <h4>Liveness detection</h4>
105
- <div>
106
- Mode:
107
- <select id="select-mode"></select>
108
- </div>
35
+ </label>
36
+ </div>
37
+ <div style="margin-bottom: 10px">
38
+ <label>
39
+ Access key
40
+ <input id="access-key" class="key-input" />
41
+ </label>
42
+ </div>
43
+ <div style="margin-bottom: 10px">
44
+ <label>
45
+ Secret key
46
+ <input id="secret-key" class="key-input" />
47
+ </label>
48
+ </div>
49
+ <div style="margin-bottom: 10px">
50
+ <label>
51
+ API URL
52
+ <input id="api-url" class="key-input" />
53
+ </label>
54
+ </div>
55
+ <div>
56
+ Api check
57
+ <select id="select-api-check">
58
+ <option value="false">false</option>
59
+ <option value="true" selected>true</option>
60
+ </select>
61
+ </div>
62
+
63
+ <div style="display: none; margin-top: 10px;">
64
+ <label>
65
+ Cached User ID
66
+ <input id="user-id" readonly style="width: 300px" />
67
+ </label>
68
+ <button onclick="clearUserId()">Clear user id (x-request-id)</button>
69
+ </div>
70
+
71
+ <div style="display: none; margin-top: 10px;">
109
72
  <div>
110
- Camera:
111
- <select id="select-camera">
112
- <option value="true">Front</option>
113
- <option value="false">Back</option>
73
+ Tracking config
74
+ <select id="select-tracking-config-template" onchange="onSelectTrackingConfigTemplate()">
75
+ <option value="0" selected>default</option>
76
+ <option value="1">Engineering test (...9fe5)</option>
114
77
  </select>
115
78
  </div>
116
- <div>
117
- <div>Custom step time constraints (ms):</div>
118
- <textarea cols="25" rows="15" id="custom-step-time-constraints"></textarea>
119
- </div>
120
- <button onclick="startLivenessDetection()" id="btn-start-liveness">
121
- Liveness detection
122
- </button>
123
- <div id="liveness-loading" style="padding-top: 10px; display: none;">
124
- Api checking
125
- <div class="dot-windmill"></div>
126
- </div>
127
- <div id="result-liveness-detection"></div>
128
- <script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"></script>
129
- <script src="https://unpkg.com/@tsocial/trustvision-sdk@2.10.1/dist/trustvision-sdk.umd.js"></script>
130
- <script src="../../build/tvweb-sdk.tcb.standalone.min.js"></script>
131
- <script>
132
- const keys = [
133
- {
134
- accessKey: "f051dfd3-8a6e-4a15-a4e8-7ea8cdc84a31",
135
- secretKey: "vgiKCenoKvhPq79KABbFmxCBu6WX1tdw",
136
- },
137
- {
138
- accessKey: "b96f7a1a-a7f1-46e8-9d7f-5f43d2d51217",
139
- secretKey: "SYsUyQ792pLm7rnDRQFfIL6cgAecZCOp",
140
- },
141
- {
142
- accessKey: "db3d055f-ba7b-4177-b7e8-110068bda3b2",
143
- secretKey: "R1zjKNbTH3RkT2xgO2CarxAsFbcLCdsf",
144
- },
145
- {
146
- accessKey: "4e24c8f3-7fe0-4824-9339-9a1216a72ac4",
147
- secretKey: "CkoyKslrfBGv4m53LIlH0Q8yJYf4O56e",
148
- },
149
- ];
150
- function onSelectKey() {
151
- const selectedKey = document.getElementById("select-api-key").value;
152
- const { accessKey, secretKey } = keys[selectedKey];
153
- inputAccessKey.value = accessKey;
154
- inputSecretKey.value = secretKey;
155
- }
156
- </script>
157
- <script type="text/javascript">
158
- const tv = new TVWebSDK.SDK({
159
- container: document.getElementById("container"),
160
- lang: "vi",
161
- assetRoot: "https://unpkg.com/@tsocial/tvweb-sdk.tcb@latest/assets",
162
- enableAntiDebug: false,
163
- });
164
- window.tv = tv;
165
- const resultExtractIdInfoEl = document.getElementById(
166
- "result-extract-id-info"
167
- );
168
- const resultLivenessDetectionEl = document.getElementById(
169
- "result-liveness-detection"
170
- );
171
- const selectModeEl = document.getElementById("select-mode");
172
- const selectApiCheckEl = document.getElementById("select-api-check");
173
- const inputAccessKey = document.getElementById("access-key");
174
- const inputSecretKey = document.getElementById("secret-key");
175
- const inputApiUrl = document.getElementById("api-url");
176
- const userIdEl = document.getElementById("user-id");
177
- const trackingConfigEl = document.getElementById("tracking-config");
178
- const encryptionConfigEl = document.getElementById("encryption-config");
179
- const readIdCardLoadingEl = document.getElementById("read-id-card-loading");
180
- const customStepTimeConstraintsEl = document.getElementById("custom-step-time-constraints");
181
- const statusWarmupReadIDCardEl = document.getElementById("status-warmup-read-id-card");
182
- const livenessLoadingEl = document.getElementById("liveness-loading");
183
- const startLivenessBtn = document.getElementById("btn-start-liveness");
184
- const idCardSettingsEl = document.getElementById("id-card-settings");
185
- const idCardStepsEl = document.getElementById("id-card-steps");
186
- inputAccessKey.value = "f051dfd3-8a6e-4a15-a4e8-7ea8cdc84a31";
187
- inputSecretKey.value = "vgiKCenoKvhPq79KABbFmxCBu6WX1tdw";
188
- inputApiUrl.value = "https://tv-testing.trustingsocial.com/api";
189
- userIdEl.value = JSON.parse(localStorage.getItem("user-id"));
190
-
191
- const trackingConfigTemplates = [
192
- TVWebSDK.TrackingContext.defaultTrackingConfig,
193
- {
194
- "enable": true,
195
- "accessKey": "4df5f9b9-f34d-4ffa-829f-aa4889bc9fe5",
196
- "secretKey": "dQDfxkVYXfAxpdReqdOd1zJP4pJ088Y7",
197
- "apiUrl": "https://tv-testing.trustingsocial.com/api",
198
- "userId": ""
199
- },
200
- ];
201
- function onSelectTrackingConfigTemplate() {
202
- const selected = document.getElementById("select-tracking-config-template").value;
203
- trackingConfigEl.value = JSON.stringify(trackingConfigTemplates[selected], null, 2);
79
+ <textarea cols="40" rows="8" id="tracking-config"></textarea>
80
+ </div>
81
+
82
+ <hr />
83
+ <h4>Extract ID Info</h4>
84
+ <div style="display: none; margin-right: 20px;">
85
+ <div>Settings (notice that if <strong>Api check: true</strong>, settings from api will overwrite these settings)</div>
86
+ <textarea cols="40" rows="15" id="id-card-settings"></textarea>
87
+ </div>
88
+ <div style="display: none">
89
+ <div>Steps</div>
90
+ <textarea cols="40" rows="15" id="id-card-steps"></textarea>
91
+ </div>
92
+ <button onclick="startExtractIDInfo()">Start</button>
93
+ <pre id="result-extract-id-info"></pre>
94
+ <div id="read-id-card-loading" style="margin-top: 10px; display: none;">
95
+ Api checking
96
+ <div class="dot-windmill"></div>
97
+ </div>
98
+
99
+ <hr />
100
+
101
+ <h4>Liveness detection</h4>
102
+ <div>
103
+ Mode:
104
+ <select id="select-mode"></select>
105
+ </div>
106
+ <div style="display: none">
107
+ Camera:
108
+ <select id="select-camera">
109
+ <option value="true">Front</option>
110
+ <option value="false">Back</option>
111
+ </select>
112
+ </div>
113
+ <button onclick="startLivenessDetection()" id="btn-start-liveness" style="margin-top: 10px">
114
+ Liveness detection
115
+ </button>
116
+ <div id="liveness-loading" style="padding-top: 10px; display: none;">
117
+ Api checking
118
+ <div class="dot-windmill"></div>
119
+ </div>
120
+ <div id="result-liveness-detection"></div>
121
+ </div>
122
+
123
+ <script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"></script>
124
+ <script src="https://unpkg.com/@tsocial/trustvision-sdk@2.10.1/dist/trustvision-sdk.umd.js"></script>
125
+ <script src="../../build/tvweb-sdk.tcb.standalone.min.js"></script>
126
+ <script>
127
+ const keys = [
128
+ {
129
+ accessKey: "f051dfd3-8a6e-4a15-a4e8-7ea8cdc84a31",
130
+ secretKey: "vgiKCenoKvhPq79KABbFmxCBu6WX1tdw",
131
+ },
132
+ {
133
+ accessKey: "b96f7a1a-a7f1-46e8-9d7f-5f43d2d51217",
134
+ secretKey: "SYsUyQ792pLm7rnDRQFfIL6cgAecZCOp",
135
+ },
136
+ {
137
+ accessKey: "db3d055f-ba7b-4177-b7e8-110068bda3b2",
138
+ secretKey: "R1zjKNbTH3RkT2xgO2CarxAsFbcLCdsf",
139
+ },
140
+ {
141
+ accessKey: "4e24c8f3-7fe0-4824-9339-9a1216a72ac4",
142
+ secretKey: "CkoyKslrfBGv4m53LIlH0Q8yJYf4O56e",
143
+ },
144
+ ];
145
+ let listObjUrls = [];
146
+ function onSelectKey() {
147
+ const selectedKey = document.getElementById("select-api-key").value;
148
+ const { accessKey, secretKey } = keys[selectedKey];
149
+ inputAccessKey.value = accessKey;
150
+ inputSecretKey.value = secretKey;
151
+ }
152
+ function onSelectLang() {
153
+ const langEle = document.getElementById("select-lang");
154
+ localStorage.setItem('lang', langEle?.value);
155
+ location.reload();
156
+ }
157
+ function createObjectURL(blob) {
158
+ const objUrl = URL.createObjectURL(blob);
159
+ listObjUrls.push(objUrl);
160
+ return objUrl;
161
+ }
162
+ function revokeObjectURL() {
163
+ if (listObjUrls.length === 0) return;
164
+ listObjUrls.map((item) => URL.revokeObjectURL(item));
165
+ listObjUrls = [];
166
+ }
167
+ </script>
168
+ <script type="text/javascript">
169
+ const lang = localStorage.getItem('lang');
170
+ if (lang) {
171
+ const langEle = document.getElementById("select-lang");
172
+ langEle.value = lang;
173
+ }
174
+ const tv = new TVWebSDK.SDK({
175
+ container: document.getElementById("container"),
176
+ lang: lang || "vi",
177
+ assetRoot: "https://unpkg.com/@tsocial/tvweb-sdk.tcb@latest/assets",
178
+ enableAntiDebug: false,
179
+ });
180
+ window.tv = tv;
181
+ tv.runPreloadEKYCResources();
182
+ const resultExtractIdInfoEl = document.getElementById(
183
+ "result-extract-id-info"
184
+ );
185
+ const resultLivenessDetectionEl = document.getElementById(
186
+ "result-liveness-detection"
187
+ );
188
+ const selectModeEl = document.getElementById("select-mode");
189
+ const selectApiCheckEl = document.getElementById("select-api-check");
190
+ const inputAccessKey = document.getElementById("access-key");
191
+ const inputSecretKey = document.getElementById("secret-key");
192
+ const inputApiUrl = document.getElementById("api-url");
193
+ const userIdEl = document.getElementById("user-id");
194
+ const trackingConfigEl = document.getElementById("tracking-config");
195
+ const readIdCardLoadingEl = document.getElementById("read-id-card-loading");
196
+ const statusWarmupReadIDCardEl = document.getElementById("status-warmup-read-id-card");
197
+ const livenessLoadingEl = document.getElementById("liveness-loading");
198
+ const startLivenessBtn = document.getElementById("btn-start-liveness");
199
+ const idCardSettingsEl = document.getElementById("id-card-settings");
200
+ const idCardStepsEl = document.getElementById("id-card-steps");
201
+ inputAccessKey.value = "f051dfd3-8a6e-4a15-a4e8-7ea8cdc84a31";
202
+ inputSecretKey.value = "vgiKCenoKvhPq79KABbFmxCBu6WX1tdw";
203
+ inputApiUrl.value = "https://tv-testing.trustingsocial.com/api";
204
+ userIdEl.value = JSON.parse(localStorage.getItem("user-id"));
205
+
206
+ const trackingConfigTemplates = [
207
+ TVWebSDK.TrackingContext.defaultTrackingConfig,
208
+ {
209
+ "enable": true,
210
+ "accessKey": "4df5f9b9-f34d-4ffa-829f-aa4889bc9fe5",
211
+ "secretKey": "dQDfxkVYXfAxpdReqdOd1zJP4pJ088Y7",
212
+ "apiUrl": "https://tv-testing.trustingsocial.com/api",
213
+ "userId": ""
214
+ },
215
+ ];
216
+ function onSelectTrackingConfigTemplate() {
217
+ const selected = document.getElementById("select-tracking-config-template").value;
218
+ trackingConfigEl.value = JSON.stringify(trackingConfigTemplates[selected], null, 2);
219
+ }
220
+
221
+ Object.keys(TVWebSDK.Constants.Mode).forEach((k) => {
222
+ const option = document.createElement("option");
223
+ option.appendChild(document.createTextNode(k));
224
+ option.setAttribute("value", TVWebSDK.Constants.Mode[k]);
225
+ selectModeEl.appendChild(option);
226
+ });
227
+
228
+ idCardSettingsEl.value = JSON.stringify(TVWebSDK.defaultClientSettings, null, 2);
229
+ idCardStepsEl.value = JSON.stringify(TVWebSDK.defaultReadIDCardSteps, null, 2);
230
+ trackingConfigEl.value = JSON.stringify(TVWebSDK.TrackingContext.defaultTrackingConfig, null, 2);
231
+
232
+ function clearUserId() {
233
+ window.localStorage.removeItem('user-id');
234
+ userIdEl.value = JSON.parse(localStorage.getItem("user-id"));
235
+ }
236
+
237
+ function handleStepDoneIDCard ({ stepNumber, image, qrScannedResult, recordedVideos, apiResult }) {
238
+ const steps = JSON.parse(idCardStepsEl.value)
239
+ console.log('image', image)
240
+
241
+ resultExtractIdInfoEl.appendChild(document.createTextNode(`\n-----------------------------------------\n`))
242
+ resultExtractIdInfoEl.appendChild(document.createTextNode(`\nSTEP NUMBER ${stepNumber}:\n`));
243
+
244
+
245
+ const imgEl = document.createElement("img");
246
+ imgEl.width = "300";
247
+ imgEl.src = createObjectURL(image.blob);
248
+ resultExtractIdInfoEl.appendChild(imgEl);
249
+ resultExtractIdInfoEl.appendChild(document.createElement("br"));
250
+ resultExtractIdInfoEl.appendChild(document.createTextNode(`Recorded videos: ${recordedVideos.length}\n`));
251
+
252
+ if (qrScannedResult) {
253
+ const { result, image } = qrScannedResult
254
+
255
+ if (image && image.blob) {
256
+ const qrImgEl = document.createElement("img");
257
+ qrImgEl.width = "200";
258
+ qrImgEl.src = URL.createObjectURL(image.blob);
259
+ resultExtractIdInfoEl.appendChild(qrImgEl);
204
260
  }
205
-
206
- Object.keys(TVWebSDK.Constants.Mode).forEach((k) => {
207
- const option = document.createElement("option");
208
- option.appendChild(document.createTextNode(k));
209
- option.setAttribute("value", TVWebSDK.Constants.Mode[k]);
210
- selectModeEl.appendChild(option);
211
- });
212
-
213
- const customStepTimeConstraintsData = {
214
- [TVWebSDK.Constants.FaceDirection.UP]: { delayTime: 1000 },
215
- [TVWebSDK.Constants.FaceDirection.LEFT]: { delayTime: 1000 },
216
- [TVWebSDK.Constants.FaceDirection.RIGHT]: { delayTime: 1000 },
217
- [TVWebSDK.Constants.FaceDirection.FRONTAL]: { delayTime: 2000 },
218
- };
219
-
220
- customStepTimeConstraintsEl.value = JSON.stringify(customStepTimeConstraintsData, null, 2);
221
- idCardSettingsEl.value = JSON.stringify(TVWebSDK.defaultClientSettings, null, 2);
222
- idCardStepsEl.value = JSON.stringify(TVWebSDK.defaultReadIDCardSteps, null, 2);
223
- trackingConfigEl.value = JSON.stringify(TVWebSDK.TrackingContext.defaultTrackingConfig, null, 2);
224
- encryptionConfigEl.value = JSON.stringify({ key: '' }, null, 2);
225
-
226
- function clearUserId() {
227
- window.localStorage.removeItem('user-id');
228
- userIdEl.value = JSON.parse(localStorage.getItem("user-id"));
261
+ resultExtractIdInfoEl.appendChild(document.createTextNode(`\n${result}\n`));
262
+ }
263
+
264
+ if (apiResult) {
265
+ resultExtractIdInfoEl.appendChild(document.createTextNode("API Result:\n"));
266
+ const apiResultEl = document.createElement('textarea');
267
+ apiResultEl.value = JSON.stringify(apiResult, null, 2);
268
+ apiResultEl.cols = 55
269
+ apiResultEl.rows = 15
270
+ resultExtractIdInfoEl.appendChild(apiResultEl);
271
+ }
272
+
273
+ // all steps done
274
+ if (stepNumber === steps.length - 1) {
275
+ tv.destroyView();
276
+ readIdCardLoadingEl.style.display = 'none';
277
+ }
278
+ }
279
+
280
+ async function handleDetectIdCard (props) {
281
+ const { cardType, image, cardSide } = props
282
+ const apiClient = new trustvisionSdk.default(inputAccessKey.value, inputSecretKey.value, inputApiUrl.value);
283
+ const resultUpload = await apiClient.uploadImage({
284
+ file: image.blob,
285
+ label: `id_card.${cardType}.${cardSide}`,
286
+ });
287
+ const imageId = resultUpload.data.image_id
288
+ const resultDetect = await apiClient.httpClient.post('/v1/detect_id_cards_sync', {
289
+ card_type: cardType,
290
+ image: {
291
+ id: imageId,
229
292
  }
230
-
231
- function runWarmUpReadIDCard() {
232
- statusWarmupReadIDCardEl.innerHTML = "..."
233
- tv.runWarmUpReadIDCard().then(function() {
234
- statusWarmupReadIDCardEl.innerHTML = "...done"
235
- })
236
- }
237
-
238
- function handleStepDoneIDCard ({ stepNumber, image, qrScannedResult, recordedVideos, apiResult }) {
239
- const steps = JSON.parse(idCardStepsEl.value)
240
-
241
- resultExtractIdInfoEl.appendChild(document.createTextNode(`\n-----------------------------------------\n`))
242
- resultExtractIdInfoEl.appendChild(document.createTextNode(`\nSTEP NUMBER ${stepNumber}:\n`));
243
- const imgEl = document.createElement("img");
244
- imgEl.width = "300";
245
- imgEl.src = URL.createObjectURL(image.blob);
246
- resultExtractIdInfoEl.appendChild(imgEl);
247
- resultExtractIdInfoEl.appendChild(document.createElement("br"));
248
- resultExtractIdInfoEl.appendChild(document.createTextNode(`Recorded videos: ${recordedVideos.length}\n`));
249
-
250
- if (qrScannedResult) {
251
- const { result, image } = qrScannedResult
252
-
253
- const qrImgEl = document.createElement("img");
254
- qrImgEl.width = "200";
255
- qrImgEl.src = URL.createObjectURL(image.blob);
256
- resultExtractIdInfoEl.appendChild(qrImgEl);
257
- resultExtractIdInfoEl.appendChild(document.createTextNode(`\n${result}\n`));
258
- }
259
-
260
- if (apiResult) {
261
- resultExtractIdInfoEl.appendChild(document.createTextNode("API Result:\n"));
262
- const apiResultEl = document.createElement('textarea');
263
- apiResultEl.value = JSON.stringify(apiResult, null, 2);
264
- apiResultEl.cols = 55
265
- apiResultEl.rows = 15
266
- resultExtractIdInfoEl.appendChild(apiResultEl);
267
- }
268
-
269
- // all steps done
270
- if (stepNumber === steps.length - 1) {
271
- tv.destroyView();
272
- readIdCardLoadingEl.style.display = 'none';
273
- }
274
- }
275
-
276
- async function handleDetectIdCard (props) {
277
- const { cardType, image, cardSide } = props
278
- const apiClient = new trustvisionSdk.default(inputAccessKey.value, inputSecretKey.value, inputApiUrl.value);
279
- const resultUpload = await apiClient.uploadImage({
280
- file: image.blob,
281
- label: `id_card.${cardType}.${cardSide}`,
282
- });
283
- const imageId = resultUpload.data.image_id
284
- const resultDetect = await apiClient.httpClient.post('/v1/detect_id_cards_sync', {
285
- card_type: cardType,
286
- image: {
287
- id: imageId,
288
- }
289
- });
290
- return _.get(resultDetect, 'data.image.cards.0')
291
- }
292
-
293
- function startExtractIDInfo() {
294
- const apiCheck = selectApiCheckEl.value === "true";
295
- resultExtractIdInfoEl.innerHTML = "";
296
-
297
- const commonProps = {
298
- onError: (e) => {
299
- resultExtractIdInfoEl.appendChild(
300
- document.createTextNode(`Error:\n${JSON.stringify(e, null, 2)}`)
301
- );
302
- tv.destroyView();
303
- readIdCardLoadingEl.style.display = 'none';
304
- },
305
- clientSettings: JSON.parse(idCardSettingsEl.value),
306
- detectIdCard: handleDetectIdCard,
307
- onStepDone: handleStepDoneIDCard,
308
- steps: JSON.parse(idCardStepsEl.value),
309
- tracking: JSON.parse(trackingConfigEl.value),
310
- outputEncryptionSettings: JSON.parse(encryptionConfigEl.value),
311
- }
312
-
313
- if (apiCheck) {
314
- console.log('With api call')
315
- tv.readIDCardWithApiCall({
316
- apiCredentials: {
317
- accessKey: inputAccessKey.value,
318
- secretKey: inputSecretKey.value,
319
- apiUrl: inputApiUrl.value,
320
- },
321
- ...commonProps,
322
- })
323
- } else {
324
- console.log('UI only')
325
- tv.readIDCardUIOnly(commonProps)
326
- }
327
- }
328
-
329
- function startLivenessDetection() {
330
- const livenessDetectionMode = selectModeEl.value;
331
- const apiCheck = selectApiCheckEl.value === "true";
332
- const cameraSelected = document.getElementById("select-camera");
333
-
334
- tv.livenessDetection({
335
- apiCheck: apiCheck,
336
- mode: livenessDetectionMode,
293
+ });
294
+ return _.get(resultDetect, 'data.image.cards.0')
295
+ }
296
+
297
+ function startExtractIDInfo() {
298
+ revokeObjectURL();
299
+ const apiCheck = selectApiCheckEl.value === "true";
300
+ resultExtractIdInfoEl.innerHTML = "";
301
+ document.body.style.height = 0;
302
+
303
+ const commonProps = {
304
+ onError: (e) => {
305
+ resultExtractIdInfoEl.appendChild(
306
+ document.createTextNode(`Error:\n${JSON.stringify(e, null, 2)}`)
307
+ );
308
+ tv.destroyView();
309
+ document.body.style.height = 'auto';
310
+ readIdCardLoadingEl.style.display = 'none';
311
+ },
312
+ onClose: () => {
313
+ document.body.style.height = 'auto';
314
+ tv.destroyView();
315
+ },
316
+ clientSettings: JSON.parse(idCardSettingsEl.value),
317
+ detectIdCard: handleDetectIdCard,
318
+ onStepDone: handleStepDoneIDCard,
319
+ steps: JSON.parse(idCardStepsEl.value),
320
+ tracking: JSON.parse(trackingConfigEl.value),
321
+ }
322
+
323
+ if (apiCheck) {
324
+ console.log('With api call')
325
+ tv.readIDCardWithApiCall({
326
+ apiCredentials: {
337
327
  accessKey: inputAccessKey.value,
338
328
  secretKey: inputSecretKey.value,
339
329
  apiUrl: inputApiUrl.value,
340
- onLivenessDetectionDone: handleLivenessDetectionDone,
341
- customStepTimeConstraints: JSON.parse(customStepTimeConstraintsEl.value),
342
- captureFrameSettings: {
343
- enable: true,
344
- framesIntervalTime: 180,
345
- framesBatchLength: 0,
346
- },
347
- onError: (e) => {
348
- livenessLoadingEl.style.display = "none";
349
- startLivenessBtn.disabled = false;
350
- resultLivenessDetectionEl.appendChild(
351
- document.createTextNode(`${JSON.stringify(e, null, 2)}`)
352
- );
353
- },
354
- frontCamera: cameraSelected.value === "true",
355
- onProcessing: () => {
356
- livenessLoadingEl.style.display = "block";
357
- startLivenessBtn.disabled = true;
358
-
359
- resultLivenessDetectionEl.innerHTML = "";
330
+ },
331
+ ...commonProps,
332
+ })
333
+ } else {
334
+ console.log('UI only')
335
+ tv.readIDCardUIOnly(commonProps)
336
+ }
337
+ }
338
+
339
+ function startLivenessDetection() {
340
+ revokeObjectURL();
341
+ const livenessDetectionMode = selectModeEl.value;
342
+ const apiCheck = selectApiCheckEl.value === "true";
343
+ const cameraSelected = document.getElementById("select-camera");
344
+ document.body.style.height = 0;
345
+
346
+ tv.livenessDetection({
347
+ apiCheck: apiCheck,
348
+ mode: livenessDetectionMode,
349
+ apiCredentials: {
350
+ accessKey: inputAccessKey.value,
351
+ secretKey: inputSecretKey.value,
352
+ apiUrl: inputApiUrl.value,
353
+ },
354
+ onLivenessDetectionDone: handleLivenessDetectionDone,
355
+ captureFrameSettings: {
356
+ enable: true,
357
+ framesIntervalTime: 180,
358
+ framesBatchLength: 15,
359
+ },
360
+ onError: (e) => {
361
+ livenessLoadingEl.style.display = "none";
362
+ startLivenessBtn.disabled = false;
363
+ resultLivenessDetectionEl.appendChild(
364
+ document.createTextNode(`${JSON.stringify(e, null, 2)}`)
365
+ );
366
+ },
367
+ frontCamera: cameraSelected.value === "true",
368
+ onProcessing: () => {
369
+ livenessLoadingEl.style.display = "block";
370
+ startLivenessBtn.disabled = true;
360
371
 
361
- setTimeout(() => {
362
- tv.destroyView();
363
- }, 250);
364
- },
365
- });
372
+ resultLivenessDetectionEl.innerHTML = "";
373
+ document.body.style.height = 'auto';
374
+ setTimeout(() => {
375
+ tv.destroyView();
376
+ }, 250);
377
+ },
378
+ onClose: () => { document.body.style.height = 'auto'; tv.destroyView(); },
379
+ });
380
+ }
381
+
382
+ function handleReadIDCardResult({ image, recordedVideos, apiResult }) {
383
+ const apiCheck = selectApiCheckEl.value === "true";
384
+
385
+ const imgEl = document.createElement("img");
386
+ imgEl.width = "200";
387
+ imgEl.src = createObjectURL(image);
388
+ resultExtractIdInfoEl.appendChild(imgEl);
389
+ resultExtractIdInfoEl.appendChild(document.createElement("br"));
390
+ resultExtractIdInfoEl.appendChild(document.createTextNode(`Recorded videos: ${recordedVideos.length}\n`));
391
+
392
+ if (apiCheck) {
393
+ resultExtractIdInfoEl.appendChild(document.createTextNode("API Result:\n"));
394
+ resultExtractIdInfoEl.appendChild(
395
+ document.createTextNode(`${JSON.stringify(apiResult, null, 2)}`)
396
+ );
397
+ if (cardSide === TVWebSDK.Constants.IDCardSide.FRONT) {
398
+ const frontCardId = apiResult.cardInfo.image1.id;
399
+ inputFrontIdEl.value = frontCardId;
366
400
  }
367
-
368
- function handleReadIDCardResult({ image, recordedVideos, apiResult }) {
369
- const apiCheck = selectApiCheckEl.value === "true";
370
-
401
+ }
402
+
403
+ tv.destroyView();
404
+ readIdCardLoadingEl.style.display = 'none';
405
+ }
406
+
407
+ function handleLivenessDetectionDone(result) {
408
+ const { frontalFaces, apiCheckPassed, steps } = result;
409
+ const apiCheck = selectApiCheckEl.value === "true";
410
+ resultLivenessDetectionEl.innerHTML = "";
411
+
412
+ if (apiCheck === false) {
413
+ livenessLoadingEl.style.display = "none";
414
+ startLivenessBtn.disabled = false;
415
+ resultLivenessDetectionEl.appendChild(
416
+ document.createTextNode("Random frontal faces detected: ")
417
+ );
418
+ frontalFaces.forEach((blob) => {
371
419
  const imgEl = document.createElement("img");
372
420
  imgEl.width = "200";
373
- imgEl.src = URL.createObjectURL(image);
374
- resultExtractIdInfoEl.appendChild(imgEl);
375
- resultExtractIdInfoEl.appendChild(document.createElement("br"));
376
- resultExtractIdInfoEl.appendChild(document.createTextNode(`Recorded videos: ${recordedVideos.length}\n`));
377
-
378
- if (apiCheck) {
379
- resultExtractIdInfoEl.appendChild(document.createTextNode("API Result:\n"));
380
- resultExtractIdInfoEl.appendChild(
381
- document.createTextNode(`${JSON.stringify(apiResult, null, 2)}`)
382
- );
383
- if (cardSide === TVWebSDK.Constants.IDCardSide.FRONT) {
384
- const frontCardId = apiResult.cardInfo.image1.id;
385
- inputFrontIdEl.value = frontCardId;
386
- }
387
- }
388
-
389
- tv.destroyView();
390
- readIdCardLoadingEl.style.display = 'none';
391
- }
392
-
393
- function handleLivenessDetectionDone(result) {
394
- const { frontalFaces, apiCheckPassed, steps } = result;
395
- const apiCheck = selectApiCheckEl.value === "true";
396
- resultLivenessDetectionEl.innerHTML = "";
397
-
398
- if (apiCheck === false) {
399
- livenessLoadingEl.style.display = "none";
400
- startLivenessBtn.disabled = false;
401
- resultLivenessDetectionEl.appendChild(
402
- document.createTextNode("Random frontal faces detected: ")
403
- );
404
- frontalFaces.forEach((blob) => {
405
- const imgEl = document.createElement("img");
406
- imgEl.width = "200";
407
- imgEl.style.marginRight = "5px";
408
- imgEl.src = URL.createObjectURL(blob);
409
- resultLivenessDetectionEl.appendChild(imgEl);
410
- });
411
- resultLivenessDetectionEl.appendChild(document.createElement("br"));
412
- resultLivenessDetectionEl.appendChild(document.createElement("br"));
413
- resultLivenessDetectionEl.appendChild(
414
- document.createTextNode("Directional faces:")
415
- );
416
- steps.forEach((s) => {
417
- const imgEl = document.createElement("img");
418
- imgEl.width = "200";
419
- imgEl.style.marginRight = "5px";
420
- imgEl.src = URL.createObjectURL(s.image.blob);
421
- resultLivenessDetectionEl.appendChild(imgEl);
422
- });
423
- resultLivenessDetectionEl.appendChild(document.createElement("br"));
424
- resultLivenessDetectionEl.appendChild(document.createElement("br"));
425
- resultLivenessDetectionEl.appendChild(
426
- document.createTextNode("Video:")
427
- );
428
- } else {
429
- livenessLoadingEl.style.display = "none";
430
- startLivenessBtn.disabled = false;
431
- resultLivenessDetectionEl.appendChild(
432
- document.createTextNode(`apiCheckPassed: ${apiCheckPassed}`)
433
- );
434
- }
435
- }
436
- </script>
437
- </body>
421
+ imgEl.style.marginRight = "5px";
422
+ imgEl.src = createObjectURL(blob);
423
+ resultLivenessDetectionEl.appendChild(imgEl);
424
+ });
425
+ resultLivenessDetectionEl.appendChild(document.createElement("br"));
426
+ resultLivenessDetectionEl.appendChild(document.createElement("br"));
427
+ resultLivenessDetectionEl.appendChild(
428
+ document.createTextNode("Directional faces:")
429
+ );
430
+ steps.forEach((s) => {
431
+ const imgEl = document.createElement("img");
432
+ imgEl.width = "200";
433
+ imgEl.style.marginRight = "5px";
434
+ imgEl.src = createObjectURL(s.image.blob);
435
+ resultLivenessDetectionEl.appendChild(imgEl);
436
+ });
437
+ resultLivenessDetectionEl.appendChild(document.createElement("br"));
438
+ resultLivenessDetectionEl.appendChild(document.createElement("br"));
439
+ resultLivenessDetectionEl.appendChild(
440
+ document.createTextNode("Video:")
441
+ );
442
+ } else {
443
+ livenessLoadingEl.style.display = "none";
444
+ startLivenessBtn.disabled = false;
445
+ resultLivenessDetectionEl.appendChild(
446
+ document.createTextNode(`apiCheckPassed: ${apiCheckPassed}`)
447
+ );
448
+ }
449
+ }
450
+ </script>
451
+ </body>
438
452
  </html>