scandoc-ai-components 0.0.36 → 0.0.38

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.
Files changed (2) hide show
  1. package/dist/index.js +12 -36
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -11188,10 +11188,7 @@ class ExtractorVideo {
11188
11188
  this.pastBlurValues = [];
11189
11189
  this.isRunning = false;
11190
11190
  this.scanStartTime = null;
11191
- this.timeoutTimer = null;
11192
- this.validationStartTime = null;
11193
- this.validationTimedOut = false;
11194
- this.wasDocumentPreviouslyDetected = false;
11191
+ this.documentDetectionStartTime = null;
11195
11192
  }
11196
11193
  async analyzeVideoStream() {
11197
11194
  if (!this.isRunning) {
@@ -11216,38 +11213,27 @@ class ExtractorVideo {
11216
11213
  const fullImage = (0,_utils__WEBPACK_IMPORTED_MODULE_4__.videoImgToBase64)(video, canvas, video.videoWidth, video.videoHeight, false);
11217
11214
  const validationImage = (0,_utils__WEBPACK_IMPORTED_MODULE_4__.videoImgToBase64)(video, canvas, ExtractorVideo.VALIDATION_IMG_WIDTH, ExtractorVideo.VALIDATION_IMG_HEIGHT, true);
11218
11215
  DOCUMENT_DETECTOR.isDocumentPresent(video).then(async isPresent => {
11219
- const now_valid = Date.now();
11220
11216
  if (isPresent) {
11221
- if (!this.wasDocumentPreviouslyDetected || this.validationStartTime === null) {
11222
- this.validationStartTime = now_valid;
11223
- console.log("Document detected. Validation timer started:", this.validationStartTime);
11224
- this.wasDocumentPreviouslyDetected = true;
11225
- return;
11226
- }
11227
- this.wasDocumentPreviouslyDetected = true;
11228
- console.log("Validation timer:", {
11229
- start: this.validationStartTime,
11230
- now: now_valid,
11231
- elapsed: now_valid - this.validationStartTime,
11232
- limit: cfgValues.VALIDATION_TIMEOUT_MS
11233
- });
11234
- if (this.validationStartTime && now_valid - this.validationStartTime > cfgValues.VALIDATION_TIMEOUT_MS) {
11235
- this.stopVideo();
11236
- this.onExtractedResults({
11237
- success: false,
11238
- code: "002",
11239
- info: "Document was detected but validation did not succeed in time."
11240
- });
11241
- return;
11217
+ if (!this.documentDetectionStartTime) {
11218
+ this.documentDetectionStartTime = Date.now();
11242
11219
  }
11243
11220
  this.candidateImages.push({
11244
11221
  fullImg: fullImage,
11245
11222
  validationImg: validationImage
11246
11223
  });
11247
11224
  const images = [...this.candidateImages];
11225
+ const timeSinceFirstDetection = Date.now() - this.documentDetectionStartTime;
11226
+ console.log(timeSinceFirstDetection);
11227
+ if (timeSinceFirstDetection > cfgValues.VALIDATION_TIMEOUT_MS) {
11228
+ this.showMessage("Validation failed: timeout after 5 seconds.");
11229
+ this.documentDetectionStartTime = null;
11230
+ this.candidateImages = [];
11231
+ return;
11232
+ }
11248
11233
  if (images.length >= ExtractorVideo.VALIDATION_BATCH_SIZE) {
11249
11234
  const [isValidationOk, response] = await (0,_requests_validation__WEBPACK_IMPORTED_MODULE_3__["default"])(images.map(e => e["validationImg"]), this.pastBlurValues, {});
11250
11235
  if (isValidationOk) {
11236
+ this.documentDetectionStartTime = null;
11251
11237
  this.showMessage(response["Info"]);
11252
11238
  //
11253
11239
  if ("DetectedBlurValue" in response) {
@@ -11290,19 +11276,9 @@ class ExtractorVideo {
11290
11276
  this.onExtraction(isExtractionOk, extractionData);
11291
11277
  return;
11292
11278
  }
11293
- } else {
11294
- this.wasDocumentPreviouslyDetected = false;
11295
- this.candidateImages = [];
11296
11279
  }
11297
- this.validationStartTime = null;
11298
11280
  this.candidateImages = [];
11299
11281
  }
11300
- } else {
11301
- if (this.wasDocumentPreviouslyDetected) {
11302
- console.log("Document lost. Resetting validation timer.");
11303
- }
11304
- this.wasDocumentPreviouslyDetected = false;
11305
- this.validationStartTime = null;
11306
11282
  }
11307
11283
  }).finally(() => {
11308
11284
  setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "scandoc-ai-components",
3
3
  "author": "ScanDoc-AI",
4
- "version": "0.0.36",
4
+ "version": "0.0.38",
5
5
  "private": false,
6
6
  "description": "Pure JavaScript package for integrating ScanDoc-AI services.",
7
7
  "keywords": [