@swan-admin/swan-ai-measurements 1.0.15 → 1.0.16
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/auth.js +12 -4
- package/measurement.js +36 -12
- package/package.json +1 -1
package/auth.js
CHANGED
|
@@ -43,20 +43,28 @@ export const handleAuthSocket = ({ email, scanId, accessKey, onError, onSuccess,
|
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
socketRef.onopen = () => {
|
|
46
|
-
onOpen
|
|
46
|
+
if (onOpen) {
|
|
47
|
+
onOpen();
|
|
48
|
+
}
|
|
47
49
|
socketRef.send(JSON.stringify(detailObj));
|
|
48
50
|
};
|
|
49
51
|
|
|
50
52
|
socketRef.onmessage = (event) => {
|
|
51
53
|
const data = JSON.parse(event.data);
|
|
52
|
-
onSuccess
|
|
54
|
+
if (onSuccess) {
|
|
55
|
+
onSuccess(data);
|
|
56
|
+
}
|
|
53
57
|
};
|
|
54
58
|
|
|
55
59
|
socketRef.onclose = () => {
|
|
56
|
-
onClose
|
|
60
|
+
if (onClose) {
|
|
61
|
+
onClose();
|
|
62
|
+
}
|
|
57
63
|
};
|
|
58
64
|
|
|
59
65
|
socketRef.current.onerror = (event) => {
|
|
60
|
-
onError
|
|
66
|
+
if (onError) {
|
|
67
|
+
onError(event);
|
|
68
|
+
}
|
|
61
69
|
};
|
|
62
70
|
};
|
package/measurement.js
CHANGED
|
@@ -42,24 +42,34 @@ export const handleTryOnSocket = ({
|
|
|
42
42
|
tryOnSocketRef = new WebSocket(url);
|
|
43
43
|
|
|
44
44
|
tryOnSocketRef.onopen = () => {
|
|
45
|
-
onOpen
|
|
45
|
+
if (onOpen) {
|
|
46
|
+
onOpen();
|
|
47
|
+
}
|
|
46
48
|
};
|
|
47
49
|
|
|
48
50
|
tryOnSocketRef.onmessage = (event) => {
|
|
49
51
|
const data = JSON.parse(event.data);
|
|
50
52
|
if (data?.tryOnProcessStatus === "available") {
|
|
51
|
-
onSuccess
|
|
53
|
+
if (onSuccess) {
|
|
54
|
+
onSuccess(data);
|
|
55
|
+
}
|
|
52
56
|
} else {
|
|
53
|
-
onError
|
|
57
|
+
if (onError) {
|
|
58
|
+
onError({ message: "failed to get image urls" });
|
|
59
|
+
}
|
|
54
60
|
}
|
|
55
61
|
};
|
|
56
62
|
|
|
57
63
|
tryOnSocketRef.onclose = () => {
|
|
58
|
-
onClose
|
|
64
|
+
if (onClose) {
|
|
65
|
+
onClose();
|
|
66
|
+
}
|
|
59
67
|
};
|
|
60
68
|
|
|
61
69
|
tryOnSocketRef.onerror = (event) => {
|
|
62
|
-
onError
|
|
70
|
+
if (onError) {
|
|
71
|
+
onError(event);
|
|
72
|
+
}
|
|
63
73
|
};
|
|
64
74
|
};
|
|
65
75
|
|
|
@@ -67,12 +77,16 @@ const getMeasurementsCheck = async (onSuccess, onError, scanId, accessKey) => {
|
|
|
67
77
|
try {
|
|
68
78
|
const res = await getMeasurementStatus(scanId, accessKey);
|
|
69
79
|
if (res?.data && res?.data?.[0]?.isMeasured === true) {
|
|
70
|
-
onSuccess
|
|
80
|
+
if (onSuccess) {
|
|
81
|
+
onSuccess(res?.data);
|
|
82
|
+
}
|
|
71
83
|
clearInterval(timerPollingRef);
|
|
72
84
|
}
|
|
73
85
|
} catch (e) {
|
|
74
86
|
clearInterval(timerPollingRef);
|
|
75
|
-
onError
|
|
87
|
+
if (onError) {
|
|
88
|
+
onError(e);
|
|
89
|
+
}
|
|
76
90
|
}
|
|
77
91
|
};
|
|
78
92
|
|
|
@@ -103,25 +117,35 @@ export const handleMeasurementSocket = ({ scanId, accessKey, onError, onSuccess,
|
|
|
103
117
|
measurementSocketRef = new WebSocket(url);
|
|
104
118
|
|
|
105
119
|
measurementSocketRef.onopen = () => {
|
|
106
|
-
onOpen
|
|
120
|
+
if (onOpen) {
|
|
121
|
+
onOpen();
|
|
122
|
+
}
|
|
107
123
|
handleTimeOut(onSuccess, onError);
|
|
108
124
|
};
|
|
109
125
|
|
|
110
126
|
measurementSocketRef.onmessage = (event) => {
|
|
111
127
|
const data = JSON.parse(event.data);
|
|
112
128
|
if (data?.code === 200 && data?.scanStatus === "success") {
|
|
113
|
-
onSuccess
|
|
129
|
+
if (onSuccess) {
|
|
130
|
+
onSuccess(data);
|
|
131
|
+
}
|
|
114
132
|
} else {
|
|
115
|
-
onError
|
|
133
|
+
if (onError) {
|
|
134
|
+
onError(data);
|
|
135
|
+
}
|
|
116
136
|
}
|
|
117
137
|
clearTimeout(timerWaitingRef);
|
|
118
138
|
};
|
|
119
139
|
|
|
120
140
|
measurementSocketRef.onclose = () => {
|
|
121
|
-
onClose
|
|
141
|
+
if (onClose) {
|
|
142
|
+
onClose();
|
|
143
|
+
}
|
|
122
144
|
};
|
|
123
145
|
|
|
124
146
|
measurementSocketRef.current.onerror = (event) => {
|
|
125
|
-
onError
|
|
147
|
+
if (onError) {
|
|
148
|
+
onError(event);
|
|
149
|
+
}
|
|
126
150
|
};
|
|
127
151
|
};
|