@authme/util 2.2.0 → 2.2.1-rc.1
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/CHANGELOG.md +12 -0
- package/package.json +1 -1
- package/src/lib/authme-error.d.ts +27 -0
- package/src/lib/authme-error.js +49 -0
- package/src/lib/authme-error.js.map +1 -0
- package/src/lib/authme-log.d.ts +1 -0
- package/src/lib/authme-log.js +10 -0
- package/src/lib/authme-log.js.map +1 -0
- package/src/lib/enum/index.d.ts +1 -0
- package/src/lib/enum/index.js +5 -0
- package/src/lib/enum/index.js.map +1 -0
- package/src/lib/enum/timeUnit.enum.d.ts +5 -0
- package/src/lib/enum/timeUnit.enum.js +10 -0
- package/src/lib/enum/timeUnit.enum.js.map +1 -0
- package/src/lib/shared-util.d.ts +3 -0
- package/src/lib/shared-util.js +3 -0
- package/src/lib/shared-util.js.map +1 -1
- package/src/ui/camera.d.ts +6 -1
- package/src/ui/camera.js +149 -84
- package/src/ui/camera.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [2.2.1-rc.1](https://github.com/AuthMe01/web-client-sdk/compare/v2.2.1-rc.0...v2.2.1-rc.1) (2022-12-28)
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
- 1. orc mod implement timeout 2. implement TIME_UNIT enum ([90197c5](https://github.com/AuthMe01/web-client-sdk/commit/90197c5ae1243bfbe27c4136a70576a55157204a))
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
- camera error handler consistency ([f3e4aa5](https://github.com/AuthMe01/web-client-sdk/commit/f3e4aa54874bf2fa4dc00963222505d78c2a3abf))
|
|
14
|
+
|
|
15
|
+
## [2.2.1-rc.0](https://github.com/AuthMe01/web-client-sdk/compare/v2.2.0...v2.2.1-rc.0) (2022-12-22)
|
|
16
|
+
|
|
5
17
|
## [2.2.0](https://github.com/AuthMe01/web-client-sdk/compare/v2.2.0-rc.13...v2.2.0) (2022-12-19)
|
|
6
18
|
|
|
7
19
|
## [2.2.0-rc.13](https://github.com/AuthMe01/web-client-sdk/compare/v2.2.0-rc.12...v2.2.0-rc.13) (2022-12-19)
|
package/package.json
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare class AuthmeError {
|
|
2
|
+
private _cause;
|
|
3
|
+
private _code;
|
|
4
|
+
constructor(code: ErrorCode, cause?: any);
|
|
5
|
+
get message(): string;
|
|
6
|
+
setCode(code: ErrorCode): void;
|
|
7
|
+
get code(): ErrorCode;
|
|
8
|
+
get cause(): any;
|
|
9
|
+
}
|
|
10
|
+
export declare enum ErrorCode {
|
|
11
|
+
BROWSER_NOT_SUPPORT = 100,
|
|
12
|
+
ENGINE_INIT_ERROR = 101,
|
|
13
|
+
ENGINE_MODULE_IS_INITIALIZING = 102,
|
|
14
|
+
ENGINE_MODULE_INIT_ERROR = 103,
|
|
15
|
+
RECOGNITION_NOT_AVAILABLE = 104,
|
|
16
|
+
RECOGNITION_ERROR = 105,
|
|
17
|
+
INVALID_AUTH_ERROR = 106,
|
|
18
|
+
LIVENESS_NOT_PASSED = 201,
|
|
19
|
+
ID_RECOGNITION_CONFIRM_INFO_ERROR = 301,
|
|
20
|
+
ID_RECOGNITION_TIMEOUT = 302,
|
|
21
|
+
ID_RECOGNITION_ANTI_FRAUD_NOT_PASSED = 401,
|
|
22
|
+
SDK_INTERNAL_ERROR = 900,
|
|
23
|
+
NETWORK_ERROR = 901,
|
|
24
|
+
HTTP_ERROR_RESPONSE = 902,
|
|
25
|
+
USER_CANCEL = 903,
|
|
26
|
+
CAMERA_NOT_SUPPORT = 904
|
|
27
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ErrorCode = exports.AuthmeError = void 0;
|
|
4
|
+
class AuthmeError {
|
|
5
|
+
constructor(code, cause = null) {
|
|
6
|
+
this._cause = null;
|
|
7
|
+
this._code = null;
|
|
8
|
+
this._code = code;
|
|
9
|
+
this._cause = cause;
|
|
10
|
+
}
|
|
11
|
+
get message() {
|
|
12
|
+
return '[Authme SDK Error] Code: ' + this.code;
|
|
13
|
+
}
|
|
14
|
+
setCode(code) {
|
|
15
|
+
this._code = code;
|
|
16
|
+
}
|
|
17
|
+
get code() {
|
|
18
|
+
return this._code;
|
|
19
|
+
}
|
|
20
|
+
get cause() {
|
|
21
|
+
return this._cause;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.AuthmeError = AuthmeError;
|
|
25
|
+
var ErrorCode;
|
|
26
|
+
(function (ErrorCode) {
|
|
27
|
+
// 1XX for engine
|
|
28
|
+
ErrorCode[ErrorCode["BROWSER_NOT_SUPPORT"] = 100] = "BROWSER_NOT_SUPPORT";
|
|
29
|
+
ErrorCode[ErrorCode["ENGINE_INIT_ERROR"] = 101] = "ENGINE_INIT_ERROR";
|
|
30
|
+
ErrorCode[ErrorCode["ENGINE_MODULE_IS_INITIALIZING"] = 102] = "ENGINE_MODULE_IS_INITIALIZING";
|
|
31
|
+
ErrorCode[ErrorCode["ENGINE_MODULE_INIT_ERROR"] = 103] = "ENGINE_MODULE_INIT_ERROR";
|
|
32
|
+
ErrorCode[ErrorCode["RECOGNITION_NOT_AVAILABLE"] = 104] = "RECOGNITION_NOT_AVAILABLE";
|
|
33
|
+
ErrorCode[ErrorCode["RECOGNITION_ERROR"] = 105] = "RECOGNITION_ERROR";
|
|
34
|
+
ErrorCode[ErrorCode["INVALID_AUTH_ERROR"] = 106] = "INVALID_AUTH_ERROR";
|
|
35
|
+
// 2 for LIVENESS
|
|
36
|
+
ErrorCode[ErrorCode["LIVENESS_NOT_PASSED"] = 201] = "LIVENESS_NOT_PASSED";
|
|
37
|
+
// 3 for ID-Recognition
|
|
38
|
+
ErrorCode[ErrorCode["ID_RECOGNITION_CONFIRM_INFO_ERROR"] = 301] = "ID_RECOGNITION_CONFIRM_INFO_ERROR";
|
|
39
|
+
ErrorCode[ErrorCode["ID_RECOGNITION_TIMEOUT"] = 302] = "ID_RECOGNITION_TIMEOUT";
|
|
40
|
+
// 4 for Anti-fraud
|
|
41
|
+
ErrorCode[ErrorCode["ID_RECOGNITION_ANTI_FRAUD_NOT_PASSED"] = 401] = "ID_RECOGNITION_ANTI_FRAUD_NOT_PASSED";
|
|
42
|
+
// 9 for common
|
|
43
|
+
ErrorCode[ErrorCode["SDK_INTERNAL_ERROR"] = 900] = "SDK_INTERNAL_ERROR";
|
|
44
|
+
ErrorCode[ErrorCode["NETWORK_ERROR"] = 901] = "NETWORK_ERROR";
|
|
45
|
+
ErrorCode[ErrorCode["HTTP_ERROR_RESPONSE"] = 902] = "HTTP_ERROR_RESPONSE";
|
|
46
|
+
ErrorCode[ErrorCode["USER_CANCEL"] = 903] = "USER_CANCEL";
|
|
47
|
+
ErrorCode[ErrorCode["CAMERA_NOT_SUPPORT"] = 904] = "CAMERA_NOT_SUPPORT";
|
|
48
|
+
})(ErrorCode = exports.ErrorCode || (exports.ErrorCode = {}));
|
|
49
|
+
//# sourceMappingURL=authme-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authme-error.js","sourceRoot":"","sources":["../../../../../../libs/shared/util/src/lib/authme-error.ts"],"names":[],"mappings":";;;AAAA,MAAa,WAAW;IAItB,YAAY,IAAe,EAAE,QAAa,IAAI;QAHtC,WAAM,GAAQ,IAAI,CAAC;QACnB,UAAK,GAAqB,IAAI,CAAC;QAGrC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,IAAI,OAAO;QACT,OAAO,2BAA2B,GAAG,IAAI,CAAC,IAAI,CAAC;IACjD,CAAC;IAEM,OAAO,CAAC,IAAe;QAC5B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IACD,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF;AAvBD,kCAuBC;AAED,IAAY,SAyBX;AAzBD,WAAY,SAAS;IACnB,iBAAiB;IACjB,yEAAyB,CAAA;IACzB,qEAAuB,CAAA;IACvB,6FAAmC,CAAA;IACnC,mFAA8B,CAAA;IAC9B,qFAA+B,CAAA;IAC/B,qEAAuB,CAAA;IACvB,uEAAwB,CAAA;IAExB,iBAAiB;IACjB,yEAAyB,CAAA;IAEzB,uBAAuB;IACvB,qGAAuC,CAAA;IACvC,+EAA4B,CAAA;IAC5B,mBAAmB;IACnB,2GAA0C,CAAA;IAE1C,eAAe;IACf,uEAAwB,CAAA;IACxB,6DAAmB,CAAA;IACnB,yEAAyB,CAAA;IACzB,yDAAiB,CAAA;IACjB,uEAAwB,CAAA;AAC1B,CAAC,EAzBW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAyBpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function debugLog(message?: any, ...others: any[]): void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.debugLog = void 0;
|
|
4
|
+
function debugLog(message, ...others) {
|
|
5
|
+
if (new URLSearchParams(location.search).get('authme-debug') === 'true') {
|
|
6
|
+
console.log(message, ...others);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.debugLog = debugLog;
|
|
10
|
+
//# sourceMappingURL=authme-log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authme-log.js","sourceRoot":"","sources":["../../../../../../libs/shared/util/src/lib/authme-log.ts"],"names":[],"mappings":";;;AAAA,SAAgB,QAAQ,CAAC,OAAa,EAAE,GAAG,MAAa;IACtD,IAAI,IAAI,eAAe,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC,KAAK,MAAM,EAAE;QACvE,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,CAAC;KACjC;AACH,CAAC;AAJD,4BAIC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './timeUnit.enum';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../libs/shared/util/src/lib/enum/index.ts"],"names":[],"mappings":";;;AAAA,0DAAgC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TIME_UNIT = void 0;
|
|
4
|
+
var TIME_UNIT;
|
|
5
|
+
(function (TIME_UNIT) {
|
|
6
|
+
TIME_UNIT[TIME_UNIT["SECOND"] = 1000] = "SECOND";
|
|
7
|
+
TIME_UNIT[TIME_UNIT["MINUTE"] = 60000] = "MINUTE";
|
|
8
|
+
TIME_UNIT[TIME_UNIT["HOUR"] = 3600000] = "HOUR";
|
|
9
|
+
})(TIME_UNIT = exports.TIME_UNIT || (exports.TIME_UNIT = {}));
|
|
10
|
+
//# sourceMappingURL=timeUnit.enum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeUnit.enum.js","sourceRoot":"","sources":["../../../../../../../libs/shared/util/src/lib/enum/timeUnit.enum.ts"],"names":[],"mappings":";;;AAAA,IAAY,SAIX;AAJD,WAAY,SAAS;IACnB,gDAAa,CAAA;IACb,iDAAkB,CAAA;IAClB,+CAAqB,CAAA;AACvB,CAAC,EAJW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAIpB"}
|
package/src/lib/shared-util.d.ts
CHANGED
package/src/lib/shared-util.js
CHANGED
|
@@ -3,4 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./storage"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./common"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./authme-error"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./authme-log"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./enum"), exports);
|
|
6
9
|
//# sourceMappingURL=shared-util.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared-util.js","sourceRoot":"","sources":["../../../../../../libs/shared/util/src/lib/shared-util.ts"],"names":[],"mappings":";;;AAAA,oDAA0B;AAC1B,mDAAyB"}
|
|
1
|
+
{"version":3,"file":"shared-util.js","sourceRoot":"","sources":["../../../../../../libs/shared/util/src/lib/shared-util.ts"],"names":[],"mappings":";;;AAAA,oDAA0B;AAC1B,mDAAyB;AACzB,yDAA+B;AAC/B,uDAA6B;AAC7B,iDAAuB"}
|
package/src/ui/camera.d.ts
CHANGED
|
@@ -27,4 +27,9 @@ export declare const videoConstraintsFactory: (isPC: boolean, facingMode: 'user'
|
|
|
27
27
|
facingMode: "user" | "environment";
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
|
-
export declare
|
|
30
|
+
export declare function requestCamera({ video, facingMode, translate, showMessage, }: {
|
|
31
|
+
video: HTMLVideoElement;
|
|
32
|
+
facingMode: 'front' | 'back';
|
|
33
|
+
translate: (key: string) => string;
|
|
34
|
+
showMessage: (text: string) => void;
|
|
35
|
+
}): Promise<'front' | 'back'>;
|
package/src/ui/camera.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.requestCamera = exports.videoConstraintsFactory = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const authme_error_1 = require("../lib/authme-error");
|
|
6
|
+
const authme_log_1 = require("../lib/authme-log");
|
|
5
7
|
const videoConstraintsFactory = (isPC, facingMode) => {
|
|
6
8
|
return isPC
|
|
7
9
|
? {
|
|
@@ -45,99 +47,162 @@ function inferFacingModeFromMixedInfo(fromLabel, fromCapabilities) {
|
|
|
45
47
|
var _a;
|
|
46
48
|
return (_a = fromLabel !== null && fromLabel !== void 0 ? fromLabel : fromCapabilities) !== null && _a !== void 0 ? _a : 'front';
|
|
47
49
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
let isSamsung = false;
|
|
54
|
-
if (navigator.userAgent.match(/SAMSUNG|Samsung|SGH-[I|N|T]|GT-[I|N]|SM-[A|G|N|P|T|Z|S]|SHV-E|SCH-[I|J|R|S]|SPH-L/i)) {
|
|
55
|
-
isSamsung = true;
|
|
56
|
-
}
|
|
57
|
-
// 必須先請求攝影機權限,才能透過 enumerateDevices 取得攝影機 Label 資訊
|
|
58
|
-
const media = yield navigator.mediaDevices.getUserMedia({
|
|
59
|
-
video: true,
|
|
50
|
+
function asyncMap(mapping, items) {
|
|
51
|
+
return tslib_1.__asyncGenerator(this, arguments, function* asyncMap_1() {
|
|
52
|
+
for (const item of items) {
|
|
53
|
+
yield yield tslib_1.__await(yield tslib_1.__await(mapping(item)));
|
|
54
|
+
}
|
|
60
55
|
});
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
}
|
|
57
|
+
function arrayFromAsync(asyncIterable) {
|
|
58
|
+
var asyncIterable_1, asyncIterable_1_1;
|
|
59
|
+
var e_1, _a;
|
|
60
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
const result = [];
|
|
62
|
+
try {
|
|
63
|
+
for (asyncIterable_1 = tslib_1.__asyncValues(asyncIterable); asyncIterable_1_1 = yield asyncIterable_1.next(), !asyncIterable_1_1.done;) {
|
|
64
|
+
const item = asyncIterable_1_1.value;
|
|
65
|
+
result.push(item);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
69
|
+
finally {
|
|
70
|
+
try {
|
|
71
|
+
if (asyncIterable_1_1 && !asyncIterable_1_1.done && (_a = asyncIterable_1.return)) yield _a.call(asyncIterable_1);
|
|
72
|
+
}
|
|
73
|
+
finally { if (e_1) throw e_1.error; }
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
63
76
|
});
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
77
|
+
}
|
|
78
|
+
function _requestCamera(video, facingMode) {
|
|
79
|
+
var _a;
|
|
80
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
if (!('mediaDevices' in navigator)) {
|
|
82
|
+
throw 'NOT_SUPPORT';
|
|
83
|
+
}
|
|
84
|
+
let isSamsung = false;
|
|
85
|
+
if (navigator.userAgent.match(/SAMSUNG|Samsung|SGH-[I|N|T]|GT-[I|N]|SM-[A|G|N|P|T|Z|S]|SHV-E|SCH-[I|J|R|S]|SPH-L/i)) {
|
|
86
|
+
isSamsung = true;
|
|
87
|
+
}
|
|
88
|
+
// 必須先請求攝影機權限,才能透過 enumerateDevices 取得攝影機 Label 資訊
|
|
89
|
+
const media = yield navigator.mediaDevices.getUserMedia({
|
|
90
|
+
video: true,
|
|
91
|
+
});
|
|
92
|
+
media.getTracks().forEach(function (track) {
|
|
93
|
+
track.stop(); // 取得後會啟用攝影機,所以要關閉
|
|
94
|
+
});
|
|
95
|
+
// 輪詢取得攝影機 解析度等資訊
|
|
96
|
+
const videoDevices = (yield navigator.mediaDevices.enumerateDevices()).filter((device) => device.kind === 'videoinput');
|
|
97
|
+
const deviceMetas = yield arrayFromAsync(asyncMap((device) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
var _b, _c, _d, _e;
|
|
99
|
+
const stream = yield navigator.mediaDevices.getUserMedia({
|
|
100
|
+
video: {
|
|
101
|
+
deviceId: {
|
|
102
|
+
exact: device.deviceId,
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
const track = (_b = stream.getVideoTracks()) === null || _b === void 0 ? void 0 : _b[0];
|
|
107
|
+
const capabilities = ((_c = track === null || track === void 0 ? void 0 : track.getCapabilities) !== null && _c !== void 0 ? _c : (() => undefined)).bind(track)(); // firefox 沒有 getCapabilities 可以用。
|
|
108
|
+
const widthMax = (_d = capabilities === null || capabilities === void 0 ? void 0 : capabilities.width) === null || _d === void 0 ? void 0 : _d.max;
|
|
109
|
+
const heightMax = (_e = capabilities === null || capabilities === void 0 ? void 0 : capabilities.height) === null || _e === void 0 ? void 0 : _e.max;
|
|
110
|
+
const resolution = widthMax && heightMax ? widthMax * heightMax : 0;
|
|
111
|
+
const facingModeFromLabel = inferFacingModeFromLabel(device === null || device === void 0 ? void 0 : device.label);
|
|
112
|
+
const facingModeFromapabilities = inferFacingModeFromCapabilities(capabilities);
|
|
113
|
+
const facingMode = inferFacingModeFromMixedInfo(facingModeFromLabel, facingModeFromapabilities);
|
|
114
|
+
const meta = {
|
|
115
|
+
resolution,
|
|
116
|
+
facingMode,
|
|
117
|
+
facingModeFromLabel,
|
|
118
|
+
facingModeFromapabilities,
|
|
119
|
+
capabilities,
|
|
120
|
+
};
|
|
121
|
+
track === null || track === void 0 ? void 0 : track.stop();
|
|
122
|
+
return { device, meta, capabilities };
|
|
123
|
+
}), videoDevices));
|
|
124
|
+
const firstDevice = (_a = deviceMetas.sort((a, b) => {
|
|
125
|
+
// 若是 Samsung 手機且模式為後鏡頭,則優先使用Label為 camera2 0 的鏡頭
|
|
126
|
+
let samsungCondition = 0;
|
|
127
|
+
if (isSamsung && facingMode === 'back') {
|
|
128
|
+
const samsungCamera = 'camera2 0';
|
|
129
|
+
const bScore = b.device.label.includes(samsungCamera) ? 1 : 0; // 特定鏡頭優先
|
|
130
|
+
const aScore = a.device.label.includes(samsungCamera) ? 1 : 0;
|
|
131
|
+
samsungCondition = bScore - aScore;
|
|
132
|
+
}
|
|
133
|
+
let cameraFacingCondition = 0;
|
|
134
|
+
{
|
|
135
|
+
const aFacingMode = a.meta.facingMode;
|
|
136
|
+
const bFacingMode = b.meta.facingMode;
|
|
137
|
+
const bScore = bFacingMode === facingMode ? 1 : 0; // 鏡頭符合 faceMode 優先。
|
|
138
|
+
const aScore = aFacingMode === facingMode ? 1 : 0;
|
|
139
|
+
cameraFacingCondition = bScore - aScore;
|
|
140
|
+
}
|
|
141
|
+
const resolutionCondition = b.meta.resolution - a.meta.resolution;
|
|
142
|
+
return samsungCondition || cameraFacingCondition || resolutionCondition;
|
|
143
|
+
})) === null || _a === void 0 ? void 0 : _a[0];
|
|
144
|
+
const deviceId = firstDevice.device.deviceId;
|
|
145
|
+
if (!deviceId) {
|
|
146
|
+
throw 'NO_CAMERA';
|
|
147
|
+
}
|
|
148
|
+
const constraints = {
|
|
69
149
|
video: {
|
|
150
|
+
// 推測依然需要使用 width & height 的限制條件,
|
|
151
|
+
// 否則即使是高解析度相機,也有可能拿到低解析度的圖片。(待驗證)
|
|
152
|
+
width: { min: 1280, ideal: 1920, max: 1920 },
|
|
153
|
+
height: { min: 720, ideal: 1080, max: 1080 },
|
|
154
|
+
focusMode: 'auto',
|
|
70
155
|
deviceId: {
|
|
71
|
-
exact:
|
|
156
|
+
exact: deviceId,
|
|
72
157
|
},
|
|
73
158
|
},
|
|
74
|
-
});
|
|
75
|
-
const track = (_a = stream.getVideoTracks()) === null || _a === void 0 ? void 0 : _a[0];
|
|
76
|
-
const capabilities = ((_b = track === null || track === void 0 ? void 0 : track.getCapabilities) !== null && _b !== void 0 ? _b : (() => undefined)).bind(track)(); // firefox 沒有 getCapabilities 可以用。
|
|
77
|
-
const widthMax = (_c = capabilities === null || capabilities === void 0 ? void 0 : capabilities.width) === null || _c === void 0 ? void 0 : _c.max;
|
|
78
|
-
const heightMax = (_d = capabilities === null || capabilities === void 0 ? void 0 : capabilities.height) === null || _d === void 0 ? void 0 : _d.max;
|
|
79
|
-
const resolution = widthMax && heightMax ? widthMax * heightMax : 0;
|
|
80
|
-
const facingModeFromLabel = inferFacingModeFromLabel(device === null || device === void 0 ? void 0 : device.label);
|
|
81
|
-
const facingModeFromapabilities = inferFacingModeFromCapabilities(capabilities);
|
|
82
|
-
const facingMode = inferFacingModeFromMixedInfo(facingModeFromLabel, facingModeFromapabilities);
|
|
83
|
-
const meta = {
|
|
84
|
-
resolution,
|
|
85
|
-
facingMode,
|
|
86
|
-
facingModeFromLabel,
|
|
87
|
-
facingModeFromapabilities,
|
|
88
|
-
capabilities,
|
|
89
159
|
};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
const firstDevice = (_e = deviceMetas.sort((a, b) => {
|
|
94
|
-
// 若是 Samsung 手機且模式為後鏡頭,則優先使用Label為 camera2 0 的鏡頭
|
|
95
|
-
let samsungCondition = 0;
|
|
96
|
-
if (isSamsung && facingMode === 'back') {
|
|
97
|
-
const samsungCamera = 'camera2 0';
|
|
98
|
-
const bScore = b.device.label.includes(samsungCamera) ? 1 : 0; // 特定鏡頭優先
|
|
99
|
-
const aScore = a.device.label.includes(samsungCamera) ? 1 : 0;
|
|
100
|
-
samsungCondition = bScore - aScore;
|
|
101
|
-
}
|
|
102
|
-
let cameraFacingCondition = 0;
|
|
103
|
-
{
|
|
104
|
-
const aFacingMode = a.meta.facingMode;
|
|
105
|
-
const bFacingMode = b.meta.facingMode;
|
|
106
|
-
const bScore = bFacingMode === facingMode ? 1 : 0; // 鏡頭符合 faceMode 優先。
|
|
107
|
-
const aScore = aFacingMode === facingMode ? 1 : 0;
|
|
108
|
-
cameraFacingCondition = bScore - aScore;
|
|
109
|
-
}
|
|
110
|
-
const resolutionCondition = b.meta.resolution - a.meta.resolution;
|
|
111
|
-
return samsungCondition || cameraFacingCondition || resolutionCondition;
|
|
112
|
-
})) === null || _e === void 0 ? void 0 : _e[0];
|
|
113
|
-
const deviceId = firstDevice.device.deviceId;
|
|
114
|
-
if (!deviceId) {
|
|
115
|
-
throw 'NO_CAMERA';
|
|
116
|
-
}
|
|
117
|
-
const constraints = {
|
|
118
|
-
video: {
|
|
119
|
-
// 推測依然需要使用 width & height 的限制條件,
|
|
120
|
-
// 否則即使是高解析度相機,也有可能拿到低解析度的圖片。(待驗證)
|
|
121
|
-
width: { min: 1280, ideal: 1920, max: 1920 },
|
|
122
|
-
height: { min: 720, ideal: 1080, max: 1080 },
|
|
123
|
-
focusMode: 'auto',
|
|
124
|
-
deviceId: {
|
|
125
|
-
exact: deviceId,
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
const stream = yield navigator.mediaDevices.getUserMedia(constraints);
|
|
130
|
-
video.srcObject = stream;
|
|
131
|
-
yield video.play();
|
|
132
|
-
// Note: Fix Safari 15 video not showing bug
|
|
133
|
-
video.srcObject = null;
|
|
134
|
-
setTimeout(() => {
|
|
160
|
+
(0, authme_log_1.debugLog)('camera info', { firstDevice, deviceMetas });
|
|
161
|
+
const stream = yield navigator.mediaDevices.getUserMedia(constraints);
|
|
135
162
|
video.srcObject = stream;
|
|
136
|
-
|
|
137
|
-
|
|
163
|
+
yield video.play();
|
|
164
|
+
// Note: Fix Safari 15 video not showing bug
|
|
165
|
+
video.srcObject = null;
|
|
166
|
+
setTimeout(() => {
|
|
167
|
+
video.srcObject = stream;
|
|
168
|
+
}, 10);
|
|
138
169
|
return firstDevice.meta.facingMode;
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
function isOverconstrainedError(error) {
|
|
173
|
+
if (error === null || typeof error === 'undefined') {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
if (typeof error !== 'object') {
|
|
177
|
+
return false;
|
|
139
178
|
}
|
|
140
|
-
return
|
|
141
|
-
}
|
|
179
|
+
return 'constraint' in error;
|
|
180
|
+
}
|
|
181
|
+
function requestCamera({ video, facingMode, translate, showMessage, }) {
|
|
182
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
183
|
+
try {
|
|
184
|
+
return yield _requestCamera(video, facingMode);
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
if (error === 'NOT_SUPPORT') {
|
|
188
|
+
showMessage(translate('camera.error.notFound'));
|
|
189
|
+
throw new authme_error_1.AuthmeError(authme_error_1.ErrorCode.CAMERA_NOT_SUPPORT, 'Browser not support WebRTC, or https required.');
|
|
190
|
+
}
|
|
191
|
+
if (error === 'NO_CAMERA') {
|
|
192
|
+
showMessage(translate('camera.error.notFound'));
|
|
193
|
+
throw new authme_error_1.AuthmeError(authme_error_1.ErrorCode.CAMERA_NOT_SUPPORT, 'camera not found');
|
|
194
|
+
}
|
|
195
|
+
if ((error === null || error === void 0 ? void 0 : error.name) === 'NotAllowedError') {
|
|
196
|
+
showMessage(translate('camera.error.notFound'));
|
|
197
|
+
throw new authme_error_1.AuthmeError(authme_error_1.ErrorCode.CAMERA_NOT_SUPPORT, error);
|
|
198
|
+
}
|
|
199
|
+
if (isOverconstrainedError(error)) {
|
|
200
|
+
showMessage(translate('camera.error.lowResolution'));
|
|
201
|
+
throw new authme_error_1.AuthmeError(authme_error_1.ErrorCode.CAMERA_NOT_SUPPORT, error);
|
|
202
|
+
}
|
|
203
|
+
throw error;
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
142
207
|
exports.requestCamera = requestCamera;
|
|
143
208
|
//# sourceMappingURL=camera.js.map
|
package/src/ui/camera.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"camera.js","sourceRoot":"","sources":["../../../../../../libs/shared/util/src/ui/camera.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"camera.js","sourceRoot":"","sources":["../../../../../../libs/shared/util/src/ui/camera.ts"],"names":[],"mappings":";;;;AAAA,sDAA6D;AAC7D,kDAA6C;AAEtC,MAAM,uBAAuB,GAAG,CACrC,IAAa,EACb,UAAkC,EAClC,EAAE;IACF,OAAO,IAAI;QACT,CAAC,CAAC;YACE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