scandoc-ai-components 0.0.28 → 0.0.30
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/dist/index.js +50 -16
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11157,9 +11157,11 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
11157
11157
|
/* harmony export */ "default": () => (/* binding */ getExtractionVideo)
|
|
11158
11158
|
/* harmony export */ });
|
|
11159
11159
|
/* harmony import */ var _ai_detect_document__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../ai/detect-document */ "./src/lib/ai/detect-document.js");
|
|
11160
|
-
/* harmony import */ var
|
|
11161
|
-
/* harmony import */ var
|
|
11162
|
-
/* harmony import */ var
|
|
11160
|
+
/* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../config */ "./src/lib/config.js");
|
|
11161
|
+
/* harmony import */ var _requests_extraction__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../requests/extraction */ "./src/lib/requests/extraction.js");
|
|
11162
|
+
/* harmony import */ var _requests_validation__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../requests/validation */ "./src/lib/requests/validation.js");
|
|
11163
|
+
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./utils */ "./src/lib/components/utils.js");
|
|
11164
|
+
|
|
11163
11165
|
|
|
11164
11166
|
|
|
11165
11167
|
|
|
@@ -11170,7 +11172,6 @@ class ExtractorVideo {
|
|
|
11170
11172
|
static VALIDATION_BATCH_SIZE = 1;
|
|
11171
11173
|
static VALIDATION_IMG_WIDTH = 384;
|
|
11172
11174
|
static VALIDATION_IMG_HEIGHT = 384;
|
|
11173
|
-
static MAX_SCAN_DURATION_MS = 10000;
|
|
11174
11175
|
static VIDEO_SETTINGS = Object.freeze({
|
|
11175
11176
|
width: {
|
|
11176
11177
|
ideal: 1920
|
|
@@ -11188,6 +11189,9 @@ class ExtractorVideo {
|
|
|
11188
11189
|
this.isRunning = false;
|
|
11189
11190
|
this.scanStartTime = null;
|
|
11190
11191
|
this.timeoutTimer = null;
|
|
11192
|
+
this.validationStartTime = null;
|
|
11193
|
+
this.validationTimedOut = false;
|
|
11194
|
+
this.wasDocumentPreviouslyDetected = false;
|
|
11191
11195
|
}
|
|
11192
11196
|
async analyzeVideoStream() {
|
|
11193
11197
|
if (!this.isRunning) {
|
|
@@ -11195,11 +11199,12 @@ class ExtractorVideo {
|
|
|
11195
11199
|
}
|
|
11196
11200
|
//
|
|
11197
11201
|
const now = Date.now();
|
|
11198
|
-
|
|
11202
|
+
const cfgValues = (0,_config__WEBPACK_IMPORTED_MODULE_1__.getScanDocAIConfigValues)();
|
|
11203
|
+
if (this.scanStartTime && now - this.scanStartTime > cfgValues.MAX_SCAN_DURATION_MS) {
|
|
11199
11204
|
this.stopVideo();
|
|
11200
11205
|
this.onExtractedResults({
|
|
11201
11206
|
success: false,
|
|
11202
|
-
code: "
|
|
11207
|
+
code: "003",
|
|
11203
11208
|
info: "Document not detected within time limit."
|
|
11204
11209
|
});
|
|
11205
11210
|
return;
|
|
@@ -11208,17 +11213,31 @@ class ExtractorVideo {
|
|
|
11208
11213
|
const canvas = document.createElement("canvas");
|
|
11209
11214
|
let video = document.getElementById("ScanDocAIVideoElement");
|
|
11210
11215
|
//
|
|
11211
|
-
const fullImage = (0,
|
|
11212
|
-
const validationImage = (0,
|
|
11216
|
+
const fullImage = (0,_utils__WEBPACK_IMPORTED_MODULE_4__.videoImgToBase64)(video, canvas, video.videoWidth, video.videoHeight, false);
|
|
11217
|
+
const validationImage = (0,_utils__WEBPACK_IMPORTED_MODULE_4__.videoImgToBase64)(video, canvas, ExtractorVideo.VALIDATION_IMG_WIDTH, ExtractorVideo.VALIDATION_IMG_HEIGHT, true);
|
|
11213
11218
|
DOCUMENT_DETECTOR.isDocumentPresent(video).then(async isPresent => {
|
|
11214
11219
|
if (isPresent) {
|
|
11220
|
+
if (!this.wasDocumentPreviouslyDetected) {
|
|
11221
|
+
this.validationStartTime = Date.now();
|
|
11222
|
+
}
|
|
11223
|
+
this.wasDocumentPreviouslyDetected = true;
|
|
11215
11224
|
this.candidateImages.push({
|
|
11216
11225
|
fullImg: fullImage,
|
|
11217
11226
|
validationImg: validationImage
|
|
11218
11227
|
});
|
|
11219
11228
|
const images = [...this.candidateImages];
|
|
11229
|
+
const now = Date.now();
|
|
11230
|
+
if (this.validationStartTime && now - this.validationStartTime > cfgValues.VALIDATION_TIMEOUT_MS) {
|
|
11231
|
+
this.stopVideo();
|
|
11232
|
+
this.onExtractedResults({
|
|
11233
|
+
success: false,
|
|
11234
|
+
code: "002",
|
|
11235
|
+
info: "Document was detected but validation did not succeed in time."
|
|
11236
|
+
});
|
|
11237
|
+
return;
|
|
11238
|
+
}
|
|
11220
11239
|
if (images.length >= ExtractorVideo.VALIDATION_BATCH_SIZE) {
|
|
11221
|
-
const [isValidationOk, response] = await (0,
|
|
11240
|
+
const [isValidationOk, response] = await (0,_requests_validation__WEBPACK_IMPORTED_MODULE_3__["default"])(images.map(e => e["validationImg"]), this.pastBlurValues, {});
|
|
11222
11241
|
if (isValidationOk) {
|
|
11223
11242
|
this.showMessage(response["Info"]);
|
|
11224
11243
|
//
|
|
@@ -11245,7 +11264,7 @@ class ExtractorVideo {
|
|
|
11245
11264
|
if (Object.keys(extractionImages).length === 2) {
|
|
11246
11265
|
this.showMessage("Validation successful");
|
|
11247
11266
|
alert("Sending document to analysis");
|
|
11248
|
-
const [isExtractionOk, extractionData] = await (0,
|
|
11267
|
+
const [isExtractionOk, extractionData] = await (0,_requests_extraction__WEBPACK_IMPORTED_MODULE_2__["default"])(extractionImages["FRONT"], extractionImages["BACK"], {
|
|
11249
11268
|
IgnoreBackImage: false
|
|
11250
11269
|
});
|
|
11251
11270
|
this.onExtraction(isExtractionOk, extractionData);
|
|
@@ -11256,13 +11275,25 @@ class ExtractorVideo {
|
|
|
11256
11275
|
this.showMessage("Extracting data");
|
|
11257
11276
|
const imageId = response["Index"];
|
|
11258
11277
|
const image = images[imageId]["fullImg"];
|
|
11259
|
-
const [isExtractionOk, extractionData] = await (0,
|
|
11278
|
+
const [isExtractionOk, extractionData] = await (0,_requests_extraction__WEBPACK_IMPORTED_MODULE_2__["default"])(image, undefined, {
|
|
11260
11279
|
IgnoreBackImage: true
|
|
11261
11280
|
});
|
|
11262
11281
|
this.onExtraction(isExtractionOk, extractionData);
|
|
11263
11282
|
return;
|
|
11264
11283
|
}
|
|
11284
|
+
} else {
|
|
11285
|
+
this.candidateImages = [];
|
|
11286
|
+
if (response?.statusCode === 401 || response?.statusCode === 403) {
|
|
11287
|
+
this.stopVideo();
|
|
11288
|
+
this.onExtractedResults({
|
|
11289
|
+
success: false,
|
|
11290
|
+
code: "004",
|
|
11291
|
+
info: "Unauthorized. Please check your key."
|
|
11292
|
+
});
|
|
11293
|
+
return;
|
|
11294
|
+
}
|
|
11265
11295
|
}
|
|
11296
|
+
this.validationStartTime = null;
|
|
11266
11297
|
this.candidateImages = [];
|
|
11267
11298
|
}
|
|
11268
11299
|
}
|
|
@@ -11278,7 +11309,7 @@ class ExtractorVideo {
|
|
|
11278
11309
|
this.showMessage("Success - data extracted", "success");
|
|
11279
11310
|
const shouldStop = this.onExtractedResults({
|
|
11280
11311
|
success: true,
|
|
11281
|
-
code: "
|
|
11312
|
+
code: "001",
|
|
11282
11313
|
info: "Document extracted successfully.",
|
|
11283
11314
|
data: extractionData
|
|
11284
11315
|
});
|
|
@@ -11288,7 +11319,7 @@ class ExtractorVideo {
|
|
|
11288
11319
|
} else {
|
|
11289
11320
|
this.onExtractedResults({
|
|
11290
11321
|
success: false,
|
|
11291
|
-
code: "
|
|
11322
|
+
code: "005",
|
|
11292
11323
|
info: "Document validation passed but extraction failed."
|
|
11293
11324
|
});
|
|
11294
11325
|
setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
|
|
@@ -11328,7 +11359,7 @@ class ExtractorVideo {
|
|
|
11328
11359
|
console.log("Error accessing the camera: " + error);
|
|
11329
11360
|
this.onExtractedResults({
|
|
11330
11361
|
success: false,
|
|
11331
|
-
code: "
|
|
11362
|
+
code: "005",
|
|
11332
11363
|
info: "Could not access the camera. Permission denied or not found."
|
|
11333
11364
|
});
|
|
11334
11365
|
});
|
|
@@ -11337,7 +11368,7 @@ class ExtractorVideo {
|
|
|
11337
11368
|
console.log("Error accessing the camera: " + error);
|
|
11338
11369
|
this.onExtractedResults({
|
|
11339
11370
|
success: false,
|
|
11340
|
-
code: "
|
|
11371
|
+
code: "005",
|
|
11341
11372
|
info: "Could not enumerate video input devices."
|
|
11342
11373
|
});
|
|
11343
11374
|
});
|
|
@@ -11577,7 +11608,10 @@ let internalConfig = {
|
|
|
11577
11608
|
DONT_USE_VALIDATION: null,
|
|
11578
11609
|
SEGMENTED_IMAGE_RESIZE: null,
|
|
11579
11610
|
SIGNATURE_IMAGE_RESIZE: null,
|
|
11580
|
-
FACE_IMAGE_RESIZE: null
|
|
11611
|
+
FACE_IMAGE_RESIZE: null,
|
|
11612
|
+
// timeout settings:
|
|
11613
|
+
MAX_SCAN_DURATION_MS: 10000,
|
|
11614
|
+
VALIDATION_TIMEOUT_MS: 5000
|
|
11581
11615
|
};
|
|
11582
11616
|
//
|
|
11583
11617
|
function setScanDocAIConfig(newConfig = {}) {
|