scandoc-ai-components 0.0.41 → 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 -61
- 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,8 +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
|
-
|
|
11238
|
-
|
|
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
|
+
}
|
|
11239
11266
|
this.showMessage(response["Info"]);
|
|
11240
11267
|
//
|
|
11241
11268
|
if ("DetectedBlurValue" in response) {
|
|
@@ -11313,67 +11340,49 @@ class ExtractorVideo {
|
|
|
11313
11340
|
async startVideo() {
|
|
11314
11341
|
try {
|
|
11315
11342
|
const serviceConfig = (0,_config__WEBPACK_IMPORTED_MODULE_1__.getScanDocAIConfig)();
|
|
11316
|
-
await serviceConfig.getAccessToken(true);
|
|
11317
|
-
|
|
11318
|
-
|
|
11319
|
-
|
|
11320
|
-
|
|
11321
|
-
|
|
11322
|
-
code: "004",
|
|
11323
|
-
info: "Authentication failed."
|
|
11324
|
-
});
|
|
11325
|
-
return false;
|
|
11326
|
-
}
|
|
11327
|
-
const videoElem = document.getElementById("ScanDocAIVideoElement");
|
|
11328
|
-
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
|
+
}
|
|
11329
11349
|
this.video = videoElem;
|
|
11330
11350
|
this.isRunning = true;
|
|
11331
11351
|
this.scanStartTime = Date.now();
|
|
11332
|
-
navigator.mediaDevices.enumerateDevices()
|
|
11333
|
-
|
|
11334
|
-
|
|
11335
|
-
|
|
11336
|
-
|
|
11337
|
-
|
|
11338
|
-
|
|
11339
|
-
|
|
11340
|
-
|
|
11341
|
-
|
|
11342
|
-
|
|
11343
|
-
|
|
11344
|
-
|
|
11345
|
-
|
|
11346
|
-
|
|
11347
|
-
|
|
11348
|
-
|
|
11349
|
-
|
|
11350
|
-
|
|
11351
|
-
this.video.play().catch(e => {
|
|
11352
|
-
console.warn(`Error on video play: ${e}`);
|
|
11353
|
-
});
|
|
11354
|
-
this.scanStartTime = Date.now(); // Reset timer
|
|
11355
|
-
setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
|
|
11356
|
-
}).catch(error => {
|
|
11357
|
-
console.log("Error accessing the camera: " + error);
|
|
11358
|
-
this.onExtractedResults({
|
|
11359
|
-
success: false,
|
|
11360
|
-
code: "005",
|
|
11361
|
-
info: "Could not access the camera. Permission denied or not found."
|
|
11362
|
-
});
|
|
11363
|
-
});
|
|
11364
|
-
});
|
|
11365
|
-
}).catch(error => {
|
|
11366
|
-
console.log("Error accessing the camera: " + error);
|
|
11367
|
-
this.onExtractedResults({
|
|
11368
|
-
success: false,
|
|
11369
|
-
code: "005",
|
|
11370
|
-
info: "Could not enumerate video input devices."
|
|
11371
|
-
});
|
|
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}`);
|
|
11372
11371
|
});
|
|
11372
|
+
this.scanStartTime = Date.now();
|
|
11373
|
+
setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
|
|
11373
11374
|
this.showMessage("Starting scanning");
|
|
11374
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;
|
|
11375
11385
|
}
|
|
11376
|
-
return false;
|
|
11377
11386
|
}
|
|
11378
11387
|
stopVideo() {
|
|
11379
11388
|
this.isRunning = false;
|
|
@@ -11609,7 +11618,7 @@ let internalConfig = {
|
|
|
11609
11618
|
FACE_IMAGE_RESIZE: null,
|
|
11610
11619
|
// timeout settings:
|
|
11611
11620
|
MAX_SCAN_DURATION_MS: 10000,
|
|
11612
|
-
|
|
11621
|
+
MAX_UNSUPPORTED_ATTEMPTS: 5
|
|
11613
11622
|
};
|
|
11614
11623
|
//
|
|
11615
11624
|
function setScanDocAIConfig(newConfig = {}) {
|