scandoc-ai-components 0.0.35 → 0.0.37

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 +11 -34
  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,36 +11213,26 @@ 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
- }
11225
- this.wasDocumentPreviouslyDetected = true;
11226
- console.log("Validation timer:", {
11227
- start: this.validationStartTime,
11228
- now: now_valid,
11229
- elapsed: now_valid - this.validationStartTime,
11230
- limit: cfgValues.VALIDATION_TIMEOUT_MS
11231
- });
11232
- if (this.validationStartTime && now_valid - this.validationStartTime > cfgValues.VALIDATION_TIMEOUT_MS) {
11233
- this.stopVideo();
11234
- this.onExtractedResults({
11235
- success: false,
11236
- code: "002",
11237
- info: "Document was detected but validation did not succeed in time."
11238
- });
11239
- return;
11217
+ if (!this.documentDetectionStartTime) {
11218
+ this.documentDetectionStartTime = Date.now();
11240
11219
  }
11241
11220
  this.candidateImages.push({
11242
11221
  fullImg: fullImage,
11243
11222
  validationImg: validationImage
11244
11223
  });
11245
11224
  const images = [...this.candidateImages];
11225
+ const timeSinceFirstDetection = Date.now() - this.documentDetectionStartTime;
11226
+ if (timeSinceFirstDetection > cfgValues.VALIDATION_TIMEOUT_MS) {
11227
+ this.showMessage("Validation failed: timeout after 5 seconds.");
11228
+ this.documentDetectionStartTime = null;
11229
+ this.candidateImages = [];
11230
+ return;
11231
+ }
11246
11232
  if (images.length >= ExtractorVideo.VALIDATION_BATCH_SIZE) {
11247
11233
  const [isValidationOk, response] = await (0,_requests_validation__WEBPACK_IMPORTED_MODULE_3__["default"])(images.map(e => e["validationImg"]), this.pastBlurValues, {});
11248
11234
  if (isValidationOk) {
11235
+ this.documentDetectionStartTime = null;
11249
11236
  this.showMessage(response["Info"]);
11250
11237
  //
11251
11238
  if ("DetectedBlurValue" in response) {
@@ -11288,19 +11275,9 @@ class ExtractorVideo {
11288
11275
  this.onExtraction(isExtractionOk, extractionData);
11289
11276
  return;
11290
11277
  }
11291
- } else {
11292
- this.wasDocumentPreviouslyDetected = false;
11293
- this.candidateImages = [];
11294
11278
  }
11295
- this.validationStartTime = null;
11296
11279
  this.candidateImages = [];
11297
11280
  }
11298
- } else {
11299
- if (this.wasDocumentPreviouslyDetected) {
11300
- console.log("Document lost. Resetting validation timer.");
11301
- }
11302
- this.wasDocumentPreviouslyDetected = false;
11303
- this.validationStartTime = null;
11304
11281
  }
11305
11282
  }).finally(() => {
11306
11283
  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.35",
4
+ "version": "0.0.37",
5
5
  "private": false,
6
6
  "description": "Pure JavaScript package for integrating ScanDoc-AI services.",
7
7
  "keywords": [