@swan-admin/swan-ai-measurements 1.0.28 → 1.0.29
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 +67 -60
- package/custom.js +13 -7
- package/fileUpload.js +85 -81
- package/index.js +24 -77
- package/measurement.js +120 -136
- package/package.json +1 -1
- package/poseDetection.js +46 -44
package/auth.js
CHANGED
|
@@ -1,60 +1,67 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
import { API_ENDPOINTS, APP_AUTH_BASE_URL, APP_AUTH_WEBSOCKET_URL, APP_BASE_URL } from "./constants.js";
|
|
3
|
-
let socketRef;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { API_ENDPOINTS, APP_AUTH_BASE_URL, APP_AUTH_WEBSOCKET_URL, APP_BASE_URL } from "./constants.js";
|
|
3
|
+
let socketRef;
|
|
4
|
+
|
|
5
|
+
class Auth {
|
|
6
|
+
static accessKey;
|
|
7
|
+
constructor(key) {
|
|
8
|
+
Auth.accessKey = key;
|
|
9
|
+
}
|
|
10
|
+
registerUser({ email, appVerifyUrl, gender, height, username }) {
|
|
11
|
+
let body = {
|
|
12
|
+
username,
|
|
13
|
+
email,
|
|
14
|
+
appVerifyUrl,
|
|
15
|
+
};
|
|
16
|
+
if (gender && height) {
|
|
17
|
+
body = { ...body, attributes: { gender, height } };
|
|
18
|
+
}
|
|
19
|
+
return axios.post(`${APP_AUTH_BASE_URL}${API_ENDPOINTS.REGISTER_USER}`, body);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
verifyToken = (token) =>
|
|
23
|
+
axios.post(`${APP_AUTH_BASE_URL}${API_ENDPOINTS.VERIFY_USER}`, null, {
|
|
24
|
+
params: { token },
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
addUser = ({ scanId, email, name, height, gender, offsetMarketingConsent }) =>
|
|
28
|
+
axios.post(`${APP_AUTH_BASE_URL}${API_ENDPOINTS.ADD_USER}`, {
|
|
29
|
+
scan_id: scanId,
|
|
30
|
+
email,
|
|
31
|
+
name,
|
|
32
|
+
offsetMarketingConsent,
|
|
33
|
+
attributes: JSON.stringify({ height, gender }),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
getUserDetail = (email) => axios.get(`${APP_BASE_URL}${API_ENDPOINTS.GET_USER_DETAIL}/${email}`);
|
|
37
|
+
|
|
38
|
+
handleAuthSocket = ({ email, scanId, onError, onSuccess, onClose, onOpen }) => {
|
|
39
|
+
socketRef?.close?.();
|
|
40
|
+
|
|
41
|
+
socketRef = new WebSocket(APP_AUTH_WEBSOCKET_URL);
|
|
42
|
+
const detailObj = {
|
|
43
|
+
email,
|
|
44
|
+
scanId,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
socketRef.onopen = () => {
|
|
48
|
+
onOpen?.();
|
|
49
|
+
socketRef.send(JSON.stringify(detailObj));
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
socketRef.onmessage = (event) => {
|
|
53
|
+
const data = JSON.parse(event.data);
|
|
54
|
+
onSuccess?.(data);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
socketRef.onclose = () => {
|
|
58
|
+
onClose?.();
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
socketRef.onerror = (event) => {
|
|
62
|
+
onError?.(event);
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export default Auth;
|
package/custom.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
import { API_ENDPOINTS, APP_AUTH_BASE_URL } from "./constants.js";
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { API_ENDPOINTS, APP_AUTH_BASE_URL } from "./constants.js";
|
|
3
|
+
|
|
4
|
+
export default class Custom {
|
|
5
|
+
static accessKey;
|
|
6
|
+
constructor(key) {
|
|
7
|
+
Custom.accessKey = key;
|
|
8
|
+
}
|
|
9
|
+
getCustomCustomerConfig = (store_url) =>
|
|
10
|
+
axios.get(`${APP_AUTH_BASE_URL}${API_ENDPOINTS.CUSTOM_CUSTOMER}`, { params: { store_url } });
|
|
11
|
+
|
|
12
|
+
getModelUrl = (id) => axios.get(`${APP_AUTH_BASE_URL}${API_ENDPOINTS.MODEL}/${id}`);
|
|
13
|
+
}
|
package/fileUpload.js
CHANGED
|
@@ -1,81 +1,85 @@
|
|
|
1
|
-
import AwsS3Multipart from "@uppy/aws-s3-multipart";
|
|
2
|
-
import Uppy from "@uppy/core";
|
|
3
|
-
import { FILE_UPLOAD_KEY, UPPY_FILE_UPLOAD_ENDPOINT } from "./constants.js";
|
|
4
|
-
import { fetchData } from "./utils.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
1
|
+
import AwsS3Multipart from "@uppy/aws-s3-multipart";
|
|
2
|
+
import Uppy from "@uppy/core";
|
|
3
|
+
import { FILE_UPLOAD_KEY, UPPY_FILE_UPLOAD_ENDPOINT } from "./constants.js";
|
|
4
|
+
import { fetchData } from "./utils.js";
|
|
5
|
+
|
|
6
|
+
export default class FileUpload {
|
|
7
|
+
static accessKey;
|
|
8
|
+
constructor(key) {
|
|
9
|
+
FileUpload.accessKey = key;
|
|
10
|
+
}
|
|
11
|
+
uploadFile({ file, objMetaData, scanId }) {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
const uppyIns = new Uppy({ autoProceed: true });
|
|
14
|
+
uppyIns.use(AwsS3Multipart, {
|
|
15
|
+
limit: 10,
|
|
16
|
+
retryDelays: [0, 1000, 3000, 5000],
|
|
17
|
+
getChunkSize: () => 5 * 1024 * 1024,
|
|
18
|
+
createMultipartUpload: (file) => {
|
|
19
|
+
const objectKey = `${scanId}.${file.extension}`;
|
|
20
|
+
return fetchData({
|
|
21
|
+
path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_START,
|
|
22
|
+
apiKey: FILE_UPLOAD_KEY,
|
|
23
|
+
body: {
|
|
24
|
+
objectKey,
|
|
25
|
+
contentType: file.type,
|
|
26
|
+
objectMetadata: objMetaData,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
completeMultipartUpload: (file, { uploadId, key, parts }) =>
|
|
31
|
+
fetchData({
|
|
32
|
+
path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_COMPLETE,
|
|
33
|
+
apiKey: FILE_UPLOAD_KEY,
|
|
34
|
+
body: {
|
|
35
|
+
uploadId,
|
|
36
|
+
objectKey: key,
|
|
37
|
+
parts,
|
|
38
|
+
originalFileName: file.name,
|
|
39
|
+
},
|
|
40
|
+
}),
|
|
41
|
+
|
|
42
|
+
signPart: (file, partData) =>
|
|
43
|
+
fetchData({
|
|
44
|
+
path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_SIGN_PART,
|
|
45
|
+
apiKey: FILE_UPLOAD_KEY,
|
|
46
|
+
body: {
|
|
47
|
+
objectKey: partData.key,
|
|
48
|
+
uploadId: partData.uploadId,
|
|
49
|
+
partNumber: partData.partNumber,
|
|
50
|
+
},
|
|
51
|
+
}),
|
|
52
|
+
|
|
53
|
+
abortMultipartUpload: (file, { uploadId, key }) =>
|
|
54
|
+
fetchData({
|
|
55
|
+
path: UPPY_FILE_UPLOAD_ENDPOINT.UPLOAD_ABORT,
|
|
56
|
+
apiKey: FILE_UPLOAD_KEY,
|
|
57
|
+
body: {
|
|
58
|
+
uploadId,
|
|
59
|
+
objectKey: key,
|
|
60
|
+
originalFileName: file.name,
|
|
61
|
+
},
|
|
62
|
+
}),
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
uppyIns.addFile({
|
|
66
|
+
source: "manual",
|
|
67
|
+
name: file.name,
|
|
68
|
+
type: file.type,
|
|
69
|
+
data: file,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
uppyIns.on("upload-error", (file, error, response) => {
|
|
73
|
+
reject(error);
|
|
74
|
+
});
|
|
75
|
+
uppyIns.on("upload-success", () => {
|
|
76
|
+
resolve({ message: "file uploaded successfully" });
|
|
77
|
+
});
|
|
78
|
+
uppyIns.on("complete", (result) => {
|
|
79
|
+
if (uppyIns) {
|
|
80
|
+
uppyIns.close();
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
package/index.js
CHANGED
|
@@ -1,77 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
addUser({ scanId, email, name, height, gender, offsetMarketingConsent }) {
|
|
28
|
-
return addUser({ scanId, email, name, height, gender, offsetMarketingConsent, accessKey: this.accessKey });
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
getUserDetail(email) {
|
|
32
|
-
return getUserDetail(email, this.accessKey);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
uploadFile({ file, objMetaData, scanId }) {
|
|
36
|
-
return uploadFile({ file, objMetaData, scanId, accessKey: this.accessKey });
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
getModelUrl(id) {
|
|
40
|
-
return getModelUrl(id, this.accessKey);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
getCustomCustomerConfig(storeUrl) {
|
|
44
|
-
return getCustomCustomerConfig(storeUrl, this.accessKey);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
getMeasurementStatus(scanId) {
|
|
48
|
-
return getMeasurementStatus(scanId, this.accessKey);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
getTryOnMeasurements({ scanId, shopDomain, productName }) {
|
|
52
|
-
return getTryOnMeasurements({ scanId, shopDomain, productName, accessKey: this.accessKey });
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
handleTryOnSocket({ shopDomain, scanId, productName, onError, onSuccess, onClose, onOpen }) {
|
|
56
|
-
return handleTryOnSocket({
|
|
57
|
-
shopDomain,
|
|
58
|
-
scanId,
|
|
59
|
-
productName,
|
|
60
|
-
accessKey: this.accessKey,
|
|
61
|
-
onError,
|
|
62
|
-
onSuccess,
|
|
63
|
-
onClose,
|
|
64
|
-
onOpen,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
handleMeasurementSocket({ scanId, onError, onSuccess, onClose, onOpen }) {
|
|
69
|
-
return handleMeasurementSocket({ scanId, accessKey: this.accessKey, onError, onSuccess, onClose, onOpen });
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
handleAuthSocket({ email, scanId, onError, onSuccess, onClose, onOpen }) {
|
|
73
|
-
return handleAuthSocket({ email, scanId, accessKey: this.accessKey, onError, onSuccess, onClose, onOpen });
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
handlePoseDetectionSocket = handlePoseDetectionSocket;
|
|
77
|
-
}
|
|
1
|
+
import Auth from "./auth.js";
|
|
2
|
+
import Custom from "./custom.js";
|
|
3
|
+
import FileUpload from "./fileUpload.js";
|
|
4
|
+
import Measurement from "./measurement.js";
|
|
5
|
+
import PoseDetection from "./poseDetection.js";
|
|
6
|
+
export default class Swan {
|
|
7
|
+
static accessKey;
|
|
8
|
+
constructor(key) {
|
|
9
|
+
if (key !== 9876543210) {
|
|
10
|
+
throw new Error("wrong access key");
|
|
11
|
+
}
|
|
12
|
+
Swan.accessKey = key;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
auth = new Auth(Swan.accessKey);
|
|
16
|
+
|
|
17
|
+
custom = new Custom(Swan.accessKey);
|
|
18
|
+
|
|
19
|
+
fileUpload = new FileUpload(Swan.accessKey);
|
|
20
|
+
|
|
21
|
+
measurement = new Measurement(Swan.accessKey);
|
|
22
|
+
|
|
23
|
+
poseDetection = new PoseDetection(Swan.accessKey);
|
|
24
|
+
}
|
package/measurement.js
CHANGED
|
@@ -1,136 +1,120 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
import {
|
|
3
|
-
API_ENDPOINTS,
|
|
4
|
-
APP_AUTH_BASE_URL,
|
|
5
|
-
APP_RECOMMENDATION_WEBSOCKET_URL,
|
|
6
|
-
APP_TRY_ON_WEBSOCKET_URL,
|
|
7
|
-
FILE_UPLOAD_KEY,
|
|
8
|
-
} from "./constants.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
onError,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
tryOnSocketRef.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
measurementSocketRef.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (data?.code === 200 && data?.scanStatus === "success") {
|
|
122
|
-
onSuccess?.(data);
|
|
123
|
-
} else {
|
|
124
|
-
onError?.(data);
|
|
125
|
-
}
|
|
126
|
-
clearTimeout(timerWaitingRef);
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
measurementSocketRef.onclose = () => {
|
|
130
|
-
onClose?.();
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
measurementSocketRef.onerror = (event) => {
|
|
134
|
-
onError?.(event);
|
|
135
|
-
};
|
|
136
|
-
};
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import {
|
|
3
|
+
API_ENDPOINTS,
|
|
4
|
+
APP_AUTH_BASE_URL,
|
|
5
|
+
APP_RECOMMENDATION_WEBSOCKET_URL,
|
|
6
|
+
APP_TRY_ON_WEBSOCKET_URL,
|
|
7
|
+
FILE_UPLOAD_KEY,
|
|
8
|
+
} from "./constants.js";
|
|
9
|
+
|
|
10
|
+
export default class Measurement {
|
|
11
|
+
static accessKey;
|
|
12
|
+
constructor(key) {
|
|
13
|
+
Measurement.accessKey = key;
|
|
14
|
+
}
|
|
15
|
+
static tryOnSocketRef = null;
|
|
16
|
+
static measurementSocketRef = null;
|
|
17
|
+
static timerPollingRef = null;
|
|
18
|
+
static timerWaitingRef = null;
|
|
19
|
+
|
|
20
|
+
getMeasurementStatus(scanId) {
|
|
21
|
+
const url = `${APP_AUTH_BASE_URL}/measurements?scanId=${scanId}`;
|
|
22
|
+
return axios.get(url, {
|
|
23
|
+
headers: { "X-Api-Key": FILE_UPLOAD_KEY },
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
getTryOnMeasurements({ scanId, shopDomain, productName }) {
|
|
28
|
+
const tryOnUrl = `${APP_AUTH_BASE_URL}${API_ENDPOINTS.TRY_ON}/${scanId}/shop/${shopDomain}/product/${productName}`;
|
|
29
|
+
return axios.get(tryOnUrl);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
handleTryOnSocket({ shopDomain, scanId, productName, onError, onSuccess, onClose, onOpen }) {
|
|
33
|
+
Measurement.tryOnSocketRef?.close();
|
|
34
|
+
|
|
35
|
+
const url = `${APP_TRY_ON_WEBSOCKET_URL}/develop?store_url=${shopDomain}&product_name=${productName}&scan_id=${scanId}`;
|
|
36
|
+
Measurement.tryOnSocketRef = new WebSocket(url);
|
|
37
|
+
|
|
38
|
+
Measurement.tryOnSocketRef.onopen = () => {
|
|
39
|
+
onOpen?.();
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
Measurement.tryOnSocketRef.onmessage = (event) => {
|
|
43
|
+
const data = JSON.parse(event.data);
|
|
44
|
+
if (data?.tryOnProcessStatus === "available") {
|
|
45
|
+
onSuccess?.(data);
|
|
46
|
+
} else {
|
|
47
|
+
onError?.({ message: "failed to get image urls" });
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
Measurement.tryOnSocketRef.onclose = () => {
|
|
52
|
+
onClose?.();
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
Measurement.tryOnSocketRef.onerror = (event) => {
|
|
56
|
+
onError?.(event);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static getMeasurementsCheck = async (onSuccess, onError, scanId) => {
|
|
61
|
+
try {
|
|
62
|
+
const res = await getMeasurementStatus(scanId);
|
|
63
|
+
if (res?.data && res?.data?.[0]?.isMeasured === true) {
|
|
64
|
+
onSuccess?.(res?.data);
|
|
65
|
+
clearInterval(Measurement.timerPollingRef);
|
|
66
|
+
}
|
|
67
|
+
} catch (e) {
|
|
68
|
+
clearInterval(Measurement.timerPollingRef);
|
|
69
|
+
onError?.(e);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
static handlePolling(onSuccess, onError) {
|
|
74
|
+
clearInterval(Measurement.timerPollingRef);
|
|
75
|
+
Measurement.timerPollingRef = setInterval(() => {
|
|
76
|
+
Measurement.getMeasurementsCheck(onSuccess, onError);
|
|
77
|
+
}, 5000);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
static disconnectSocket = () => {
|
|
81
|
+
Measurement.measurementSocketRef?.close();
|
|
82
|
+
clearTimeout(Measurement.timerWaitingRef);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
static handleTimeOut = (onSuccess, onError) => {
|
|
86
|
+
Measurement.timerWaitingRef = setTimeout(() => {
|
|
87
|
+
Measurement.handlePolling(onSuccess, onError);
|
|
88
|
+
disconnectSocket();
|
|
89
|
+
}, 2 * 60000);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
handleMeasurementSocket = ({ scanId, onError, onSuccess, onClose, onOpen }) => {
|
|
93
|
+
Measurement.disconnectSocket();
|
|
94
|
+
const url = `${APP_RECOMMENDATION_WEBSOCKET_URL}?scanId=${scanId}`;
|
|
95
|
+
Measurement.measurementSocketRef = new WebSocket(url);
|
|
96
|
+
|
|
97
|
+
Measurement.measurementSocketRef.onopen = () => {
|
|
98
|
+
onOpen?.();
|
|
99
|
+
Measurement.handleTimeOut(onSuccess, onError);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
Measurement.measurementSocketRef.onmessage = (event) => {
|
|
103
|
+
const data = JSON.parse(event.data);
|
|
104
|
+
if (data?.code === 200 && data?.scanStatus === "success") {
|
|
105
|
+
onSuccess?.(data);
|
|
106
|
+
} else {
|
|
107
|
+
onError?.(data);
|
|
108
|
+
}
|
|
109
|
+
clearTimeout(Measurement.timerWaitingRef);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
Measurement.measurementSocketRef.onclose = () => {
|
|
113
|
+
onClose?.();
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
Measurement.measurementSocketRef.onerror = (event) => {
|
|
117
|
+
onError?.(event);
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
}
|
package/package.json
CHANGED
package/poseDetection.js
CHANGED
|
@@ -1,44 +1,46 @@
|
|
|
1
|
-
import { APP_POSE_DETECTION_WEbSOCKET_URL } from "./constants.js";
|
|
2
|
-
import { io } from "socket.io-client";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
1
|
+
import { APP_POSE_DETECTION_WEbSOCKET_URL } from "./constants.js";
|
|
2
|
+
import { io } from "socket.io-client";
|
|
3
|
+
|
|
4
|
+
export default class PoseDetection {
|
|
5
|
+
static socket = null;
|
|
6
|
+
static accessKey;
|
|
7
|
+
constructor(key) {
|
|
8
|
+
PoseDetection.accessKey = key;
|
|
9
|
+
}
|
|
10
|
+
connect() {
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
PoseDetection.socket = io.connect(APP_POSE_DETECTION_WEbSOCKET_URL);
|
|
13
|
+
PoseDetection.socket?.on("connect", () => {
|
|
14
|
+
resolve(PoseDetection.socket.id); // "G5p5..."
|
|
15
|
+
});
|
|
16
|
+
PoseDetection.socket?.on("connect_error", (err) => reject(err));
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
videoEmit({ image, scanId }) {
|
|
21
|
+
if (!PoseDetection.socket) {
|
|
22
|
+
throw new Error("socket is not connected");
|
|
23
|
+
}
|
|
24
|
+
PoseDetection.socket.emit("video", {
|
|
25
|
+
image,
|
|
26
|
+
user_unique_key: scanId,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
disconnect() {
|
|
31
|
+
PoseDetection.socket?.disconnect?.();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
poseStatus(callBack) {
|
|
35
|
+
if (!PoseDetection.socket) {
|
|
36
|
+
throw new Error("socket is not connected");
|
|
37
|
+
}
|
|
38
|
+
PoseDetection.socket.on("pose_status", (data) => {
|
|
39
|
+
callBack(data);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
connected() {
|
|
44
|
+
return !!PoseDetection.socket?.connected;
|
|
45
|
+
}
|
|
46
|
+
}
|