scandoc-ai-components 0.0.41 → 0.0.43
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 +69 -71
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11188,7 +11188,20 @@ class ExtractorVideo {
|
|
|
11188
11188
|
this.pastBlurValues = [];
|
|
11189
11189
|
this.isRunning = false;
|
|
11190
11190
|
this.scanStartTime = null;
|
|
11191
|
-
this.
|
|
11191
|
+
this.unsupportedDocCount = 0;
|
|
11192
|
+
this.video = null;
|
|
11193
|
+
}
|
|
11194
|
+
reset() {
|
|
11195
|
+
this.stopVideo();
|
|
11196
|
+
this.candidateImages = [];
|
|
11197
|
+
this.extractionImages = {};
|
|
11198
|
+
this.pastBlurValues = [];
|
|
11199
|
+
this.scanStartTime = null;
|
|
11200
|
+
this.timeoutTimer = null;
|
|
11201
|
+
this.isRunning = false;
|
|
11202
|
+
this.unsupportedDocStartTime = null;
|
|
11203
|
+
this.unsupportedDocCount = 0;
|
|
11204
|
+
this.video = null;
|
|
11192
11205
|
}
|
|
11193
11206
|
async analyzeVideoStream() {
|
|
11194
11207
|
if (!this.isRunning) {
|
|
@@ -11214,28 +11227,30 @@ class ExtractorVideo {
|
|
|
11214
11227
|
const validationImage = (0,_utils__WEBPACK_IMPORTED_MODULE_4__.videoImgToBase64)(video, canvas, ExtractorVideo.VALIDATION_IMG_WIDTH, ExtractorVideo.VALIDATION_IMG_HEIGHT, true);
|
|
11215
11228
|
DOCUMENT_DETECTOR.isDocumentPresent(video).then(async isPresent => {
|
|
11216
11229
|
if (isPresent) {
|
|
11217
|
-
if (!this.documentDetectionStartTime) {
|
|
11218
|
-
console.log('here');
|
|
11219
|
-
this.documentDetectionStartTime = Date.now();
|
|
11220
|
-
}
|
|
11221
11230
|
this.candidateImages.push({
|
|
11222
11231
|
fullImg: fullImage,
|
|
11223
11232
|
validationImg: validationImage
|
|
11224
11233
|
});
|
|
11225
11234
|
const images = [...this.candidateImages];
|
|
11226
|
-
const timeSinceFirstDetection = Date.now() - this.documentDetectionStartTime;
|
|
11227
|
-
console.log(timeSinceFirstDetection);
|
|
11228
|
-
if (timeSinceFirstDetection > cfgValues.VALIDATION_TIMEOUT_MS) {
|
|
11229
|
-
this.showMessage("Validation failed: timeout after 5 seconds.");
|
|
11230
|
-
this.documentDetectionStartTime = null;
|
|
11231
|
-
this.candidateImages = [];
|
|
11232
|
-
return;
|
|
11233
|
-
}
|
|
11234
11235
|
if (images.length >= ExtractorVideo.VALIDATION_BATCH_SIZE) {
|
|
11235
11236
|
const [isValidationOk, response] = await (0,_requests_validation__WEBPACK_IMPORTED_MODULE_3__["default"])(images.map(e => e["validationImg"]), this.pastBlurValues, {});
|
|
11236
11237
|
if (isValidationOk) {
|
|
11237
|
-
|
|
11238
|
-
|
|
11238
|
+
if (response["InfoCode"] === "1006") {
|
|
11239
|
+
this.unsupportedDocCount += 1;
|
|
11240
|
+
if (this.unsupportedDocCount >= cfgValues.MAX_UNSUPPORTED_ATTEMPTS) {
|
|
11241
|
+
this.stopVideo();
|
|
11242
|
+
this.onExtractedResults({
|
|
11243
|
+
success: false,
|
|
11244
|
+
code: "002",
|
|
11245
|
+
info: "Document template not supported."
|
|
11246
|
+
});
|
|
11247
|
+
this.unsupportedDocCount = 0;
|
|
11248
|
+
this.candidateImages = [];
|
|
11249
|
+
return;
|
|
11250
|
+
}
|
|
11251
|
+
} else {
|
|
11252
|
+
this.unsupportedDocCount = 0;
|
|
11253
|
+
}
|
|
11239
11254
|
this.showMessage(response["Info"]);
|
|
11240
11255
|
//
|
|
11241
11256
|
if ("DetectedBlurValue" in response) {
|
|
@@ -11314,66 +11329,47 @@ class ExtractorVideo {
|
|
|
11314
11329
|
try {
|
|
11315
11330
|
const serviceConfig = (0,_config__WEBPACK_IMPORTED_MODULE_1__.getScanDocAIConfig)();
|
|
11316
11331
|
await serviceConfig.getAccessToken(true);
|
|
11317
|
-
|
|
11318
|
-
|
|
11319
|
-
|
|
11320
|
-
|
|
11321
|
-
success: false,
|
|
11322
|
-
code: "004",
|
|
11323
|
-
info: "Authentication failed."
|
|
11324
|
-
});
|
|
11325
|
-
return false;
|
|
11326
|
-
}
|
|
11327
|
-
const videoElem = document.getElementById("ScanDocAIVideoElement");
|
|
11328
|
-
if (videoElem !== undefined) {
|
|
11332
|
+
const videoElem = document.getElementById("ScanDocAIVideoElement");
|
|
11333
|
+
if (!videoElem) {
|
|
11334
|
+
throw new Error("Video element not found.");
|
|
11335
|
+
}
|
|
11329
11336
|
this.video = videoElem;
|
|
11330
11337
|
this.isRunning = true;
|
|
11331
11338
|
this.scanStartTime = Date.now();
|
|
11332
|
-
navigator.mediaDevices.enumerateDevices()
|
|
11333
|
-
|
|
11334
|
-
|
|
11335
|
-
|
|
11336
|
-
|
|
11337
|
-
|
|
11338
|
-
|
|
11339
|
-
|
|
11340
|
-
|
|
11341
|
-
|
|
11342
|
-
|
|
11343
|
-
|
|
11344
|
-
|
|
11345
|
-
|
|
11346
|
-
|
|
11347
|
-
navigator.mediaDevices.getUserMedia({
|
|
11348
|
-
video: userMediaConstraints
|
|
11349
|
-
}).then(stream => {
|
|
11350
|
-
this.video.srcObject = stream;
|
|
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
|
-
});
|
|
11339
|
+
const devices = await navigator.mediaDevices.enumerateDevices();
|
|
11340
|
+
const environmentCameras = devices.filter(device => device.kind === "videoinput" && device.label.toLowerCase().includes("back"));
|
|
11341
|
+
const cameras = await checkAutofocusSupport(environmentCameras);
|
|
11342
|
+
let deviceId;
|
|
11343
|
+
if (cameras.length > 0) {
|
|
11344
|
+
deviceId = cameras[0].deviceId;
|
|
11345
|
+
}
|
|
11346
|
+
const userMediaConstraints = {
|
|
11347
|
+
...ExtractorVideo.VIDEO_SETTINGS
|
|
11348
|
+
};
|
|
11349
|
+
if (deviceId) {
|
|
11350
|
+
userMediaConstraints.deviceId = deviceId;
|
|
11351
|
+
}
|
|
11352
|
+
const stream = await navigator.mediaDevices.getUserMedia({
|
|
11353
|
+
video: userMediaConstraints
|
|
11372
11354
|
});
|
|
11355
|
+
this.video.srcObject = stream;
|
|
11356
|
+
await this.video.play().catch(e => {
|
|
11357
|
+
console.warn(`Error on video play: ${e}`);
|
|
11358
|
+
});
|
|
11359
|
+
this.scanStartTime = Date.now(); // Reset timer
|
|
11360
|
+
setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
|
|
11373
11361
|
this.showMessage("Starting scanning");
|
|
11374
11362
|
return true;
|
|
11363
|
+
} catch (error) {
|
|
11364
|
+
this.isRunning = false;
|
|
11365
|
+
this.stopVideo();
|
|
11366
|
+
this.onExtractedResults({
|
|
11367
|
+
success: false,
|
|
11368
|
+
code: error.status === 401 ? "004" : "005",
|
|
11369
|
+
info: error.status === 401 ? "Authentication failed." : error.message || "Error"
|
|
11370
|
+
});
|
|
11371
|
+
return false;
|
|
11375
11372
|
}
|
|
11376
|
-
return false;
|
|
11377
11373
|
}
|
|
11378
11374
|
stopVideo() {
|
|
11379
11375
|
this.isRunning = false;
|
|
@@ -11609,7 +11605,7 @@ let internalConfig = {
|
|
|
11609
11605
|
FACE_IMAGE_RESIZE: null,
|
|
11610
11606
|
// timeout settings:
|
|
11611
11607
|
MAX_SCAN_DURATION_MS: 10000,
|
|
11612
|
-
|
|
11608
|
+
MAX_UNSUPPORTED_ATTEMPTS: 5
|
|
11613
11609
|
};
|
|
11614
11610
|
//
|
|
11615
11611
|
function setScanDocAIConfig(newConfig = {}) {
|
|
@@ -11633,11 +11629,13 @@ class ServiceConfig {
|
|
|
11633
11629
|
if (isOk) {
|
|
11634
11630
|
this.accessToken = data["access_token"];
|
|
11635
11631
|
this.refreshToken = data["refresh_token"];
|
|
11632
|
+
return this.accessToken;
|
|
11636
11633
|
} else {
|
|
11637
|
-
|
|
11634
|
+
const error = new Error("Authentication failed");
|
|
11635
|
+
error.status = 401;
|
|
11636
|
+
throw error;
|
|
11638
11637
|
}
|
|
11639
11638
|
}
|
|
11640
|
-
return this.accessToken;
|
|
11641
11639
|
}
|
|
11642
11640
|
async refreshTokens() {
|
|
11643
11641
|
if (this.refreshToken !== undefined) {
|