@authme/util 2.4.2 → 2.4.7
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.
- package/index.cjs +494 -54
- package/index.js +489 -54
- package/package.json +6 -1
- package/src/index.d.ts +1 -0
- package/src/lib/authme-error.d.ts +2 -1
- package/src/lib/authme-log.d.ts +46 -0
- package/src/lib/background-request-process.d.ts +1 -0
- package/src/lib/common/index.d.ts +1 -1
- package/src/lib/file-saver.d.ts +11 -0
- package/src/ui/camera.d.ts +19 -1
- package/src/ui/error-message.d.ts +12 -2
- package/src/ui/spinner.d.ts +1 -1
package/index.cjs
CHANGED
|
@@ -11,19 +11,22 @@ require('core-js/modules/es.typed-array.sort.js');
|
|
|
11
11
|
require('core-js/modules/es.typed-array.to-locale-string.js');
|
|
12
12
|
require('core-js/modules/es.promise.js');
|
|
13
13
|
require('core-js/modules/es.regexp.exec.js');
|
|
14
|
+
require('core-js/modules/es.string.match.js');
|
|
15
|
+
require('core-js/modules/es.string.replace.js');
|
|
14
16
|
require('core-js/modules/es.regexp.to-string.js');
|
|
15
17
|
require('core-js/modules/web.dom-collections.iterator.js');
|
|
16
18
|
require('core-js/modules/es.object.assign.js');
|
|
17
19
|
require('core-js/modules/es.number.parse-int.js');
|
|
18
20
|
var jwt_decode = require('jwt-decode');
|
|
19
|
-
require('core-js/modules/es.string.match.js');
|
|
20
|
-
require('core-js/modules/es.string.replace.js');
|
|
21
21
|
require('core-js/modules/web.url-search-params.js');
|
|
22
22
|
require('core-js/modules/es.string.search.js');
|
|
23
|
-
|
|
24
|
-
require('core-js/modules/es.array.sort.js');
|
|
23
|
+
require('core-js/modules/es.typed-array.uint32-array.js');
|
|
25
24
|
require('core-js/modules/es.array.includes.js');
|
|
26
25
|
require('core-js/modules/es.string.includes.js');
|
|
26
|
+
var fileSaver = require('file-saver');
|
|
27
|
+
var JSZip = require('jszip');
|
|
28
|
+
var Lottie = require('lottie-web');
|
|
29
|
+
require('core-js/modules/es.array.sort.js');
|
|
27
30
|
require('core-js/modules/es.parse-int.js');
|
|
28
31
|
require('core-js/modules/es.string.trim.js');
|
|
29
32
|
require('core-js/modules/es.string.starts-with.js');
|
|
@@ -32,6 +35,7 @@ require('core-js/modules/es.symbol.description.js');
|
|
|
32
35
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
33
36
|
|
|
34
37
|
var jwt_decode__default = /*#__PURE__*/_interopDefaultLegacy(jwt_decode);
|
|
38
|
+
var JSZip__default = /*#__PURE__*/_interopDefaultLegacy(JSZip);
|
|
35
39
|
var Lottie__default = /*#__PURE__*/_interopDefaultLegacy(Lottie);
|
|
36
40
|
|
|
37
41
|
const GLOBAL_KEY = '_AuthmeConfig';
|
|
@@ -185,6 +189,7 @@ exports.ErrorCode = void 0;
|
|
|
185
189
|
ErrorCode[ErrorCode["USER_CANCEL"] = 903] = "USER_CANCEL";
|
|
186
190
|
ErrorCode[ErrorCode["CAMERA_NOT_SUPPORT"] = 904] = "CAMERA_NOT_SUPPORT";
|
|
187
191
|
ErrorCode[ErrorCode["SERVER_ERROR"] = 905] = "SERVER_ERROR";
|
|
192
|
+
ErrorCode[ErrorCode["EVENT_NAME_WRONG"] = 906] = "EVENT_NAME_WRONG";
|
|
188
193
|
})(exports.ErrorCode || (exports.ErrorCode = {}));
|
|
189
194
|
|
|
190
195
|
function decodeToken(token) {
|
|
@@ -383,9 +388,6 @@ function retryPromiseWithCondition(promiseFactory, conditionFactory) {
|
|
|
383
388
|
}
|
|
384
389
|
});
|
|
385
390
|
}
|
|
386
|
-
function getUserAgent() {
|
|
387
|
-
return `platform: ${navigator === null || navigator === void 0 ? void 0 : navigator.platform}`;
|
|
388
|
-
}
|
|
389
391
|
function isMobileOrTablet() {
|
|
390
392
|
return function (a) {
|
|
391
393
|
return !!(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test(a.substr(0, 4)) || /Android|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) || navigator.maxTouchPoints && navigator.maxTouchPoints > 2);
|
|
@@ -396,6 +398,25 @@ function isMobile() {
|
|
|
396
398
|
return !!(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test(a.substr(0, 4)) || /Android|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
|
|
397
399
|
}(navigator.userAgent || navigator.vendor || window.opera);
|
|
398
400
|
}
|
|
401
|
+
function osVersion() {
|
|
402
|
+
let version = '';
|
|
403
|
+
const android = navigator.userAgent.match(/Android\s+([\d\\.]+)/i);
|
|
404
|
+
if (android) {
|
|
405
|
+
version = android[0];
|
|
406
|
+
}
|
|
407
|
+
const ios = navigator.userAgent.match(/OS\s+([\d\\_]+)/i);
|
|
408
|
+
if (ios) {
|
|
409
|
+
version = ios[0].replace('OS ', 'iOS');
|
|
410
|
+
}
|
|
411
|
+
const win = navigator.userAgent.match(/Windows NT (\d+\.\d+)/);
|
|
412
|
+
if (win) {
|
|
413
|
+
version = win[0];
|
|
414
|
+
}
|
|
415
|
+
if (!version) {
|
|
416
|
+
version = navigator.platform;
|
|
417
|
+
}
|
|
418
|
+
return version;
|
|
419
|
+
}
|
|
399
420
|
function splitResult(result) {
|
|
400
421
|
if (result.address) {
|
|
401
422
|
const originAddress = result.address;
|
|
@@ -478,11 +499,336 @@ const isIphone14proOrProMax = () => {
|
|
|
478
499
|
return isIphone() && (screen.width === 430 && screen.height === 932 || screen.width === 393 && screen.height === 852);
|
|
479
500
|
};
|
|
480
501
|
|
|
502
|
+
function fileSaverService() {
|
|
503
|
+
const filesQueue = [];
|
|
504
|
+
function pushFile(file) {
|
|
505
|
+
filesQueue.push(file);
|
|
506
|
+
}
|
|
507
|
+
function popAllFiles() {
|
|
508
|
+
filesQueue.splice(0, filesQueue.length);
|
|
509
|
+
}
|
|
510
|
+
function saveFiles(fileName, json) {
|
|
511
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
512
|
+
const zip = new JSZip__default["default"]();
|
|
513
|
+
filesQueue.forEach(fileItem => {
|
|
514
|
+
zip.file(fileItem.name, fileItem.file);
|
|
515
|
+
});
|
|
516
|
+
if (json) zip.file('data.json', JSON.stringify(json));
|
|
517
|
+
const content = yield zip.generateAsync({
|
|
518
|
+
type: 'blob'
|
|
519
|
+
});
|
|
520
|
+
fileSaver.saveAs(content, `${fileName}.zip`);
|
|
521
|
+
popAllFiles();
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
return {
|
|
525
|
+
pushFile,
|
|
526
|
+
saveFiles
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
const {
|
|
531
|
+
saveFiles,
|
|
532
|
+
pushFile
|
|
533
|
+
} = fileSaverService();
|
|
534
|
+
exports.RUN_FUNCTION_NAME = void 0;
|
|
535
|
+
(function (RUN_FUNCTION_NAME) {
|
|
536
|
+
RUN_FUNCTION_NAME["RECOGNITION"] = "service.recognition";
|
|
537
|
+
RUN_FUNCTION_NAME["ANTI_FARUD_RECOGNITION"] = "antiFraudInstance.recognition";
|
|
538
|
+
RUN_FUNCTION_NAME["API_REQUEST"] = "api.request";
|
|
539
|
+
})(exports.RUN_FUNCTION_NAME || (exports.RUN_FUNCTION_NAME = {}));
|
|
481
540
|
function debugLog(message, ...others) {
|
|
482
541
|
if (new URLSearchParams(location.search).get('authme-debug') === 'true') {
|
|
483
542
|
console.log(message, ...others);
|
|
484
543
|
}
|
|
485
544
|
}
|
|
545
|
+
function generateUniqueId(length = 32) {
|
|
546
|
+
if (length <= 0) {
|
|
547
|
+
throw new Error('Length should be a positive integer.');
|
|
548
|
+
}
|
|
549
|
+
// 定義可能的字元
|
|
550
|
+
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
551
|
+
const charactersLength = characters.length;
|
|
552
|
+
const randomValues = new Uint32Array(length);
|
|
553
|
+
// 使用window.crypto.getRandomValues取得真正的隨機值
|
|
554
|
+
window.crypto.getRandomValues(randomValues);
|
|
555
|
+
let result = '';
|
|
556
|
+
for (let i = 0; i < length; i++) {
|
|
557
|
+
result += characters[randomValues[i] % charactersLength];
|
|
558
|
+
}
|
|
559
|
+
return result;
|
|
560
|
+
}
|
|
561
|
+
function debugTools() {
|
|
562
|
+
const debugMode = new URLSearchParams(location.search).get('authme-debug') === 'true';
|
|
563
|
+
const debugModeUI = new URLSearchParams(location.search).get('authme-debug-info') === 'true';
|
|
564
|
+
const shouldGetDebugImage = new URLSearchParams(location.search).get('authme-debug-get-image') === 'true';
|
|
565
|
+
const debugLogs = [];
|
|
566
|
+
const logInfo = {
|
|
567
|
+
userAgent: navigator.userAgent,
|
|
568
|
+
token: '',
|
|
569
|
+
message: ''
|
|
570
|
+
};
|
|
571
|
+
let currentRoundId = generateUniqueId(8);
|
|
572
|
+
let currentType = null;
|
|
573
|
+
const interiaTimeObj = {};
|
|
574
|
+
function pushNewDebugLog(logParams) {
|
|
575
|
+
var _a;
|
|
576
|
+
if (!debugMode) return;
|
|
577
|
+
const now = new Date();
|
|
578
|
+
const _logParams = JSON.parse(JSON.stringify(logParams));
|
|
579
|
+
if (_logParams.result) {
|
|
580
|
+
(_a = _logParams.result) === null || _a === void 0 ? true : delete _a.imageData;
|
|
581
|
+
}
|
|
582
|
+
const newDebugLog = Object.assign(Object.assign({
|
|
583
|
+
dateTime: now.toLocaleString(),
|
|
584
|
+
roundId: currentRoundId,
|
|
585
|
+
type: currentType !== null && currentType !== void 0 ? currentType : undefined
|
|
586
|
+
}, _logParams), {
|
|
587
|
+
time: now.getTime(),
|
|
588
|
+
_id: generateUniqueId()
|
|
589
|
+
});
|
|
590
|
+
debugLogs.push(newDebugLog);
|
|
591
|
+
return newDebugLog;
|
|
592
|
+
}
|
|
593
|
+
function pushNewDebugImage(image, log, options) {
|
|
594
|
+
var _a, _b;
|
|
595
|
+
if (!debugMode) return;
|
|
596
|
+
const newLog = pushNewDebugLog(log);
|
|
597
|
+
const recognitionFunctions = [exports.RUN_FUNCTION_NAME.ANTI_FARUD_RECOGNITION, exports.RUN_FUNCTION_NAME.RECOGNITION];
|
|
598
|
+
const currentRoundRecognitionResultItem = debugLogs.find(item => item.roundId === (newLog === null || newLog === void 0 ? void 0 : newLog.roundId) && item.status === 'run-end' && (item.runFunction ? recognitionFunctions.includes(item.runFunction) : false));
|
|
599
|
+
const imageStatus = (_a = currentRoundRecognitionResultItem === null || currentRoundRecognitionResultItem === void 0 ? void 0 : currentRoundRecognitionResultItem.result) === null || _a === void 0 ? void 0 : _a.eStatus;
|
|
600
|
+
pushFile({
|
|
601
|
+
name: `${(_b = options === null || options === void 0 ? void 0 : options.prefix) !== null && _b !== void 0 ? _b : ''}${newLog === null || newLog === void 0 ? void 0 : newLog.time}-${newLog === null || newLog === void 0 ? void 0 : newLog._id}${imageStatus ? `__${imageStatus}` : ''}.jpeg`,
|
|
602
|
+
file: image
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
function functionLogging(func, logParams) {
|
|
606
|
+
return new Promise((resolve, reject) => {
|
|
607
|
+
pushNewDebugLog(Object.assign(Object.assign({}, logParams), {
|
|
608
|
+
status: 'run-start'
|
|
609
|
+
}));
|
|
610
|
+
func().then(result => {
|
|
611
|
+
pushNewDebugLog(Object.assign(Object.assign({}, logParams), {
|
|
612
|
+
status: 'run-end',
|
|
613
|
+
roundId: currentRoundId,
|
|
614
|
+
result
|
|
615
|
+
}));
|
|
616
|
+
resolve(result);
|
|
617
|
+
}).catch(error => {
|
|
618
|
+
pushNewDebugLog(Object.assign(Object.assign({}, logParams), {
|
|
619
|
+
status: 'run-error',
|
|
620
|
+
roundId: currentRoundId,
|
|
621
|
+
result: error
|
|
622
|
+
}));
|
|
623
|
+
reject(error);
|
|
624
|
+
});
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
function renderDebugTips() {
|
|
628
|
+
if (document.getElementById('debug-tips')) {
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
const debugTips = document.createElement('div');
|
|
632
|
+
debugTips.style.position = 'fixed';
|
|
633
|
+
debugTips.style.top = '50px';
|
|
634
|
+
debugTips.style.right = '0';
|
|
635
|
+
debugTips.style.zIndex = '999';
|
|
636
|
+
debugTips.innerHTML = 'Debug Mode';
|
|
637
|
+
debugTips.style.color = 'red';
|
|
638
|
+
debugTips.style.fontWeight = 'bold';
|
|
639
|
+
debugTips.setAttribute('id', 'debug-tips');
|
|
640
|
+
document.body.appendChild(debugTips);
|
|
641
|
+
}
|
|
642
|
+
function renderDebugUI() {
|
|
643
|
+
if (document.getElementById('debug-ui')) {
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
const debugUI = document.createElement('div');
|
|
647
|
+
debugUI.style.position = 'fixed';
|
|
648
|
+
debugUI.style.top = '0';
|
|
649
|
+
debugUI.style.right = '0';
|
|
650
|
+
debugUI.style.zIndex = '777';
|
|
651
|
+
debugUI.style.backgroundColor = 'black';
|
|
652
|
+
debugUI.style.color = 'white';
|
|
653
|
+
debugUI.style.padding = '10px';
|
|
654
|
+
debugUI.style.paddingRight = '150px';
|
|
655
|
+
debugUI.style.fontSize = '12px';
|
|
656
|
+
debugUI.style.opacity = '0.7';
|
|
657
|
+
debugUI.style.boxSizing = 'border-box';
|
|
658
|
+
debugUI.style.width = '100%';
|
|
659
|
+
debugUI.style.maxHeight = '50vh';
|
|
660
|
+
debugUI.style.overflow = 'auto';
|
|
661
|
+
debugUI.setAttribute('id', 'debug-ui');
|
|
662
|
+
const closeUI = document.createElement('button');
|
|
663
|
+
closeUI.style.position = 'fixed';
|
|
664
|
+
closeUI.style.top = '0';
|
|
665
|
+
closeUI.style.right = '100px';
|
|
666
|
+
closeUI.innerHTML = 'close';
|
|
667
|
+
closeUI.addEventListener('click', () => {
|
|
668
|
+
debugUI.style.display = 'none';
|
|
669
|
+
});
|
|
670
|
+
debugUI.appendChild(closeUI);
|
|
671
|
+
const accordionUI = document.createElement('button');
|
|
672
|
+
accordionUI.style.position = 'fixed';
|
|
673
|
+
accordionUI.style.top = '0';
|
|
674
|
+
accordionUI.style.right = '0';
|
|
675
|
+
accordionUI.innerHTML = '收合/展開';
|
|
676
|
+
accordionUI.addEventListener('click', () => {
|
|
677
|
+
if (debugUI.style.maxHeight === '50vh') {
|
|
678
|
+
debugUI.style.maxHeight = '5vh';
|
|
679
|
+
} else {
|
|
680
|
+
debugUI.style.maxHeight = '50vh';
|
|
681
|
+
}
|
|
682
|
+
});
|
|
683
|
+
debugUI.appendChild(accordionUI);
|
|
684
|
+
document.body.appendChild(debugUI);
|
|
685
|
+
}
|
|
686
|
+
function setTimeStart(behavior) {
|
|
687
|
+
if (!debugModeUI) {
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
const dStart = new Date();
|
|
691
|
+
const nStart = dStart.getTime();
|
|
692
|
+
if (interiaTimeObj && interiaTimeObj[behavior]) {
|
|
693
|
+
console.error('debugmode: setTimeStart duplicate', behavior);
|
|
694
|
+
return false;
|
|
695
|
+
}
|
|
696
|
+
interiaTimeObj[behavior] = {
|
|
697
|
+
behavior,
|
|
698
|
+
start: nStart / 1000,
|
|
699
|
+
duration: 0,
|
|
700
|
+
end: 0
|
|
701
|
+
};
|
|
702
|
+
// console.log(interiaTimeObj[behavior])
|
|
703
|
+
renderTimeInfo(behavior);
|
|
704
|
+
return interiaTimeObj[behavior];
|
|
705
|
+
}
|
|
706
|
+
function setTimeEnd(behavior) {
|
|
707
|
+
if (!debugModeUI) {
|
|
708
|
+
return;
|
|
709
|
+
}
|
|
710
|
+
const dEnd = new Date();
|
|
711
|
+
const nEnd = dEnd.getTime();
|
|
712
|
+
if (!interiaTimeObj[behavior]) {
|
|
713
|
+
console.error('debugmode: setTimeEnd not found', behavior);
|
|
714
|
+
return false;
|
|
715
|
+
}
|
|
716
|
+
interiaTimeObj[behavior].end = nEnd / 1000;
|
|
717
|
+
interiaTimeObj[behavior].duration = interiaTimeObj[behavior].end - interiaTimeObj[behavior].start;
|
|
718
|
+
// console.log(interiaTimeObj[behavior])
|
|
719
|
+
renderTimeInfo(behavior);
|
|
720
|
+
return interiaTimeObj[behavior];
|
|
721
|
+
}
|
|
722
|
+
function setTimeDuration(behavior) {
|
|
723
|
+
const ts = Date.now();
|
|
724
|
+
setTimeStart(`${behavior}_${ts}`);
|
|
725
|
+
return {
|
|
726
|
+
end: () => {
|
|
727
|
+
setTimeEnd(`${behavior}_${ts}`);
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
}
|
|
731
|
+
function renderTimeInfo(behavior) {
|
|
732
|
+
const dom = document.querySelector(`#debug-ui-${behavior}`);
|
|
733
|
+
const info = `{"behavior":<span style="color:green;">"${behavior}"</span>, "start": ${interiaTimeObj[behavior].start}, "duration": ${interiaTimeObj[behavior].duration}, "end": ${interiaTimeObj[behavior].end}}`;
|
|
734
|
+
// const info = `<span style="color:green;">${behavior}</span>: Duration: ${interiaTimeObj[behavior].duration}s`;
|
|
735
|
+
if (dom) {
|
|
736
|
+
dom.innerHTML = info;
|
|
737
|
+
return;
|
|
738
|
+
}
|
|
739
|
+
const debugUI = document.getElementById('debug-ui');
|
|
740
|
+
const div = document.createElement('div');
|
|
741
|
+
div.setAttribute('class', 'debug-ui-item');
|
|
742
|
+
div.setAttribute('id', `debug-ui-${behavior}`);
|
|
743
|
+
div.innerHTML = info;
|
|
744
|
+
debugUI.appendChild(div);
|
|
745
|
+
}
|
|
746
|
+
function functionRunTime() {
|
|
747
|
+
const arr = [];
|
|
748
|
+
const items = document.querySelectorAll('.debug-ui-item');
|
|
749
|
+
items.forEach(item => {
|
|
750
|
+
arr.push(JSON.parse(item.innerText));
|
|
751
|
+
});
|
|
752
|
+
return arr;
|
|
753
|
+
}
|
|
754
|
+
if (debugMode) {
|
|
755
|
+
renderDebugTips();
|
|
756
|
+
// setRequestLoggingFunc(functionLogging)
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
if (debugModeUI) {
|
|
760
|
+
console.log('debugModeUI Init');
|
|
761
|
+
renderDebugUI();
|
|
762
|
+
}
|
|
763
|
+
function saveDebugImage({
|
|
764
|
+
getDebugImageData,
|
|
765
|
+
data,
|
|
766
|
+
width,
|
|
767
|
+
height,
|
|
768
|
+
result,
|
|
769
|
+
type
|
|
770
|
+
}) {
|
|
771
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
772
|
+
if (!debugMode || !shouldGetDebugImage) return;
|
|
773
|
+
const debugImage = yield getDebugImageData(data);
|
|
774
|
+
// 創建一個虛擬的 canvas
|
|
775
|
+
const canvas = document.createElement('canvas');
|
|
776
|
+
const ctx = canvas.getContext('2d');
|
|
777
|
+
// 設置 canvas 的尺寸
|
|
778
|
+
canvas.width = width;
|
|
779
|
+
canvas.height = height;
|
|
780
|
+
// 使用 Uint8ClampedArray 將圖像數據繪製到 canvas 上
|
|
781
|
+
const imgData = ctx === null || ctx === void 0 ? void 0 : ctx.createImageData(width, height);
|
|
782
|
+
if (imgData) {
|
|
783
|
+
imgData.data.set(debugImage);
|
|
784
|
+
ctx === null || ctx === void 0 ? void 0 : ctx.putImageData(imgData, 0, 0);
|
|
785
|
+
canvas.toBlob(blob => {
|
|
786
|
+
if (blob) {
|
|
787
|
+
pushNewDebugImage(blob, {
|
|
788
|
+
result: result,
|
|
789
|
+
status: 'recognition',
|
|
790
|
+
type: type
|
|
791
|
+
}, {
|
|
792
|
+
prefix: 'debugImage_'
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
}, 'image/jpeg');
|
|
796
|
+
}
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
return {
|
|
800
|
+
debugMode,
|
|
801
|
+
debugModeUI,
|
|
802
|
+
pushNewDebugLog,
|
|
803
|
+
getDebugLogs: () => debugLogs,
|
|
804
|
+
getDebugLogsLength: () => debugLogs.length,
|
|
805
|
+
modifyDeubgLog: (index, logParams) => {
|
|
806
|
+
if (!debugMode) return;
|
|
807
|
+
debugLogs[index] = Object.assign(Object.assign({}, debugLogs[index]), logParams);
|
|
808
|
+
},
|
|
809
|
+
downloadDebugLogs: () => {
|
|
810
|
+
if (!debugMode) return;
|
|
811
|
+
saveFiles(`debugLog${new Date().getTime().toString()}`, {
|
|
812
|
+
info: logInfo,
|
|
813
|
+
logs: debugLogs,
|
|
814
|
+
functionRunTime: functionRunTime()
|
|
815
|
+
});
|
|
816
|
+
},
|
|
817
|
+
functionLogging,
|
|
818
|
+
nextDebugRound: type => {
|
|
819
|
+
if (!debugMode) return;
|
|
820
|
+
currentRoundId = generateUniqueId(8);
|
|
821
|
+
if (type) currentType = type;
|
|
822
|
+
},
|
|
823
|
+
modifyDebugType: type => {
|
|
824
|
+
if (!debugMode) return;
|
|
825
|
+
currentType = type;
|
|
826
|
+
},
|
|
827
|
+
pushNewDebugImage,
|
|
828
|
+
setTimeDuration: setTimeDuration,
|
|
829
|
+
saveDebugImage
|
|
830
|
+
};
|
|
831
|
+
}
|
|
486
832
|
|
|
487
833
|
exports.TIME_UNIT = void 0;
|
|
488
834
|
(function (TIME_UNIT) {
|
|
@@ -587,7 +933,7 @@ function cropByRatio(width, height, ratio) {
|
|
|
587
933
|
};
|
|
588
934
|
}
|
|
589
935
|
|
|
590
|
-
function startSpinner(text) {
|
|
936
|
+
function startSpinner(text, backgroundOpaque) {
|
|
591
937
|
const loadingLottie = Storage.getItem(exports.STORAGE_KEY.LOADING_LOTTIE);
|
|
592
938
|
const body = document.querySelector('.authme-container');
|
|
593
939
|
if (loadingLottie) {
|
|
@@ -611,6 +957,9 @@ function startSpinner(text) {
|
|
|
611
957
|
loadingSDKText.textContent = text;
|
|
612
958
|
loadingSDKContent.appendChild(loadingSDKText);
|
|
613
959
|
}
|
|
960
|
+
if (backgroundOpaque) {
|
|
961
|
+
loadingSDKOuter.classList.add('authme-loading-sdk-outer--opaque');
|
|
962
|
+
}
|
|
614
963
|
return;
|
|
615
964
|
}
|
|
616
965
|
const spinnerOuter = document.createElement('div');
|
|
@@ -624,6 +973,9 @@ function startSpinner(text) {
|
|
|
624
973
|
spinnerText.textContent = text;
|
|
625
974
|
spinnerOuter.appendChild(spinnerText);
|
|
626
975
|
}
|
|
976
|
+
if (backgroundOpaque) {
|
|
977
|
+
spinnerOuter.classList.add('loading-outer--opaque');
|
|
978
|
+
}
|
|
627
979
|
body === null || body === void 0 ? void 0 : body.appendChild(spinnerOuter);
|
|
628
980
|
}
|
|
629
981
|
function stopSpinner() {
|
|
@@ -644,7 +996,7 @@ exports.Icon = void 0;
|
|
|
644
996
|
Icon["PictureIcon"] = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAYAAACOEfKtAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAt9SURBVHgB7VxdTFRJFq7q23/Q0NC6IKDGhrgiG4mSGAejmyDoToxri5F1ZV9Gk0lWn8CnyY4Pgw9rsk+LT2M2k+juw+KOGBU3cUYjsoljNDFRA1llZwNNEJVGpIFu+v/W1mmmtar63u6G/pHu7e9Fq/rem3s/vlPnVNU5hVAeeeSRx/8vMPqImGntLEWFfisKBZs0RNpAELIiRLaFfyTwfwYY2RHBTvqDE2P8VMahMYQ1Ty2XLwygj4iMExgmzbBwHMuaQ4tk4VKUPAYo+X9FEhqghNpRBpERAnnSUBNKL8JkWq5cuIQygLQSCMRp9N4OQkhnipS2FNgxRpdkDSUzjapMC4FLIS4gYcecVjM0p5NG3DrJMaXXOFxajftHc8Eke93P5zxrioKyqcwvl6/yBasLg6EaU4BU6wgpR7ERJrLk2wtnURqQcgJnjp1swjK6GOUEGFCChqaM2odDJYZHIlFLxcZ5b3ndvH9Lpdu/lxK8JcaldoLl05Zv/3IdpRApI3BRdb6vFlUXjRDG7skCbV9/RXGfw6B1ozQAyNw95W4v9sv1asrEmHTL/oKzluvdTpQCpIRAqjorVd09JdVlgjgR5b6g6ZcOV0uVO2BTIdJOJLQnFWNj0gSGTTZErimNdVMFur7vK4t7YhFXWVlpqqurq1m7dm11aWlpjclkqtZqtSadTsd9eCAQcPh8Pgf91z09PT04MTEx2t/fP4hiIKLIVb5QS/Sv2ElkdMJy9eukTDopAmd/+/sOIuNusT+AsePJ6sLz98tMih8IpG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(text, showRetryBtn, callback) {
|
|
999
|
+
function showErrorMessage(text, showRetryBtn, callback, buttonText, _titleText) {
|
|
648
1000
|
return __awaiter(this, void 0, void 0, function* () {
|
|
649
1001
|
const target = document.querySelector('.authme-container');
|
|
650
1002
|
if (!target) {
|
|
@@ -663,7 +1015,40 @@ function showErrorMessage(text, showRetryBtn, callback) {
|
|
|
663
1015
|
if (showRetryBtn) {
|
|
664
1016
|
const retryText = document.createElement('div');
|
|
665
1017
|
retryText.className = 'retry-text';
|
|
666
|
-
retryText.textContent = '重試';
|
|
1018
|
+
retryText.textContent = buttonText !== null && buttonText !== void 0 ? buttonText : '重試';
|
|
1019
|
+
errorMessagePanel.appendChild(retryText);
|
|
1020
|
+
if (callback) {
|
|
1021
|
+
retryText.addEventListener('click', e => {
|
|
1022
|
+
callback(e, {
|
|
1023
|
+
hideErrorMessage
|
|
1024
|
+
});
|
|
1025
|
+
});
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
target === null || target === void 0 ? void 0 : target.appendChild(errorMessagePanel);
|
|
1029
|
+
});
|
|
1030
|
+
}
|
|
1031
|
+
function showErrorMessageEventName(text, showRetryBtn, callback, buttonText, titleText) {
|
|
1032
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1033
|
+
const target = document.querySelector('.authme-container');
|
|
1034
|
+
if (!target) {
|
|
1035
|
+
return;
|
|
1036
|
+
}
|
|
1037
|
+
const errorMessagePanel = document.createElement('div');
|
|
1038
|
+
errorMessagePanel.classList.add('error-message-panel');
|
|
1039
|
+
errorMessagePanel.classList.add('event-name');
|
|
1040
|
+
const errorText = document.createElement('div');
|
|
1041
|
+
errorText.className = 'error-text';
|
|
1042
|
+
errorText.textContent = text;
|
|
1043
|
+
const title = document.createElement('div');
|
|
1044
|
+
title.className = 'error-title';
|
|
1045
|
+
title.textContent = titleText !== null && titleText !== void 0 ? titleText : 'error';
|
|
1046
|
+
errorMessagePanel.appendChild(title);
|
|
1047
|
+
errorMessagePanel.appendChild(errorText);
|
|
1048
|
+
if (showRetryBtn) {
|
|
1049
|
+
const retryText = document.createElement('div');
|
|
1050
|
+
retryText.className = 'retry-text';
|
|
1051
|
+
retryText.textContent = buttonText !== null && buttonText !== void 0 ? buttonText : '重試';
|
|
667
1052
|
errorMessagePanel.appendChild(retryText);
|
|
668
1053
|
if (callback) {
|
|
669
1054
|
retryText.addEventListener('click', e => {
|
|
@@ -682,27 +1067,29 @@ function hideErrorMessage() {
|
|
|
682
1067
|
body === null || body === void 0 ? void 0 : body.removeChild(errorMessagePanel);
|
|
683
1068
|
}
|
|
684
1069
|
}
|
|
685
|
-
function asyncShowErrorMessage(text, showRetryBtn) {
|
|
1070
|
+
function asyncShowErrorMessage(text, showRetryBtn, options) {
|
|
1071
|
+
var _a;
|
|
686
1072
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1073
|
+
const _showErrorMessage = (_a = options === null || options === void 0 ? void 0 : options.showErrorMessageHandler) !== null && _a !== void 0 ? _a : showErrorMessage;
|
|
687
1074
|
return new Promise((res, rej) => {
|
|
1075
|
+
var _a;
|
|
688
1076
|
const callback = () => {
|
|
689
1077
|
res(true);
|
|
690
1078
|
hideErrorMessage();
|
|
691
1079
|
};
|
|
692
|
-
|
|
1080
|
+
_showErrorMessage(text, showRetryBtn, (_a = options === null || options === void 0 ? void 0 : options.callback) !== null && _a !== void 0 ? _a : callback, options === null || options === void 0 ? void 0 : options.buttonText, options === null || options === void 0 ? void 0 : options.titleText);
|
|
693
1081
|
});
|
|
694
1082
|
});
|
|
695
1083
|
}
|
|
696
1084
|
function asyncOnLineShowErrorMessage(text, showRetryBtn) {
|
|
697
1085
|
return __awaiter(this, void 0, void 0, function* () {
|
|
698
1086
|
return new Promise((res, rej) => {
|
|
699
|
-
|
|
1087
|
+
showErrorMessage(text, showRetryBtn, (_, tools) => {
|
|
700
1088
|
if (window.navigator.onLine) {
|
|
701
1089
|
res(true);
|
|
702
|
-
hideErrorMessage();
|
|
1090
|
+
tools === null || tools === void 0 ? void 0 : tools.hideErrorMessage();
|
|
703
1091
|
}
|
|
704
|
-
};
|
|
705
|
-
showErrorMessage(text, showRetryBtn, callback);
|
|
1092
|
+
});
|
|
706
1093
|
});
|
|
707
1094
|
});
|
|
708
1095
|
}
|
|
@@ -770,7 +1157,10 @@ var BROWSER_CAMERA_ERRORS;
|
|
|
770
1157
|
BROWSER_CAMERA_ERRORS["NO_CAMERA"] = "NO_CAMERA";
|
|
771
1158
|
BROWSER_CAMERA_ERRORS["NOT_ALLOWED_ERROR"] = "NotAllowedError";
|
|
772
1159
|
BROWSER_CAMERA_ERRORS["NOT_FOUND_ERROR"] = "NotFoundError";
|
|
1160
|
+
BROWSER_CAMERA_ERRORS["NOT_READABLE_ERROR"] = "NotReadableError";
|
|
1161
|
+
BROWSER_CAMERA_ERRORS["ABORT_ERROR"] = "AbortError";
|
|
773
1162
|
})(BROWSER_CAMERA_ERRORS || (BROWSER_CAMERA_ERRORS = {}));
|
|
1163
|
+
let stream;
|
|
774
1164
|
const videoConstraintsFactory = (isPC, facingMode) => {
|
|
775
1165
|
return isPC ? {
|
|
776
1166
|
video: {
|
|
@@ -851,6 +1241,43 @@ function arrayFromAsync(asyncIterable) {
|
|
|
851
1241
|
return result;
|
|
852
1242
|
});
|
|
853
1243
|
}
|
|
1244
|
+
function switchCamera(deviceId, video) {
|
|
1245
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1246
|
+
try {
|
|
1247
|
+
if (stream) {
|
|
1248
|
+
stream.getTracks().forEach(track => track.stop());
|
|
1249
|
+
}
|
|
1250
|
+
const constraints = {
|
|
1251
|
+
video: {
|
|
1252
|
+
// 推測依然需要使用 width & height 的限制條件,
|
|
1253
|
+
// 否則即使是高解析度相機,也有可能拿到低解析度的圖片。(待驗證)
|
|
1254
|
+
width: {
|
|
1255
|
+
min: 1280,
|
|
1256
|
+
ideal: 1920,
|
|
1257
|
+
max: 1920
|
|
1258
|
+
},
|
|
1259
|
+
height: {
|
|
1260
|
+
min: 720,
|
|
1261
|
+
ideal: 1080,
|
|
1262
|
+
max: 1080
|
|
1263
|
+
},
|
|
1264
|
+
focusMode: 'auto',
|
|
1265
|
+
deviceId: deviceId
|
|
1266
|
+
}
|
|
1267
|
+
};
|
|
1268
|
+
stream = yield navigator.mediaDevices.getUserMedia(constraints);
|
|
1269
|
+
video.srcObject = stream;
|
|
1270
|
+
yield video.play();
|
|
1271
|
+
// Note: Fix Safari 15 video not showing bug
|
|
1272
|
+
video.srcObject = null;
|
|
1273
|
+
setTimeout(() => {
|
|
1274
|
+
video.srcObject = stream;
|
|
1275
|
+
}, 10);
|
|
1276
|
+
} catch (e) {
|
|
1277
|
+
throw new AuthmeError(exports.ErrorCode.CAMERA_NOT_SUPPORT, e);
|
|
1278
|
+
}
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
854
1281
|
function _requestCamera(video, facingMode) {
|
|
855
1282
|
var _a;
|
|
856
1283
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -925,39 +1352,14 @@ function _requestCamera(video, facingMode) {
|
|
|
925
1352
|
if (!deviceId) {
|
|
926
1353
|
throw BROWSER_CAMERA_ERRORS.NO_CAMERA;
|
|
927
1354
|
}
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
max: 1920
|
|
936
|
-
},
|
|
937
|
-
height: {
|
|
938
|
-
min: 720,
|
|
939
|
-
ideal: 1080,
|
|
940
|
-
max: 1080
|
|
941
|
-
},
|
|
942
|
-
focusMode: 'auto',
|
|
943
|
-
deviceId: {
|
|
944
|
-
exact: deviceId
|
|
945
|
-
}
|
|
946
|
-
}
|
|
1355
|
+
if (stream) {
|
|
1356
|
+
stream.getTracks().forEach(track => track.stop());
|
|
1357
|
+
}
|
|
1358
|
+
yield switchCamera(deviceId, video);
|
|
1359
|
+
return {
|
|
1360
|
+
facingMode: firstDevice.meta.facingMode,
|
|
1361
|
+
deviceMetas: deviceMetas
|
|
947
1362
|
};
|
|
948
|
-
debugLog('camera info', {
|
|
949
|
-
firstDevice,
|
|
950
|
-
deviceMetas
|
|
951
|
-
});
|
|
952
|
-
const stream = yield navigator.mediaDevices.getUserMedia(constraints);
|
|
953
|
-
video.srcObject = stream;
|
|
954
|
-
yield video.play();
|
|
955
|
-
// Note: Fix Safari 15 video not showing bug
|
|
956
|
-
video.srcObject = null;
|
|
957
|
-
setTimeout(() => {
|
|
958
|
-
video.srcObject = stream;
|
|
959
|
-
}, 10);
|
|
960
|
-
return firstDevice.meta.facingMode;
|
|
961
1363
|
});
|
|
962
1364
|
}
|
|
963
1365
|
function isOverconstrainedError(error) {
|
|
@@ -991,6 +1393,15 @@ function requestCamera({
|
|
|
991
1393
|
showMessage(translate('camera.error.notFound'));
|
|
992
1394
|
throw new AuthmeError(exports.ErrorCode.CAMERA_NOT_SUPPORT, error);
|
|
993
1395
|
}
|
|
1396
|
+
if ((error === null || error === void 0 ? void 0 : error.name) === BROWSER_CAMERA_ERRORS.NOT_READABLE_ERROR || (error === null || error === void 0 ? void 0 : error.name) === BROWSER_CAMERA_ERRORS.ABORT_ERROR) {
|
|
1397
|
+
showMessage(translate('camera.error.notFound'));
|
|
1398
|
+
/* NOT_READABLE_ERROR,ABORT_ERROR 這兩個錯誤是用戶授權了,但在呼叫裝置時出現錯誤,
|
|
1399
|
+
* 常發生在APP webview ,例如: 手機開啟 web 使用 sdk,儘管在 webview 層級上授權了,但手機在設定層級沒有授權 app 使用相機,會導致此問題。
|
|
1400
|
+
* 但每個 android 手機的在這方面的實作不一致,不是每個手機在這種情況下都會拋出錯誤。
|
|
1401
|
+
* 參考 https://developer.mozilla.org/zh-CN/docs/Web/API/MediaDevices/getUserMedia#notreadableerror
|
|
1402
|
+
*/
|
|
1403
|
+
throw new AuthmeError(exports.ErrorCode.CAMERA_NOT_SUPPORT, error);
|
|
1404
|
+
}
|
|
994
1405
|
if (isOverconstrainedError(error)) {
|
|
995
1406
|
showMessage(translate('camera.error.lowResolution'));
|
|
996
1407
|
throw new AuthmeError(exports.ErrorCode.CAMERA_NOT_SUPPORT, error);
|
|
@@ -1986,15 +2397,40 @@ function RGBToLottieColor(color) {
|
|
|
1986
2397
|
return color.map(c => c / 255);
|
|
1987
2398
|
}
|
|
1988
2399
|
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
2400
|
+
const QUEUE_LENGTH = 10;
|
|
2401
|
+
const requstQueue = [];
|
|
2402
|
+
function pushRequest(request) {
|
|
2403
|
+
if (requstQueue.length > QUEUE_LENGTH - 1) {
|
|
2404
|
+
requstQueue.shift();
|
|
2405
|
+
}
|
|
2406
|
+
requstQueue.push(request);
|
|
2407
|
+
}
|
|
2408
|
+
function clearRequest() {
|
|
2409
|
+
requstQueue.splice(0, requstQueue.length);
|
|
2410
|
+
}
|
|
2411
|
+
function backgroundRequest(request) {
|
|
2412
|
+
const requestPromise = request();
|
|
2413
|
+
requestPromise.catch(err => {
|
|
2414
|
+
if (err._code === exports.ErrorCode.NETWORK_ERROR) {
|
|
2415
|
+
pushRequest(request);
|
|
2416
|
+
}
|
|
2417
|
+
});
|
|
2418
|
+
}
|
|
2419
|
+
window.ononline = () => {
|
|
2420
|
+
const tasks = [...requstQueue];
|
|
2421
|
+
clearRequest();
|
|
2422
|
+
tasks.forEach(request => {
|
|
2423
|
+
backgroundRequest(request);
|
|
2424
|
+
});
|
|
1993
2425
|
};
|
|
2426
|
+
|
|
2427
|
+
var name = "authme/sdk";
|
|
2428
|
+
var version$1 = "2.4.7";
|
|
2429
|
+
var date = "2023-12-14T08:29:41+0000";
|
|
1994
2430
|
var packageInfo = {
|
|
1995
2431
|
name: name,
|
|
1996
2432
|
version: version$1,
|
|
1997
|
-
|
|
2433
|
+
date: date
|
|
1998
2434
|
};
|
|
1999
2435
|
|
|
2000
2436
|
var _a;
|
|
@@ -2010,6 +2446,7 @@ exports.UintArrayToBlob = UintArrayToBlob;
|
|
|
2010
2446
|
exports.asyncOnLineShowErrorMessage = asyncOnLineShowErrorMessage;
|
|
2011
2447
|
exports.asyncShowErrorMessage = asyncShowErrorMessage;
|
|
2012
2448
|
exports.asyncShowPopup = asyncShowPopup;
|
|
2449
|
+
exports.backgroundRequest = backgroundRequest;
|
|
2013
2450
|
exports.checkOnlineStatus = checkOnlineStatus;
|
|
2014
2451
|
exports.clearCanvas = clearCanvas;
|
|
2015
2452
|
exports.colorStringToRGB = colorStringToRGB;
|
|
@@ -2018,13 +2455,13 @@ exports.combineResult = combineResult;
|
|
|
2018
2455
|
exports.cropByRatio = cropByRatio;
|
|
2019
2456
|
exports.dataURItoBlob = dataURItoBlob;
|
|
2020
2457
|
exports.debugLog = debugLog;
|
|
2458
|
+
exports.debugTools = debugTools;
|
|
2021
2459
|
exports.decodeToken = decodeToken;
|
|
2022
2460
|
exports.getCanvasSize = getCanvasSize;
|
|
2023
2461
|
exports.getCssVariable = getCssVariable;
|
|
2024
2462
|
exports.getDeviceInfo = getDeviceInfo;
|
|
2025
2463
|
exports.getImageData = getImageData;
|
|
2026
2464
|
exports.getSystemInfo = getSystemInfo;
|
|
2027
|
-
exports.getUserAgent = getUserAgent;
|
|
2028
2465
|
exports.hexToRGB = hexToRGB;
|
|
2029
2466
|
exports.hideElement = hideElement;
|
|
2030
2467
|
exports.hideErrorMessage = hideErrorMessage;
|
|
@@ -2032,17 +2469,20 @@ exports.hidePopup = hidePopup;
|
|
|
2032
2469
|
exports.isIphone14proOrProMax = isIphone14proOrProMax;
|
|
2033
2470
|
exports.isMobile = isMobile;
|
|
2034
2471
|
exports.isMobileOrTablet = isMobileOrTablet;
|
|
2472
|
+
exports.osVersion = osVersion;
|
|
2035
2473
|
exports.requestCamera = requestCamera;
|
|
2036
2474
|
exports.resize = resize;
|
|
2037
2475
|
exports.retryPromiseWithCondition = retryPromiseWithCondition;
|
|
2038
2476
|
exports.showElement = showElement;
|
|
2039
2477
|
exports.showErrorMessage = showErrorMessage;
|
|
2478
|
+
exports.showErrorMessageEventName = showErrorMessageEventName;
|
|
2040
2479
|
exports.showPopup = showPopup;
|
|
2041
2480
|
exports.splitResult = splitResult;
|
|
2042
2481
|
exports.startLoadingSDK = startLoadingSDK;
|
|
2043
2482
|
exports.startSpinner = startSpinner;
|
|
2044
2483
|
exports.stopLoadingSDK = stopLoadingSDK;
|
|
2045
2484
|
exports.stopSpinner = stopSpinner;
|
|
2485
|
+
exports.switchCamera = switchCamera;
|
|
2046
2486
|
exports.useState = useState;
|
|
2047
2487
|
exports.version = version;
|
|
2048
2488
|
exports.videoConstraintsFactory = videoConstraintsFactory;
|