UNPKG

@ekisa-web-sdk/addon-wacom-signature

Version:
242 lines 11.4 kB
/* eslint-disable @typescript-eslint/no-empty-function */ /* eslint-disable no-debugger */ /* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-explicit-any */ import { ChangeDetectionStrategy, Component, ElementRef, EventEmitter, Input, Output, ViewChild } from '@angular/core'; import { LICENCEKEY, SERVICEPORT } from '../../wacom/SigCaptX-Globals'; import { JSONreq, WacomGSS_SignatureSDK } from '../../wacom/wgssSigCaptX'; import * as i0 from "@angular/core"; window.JSONreq = JSONreq; export class WacomSignatureComponent { constructor() { this.width = 400; this.height = 200; this.captured = new EventEmitter(); this.capturedError = new EventEmitter(); this.sdk = null; this.sigObj = null; this.sigCtl = null; this.dynCapt = null; this.restartSession(() => { }); } restartSession(callback) { // eslint-disable-next-line @typescript-eslint/no-this-alias const that = this; const timeout = setTimeout(timedDetect, 1500); this.sdk = new WacomGSS_SignatureSDK(onDetectRunning, SERVICEPORT); function timedDetect() { if (that.sdk.running) { that.log('info', 'Signature SDK Service detected.'); start(); } else { that.log('info', 'Signature SDK Service not detected.'); } } function onDetectRunning() { if (that.sdk.running) { that.log('info', 'Signature SDK Service detected.'); clearTimeout(timeout); start(); } else { that.log('info', 'Signature SDK Service not detected.'); } } function start() { if (that.sdk.running) { that.sigCtl = new that.sdk.SigCtl(onSigCtlConstructor); } } function onSigCtlConstructor(sigCtlV, status) { var _a; if (that.sdk.ResponseStatus.OK == status) { that.sigCtl.PutLicence((_a = that.licenceKey) !== null && _a !== void 0 ? _a : LICENCEKEY, onSigCtlPutLicence); } else { that.log('info', 'SigCtl constructor error: ', status); } } function onSigCtlPutLicence(sigCtlV, status) { if (that.sdk.ResponseStatus.OK == status) { that.dynCapt = new that.sdk.DynamicCapture(onDynCaptConstructor); } else { that.log('info', 'SigCtl PutLicence error: ', status); } } function onDynCaptConstructor(dynCaptV, status) { if (that.sdk.ResponseStatus.OK == status) { that.sigCtl.GetSignature(onGetSignature); } else { that.log('info', 'DynCapt constructor error: ', status); } } function onGetSignature(sigCtlV, sigObjV, status) { if (that.sdk.ResponseStatus.OK == status) { that.sigObj = sigObjV; that.sigCtl.GetProperty('Component_FileVersion', onSigCtlGetProperty); } else { that.log('info', 'SigCapt GetSignature error: ', status); } } function onSigCtlGetProperty(sigCtlV, property, status) { if (that.sdk.ResponseStatus.OK == status) { that.log('info', 'DLL: flSigCOM.dll', 'v', property.text); that.dynCapt.GetProperty('Component_FileVersion', onDynCaptGetProperty); } else { that.log('info', 'SigCtl GetProperty error: ', status); } } function onDynCaptGetProperty(dynCaptV, property, status) { if (that.sdk.ResponseStatus.OK == status) { that.log('info', 'DLL: flSigCapt.dll', 'v', property.text); that.log('info', 'Application ready.'); that.log('info', "Press 'Capture' to capture a signature."); if (typeof callback === 'function') { callback(); } } else { that.log('info', 'DynCapt GetProperty error: ' + status); } } } capture() { // eslint-disable-next-line @typescript-eslint/no-this-alias const that = this; if (!this.sdk.running || !this.dynCapt) { this.log('info', 'Session error. Restarting the session.'); this.restartSession(this.capture); return; } this.dynCapt.Capture(this.sigCtl, this.who, this.reason, null, null, onDynCaptCapture); function onDynCaptCapture(dynCaptV, SigObjV, status) { if (that.sdk.ResponseStatus.INVALID_SESSION == status) { that.log('info', 'Error: invalid session. Restarting the session.'); that.restartSession(that.capture); } else { if (that.sdk.DynamicCaptureResult.DynCaptOK !== status) { that.capturedError.emit({ type: 'DynCaptStatus', message: status.toString(), }); } switch (status) { case that.sdk.DynamicCaptureResult.DynCaptOK: that.sigObj = SigObjV; that.log('info', 'Signature captured successfully'); // eslint-disable-next-line no-case-declarations const flags = that.sdk.RBFlags.RenderOutputPicture | that.sdk.RBFlags.RenderColor24BPP; that.sigObj.RenderBitmap('bmp', that.width, that.height, 0.7, 0x00000000, 0x00ffffff, flags, 0, 0, onRenderBitmap); break; case that.sdk.DynamicCaptureResult.DynCaptCancel: that.capturedError.emit({ type: 'DynCaptCancel', message: 'Signature capture cancelled', }); break; case that.sdk.DynamicCaptureResult.DynCaptPadError: that.capturedError.emit({ type: 'DynCaptPadError', message: 'No capture service available', }); break; case that.sdk.DynamicCaptureResult.DynCaptError: that.capturedError.emit({ type: 'DynCaptError', message: 'Tablet Error', }); break; case that.sdk.DynamicCaptureResult.DynCaptIntegrityKeyInvalid: that.capturedError.emit({ type: 'DynCaptIntegrityKeyInvalid', message: 'The integrity key parameter is invalid (obsolete)', }); break; case that.sdk.DynamicCaptureResult.DynCaptNotLicensed: that.capturedError.emit({ type: 'DynCaptNotLicensed', message: 'No valid Signature Capture licence found', }); break; case that.sdk.DynamicCaptureResult.DynCaptAbort: that.capturedError.emit({ type: 'DynCaptAbort', message: 'Error - unable to parse document contents', }); break; default: that.capturedError.emit({ type: 'Default', message: 'Capture Error ' + status, }); break; } } } function onRenderBitmap(sigObjV, bmpObj, status) { if (that.sdk.ResponseStatus.OK == status) { const ctx = that.canvas.nativeElement.getContext('2d'); ctx === null || ctx === void 0 ? void 0 : ctx.drawImage(bmpObj.image, 0, 0, that.width, that.height); that.captured.emit({ image: bmpObj.image, base64: that.canvas.nativeElement.toDataURL(), }); } else { that.log('info', 'Signature Render Bitmap error: ' + status); } } } log(type, ...message) { if (this.printLogs) { switch (type) { case 'info': console.log(...message); break; case 'warn': console.warn(...message); break; case 'error': throw new Error(...message); } } } } WacomSignatureComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: WacomSignatureComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); WacomSignatureComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.0.5", type: WacomSignatureComponent, selector: "ews-wacom-signature", inputs: { licenceKey: "licenceKey", width: "width", height: "height", who: "who", reason: "reason", printLogs: "printLogs" }, outputs: { captured: "captured", capturedError: "capturedError" }, viewQueries: [{ propertyName: "canvas", first: true, predicate: ["canvas"], descendants: true }], ngImport: i0, template: "<canvas\r\n #canvas\r\n [width]=\"width\"\r\n [height]=\"height\"\r\n style=\"display: none\"\r\n></canvas>\r\n", styles: [".signature-box{border:1px solid #d3d3d3}.sdk-status{margin:2rem 0}"], changeDetection: i0.ChangeDetectionStrategy.OnPush }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0, type: WacomSignatureComponent, decorators: [{ type: Component, args: [{ selector: 'ews-wacom-signature', templateUrl: './wacom-signature.component.html', styleUrls: ['./wacom-signature.component.css'], changeDetection: ChangeDetectionStrategy.OnPush, }] }], ctorParameters: function () { return []; }, propDecorators: { canvas: [{ type: ViewChild, args: ['canvas'] }], licenceKey: [{ type: Input }], width: [{ type: Input }], height: [{ type: Input }], who: [{ type: Input }], reason: [{ type: Input }], printLogs: [{ type: Input }], captured: [{ type: Output }], capturedError: [{ type: Output }] } }); //# sourceMappingURL=wacom-signature.component.js.map