scandoc-ai-components 0.0.24 → 0.0.25
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 +31 -49
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11170,6 +11170,7 @@ class ExtractorVideo {
|
|
|
11170
11170
|
static VALIDATION_BATCH_SIZE = 1;
|
|
11171
11171
|
static VALIDATION_IMG_WIDTH = 384;
|
|
11172
11172
|
static VALIDATION_IMG_HEIGHT = 384;
|
|
11173
|
+
static MAX_SCAN_DURATION_MS = 10000;
|
|
11173
11174
|
static VIDEO_SETTINGS = Object.freeze({
|
|
11174
11175
|
width: {
|
|
11175
11176
|
ideal: 1920
|
|
@@ -11185,25 +11186,21 @@ class ExtractorVideo {
|
|
|
11185
11186
|
this.onExtractedResults = onExtractedResults;
|
|
11186
11187
|
this.pastBlurValues = [];
|
|
11187
11188
|
this.isRunning = false;
|
|
11188
|
-
this.
|
|
11189
|
-
this.
|
|
11190
|
-
this.failedValidations = 0;
|
|
11191
|
-
this.MAX_FAILED_VALIDATIONS = 5;
|
|
11192
|
-
this.failedExtractionAttempts = 0;
|
|
11193
|
-
this.MAX_EXTRACTION_ATTEMPTS = 3;
|
|
11189
|
+
this.scanStartTime = null;
|
|
11190
|
+
this.timeoutTimer = null;
|
|
11194
11191
|
}
|
|
11195
11192
|
async analyzeVideoStream() {
|
|
11196
11193
|
if (!this.isRunning) {
|
|
11197
11194
|
return;
|
|
11198
11195
|
}
|
|
11199
11196
|
//
|
|
11200
|
-
const
|
|
11201
|
-
if (
|
|
11197
|
+
const now = Date.now();
|
|
11198
|
+
if (this.scanStartTime && now - this.scanStartTime > ExtractorVideo.MAX_SCAN_DURATION_MS) {
|
|
11202
11199
|
this.stopVideo();
|
|
11203
11200
|
this.onExtractedResults({
|
|
11204
11201
|
success: false,
|
|
11205
11202
|
code: "TIMEOUT",
|
|
11206
|
-
|
|
11203
|
+
info: "Document not detected within time limit."
|
|
11207
11204
|
});
|
|
11208
11205
|
return;
|
|
11209
11206
|
}
|
|
@@ -11222,21 +11219,6 @@ class ExtractorVideo {
|
|
|
11222
11219
|
const images = [...this.candidateImages];
|
|
11223
11220
|
if (images.length >= ExtractorVideo.VALIDATION_BATCH_SIZE) {
|
|
11224
11221
|
const [isValidationOk, response] = await (0,_requests_validation__WEBPACK_IMPORTED_MODULE_2__["default"])(images.map(e => e["validationImg"]), this.pastBlurValues, {});
|
|
11225
|
-
if (!isValidationOk) {
|
|
11226
|
-
this.failedValidations++;
|
|
11227
|
-
if (this.failedValidations >= this.MAX_FAILED_VALIDATIONS) {
|
|
11228
|
-
this.stopVideo();
|
|
11229
|
-
this.onExtractedResults({
|
|
11230
|
-
success: false,
|
|
11231
|
-
code: "VALIDATION_FAILED",
|
|
11232
|
-
message: "Document validation failed repeatedly."
|
|
11233
|
-
});
|
|
11234
|
-
return;
|
|
11235
|
-
}
|
|
11236
|
-
this.candidateImages = [];
|
|
11237
|
-
return;
|
|
11238
|
-
}
|
|
11239
|
-
this.failedValidations = 0;
|
|
11240
11222
|
if (isValidationOk) {
|
|
11241
11223
|
this.showMessage(response["Info"]);
|
|
11242
11224
|
//
|
|
@@ -11280,14 +11262,19 @@ class ExtractorVideo {
|
|
|
11280
11262
|
this.onExtraction(isExtractionOk, extractionData);
|
|
11281
11263
|
return;
|
|
11282
11264
|
}
|
|
11265
|
+
} else {
|
|
11266
|
+
this.candidateImages = [];
|
|
11267
|
+
this.onExtractedResults({
|
|
11268
|
+
success: false,
|
|
11269
|
+
code: "VALIDATION_FAILED",
|
|
11270
|
+
info: "Validation of document image failed."
|
|
11271
|
+
});
|
|
11283
11272
|
}
|
|
11284
11273
|
this.candidateImages = [];
|
|
11285
11274
|
}
|
|
11286
11275
|
}
|
|
11287
11276
|
}).finally(() => {
|
|
11288
|
-
|
|
11289
|
-
setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
|
|
11290
|
-
}
|
|
11277
|
+
setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
|
|
11291
11278
|
});
|
|
11292
11279
|
}
|
|
11293
11280
|
onExtraction(isExtractionOk, extractionData) {
|
|
@@ -11295,21 +11282,21 @@ class ExtractorVideo {
|
|
|
11295
11282
|
this.extractionImages = {};
|
|
11296
11283
|
if (isExtractionOk) {
|
|
11297
11284
|
this.showMessage("Success - data extracted", "success");
|
|
11298
|
-
const shouldStop = this.onExtractedResults(
|
|
11285
|
+
const shouldStop = this.onExtractedResults({
|
|
11286
|
+
success: true,
|
|
11287
|
+
code: "EXTRACTION_OK",
|
|
11288
|
+
info: "Document extracted successfully.",
|
|
11289
|
+
data: extractionData
|
|
11290
|
+
});
|
|
11299
11291
|
if (shouldStop === true) {
|
|
11300
11292
|
setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
|
|
11301
11293
|
}
|
|
11302
11294
|
} else {
|
|
11303
|
-
this.
|
|
11304
|
-
|
|
11305
|
-
|
|
11306
|
-
|
|
11307
|
-
|
|
11308
|
-
code: "EXTRACTION_FAILED",
|
|
11309
|
-
message: "Document extraction failed."
|
|
11310
|
-
});
|
|
11311
|
-
return;
|
|
11312
|
-
}
|
|
11295
|
+
this.onExtractedResults({
|
|
11296
|
+
success: false,
|
|
11297
|
+
code: "EXTRACTION_FAILED",
|
|
11298
|
+
info: "Document validation passed but extraction failed."
|
|
11299
|
+
});
|
|
11313
11300
|
setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
|
|
11314
11301
|
}
|
|
11315
11302
|
}
|
|
@@ -11318,10 +11305,10 @@ class ExtractorVideo {
|
|
|
11318
11305
|
if (videoElem !== undefined) {
|
|
11319
11306
|
this.video = videoElem;
|
|
11320
11307
|
this.isRunning = true;
|
|
11308
|
+
this.scanStartTime = Date.now();
|
|
11321
11309
|
navigator.mediaDevices.enumerateDevices().then(devices => {
|
|
11322
11310
|
const environmentCameras = devices.filter(device => device.kind === "videoinput" && device.label.toLowerCase().includes("back"));
|
|
11323
11311
|
checkAutofocusSupport(environmentCameras).then(cameras => {
|
|
11324
|
-
console.log("Got autofocus camera:", cameras);
|
|
11325
11312
|
let deviceId = undefined;
|
|
11326
11313
|
let deviceFound = false;
|
|
11327
11314
|
if (cameras.length > 0) {
|
|
@@ -11334,26 +11321,21 @@ class ExtractorVideo {
|
|
|
11334
11321
|
if (deviceFound) {
|
|
11335
11322
|
userMediaConstraints.deviceId = deviceId;
|
|
11336
11323
|
}
|
|
11337
|
-
//
|
|
11338
11324
|
navigator.mediaDevices.getUserMedia({
|
|
11339
11325
|
video: userMediaConstraints
|
|
11340
11326
|
}).then(stream => {
|
|
11341
11327
|
this.video.srcObject = stream;
|
|
11342
|
-
this.video.onloadedmetadata = () => {
|
|
11343
|
-
this.sessionStartTime = Date.now();
|
|
11344
|
-
this.analyzeVideoStream();
|
|
11345
|
-
};
|
|
11346
11328
|
this.video.play().catch(e => {
|
|
11347
11329
|
console.warn(`Error on video play: ${e}`);
|
|
11348
11330
|
});
|
|
11349
|
-
//
|
|
11331
|
+
this.scanStartTime = Date.now(); // Reset timer
|
|
11350
11332
|
setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
|
|
11351
11333
|
}).catch(error => {
|
|
11352
11334
|
console.log("Error accessing the camera: " + error);
|
|
11353
11335
|
this.onExtractedResults({
|
|
11354
11336
|
success: false,
|
|
11355
|
-
code: "
|
|
11356
|
-
|
|
11337
|
+
code: "CAMERA_ACCESS_DENIED",
|
|
11338
|
+
info: "Could not access the camera. Permission denied or not found."
|
|
11357
11339
|
});
|
|
11358
11340
|
});
|
|
11359
11341
|
});
|
|
@@ -11361,8 +11343,8 @@ class ExtractorVideo {
|
|
|
11361
11343
|
console.log("Error accessing the camera: " + error);
|
|
11362
11344
|
this.onExtractedResults({
|
|
11363
11345
|
success: false,
|
|
11364
|
-
code: "
|
|
11365
|
-
|
|
11346
|
+
code: "CAMERA_ENUMERATION_FAILED",
|
|
11347
|
+
info: "Could not enumerate video input devices."
|
|
11366
11348
|
});
|
|
11367
11349
|
});
|
|
11368
11350
|
this.showMessage("Starting scanning");
|