@swan-admin/swan-ai-measurements 1.0.39 → 1.0.40
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/measurement.js +28 -26
- package/package.json +1 -1
package/measurement.js
CHANGED
|
@@ -104,31 +104,33 @@ export default class Measurement {
|
|
|
104
104
|
if (!scanId) {
|
|
105
105
|
throw new Error(REQUIRED_MESSAGE);
|
|
106
106
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
107
|
+
setTimeout(() => {
|
|
108
|
+
this.#disconnectSocket();
|
|
109
|
+
const url = `${APP_RECOMMENDATION_WEBSOCKET_URL}?scanId=${scanId}`;
|
|
110
|
+
this.#measurementSocketRef = new WebSocket(url);
|
|
111
|
+
|
|
112
|
+
this.#measurementSocketRef.onopen = () => {
|
|
113
|
+
onOpen?.();
|
|
114
|
+
this.#handleTimeOut(onSuccess, onError);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
this.#measurementSocketRef.onmessage = (event) => {
|
|
118
|
+
const data = JSON.parse(event.data);
|
|
119
|
+
if (data?.code === 200 && data?.scanStatus === "success") {
|
|
120
|
+
onSuccess?.(data);
|
|
121
|
+
} else {
|
|
122
|
+
onError?.(data);
|
|
123
|
+
}
|
|
124
|
+
clearTimeout(this.#timerWaitingRef);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
this.#measurementSocketRef.onclose = () => {
|
|
128
|
+
onClose?.();
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
this.#measurementSocketRef.onerror = (event) => {
|
|
132
|
+
onError?.(event);
|
|
133
|
+
};
|
|
134
|
+
}, 5000);
|
|
133
135
|
};
|
|
134
136
|
}
|