jaakrecog-verify
Version:
This is a JAAK.AI Enroll© Angular Component for verify and authenticate users
846 lines (835 loc) • 210 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs'), require('@angular/common/http'), require('rxjs/operators'), require('builder-pattern'), require('@angular/common')) :
typeof define === 'function' && define.amd ? define('jaakrecog-verify', ['exports', '@angular/core', 'rxjs', '@angular/common/http', 'rxjs/operators', 'builder-pattern', '@angular/common'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["jaakrecog-verify"] = {}, global.ng.core, global.rxjs, global.ng.common.http, global.rxjs.operators, global.builderPattern, global.ng.common));
})(this, (function (exports, i0, rxjs, i2, operators, builderPattern, common) { 'use strict';
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n["default"] = e;
return Object.freeze(n);
}
var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
var i2__namespace = /*#__PURE__*/_interopNamespace(i2);
var VerifyService = /** @class */ (function () {
function VerifyService() {
}
return VerifyService;
}());
VerifyService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function VerifyService_Factory() { return new VerifyService(); }, token: VerifyService, providedIn: "root" });
VerifyService.decorators = [
{ type: i0.Injectable, args: [{
providedIn: 'root'
},] }
];
VerifyService.ctorParameters = function () { return []; };
var VerifyComponent = /** @class */ (function () {
function VerifyComponent() {
this.getResponse = new i0.EventEmitter();
this.showComponent = true;
var scriptTag = document.createElement('script');
scriptTag.src =
'https://storage.googleapis.com/jaakrecog-storage-front/js/face-api.min.js';
document.body.appendChild(scriptTag);
}
VerifyComponent.prototype.ngOnInit = function () { };
VerifyComponent.prototype.emitResult = function (ev) {
var _this = this;
this.showComponent = false;
this.getResponse.emit(ev);
setTimeout(function () {
_this.showComponent = true;
}, 1000);
};
return VerifyComponent;
}());
VerifyComponent.decorators = [
{ type: i0.Component, args: [{
selector: 'jaakrecog-verify',
template: "\n <lib-capture-video\n *ngIf=\"showComponent\"\n [accessToken]=\"accessToken\"\n (getResult)=\"emitResult($event)\"\n ></lib-capture-video>\n "
},] }
];
VerifyComponent.ctorParameters = function () { return []; };
VerifyComponent.propDecorators = {
accessToken: [{ type: i0.Input }],
getResponse: [{ type: i0.Output }]
};
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b)
if (Object.prototype.hasOwnProperty.call(b, p))
d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function () {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
r = Reflect.decorate(decorators, target, key, desc);
else
for (var i = decorators.length - 1; i >= 0; i--)
if (d = decorators[i])
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); };
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try {
step(generator.next(value));
}
catch (e) {
reject(e);
} }
function rejected(value) { try {
step(generator["throw"](value));
}
catch (e) {
reject(e);
} }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function () { if (t[0] & 1)
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f)
throw new TypeError("Generator is already executing.");
while (_)
try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
return t;
if (y = 0, t)
op = [op[0] & 2, t.value];
switch (op[0]) {
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return { value: op[1], done: false };
case 5:
_.label++;
y = op[1];
op = [0];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2])
_.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
}
catch (e) {
op = [6, e];
y = 0;
}
finally {
f = t = 0;
}
if (op[0] & 5)
throw op[1];
return { value: op[0] ? op[1] : void 0, done: true };
}
}
var __createBinding = Object.create ? (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
}) : (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
o[k2] = m[k];
});
function __exportStar(m, o) {
for (var p in m)
if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
__createBinding(o, m, p);
}
function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m)
return m.call(o);
if (o && typeof o.length === "number")
return {
next: function () {
if (o && i >= o.length)
o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m)
return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
ar.push(r.value);
}
catch (error) {
e = { error: error };
}
finally {
try {
if (r && !r.done && (m = i["return"]))
m.call(i);
}
finally {
if (e)
throw e.error;
}
}
return ar;
}
/** @deprecated */
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
/** @deprecated */
function __spreadArrays() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++)
s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
}
function __spreadArray(to, from, pack) {
if (pack || arguments.length === 2)
for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar)
ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
}
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n])
i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try {
step(g[n](v));
}
catch (e) {
settle(q[0][3], e);
} }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length)
resume(q[0][0], q[0][1]); }
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) {
Object.defineProperty(cooked, "raw", { value: raw });
}
else {
cooked.raw = raw;
}
return cooked;
}
;
var __setModuleDefault = Object.create ? (function (o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function (o, v) {
o["default"] = v;
};
function __importStar(mod) {
if (mod && mod.__esModule)
return mod;
var result = {};
if (mod != null)
for (var k in mod)
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
__createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
function __classPrivateFieldGet(receiver, state, kind, f) {
if (kind === "a" && !f)
throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
}
function __classPrivateFieldSet(receiver, state, value, kind, f) {
if (kind === "m")
throw new TypeError("Private method is not writable");
if (kind === "a" && !f)
throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
}
var OneToNVerify = /** @class */ (function () {
function OneToNVerify() {
}
return OneToNVerify;
}());
var EnrollService = /** @class */ (function () {
function EnrollService(config, http) {
this.config = config;
this.http = http;
}
EnrollService.prototype.oneToNVerify = function (request, accessToken) {
var headers;
if (accessToken) {
headers = new i2.HttpHeaders()
.set('authorization', "Bearer " + accessToken)
.append('auth', "Bearer " + accessToken);
}
return this.http
.post("" + (this.config.apiUrl
? this.config.apiUrl
: 'https://dev-facade-1ton-http-635t26xtnq-uc.a.run.app/api/v1/one2n/verify/'), request, {
headers: headers,
})
.pipe(operators.map(function (response) { return builderPattern.Builder(OneToNVerify)
.id(response.eventId)
.user(response.user)
.processingTime(response.processTime)
.build(); }));
};
return EnrollService;
}());
EnrollService.ɵprov = i0__namespace.ɵɵdefineInjectable({ factory: function EnrollService_Factory() { return new EnrollService(i0__namespace.ɵɵinject(LibConfigService), i0__namespace.ɵɵinject(i2__namespace.HttpClient)); }, token: EnrollService, providedIn: "root" });
EnrollService.decorators = [
{ type: i0.Injectable, args: [{
providedIn: 'root',
},] }
];
EnrollService.ctorParameters = function () { return [
{ type: undefined, decorators: [{ type: i0.Inject, args: [LibConfigService,] }] },
{ type: i2.HttpClient }
]; };
var ErrorResponse = /** @class */ (function () {
function ErrorResponse() {
}
return ErrorResponse;
}());
var CaptureVideoComponent = /** @class */ (function () {
function CaptureVideoComponent(renderer, enrollSrv) {
this.renderer = renderer;
this.enrollSrv = enrollSrv;
this.getResult = new i0.EventEmitter();
this.tracker = null;
this.stepper = new rxjs.BehaviorSubject('step1');
this.animationShow = false;
this.recordedBlobs = [];
this.showLoading = false;
this.hasPermission = false;
this.alert = false;
this.error = false;
this.alertSuccess = false;
this.messageLoading = 'Inicializando...';
this.trackDisabled = false;
this.faceExists = new rxjs.BehaviorSubject(false);
this.options = {
trackFace: true,
};
}
CaptureVideoComponent.prototype.getScreenSize = function (event) {
var scrWidth = window.innerWidth;
return scrWidth;
};
CaptureVideoComponent.prototype.ngOnInit = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_d) {
this.initStepper();
return [2 /*return*/];
});
});
};
CaptureVideoComponent.prototype.initStepper = function () {
var _this = this;
this.stepperObservable = this.stepper
.asObservable()
.subscribe(function (value) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_d) {
this.resizeEllipsis();
if (value === 'step2') {
this.step2();
}
if (value === 'step3') {
this.step3();
}
return [2 /*return*/];
});
}); });
};
CaptureVideoComponent.prototype.getPermissions = function () {
return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_d) {
navigator.mediaDevices
.getUserMedia({ video: true })
.then(function (stream) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
this.hasPermission = true;
this.stream = stream;
return [4 /*yield*/, this.initComponent()];
case 1:
_d.sent();
return [2 /*return*/];
}
});
}); })
.catch(function (e) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_d) {
this.showError();
console.log(e);
return [2 /*return*/];
});
}); });
return [2 /*return*/];
});
});
};
CaptureVideoComponent.prototype.initComponent = function () {
var _a;
return __awaiter(this, void 0, void 0, function () {
var _this = this;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
this.showLoading = true;
if (!((_a = this.options) === null || _a === void 0 ? void 0 : _a.trackFace)) return [3 /*break*/, 2];
return [4 /*yield*/, this.setupFaceApi()];
case 1:
_d.sent();
this.initVideoStreaming();
this.showLoading = false;
return [3 /*break*/, 3];
case 2:
this.initVideoStreaming();
this.showLoading = false;
_d.label = 3;
case 3:
setTimeout(function () {
_this.start();
}, 500);
return [2 /*return*/];
}
});
});
};
CaptureVideoComponent.prototype.setupFaceApi = function () {
return __awaiter(this, void 0, void 0, function () {
var path;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
path = '../../../assets/models';
return [4 /*yield*/, faceapi.nets.tinyFaceDetector.loadFromUri(path)];
case 1:
_d.sent();
return [2 /*return*/];
}
});
});
};
CaptureVideoComponent.prototype.initVideoStreaming = function () {
var _this = this;
setTimeout(function () {
_this.video.nativeElement.srcObject = new MediaStream(_this.stream);
_this.video.nativeElement.play();
}, 100);
};
CaptureVideoComponent.prototype.start = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_d) {
this.stepper.next('step2');
return [2 /*return*/];
});
});
};
CaptureVideoComponent.prototype.step2 = function () {
var _a;
return __awaiter(this, void 0, void 0, function () {
var trackFace_1;
var _this = this;
return __generator(this, function (_d) {
this.message = 'Analisis facial';
if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.trackFace) {
this.faceTracking(this.video.nativeElement);
trackFace_1 = this.faceExists.subscribe(function (value) {
if (value) {
document.getElementsByTagName('canvas')[0].style.position =
'absolute';
_this.message = 'Analisis facial';
setTimeout(function () {
clearInterval(_this.trackingFn);
trackFace_1.unsubscribe();
document.getElementsByTagName('canvas')[0].style.display = 'none';
_this.goToStep3();
}, 500);
}
else {
_this.message = 'No se ha detectado tu rostro';
}
});
}
else {
setTimeout(function () {
_this.goToStep3();
}, 1000);
}
return [2 /*return*/];
});
});
};
CaptureVideoComponent.prototype.goToStep2 = function () {
this.stepper.next('step2');
};
CaptureVideoComponent.prototype.goToStep3 = function () {
this.stepper.next('step3');
};
CaptureVideoComponent.prototype.step3 = function () {
var _this = this;
this.stepperObservable.unsubscribe();
this.message = 'Grabando';
this.startRecording();
setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
var blob, video;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
this.mediaRecorder.pause();
this.mediaRecorder.stop();
blob = this.getBlob();
this.showAlertSuccess();
return [4 /*yield*/, this.getBase64(blob)];
case 1:
video = _d.sent();
return [4 /*yield*/, this.enrroll(video)];
case 2:
_d.sent();
return [2 /*return*/];
}
});
}); }, 3500);
};
CaptureVideoComponent.prototype.startRecording = function () {
var _this = this;
var options = { mimeType: 'video/webm; codecs=opus,vp8' };
if (MediaRecorder.isTypeSupported) {
options = { mimeType: 'video/webm;codecs=vp9' };
if (!MediaRecorder.isTypeSupported(options.mimeType)) {
console.error(options.mimeType + " is not Supported");
options = { mimeType: 'video/webm;codecs=vp8' };
if (!MediaRecorder.isTypeSupported(options.mimeType)) {
console.error(options.mimeType + " is not Supported");
options = { mimeType: 'video/webm' };
if (!MediaRecorder.isTypeSupported(options.mimeType)) {
console.error(options.mimeType + " is not Supported");
options = { mimeType: '' };
}
}
}
}
else {
options = { mimeType: '' };
}
this.recordedBlobs = [];
try {
this.mediaRecorder = new MediaRecorder(this.stream, options);
}
catch (e) {
this.showError();
this.hasPermission = false;
console.log(e);
}
this.mediaRecorder.ondataavailable = function (event) {
if (event.data && event.data.size > 0) {
_this.recordedBlobs.push(event.data);
}
};
this.mediaRecorder.start(100);
};
CaptureVideoComponent.prototype.getBlob = function () {
var blob = new Blob(this.recordedBlobs, { type: 'video/webm' });
console.log(URL.createObjectURL(blob));
return blob;
};
CaptureVideoComponent.prototype.getBase64 = function (file) {
return new Promise(function (resolve, reject) {
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function () { return resolve(reader.result.split(',')[1]); };
reader.onerror = function (error) { return reject(error); };
});
};
CaptureVideoComponent.prototype.faceTracking = function (video) {
var _this = this;
var _a;
var canvas = faceapi.createCanvasFromMedia(video);
(_a = document.getElementById('video-container')) === null || _a === void 0 ? void 0 : _a.append(canvas);
document.getElementsByTagName('canvas')[0].style.transform =
'rotateY(180deg)';
var displaySize = {
width: video.clientWidth,
height: video.clientHeight,
};
faceapi.matchDimensions(canvas, displaySize);
this.trackingFn = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
var detections;
return __generator(this, function (_d) {
switch (_d.label) {
case 0: return [4 /*yield*/, faceapi.detectSingleFace(video, new faceapi.TinyFaceDetectorOptions())];
case 1:
detections = _d.sent();
if (detections) {
this.faceExists.next(true);
}
else {
this.faceExists.next(false);
}
return [2 /*return*/];
}
});
}); }, 100);
};
CaptureVideoComponent.prototype.showAlert = function () {
var _this = this;
this.alert = true;
setTimeout(function () {
_this.alert = false;
}, 3250);
};
CaptureVideoComponent.prototype.showError = function () {
var _this = this;
this.error = true;
setTimeout(function () {
_this.error = false;
}, 3250);
};
CaptureVideoComponent.prototype.showAlertSuccess = function () {
var _this = this;
this.alertSuccess = true;
setTimeout(function () {
_this.alertSuccess = false;
}, 3250);
};
CaptureVideoComponent.prototype.resizeEllipsis = function () {
var _this = this;
if (window.innerWidth < 768) {
setTimeout(function () {
var ellipsis = document.getElementById('ellipse');
var svg = document.getElementsByTagName('svg')[0];
var svgWidth = svg.clientWidth;
var svgHeight = svg.clientHeight;
var magicNumberX = 0.6956521739130435;
var magicNumberY = 0.9352708058124174;
if (ellipsis) {
_this.renderer.setAttribute(ellipsis, 'cx', (svgWidth / 2).toString());
_this.renderer.setAttribute(ellipsis, 'cy', (svgHeight / 2).toString());
_this.renderer.setAttribute(ellipsis, 'rx', ((svgWidth / 2) * magicNumberX).toString());
_this.renderer.setAttribute(ellipsis, 'ry', ((svgHeight / 2) * magicNumberY).toString());
ellipsis.style.display = 'block';
}
}, 50);
}
};
CaptureVideoComponent.prototype.enrroll = function (video) {
var _a, _b, _c;
return __awaiter(this, void 0, void 0, function () {
var request, res, e_1, error;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
this.stopStreaming();
this.showLoading = true;
_d.label = 1;
case 1:
_d.trys.push([1, 3, , 4]);
request = {
video: video,
};
return [4 /*yield*/, this.enrollSrv
.oneToNVerify(request, this.accessToken)
.pipe(operators.first())
.toPromise()];
case 2:
res = _d.sent();
this.getResult.emit(res);
return [3 /*break*/, 4];
case 3:
e_1 = _d.sent();
console.log(e_1);
if (e_1.error) {
error = builderPattern.Builder(ErrorResponse)
.message((_a = e_1.error.message) !== null && _a !== void 0 ? _a : 'Something was wrong')
.type(this.getTypeErrorByStatus(e_1.status))
.response('ERROR')
.eventId((_b = e_1.error.eventId) !== null && _b !== void 0 ? _b : '')
.code((_c = e_1.error.code) !== null && _c !== void 0 ? _c : '')
.build();
this.getResult.emit(error);
}
else {
this.getResult.emit(e_1);
}
return [3 /*break*/, 4];
case 4: return [2 /*return*/];
}
});
});
};
CaptureVideoComponent.prototype.reset = function () {
this.hasPermission = false;
this.showLoading = false;
this.stepper.next('step1');
};
CaptureVideoComponent.prototype.stopStreaming = function () {
var stream = this.video.nativeElement.srcObject;
var tracks = stream.getTracks();
tracks.forEach(function (track) {
track.stop();
});
this.video.nativeElement.srcObject = null;
};
CaptureVideoComponent.prototype.getTypeErrorByStatus = function (status) {
if (status === 400) {
return 'bad request';
}
else if (status === 401) {
return 'unauthorized';
}
else if (status === 404) {
return 'not found';
}
else if (status === 500) {
return 'server error';
}
else {
return 'unknown error';
}
};
return CaptureVideoComponent;
}());
CaptureVideoComponent.decorators = [
{ type: i0.Component, args: [{
selector: 'lib-capture-video',
template: "<div class=\"main\">\n <div class=\"header-bar\">\n <img\n src=\"https://storage.googleapis.com/jaakrecog-storage-front/images/jaak_white.png\"\n alt=\"jaak-logo\"\n />\n </div>\n <div *ngIf=\"!showLoading\" class=\"custom-container\">\n <div class=\"container\" *ngIf=\"!hasPermission && !showLoading\">\n <div class=\"d-flex justify-content-center w-100\">\n <div class=\"card\">\n <h1>Proceso de Autentificaci\u00F3n</h1>\n <p>\n Autorice los permisos de c\u00E1mara cu\u00E1ndo el navegador lo requiera para\n poder continuar\n </p>\n <button class=\"btn-primary mt-3\" (click)=\"getPermissions()\">\n Iniciar\n </button>\n </div>\n </div>\n </div>\n <div\n *ngIf=\"hasPermission && !showLoading\"\n class=\"d-flex justify-content-center\"\n >\n <div id=\"video-container\" class=\"video-container\">\n <video #video id=\"video\" autoplay></video>\n </div>\n </div>\n <svg\n *ngIf=\"stepper.value === 'step1' && hasPermission\"\n class=\"ellipse-border\"\n >\n <ellipse\n id=\"ellipse\"\n #ellipse\n cx=\"300\"\n cy=\"300\"\n rx=\"176\"\n ry=\"265\"\n style=\"fill: transparent; stroke: #9b9b9b; stroke-width: 6px\"\n />\n Sorry, your browser does not support inline SVG.\n </svg>\n <svg\n *ngIf=\"stepper.value === 'step2' && hasPermission\"\n class=\"ellipse-border pulsate-border\"\n height=\"600\"\n width=\"600\"\n id=\"border-indicator\"\n >\n <ellipse\n id=\"ellipse\"\n #ellipse\n cx=\"300\"\n cy=\"300\"\n rx=\"176\"\n ry=\"265\"\n style=\"fill: transparent; stroke: #ffffff; stroke-width: 6px\"\n />\n Sorry, your browser does not support inline SVG.\n </svg>\n <svg\n *ngIf=\"stepper.value === 'step3' && hasPermission\"\n class=\"ellipse-border fill-border\"\n height=\"600\"\n width=\"600\"\n id=\"border-indicator\"\n >\n <ellipse\n id=\"ellipse\"\n #ellipse\n cx=\"300\"\n cy=\"300\"\n rx=\"176\"\n ry=\"265\"\n style=\"fill: transparent; stroke: #ffffff; stroke-width: 6px\"\n />\n Sorry, your browser does not support inline SVG.\n </svg>\n <div class=\"progressbar-container\">\n <ul class=\"progressbar\">\n <li class=\"active\">Obtener permisos</li>\n <li\n [ngClass]=\"{\n active: hasPermission\n }\"\n >\n Enmarcar rostro\n </li>\n <li\n [ngClass]=\"{\n active: stepper.value !== 'step1'\n }\"\n >\n Anal\u00EDsis\n </li>\n <li [ngClass]=\"{ active: stepper.value === 'step3' }\">Grabando</li>\n </ul>\n </div>\n <p *ngIf=\"stepper.value === 'step1' && hasPermission\" class=\"pt-4\">\n Enmarca tu cara en el \u00F3valo\n </p>\n <div\n *ngIf=\"hasPermission && !showLoading\"\n class=\"d-flex justify-content-center\"\n >\n <div\n *ngIf=\"stepper.value !== 'step1'\"\n class=\"msg\"\n [ngClass]=\"{ record: stepper.value === 'step3' }\"\n >\n {{ message }}\n </div>\n </div>\n </div>\n <div class=\"container\" *ngIf=\"showLoading\">\n <div\n class=\"d-flex justify-content-center align-items-center w-100 custom-container\"\n >\n <div class=\"mt-5 text-center load\">\n <div\n class=\"spinner-border\"\n style=\"width: 3rem; height: 3rem; color: white\"\n role=\"status\"\n >\n <span class=\"sr-only\"></span>\n </div>\n <br />\n\n <p class=\"font-weight-bold pt-3\">Cargando...</p>\n </div>\n </div>\n </div>\n\n <div class=\"footerbar\">\n <h4>POWERED <small>by</small></h4>\n <img\n src=\"https://storage.googleapis.com/jaakrecog-storage-front/images/jaak_white.png\"\n alt=\"jaakit-logo\"\n />\n </div>\n</div>\n<div class=\"notification slide-out-right\" *ngIf=\"alert\">\n <p>No se ha detectado un rostro!</p>\n</div>\n\n<div class=\"notification slide-out-right\" *ngIf=\"error\">\n <p>Ha ocurrido un error. Intenta de nuevo</p>\n</div>\n\n<div class=\"notification slide-out-right success\" *ngIf=\"alertSuccess\">\n <p>Video capturado</p>\n</div>\n",
styles: ["@charset \"UTF-8\";@import\"https://fonts.googleapis.com/css2?family=Montserrat:wght@500&display=swap\";:root{--bs-blue: #0d6efd;--bs-indigo: #6610f2;--bs-purple: #6f42c1;--bs-pink: #d63384;--bs-red: #dc3545;--bs-orange: #fd7e14;--bs-yellow: #ffc107;--bs-green: #198754;--bs-teal: #20c997;--bs-cyan: #0dcaf0;--bs-white: #fff;--bs-gray: #6c757d;--bs-gray-dark: #343a40;--bs-gray-100: #f8f9fa;--bs-gray-200: #e9ecef;--bs-gray-300: #dee2e6;--bs-gray-400: #ced4da;--bs-gray-500: #adb5bd;--bs-gray-600: #6c757d;--bs-gray-700: #495057;--bs-gray-800: #343a40;--bs-gray-900: #212529;--bs-primary: #0d6efd;--bs-secondary: #6c757d;--bs-success: #198754;--bs-info: #0dcaf0;--bs-warning: #ffc107;--bs-danger: #dc3545;--bs-light: #f8f9fa;--bs-dark: #212529;--bs-primary-rgb: 13, 110, 253;--bs-secondary-rgb: 108, 117, 125;--bs-success-rgb: 25, 135, 84;--bs-info-rgb: 13, 202, 240;--bs-warning-rgb: 255, 193, 7;--bs-danger-rgb: 220, 53, 69;--bs-light-rgb: 248, 249, 250;--bs-dark-rgb: 33, 37, 41;--bs-white-rgb: 255, 255, 255;--bs-black-rgb: 0, 0, 0;--bs-body-color-rgb: 33, 37, 41;--bs-body-bg-rgb: 255, 255, 255;--bs-font-sans-serif: system-ui, -apple-system, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, \"Noto Sans\", \"Liberation Sans\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\";--bs-font-monospace: SFMono-Regular, Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace;--bs-gradient: linear-gradient(180deg, rgba(255, 255, 255, .15), rgba(255, 255, 255, 0));--bs-body-font-family: var(--bs-font-sans-serif);--bs-body-font-size: 1rem;--bs-body-font-weight: 400;--bs-body-line-height: 1.5;--bs-body-color: #212529;--bs-body-bg: #fff}*,*:before,*:after{box-sizing:border-box}@media (prefers-reduced-motion: no-preference){:root{scroll-behavior:smooth}}body{margin:0;font-family:var(--bs-body-font-family);font-size:var(--bs-body-font-size);font-weight:var(--bs-body-font-weight);line-height:var(--bs-body-line-height);color:var(--bs-body-color);text-align:var(--bs-body-text-align);background-color:var(--bs-body-bg);-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:rgba(0,0,0,0)}hr{margin:1rem 0;color:inherit;background-color:currentColor;border:0;opacity:.25}hr:not([size]){height:1px}h6,.h6,h5,.h5,h4,.h4,h3,.h3,h2,.h2,h1,.h1{margin-top:0;margin-bottom:.5rem;font-weight:500;line-height:1.2}h1,.h1{font-size:calc(1.375rem + 1.5vw)}@media (min-width: 1200px){h1,.h1{font-size:2.5rem}}h2,.h2{font-size:calc(1.325rem + .9vw)}@media (min-width: 1200px){h2,.h2{font-size:2rem}}h3,.h3{font-size:calc(1.3rem + .6vw)}@media (min-width: 1200px){h3,.h3{font-size:1.75rem}}h4,.h4{font-size:calc(1.275rem + .3vw)}@media (min-width: 1200px){h4,.h4{font-size:1.5rem}}h5,.h5{font-size:1.25rem}h6,.h6{font-size:1rem}p{margin-top:0;margin-bottom:1rem}abbr[title],abbr[data-bs-original-title]{-webkit-text-decoration:underline dotted;text-decoration:underline dotted;cursor:help;-webkit-text-decoration-skip-ink:none;text-decoration-skip-ink:none}address{margin-bottom:1rem;font-style:normal;line-height:inherit}ol,ul{padding-left:2rem}ol,ul,dl{margin-top:0;margin-bottom:1rem}ol ol,ul ul,ol ul,ul ol{margin-bottom:0}dt{font-weight:700}dd{margin-bottom:.5rem;margin-left:0}blockquote{margin:0 0 1rem}b,strong{font-weight:bolder}small,.small{font-size:.875em}mark,.mark{padding:.2em;background-color:#fcf8e3}sub,sup{position:relative;font-size:.75em;line-height:0;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}a{color:#0d6efd;text-decoration:underline}a:hover{color:#0a58ca}a:not([href]):not([class]),a:not([href]):not([class]):hover{color:inherit;text-decoration:none}pre,code,kbd,samp{font-family:var(--bs-font-monospace);font-size:1em;direction:ltr;unicode-bidi:bidi-override}pre{display:block;margin-top:0;margin-bottom:1rem;overflow:auto;font-size:.875em}pre code{font-size:inherit;color:inherit;word-break:normal}code{font-size:.875em;color:#d63384;word-wrap:break-word}a>code{color:inherit}kbd{padding:.2rem .4rem;font-size:.875em;color:#fff;background-color:#212529;border-radius:.2rem}kbd kbd{padding:0;font-size:1em;font-weight:700}figure{margin:0 0 1rem}img,svg{vertical-align:middle}table{caption-side:bottom;border-collapse:collapse}caption{padding-top:.5rem;padding-bottom:.5rem;color:#6c757d;text-align:left}th{text-align:inherit;text-align:-webkit-match-parent}thead,tbody,tfoot,tr,td,th{border-color:inherit;border-style:solid;border-width:0}label{display:inline-block}button{border-radius:0}button:focus:not(:focus-visible){outline:0}input,button,select,optgroup,textarea{margin:0;font-family:inherit;font-size:inherit;line-height:inherit}button,select{text-transform:none}[role=button]{cursor:pointer}select{word-wrap:normal}select:disabled{opacity:1}[list]::-webkit-calendar-picker-indicator{display:none}button,[type=button],[type=reset],[type=submit]{-webkit-appearance:button}button:not(:disabled),[type=button]:not(:disabled),[type=reset]:not(:disabled),[type=submit]:not(:disabled){cursor:pointer}::-moz-focus-inner{padding:0;border-style:none}textarea{resize:vertical}fieldset{min-width:0;padding:0;margin:0;border:0}legend{float:left;width:100%;padding:0;margin-bottom:.5rem;font-size:calc(1.275rem + .3vw);line-height:inherit}@media (min-width: 1200px){legend{font-size:1.5rem}}legend+*{clear:left}::-webkit-datetime-edit-fields-wrapper,::-webkit-datetime-edit-text,::-webkit-datetime-edit-minute,::-webkit-datetime-edit-hour-field,::-webkit-datetime-edit-day-field,::-webkit-datetime-edit-month-field,::-webkit-datetime-edit-year-field{padding:0}::-webkit-inner-spin-button{height:auto}[type=search]{outline-offset:-2px;-webkit-appearance:textfield}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-color-swatch-wrapper{padding:0}::file-selector-button{font:inherit}::-webkit-file-upload-button{font:inherit;-webkit-appearance:button}output{display:inline-block}iframe{border:0}summary{display:list-item;cursor:pointer}progress{vertical-align:baseline}[hidden]{display:none!important}.lead{font-size:1.25rem;font-weight:300}.display-1{font-size:calc(1.625rem + 4.5vw);font-weight:300;line-height:1.2}@media (min-width: 1200px){.display-1{font-size:5rem}}.display-2{font-size:calc(1.575rem + 3.9vw);font-weight:300;line-height:1.2}@media (min-width: 1200px){.display-2{font-size:4.5rem}}.display-3{font-size:calc(1.525rem + 3.3vw);font-weight:300;line-height:1.2}@media (min-width: 1200px){.display-3{font-size:4rem}}.display-4{font-size:calc(1.475rem + 2.7vw);font-weight:300;line-height:1.2}@media (min-width: 1200px){.display-4{font-size:3.5rem}}.display-5{font-size:calc(1.425rem + 2.1vw);font-weight:300;line-height:1.2}@media (min-width: 1200px){.display-5{font-size:3rem}}.display-6{font-size:calc(1.375rem + 1.5vw);font-weight:300;line-height:1.2}@media (min-width: 1200px){.display-6{font-size:2.5rem}}.list-unstyled{padding-left:0;list-style:none}.list-inline{padding-left:0;list-style:none}.list-inline-item{display:inline-block}.list-inline-item:not(:last-child){margin-right:.5rem}.initialism{font-size:.875em;text-transform:uppercase}.blockquote{margin-bottom:1rem;font-size:1.25rem}.blockquote>:last-child{margin-bottom:0}.blockquote-footer{margin-top:-1rem;margin-bottom:1rem;font-size:.875em;color:#6c757d}.blockquote-footer:before{content:\"\\2014\\a0\"}.img-fluid{max-width:100%;height:auto}.img-thumbnail{padding:.25rem;background-color:#fff;border:1px solid #dee2e6;border-radius:.25rem;max-width:100%;height:auto}.figure{display:inline-block}.figure-img{margin-bottom:.5rem;line-height:1}.figure-caption{font-size:.875em;color:#6c757d}.container,.container-fluid,.container-xxl,.container-xl,.container-lg,.container-md,.container