@reactoo/watchtogether-sdk-js 2.7.69 → 2.7.71
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/dist/watchtogether-sdk.min.js +2 -2
- package/package.json +1 -1
- package/src/models/iot.js +1 -1
- package/src/modules/wt-iot2.js +38 -12
package/package.json
CHANGED
package/src/models/iot.js
CHANGED
|
@@ -99,7 +99,7 @@ let iot = function () {
|
|
|
99
99
|
interruptCount = 0;
|
|
100
100
|
subscriptionFailureCount = 0;
|
|
101
101
|
shouldBeConnected = true;
|
|
102
|
-
|
|
102
|
+
this.__privates.iot.initWorker();
|
|
103
103
|
this.iot.__promise = new Promise((resolve, reject) => {
|
|
104
104
|
this.iot.getCredentials()
|
|
105
105
|
.then(response => {
|
package/src/modules/wt-iot2.js
CHANGED
|
@@ -32,7 +32,7 @@ class Iot {
|
|
|
32
32
|
|
|
33
33
|
terminateWorker() {
|
|
34
34
|
this.log('iot terminateWorker');
|
|
35
|
-
this.worker
|
|
35
|
+
this.worker?.terminate();
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
connect(apiMqttUrl, apiMqttClientId, region, accessKeyId, secretAccessKey, sessionToken, expiration) {
|
|
@@ -44,13 +44,16 @@ class Iot {
|
|
|
44
44
|
})
|
|
45
45
|
.then(() => {
|
|
46
46
|
this.log('iot connect');
|
|
47
|
+
|
|
48
|
+
if(!this.worker) {
|
|
49
|
+
this.log('Worker not initialized');
|
|
50
|
+
return Promise.reject(new Error('Worker not initialized', {cause: -1}));
|
|
51
|
+
}
|
|
52
|
+
|
|
47
53
|
this.abortController = new AbortController();
|
|
48
|
-
this.initWorker();
|
|
49
54
|
this.startCredentialsExpirationCheck(expiration);
|
|
50
55
|
this.lastConnectParams = { apiMqttUrl, apiMqttClientId, region, accessKeyId, secretAccessKey, sessionToken, expiration };
|
|
51
|
-
|
|
52
56
|
return new Promise((resolve, reject) => {
|
|
53
|
-
|
|
54
57
|
const stamp = new Date().getTime();
|
|
55
58
|
|
|
56
59
|
const handleConnectResult = (event) => {
|
|
@@ -76,7 +79,7 @@ class Iot {
|
|
|
76
79
|
|
|
77
80
|
this.on('worker:connect_result', handleConnectResult);
|
|
78
81
|
|
|
79
|
-
this.worker
|
|
82
|
+
this.worker?.postMessage({
|
|
80
83
|
type: 'connect',
|
|
81
84
|
params: this.lastConnectParams,
|
|
82
85
|
stamp: stamp
|
|
@@ -89,6 +92,12 @@ class Iot {
|
|
|
89
92
|
this.log('iot disconnect');
|
|
90
93
|
this.stopCredentialsExpirationCheck();
|
|
91
94
|
this.abortController?.abort();
|
|
95
|
+
|
|
96
|
+
if(!this.worker) {
|
|
97
|
+
this.log('Worker not initialized');
|
|
98
|
+
return Promise.reject(new Error('Worker not initialized', {cause: -1}));
|
|
99
|
+
}
|
|
100
|
+
|
|
92
101
|
return new Promise((resolve, reject) => {
|
|
93
102
|
|
|
94
103
|
const stamp = new Date().getTime();
|
|
@@ -115,11 +124,17 @@ class Iot {
|
|
|
115
124
|
}, 5000);
|
|
116
125
|
|
|
117
126
|
this.on('worker:disconnect_result', handleDisconnectResult);
|
|
118
|
-
this.worker
|
|
127
|
+
this.worker?.postMessage({ type: 'disconnect', stamp: stamp });
|
|
119
128
|
});
|
|
120
129
|
}
|
|
121
130
|
|
|
122
131
|
isConnected() {
|
|
132
|
+
|
|
133
|
+
if(!this.worker) {
|
|
134
|
+
this.log('Worker not initialized');
|
|
135
|
+
return Promise.reject(new Error('Worker not initialized', {cause: -1}));
|
|
136
|
+
}
|
|
137
|
+
|
|
123
138
|
return new Promise((resolve) => {
|
|
124
139
|
const handleIsConnectedResult = (event) => {
|
|
125
140
|
this.off('worker:is_connected_result', handleIsConnectedResult);
|
|
@@ -127,20 +142,25 @@ class Iot {
|
|
|
127
142
|
};
|
|
128
143
|
|
|
129
144
|
this.on('worker:is_connected_result', handleIsConnectedResult);
|
|
130
|
-
this.worker
|
|
145
|
+
this.worker?.postMessage({ type: 'is_connected' });
|
|
131
146
|
});
|
|
132
147
|
}
|
|
133
148
|
|
|
134
149
|
clearTopics() {
|
|
135
150
|
this.subscribedTopics.clear();
|
|
136
|
-
this.worker
|
|
151
|
+
this.worker?.postMessage({ type: 'clear_topics' });
|
|
137
152
|
}
|
|
138
153
|
|
|
139
154
|
subscribe(topic) {
|
|
140
155
|
this.log('iot subscribe', topic);
|
|
141
156
|
if (typeof topic === 'string' && topic.trim() !== '') {
|
|
142
|
-
return new Promise((resolve, reject) => {
|
|
143
157
|
|
|
158
|
+
if(!this.worker) {
|
|
159
|
+
this.log('Worker not initialized');
|
|
160
|
+
return Promise.reject(new Error('Worker not initialized', {cause: -1}));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return new Promise((resolve, reject) => {
|
|
144
164
|
const stamp = new Date().getTime();
|
|
145
165
|
const handleSubscribeResult = (event) => {
|
|
146
166
|
|
|
@@ -159,7 +179,7 @@ class Iot {
|
|
|
159
179
|
};
|
|
160
180
|
|
|
161
181
|
this.on('worker:subscribe_result', handleSubscribeResult);
|
|
162
|
-
this.worker
|
|
182
|
+
this.worker?.postMessage({ type: 'subscribe', topic, stamp });
|
|
163
183
|
});
|
|
164
184
|
} else {
|
|
165
185
|
this.log('Invalid topic:', topic);
|
|
@@ -170,6 +190,12 @@ class Iot {
|
|
|
170
190
|
unsubscribe(topic) {
|
|
171
191
|
this.log('iot unsubscribe', topic);
|
|
172
192
|
if (typeof topic === 'string' && topic.trim() !== '') {
|
|
193
|
+
|
|
194
|
+
if(!this.worker) {
|
|
195
|
+
this.log('Worker not initialized');
|
|
196
|
+
return Promise.reject(new Error('Worker not initialized', {cause: -1}));
|
|
197
|
+
}
|
|
198
|
+
|
|
173
199
|
return new Promise((resolve, reject) => {
|
|
174
200
|
|
|
175
201
|
const stamp = new Date().getTime();
|
|
@@ -191,7 +217,7 @@ class Iot {
|
|
|
191
217
|
};
|
|
192
218
|
|
|
193
219
|
this.on('worker:unsubscribe_result', handleUnsubscribeResult);
|
|
194
|
-
this.worker
|
|
220
|
+
this.worker?.postMessage({ type: 'unsubscribe', topic, stamp });
|
|
195
221
|
});
|
|
196
222
|
} else {
|
|
197
223
|
this.log('Invalid topic:', topic);
|
|
@@ -202,7 +228,7 @@ class Iot {
|
|
|
202
228
|
send(topic, message) {
|
|
203
229
|
this.log('iot send', topic, message);
|
|
204
230
|
let msg = typeof message === 'object' ? JSON.stringify(message) : message;
|
|
205
|
-
this.worker
|
|
231
|
+
this.worker?.postMessage({ type: 'send', topic, message: msg });
|
|
206
232
|
}
|
|
207
233
|
|
|
208
234
|
handleWorkerMessage(event) {
|