@swan-admin/swan-ai-measurements 1.0.49 → 1.0.51

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/measurement.js +13 -3
  2. package/package.json +1 -1
package/measurement.js CHANGED
@@ -13,7 +13,7 @@ export default class Measurement {
13
13
  #measurementSocketRef = null;
14
14
  #timerPollingRef = null;
15
15
  #timerWaitingRef = null;
16
-
16
+ #count = 1;
17
17
  getMeasurementStatus(scanId, accessKey) {
18
18
  if (checkParameters(scanId, accessKey) === false) {
19
19
  throw new Error(REQUIRED_MESSAGE);
@@ -68,6 +68,15 @@ export default class Measurement {
68
68
  if (res?.data && res?.data?.[0]?.isMeasured === true) {
69
69
  onSuccess?.(res?.data);
70
70
  clearInterval(this.#timerPollingRef);
71
+ } else {
72
+ if (this.#count < 8) {
73
+ this.#count++;
74
+ this.#handlePolling({ scanId, onSuccess, onError, accessKey });
75
+ } else {
76
+ this.#count = 1;
77
+ clearInterval(this.#timerPollingRef);
78
+ onError?.({ scanStatus: "failed", message: "failed to get measurement" });
79
+ }
71
80
  }
72
81
  } catch (e) {
73
82
  clearInterval(this.#timerPollingRef);
@@ -77,9 +86,9 @@ export default class Measurement {
77
86
 
78
87
  #handlePolling({ scanId, onSuccess, onError, accessKey }) {
79
88
  clearInterval(this.#timerPollingRef);
80
- this.#timerPollingRef = setInterval(() => {
89
+ this.#timerPollingRef = setTimeout(() => {
81
90
  this.#getMeasurementsCheck({ scanId, onSuccess, onError, accessKey });
82
- }, 5000);
91
+ }, this.#count * 5000);
83
92
  }
84
93
 
85
94
  #disconnectSocket = () => {
@@ -88,6 +97,7 @@ export default class Measurement {
88
97
  };
89
98
 
90
99
  #handleTimeOut = ({ scanId, onSuccess, onError, accessKey }) => {
100
+ this.#count = 1;
91
101
  this.#timerWaitingRef = setTimeout(() => {
92
102
  this.#handlePolling({ scanId, onSuccess, onError, accessKey });
93
103
  this.#disconnectSocket();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swan-admin/swan-ai-measurements",
3
- "version": "1.0.49",
3
+ "version": "1.0.51",
4
4
  "description": "provides ai measurement suggestion",
5
5
  "main": "index.js",
6
6
  "type": "module",