@tsocial/tvweb-sdk.tcb 5.12.6 → 5.13.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.
@@ -23,41 +23,8 @@
23
23
  <option value="en">en</option>
24
24
  </select>
25
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>
34
- </select>
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>
26
+
27
+ <div style="margin-bottom: 10px" id="keys-input-placeholder">
61
28
  </div>
62
29
 
63
30
  <div style="display: none; margin-top: 10px;">
@@ -120,6 +87,9 @@
120
87
  <div id="result-liveness-detection"></div>
121
88
  </div>
122
89
 
90
+ <script src="https://unpkg.com/jsqr@1.4.0/dist/jsQR.js"></script>
91
+ <script src="./qr-scanner-for-input-keys.js"></script>
92
+ <script src="./keys-input.js"></script>
123
93
  <script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"></script>
124
94
  <script src="https://unpkg.com/@tsocial/trustvision-sdk@2.10.1/dist/trustvision-sdk.umd.js"></script>
125
95
  <script src="../../build/tvweb-sdk.tcb.standalone.min.js"></script>
@@ -143,12 +113,6 @@
143
113
  },
144
114
  ];
145
115
  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
116
  function onSelectLang() {
153
117
  const langEle = document.getElementById("select-lang");
154
118
  localStorage.setItem('lang', langEle.value);
@@ -186,10 +150,7 @@
186
150
  "result-liveness-detection"
187
151
  );
188
152
  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");
153
+
193
154
  const userIdEl = document.getElementById("user-id");
194
155
  const trackingConfigEl = document.getElementById("tracking-config");
195
156
  const readIdCardLoadingEl = document.getElementById("read-id-card-loading");
@@ -198,25 +159,8 @@
198
159
  const startLivenessBtn = document.getElementById("btn-start-liveness");
199
160
  const idCardSettingsEl = document.getElementById("id-card-settings");
200
161
  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
162
 
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
- }
163
+ userIdEl.value = JSON.parse(localStorage.getItem("user-id"));
220
164
 
221
165
  Object.keys(TVWebSDK.Constants.Mode).forEach((k) => {
222
166
  const option = document.createElement("option");
@@ -296,14 +240,13 @@
296
240
 
297
241
  function startExtractIDInfo() {
298
242
  revokeObjectURL();
299
- const apiCheck = selectApiCheckEl.value === "true";
300
243
  resultExtractIdInfoEl.innerHTML = "";
301
244
  document.body.style.height = 0;
302
245
 
303
246
  const commonProps = {
304
247
  onError: (e) => {
305
248
  resultExtractIdInfoEl.appendChild(
306
- document.createTextNode(`Error:\n${JSON.stringify(e, null, 2)}`)
249
+ document.createTextNode(`Error:\n${JSON.stringify(e, null, 2)}`)
307
250
  );
308
251
  tv.destroyView();
309
252
  document.body.style.height = 'auto';
@@ -318,7 +261,7 @@
318
261
  tracking: JSON.parse(trackingConfigEl.value),
319
262
  }
320
263
 
321
- if (apiCheck) {
264
+ if (inputAccessKey.value) {
322
265
  console.log('With api call')
323
266
  tv.readIDCardWithApiCall({
324
267
  apiCredentials: {
@@ -337,12 +280,11 @@
337
280
  function startLivenessDetection() {
338
281
  revokeObjectURL();
339
282
  const livenessDetectionMode = selectModeEl.value;
340
- const apiCheck = selectApiCheckEl.value === "true";
341
283
  const cameraSelected = document.getElementById("select-camera");
342
284
  document.body.style.height = 0;
343
285
 
344
286
  tv.livenessDetection({
345
- apiCheck: apiCheck,
287
+ apiCheck: !!inputAccessKey.value,
346
288
  mode: livenessDetectionMode,
347
289
  apiCredentials: {
348
290
  accessKey: inputAccessKey.value,
@@ -359,7 +301,7 @@
359
301
  livenessLoadingEl.style.display = "none";
360
302
  startLivenessBtn.disabled = false;
361
303
  resultLivenessDetectionEl.appendChild(
362
- document.createTextNode(`${JSON.stringify(e, null, 2)}`)
304
+ document.createTextNode(`${JSON.stringify(e, null, 2)}`)
363
305
  );
364
306
  },
365
307
  frontCamera: cameraSelected.value === "true",
@@ -378,8 +320,6 @@
378
320
  }
379
321
 
380
322
  function handleReadIDCardResult({ image, recordedVideos, apiResult }) {
381
- const apiCheck = selectApiCheckEl.value === "true";
382
-
383
323
  const imgEl = document.createElement("img");
384
324
  imgEl.width = "200";
385
325
  imgEl.src = createObjectURL(image);
@@ -387,7 +327,7 @@
387
327
  resultExtractIdInfoEl.appendChild(document.createElement("br"));
388
328
  resultExtractIdInfoEl.appendChild(document.createTextNode(`Recorded videos: ${recordedVideos.length}\n`));
389
329
 
390
- if (apiCheck) {
330
+ if (!!inputAccessKey.value) {
391
331
  resultExtractIdInfoEl.appendChild(document.createTextNode("API Result:\n"));
392
332
  resultExtractIdInfoEl.appendChild(
393
333
  document.createTextNode(`${JSON.stringify(apiResult, null, 2)}`)
@@ -404,10 +344,9 @@
404
344
 
405
345
  function handleLivenessDetectionDone(result) {
406
346
  const { frontalFaces, apiCheckPassed, steps } = result;
407
- const apiCheck = selectApiCheckEl.value === "true";
408
347
  resultLivenessDetectionEl.innerHTML = "";
409
348
 
410
- if (apiCheck === false) {
349
+ if (!inputAccessKey.value) {
411
350
  livenessLoadingEl.style.display = "none";
412
351
  startLivenessBtn.disabled = false;
413
352
  resultLivenessDetectionEl.appendChild(
@@ -0,0 +1,71 @@
1
+ /* eslint-disable prefer-destructuring */
2
+ /* eslint-disable no-var */
3
+ var inputAccessKey = {
4
+ value: '',
5
+ };
6
+ var inputSecretKey = {
7
+ value: '',
8
+ };
9
+ var inputApiUrl = {
10
+ value: '',
11
+ };
12
+ const keyInputHtml = `
13
+ <button id="key-import-string">IMPORT KEYS FROM STRING</button>
14
+ <button id="key-import-qr">IMPORT KEYS FROM QR</button>
15
+ <br/>
16
+ <br/>
17
+ <textarea cols="40" rows="5" id="key-input-string" hidden></textarea>
18
+ <br/>
19
+ <div id="key-parse"></div>
20
+ `;
21
+ const keyPlaceholder = document.getElementById('keys-input-placeholder');
22
+ keyPlaceholder.insertAdjacentHTML('afterbegin', keyInputHtml);
23
+
24
+ function onImportStrClick() {
25
+ const curState = document.getElementById('key-input-string').hidden;
26
+ document.getElementById('key-input-string').hidden = !curState;
27
+
28
+ const keyParsedPlaceholder = document.getElementById('key-parse');
29
+ keyParsedPlaceholder.innerHTML = '';
30
+ }
31
+
32
+ function importKeys(keys) {
33
+ let keyStr = '';
34
+ if (keys?.inputType === 'insertFromPaste') {
35
+ keyStr = keys?.target?.value;
36
+ }
37
+ if (typeof keys === 'string') keyStr = keys;
38
+ if (!keyStr) return;
39
+ // parse key
40
+ const keyParsed = keyStr.split(',');
41
+ // format: key_name/api_url/access_key/secret_key
42
+ const keyDisplayHtml = `
43
+ <span>Key Name: <i>${keyParsed[0]}</i></span><br/>
44
+ <span id="api-url-value">Api Url: <i>${keyParsed[1]}</i></span><br/>
45
+ <span id="access-key-value">Access Key: <i>${keyParsed[2]}</i></span><br/>
46
+ <span id="secret-value">Secret Key: <i>${keyParsed[3]}</i></span><br/>
47
+ `;
48
+ const keyParsedPlaceholder = document.getElementById('key-parse');
49
+ keyParsedPlaceholder.innerHTML = keyDisplayHtml;
50
+ document.getElementById('key-input-string').hidden = true;
51
+
52
+ inputApiUrl.value = keyParsed[1];
53
+ inputAccessKey.value = keyParsed[2];
54
+ inputSecretKey.value = keyParsed[3];
55
+ }
56
+
57
+ document.getElementById('key-import-string').addEventListener('click', onImportStrClick);
58
+ // eslint-disable-next-line no-undef
59
+ document.getElementById('key-import-qr').addEventListener('click', startQRScan);
60
+ document.getElementById('key-input-string').addEventListener('input', importKeys);
61
+
62
+ // function getKeysValue() {
63
+ // const apiUrl = document.getElementById('api-url-value').innerText;
64
+ // const accessKey = document.getElementById('access-key-value').innerText;
65
+ // const secretKey = document.getElementById('secret-value').innerText;
66
+ // return {
67
+ // apiUrl: apiUrl.slice(apiUrl.indexOf(':') + 2),
68
+ // accessKey: accessKey.slice(accessKey.indexOf(':') + 2),
69
+ // secretKey: secretKey.slice(secretKey.indexOf(':') + 2),
70
+ // };
71
+ // }
@@ -0,0 +1,81 @@
1
+ /* eslint-disable vars-on-top */
2
+ /* eslint-disable no-var */
3
+ const placeholderEl = document.getElementById('keys-input-placeholder');
4
+
5
+ placeholderEl.insertAdjacentHTML(
6
+ 'beforeend',
7
+ `<div id="loadingMessage" hidden>🎥 Unable to access video stream (please make sure you have a webcam enabled)</div>
8
+ <canvas id="canvas" style="width: 100%; max-width: 640px" hidden></canvas>`
9
+ );
10
+
11
+ var video = document.createElement('video');
12
+ var canvasElement = document.getElementById('canvas');
13
+ var canvas = canvasElement.getContext('2d');
14
+ var loadingMessage = document.getElementById('loadingMessage');
15
+
16
+ var videoStream;
17
+
18
+ // eslint-disable-next-line no-unused-vars
19
+ function startQRScan() {
20
+ loadingMessage.hidden = false;
21
+ loadingMessage.innerText = '⌛ Loading video...';
22
+ const keyParsedPlaceholder = document.getElementById('key-parse');
23
+ keyParsedPlaceholder.innerHTML = '';
24
+ // Use facingMode: environment to attemt to get the front camera on phones
25
+ navigator.mediaDevices.getUserMedia({ video: { facingMode: 'environment' } }).then(function (stream) {
26
+ video.srcObject = stream;
27
+ video.setAttribute('playsinline', true); // required to tell iOS safari we don't want fullscreen
28
+ video.play();
29
+ videoStream = stream;
30
+ // eslint-disable-next-line no-use-before-define
31
+ requestAnimationFrame(tick);
32
+ });
33
+ }
34
+
35
+ function drawLine(begin, end, color) {
36
+ canvas.beginPath();
37
+ canvas.moveTo(begin.x, begin.y);
38
+ canvas.lineTo(end.x, end.y);
39
+ canvas.lineWidth = 4;
40
+ canvas.strokeStyle = color;
41
+ canvas.stroke();
42
+ }
43
+
44
+ function onScanQRDone(qr) {
45
+ // stop camera
46
+ videoStream.getTracks().forEach(function (track) {
47
+ track.stop();
48
+ });
49
+ canvasElement.hidden = true;
50
+ // eslint-disable-next-line no-undef
51
+ importKeys(qr);
52
+ }
53
+
54
+ function tick() {
55
+ let shouldStop = false;
56
+ if (video.readyState === video.HAVE_ENOUGH_DATA) {
57
+ loadingMessage.hidden = true;
58
+ canvasElement.hidden = false;
59
+
60
+ canvasElement.height = video.videoHeight;
61
+ canvasElement.width = video.videoWidth;
62
+ canvas.drawImage(video, 0, 0, canvasElement.width, canvasElement.height);
63
+ const imageData = canvas.getImageData(0, 0, canvasElement.width, canvasElement.height);
64
+ // eslint-disable-next-line no-undef
65
+ const code = jsQR(imageData.data, imageData.width, imageData.height, {
66
+ inversionAttempts: 'dontInvert',
67
+ });
68
+ if (code) {
69
+ shouldStop = true;
70
+ drawLine(code.location.topLeftCorner, code.location.topRightCorner, '#FF3B58');
71
+ drawLine(code.location.topRightCorner, code.location.bottomRightCorner, '#FF3B58');
72
+ drawLine(code.location.bottomRightCorner, code.location.bottomLeftCorner, '#FF3B58');
73
+ drawLine(code.location.bottomLeftCorner, code.location.topLeftCorner, '#FF3B58');
74
+
75
+ setTimeout(() => {
76
+ onScanQRDone(code.data);
77
+ }, 250);
78
+ }
79
+ }
80
+ if (!shouldStop) requestAnimationFrame(tick);
81
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsocial/tvweb-sdk.tcb",
3
- "version": "5.12.6",
3
+ "version": "5.13.0",
4
4
  "description": "TV Web SDK - The Standalone SDK",
5
5
  "keywords": [],
6
6
  "license": "ISC",
@@ -23,8 +23,8 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@tsocial/trustvision-sdk": "2.10.1",
26
- "@tsocial/tvweb-core": "^5.12.4",
27
- "@tsocial/tvweb-ui": "^5.12.6",
26
+ "@tsocial/tvweb-core": "^5.13.0",
27
+ "@tsocial/tvweb-ui": "^5.13.0",
28
28
  "invariant": "^2.2.4",
29
29
  "react": "^16.14.0",
30
30
  "react-app-polyfill": "^2.0.0",
@@ -32,7 +32,7 @@
32
32
  "styled-components": "^5.2.1"
33
33
  },
34
34
  "devDependencies": {
35
- "@tsocial/tvweb-builder": "^5.12.4"
35
+ "@tsocial/tvweb-builder": "^5.13.0"
36
36
  },
37
- "gitHead": "45bab10b77d380eb271aef58436d7fd0e8b3c482"
37
+ "gitHead": "1c95bf8bf8444b4e8c1942c9d9e6d2992c6e1900"
38
38
  }