scandoc-ai-components 0.0.40 → 0.0.42
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 +70 -60
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11188,7 +11188,17 @@ class ExtractorVideo {
|
|
|
11188
11188
|
this.pastBlurValues = [];
|
|
11189
11189
|
this.isRunning = false;
|
|
11190
11190
|
this.scanStartTime = null;
|
|
11191
|
-
this.
|
|
11191
|
+
this.unsupportedDocStartTime = null;
|
|
11192
|
+
}
|
|
11193
|
+
reset() {
|
|
11194
|
+
this.stopVideo();
|
|
11195
|
+
this.candidateImages = [];
|
|
11196
|
+
this.extractionImages = {};
|
|
11197
|
+
this.pastBlurValues = [];
|
|
11198
|
+
this.scanStartTime = null;
|
|
11199
|
+
this.timeoutTimer = null;
|
|
11200
|
+
this.isRunning = false;
|
|
11201
|
+
this.unsupportedDocStartTime = null;
|
|
11192
11202
|
}
|
|
11193
11203
|
async analyzeVideoStream() {
|
|
11194
11204
|
if (!this.isRunning) {
|
|
@@ -11215,7 +11225,6 @@ class ExtractorVideo {
|
|
|
11215
11225
|
DOCUMENT_DETECTOR.isDocumentPresent(video).then(async isPresent => {
|
|
11216
11226
|
if (isPresent) {
|
|
11217
11227
|
if (!this.documentDetectionStartTime) {
|
|
11218
|
-
console.log('here');
|
|
11219
11228
|
this.documentDetectionStartTime = Date.now();
|
|
11220
11229
|
}
|
|
11221
11230
|
this.candidateImages.push({
|
|
@@ -11224,9 +11233,13 @@ class ExtractorVideo {
|
|
|
11224
11233
|
});
|
|
11225
11234
|
const images = [...this.candidateImages];
|
|
11226
11235
|
const timeSinceFirstDetection = Date.now() - this.documentDetectionStartTime;
|
|
11227
|
-
console.log(timeSinceFirstDetection);
|
|
11228
11236
|
if (timeSinceFirstDetection > cfgValues.VALIDATION_TIMEOUT_MS) {
|
|
11229
|
-
this.
|
|
11237
|
+
this.stopVideo();
|
|
11238
|
+
this.onExtractedResults({
|
|
11239
|
+
success: false,
|
|
11240
|
+
code: "002",
|
|
11241
|
+
info: "Document template not supported."
|
|
11242
|
+
});
|
|
11230
11243
|
this.documentDetectionStartTime = null;
|
|
11231
11244
|
this.candidateImages = [];
|
|
11232
11245
|
return;
|
|
@@ -11234,7 +11247,22 @@ class ExtractorVideo {
|
|
|
11234
11247
|
if (images.length >= ExtractorVideo.VALIDATION_BATCH_SIZE) {
|
|
11235
11248
|
const [isValidationOk, response] = await (0,_requests_validation__WEBPACK_IMPORTED_MODULE_3__["default"])(images.map(e => e["validationImg"]), this.pastBlurValues, {});
|
|
11236
11249
|
if (isValidationOk) {
|
|
11237
|
-
|
|
11250
|
+
if (response["InfoCode"] === "1006") {
|
|
11251
|
+
this.unsupportedDocCount += 1;
|
|
11252
|
+
if (this.unsupportedDocCount >= cfgValues.MAX_UNSUPPORTED_ATTEMPTS) {
|
|
11253
|
+
this.stopVideo();
|
|
11254
|
+
this.onExtractedResults({
|
|
11255
|
+
success: false,
|
|
11256
|
+
code: "002",
|
|
11257
|
+
info: "Document template not supported."
|
|
11258
|
+
});
|
|
11259
|
+
this.unsupportedDocCount = 0;
|
|
11260
|
+
this.candidateImages = [];
|
|
11261
|
+
return;
|
|
11262
|
+
}
|
|
11263
|
+
} else {
|
|
11264
|
+
this.unsupportedDocCount = 0;
|
|
11265
|
+
}
|
|
11238
11266
|
this.showMessage(response["Info"]);
|
|
11239
11267
|
//
|
|
11240
11268
|
if ("DetectedBlurValue" in response) {
|
|
@@ -11312,67 +11340,49 @@ class ExtractorVideo {
|
|
|
11312
11340
|
async startVideo() {
|
|
11313
11341
|
try {
|
|
11314
11342
|
const serviceConfig = (0,_config__WEBPACK_IMPORTED_MODULE_1__.getScanDocAIConfig)();
|
|
11315
|
-
await serviceConfig.getAccessToken(true);
|
|
11316
|
-
|
|
11317
|
-
|
|
11318
|
-
|
|
11319
|
-
|
|
11320
|
-
|
|
11321
|
-
code: "004",
|
|
11322
|
-
info: "Authentication failed."
|
|
11323
|
-
});
|
|
11324
|
-
return false;
|
|
11325
|
-
}
|
|
11326
|
-
const videoElem = document.getElementById("ScanDocAIVideoElement");
|
|
11327
|
-
if (videoElem !== undefined) {
|
|
11343
|
+
await serviceConfig.getAccessToken(true); // This will throw if 401
|
|
11344
|
+
|
|
11345
|
+
const videoElem = document.getElementById("ScanDocAIVideoElement");
|
|
11346
|
+
if (!videoElem) {
|
|
11347
|
+
throw new Error("Video element not found.");
|
|
11348
|
+
}
|
|
11328
11349
|
this.video = videoElem;
|
|
11329
11350
|
this.isRunning = true;
|
|
11330
11351
|
this.scanStartTime = Date.now();
|
|
11331
|
-
navigator.mediaDevices.enumerateDevices()
|
|
11332
|
-
|
|
11333
|
-
|
|
11334
|
-
|
|
11335
|
-
|
|
11336
|
-
|
|
11337
|
-
|
|
11338
|
-
|
|
11339
|
-
|
|
11340
|
-
|
|
11341
|
-
|
|
11342
|
-
|
|
11343
|
-
|
|
11344
|
-
|
|
11345
|
-
|
|
11346
|
-
|
|
11347
|
-
|
|
11348
|
-
|
|
11349
|
-
|
|
11350
|
-
this.video.play().catch(e => {
|
|
11351
|
-
console.warn(`Error on video play: ${e}`);
|
|
11352
|
-
});
|
|
11353
|
-
this.scanStartTime = Date.now(); // Reset timer
|
|
11354
|
-
setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
|
|
11355
|
-
}).catch(error => {
|
|
11356
|
-
console.log("Error accessing the camera: " + error);
|
|
11357
|
-
this.onExtractedResults({
|
|
11358
|
-
success: false,
|
|
11359
|
-
code: "005",
|
|
11360
|
-
info: "Could not access the camera. Permission denied or not found."
|
|
11361
|
-
});
|
|
11362
|
-
});
|
|
11363
|
-
});
|
|
11364
|
-
}).catch(error => {
|
|
11365
|
-
console.log("Error accessing the camera: " + error);
|
|
11366
|
-
this.onExtractedResults({
|
|
11367
|
-
success: false,
|
|
11368
|
-
code: "005",
|
|
11369
|
-
info: "Could not enumerate video input devices."
|
|
11370
|
-
});
|
|
11352
|
+
const devices = await navigator.mediaDevices.enumerateDevices();
|
|
11353
|
+
const environmentCameras = devices.filter(device => device.kind === "videoinput" && device.label.toLowerCase().includes("back"));
|
|
11354
|
+
const cameras = await checkAutofocusSupport(environmentCameras);
|
|
11355
|
+
let deviceId;
|
|
11356
|
+
if (cameras.length > 0) {
|
|
11357
|
+
deviceId = cameras[0].deviceId;
|
|
11358
|
+
}
|
|
11359
|
+
const userMediaConstraints = {
|
|
11360
|
+
...ExtractorVideo.VIDEO_SETTINGS
|
|
11361
|
+
};
|
|
11362
|
+
if (deviceId) {
|
|
11363
|
+
userMediaConstraints.deviceId = deviceId;
|
|
11364
|
+
}
|
|
11365
|
+
const stream = await navigator.mediaDevices.getUserMedia({
|
|
11366
|
+
video: userMediaConstraints
|
|
11367
|
+
});
|
|
11368
|
+
this.video.srcObject = stream;
|
|
11369
|
+
await this.video.play().catch(e => {
|
|
11370
|
+
console.warn(`Error on video play: ${e}`);
|
|
11371
11371
|
});
|
|
11372
|
+
this.scanStartTime = Date.now();
|
|
11373
|
+
setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
|
|
11372
11374
|
this.showMessage("Starting scanning");
|
|
11373
11375
|
return true;
|
|
11376
|
+
} catch (error) {
|
|
11377
|
+
this.isRunning = false;
|
|
11378
|
+
this.stopVideo();
|
|
11379
|
+
this.onExtractedResults({
|
|
11380
|
+
success: false,
|
|
11381
|
+
code: error.status === 401 ? "004" : "005",
|
|
11382
|
+
info: error.status === 401 ? "Authentication failed." : "Video setup failed."
|
|
11383
|
+
});
|
|
11384
|
+
return false;
|
|
11374
11385
|
}
|
|
11375
|
-
return false;
|
|
11376
11386
|
}
|
|
11377
11387
|
stopVideo() {
|
|
11378
11388
|
this.isRunning = false;
|
|
@@ -11608,7 +11618,7 @@ let internalConfig = {
|
|
|
11608
11618
|
FACE_IMAGE_RESIZE: null,
|
|
11609
11619
|
// timeout settings:
|
|
11610
11620
|
MAX_SCAN_DURATION_MS: 10000,
|
|
11611
|
-
|
|
11621
|
+
MAX_UNSUPPORTED_ATTEMPTS: 5
|
|
11612
11622
|
};
|
|
11613
11623
|
//
|
|
11614
11624
|
function setScanDocAIConfig(newConfig = {}) {
|