@reactoo/watchtogether-sdk-js 2.7.64 → 2.7.66
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 +15 -3
- package/src/modules/wt-iot2.js +4 -0
package/package.json
CHANGED
package/src/models/iot.js
CHANGED
|
@@ -13,6 +13,11 @@ let iot = function () {
|
|
|
13
13
|
|
|
14
14
|
__promise: null,
|
|
15
15
|
|
|
16
|
+
__createNewWorker: () => {
|
|
17
|
+
this.__privates.iot.terminateWorker();
|
|
18
|
+
this.__privates.iot.initWorker();
|
|
19
|
+
},
|
|
20
|
+
|
|
16
21
|
__updateCredentials: () => {
|
|
17
22
|
this.__privates.iot.log('Updating Credentials...');
|
|
18
23
|
interruptCount = 0;
|
|
@@ -65,6 +70,7 @@ let iot = function () {
|
|
|
65
70
|
onInterrupt: (data, connectionId) => {
|
|
66
71
|
if(shouldBeConnected && !isReconnecting && interruptCount > 10) {
|
|
67
72
|
this.__privates.iot.log('Interrupt count exceeded, reconnecting...');
|
|
73
|
+
this.iot.__createNewWorker();
|
|
68
74
|
this.iot.__updateCredentials();
|
|
69
75
|
}
|
|
70
76
|
interruptCount++;
|
|
@@ -79,6 +85,7 @@ let iot = function () {
|
|
|
79
85
|
onConnectionFailure: (data, connectionId) => {
|
|
80
86
|
if(shouldBeConnected && !isReconnecting && interruptCount > 10) {
|
|
81
87
|
this.__privates.iot.log('Interrupt count exceeded, reconnecting...');
|
|
88
|
+
this.iot.__createNewWorker();
|
|
82
89
|
this.iot.__updateCredentials();
|
|
83
90
|
}
|
|
84
91
|
interruptCount++;
|
|
@@ -182,24 +189,29 @@ let iot = function () {
|
|
|
182
189
|
if(!__currentTopics.has(topic)) {
|
|
183
190
|
__currentTopics.add(topic);
|
|
184
191
|
if(!this.iot.__promise) return Promise.reject('not_connected');
|
|
185
|
-
// if subscription fails, remove the topic from the current topics
|
|
186
192
|
return this.iot.__promise
|
|
187
193
|
.then(() => this.__privates.iot.subscribe(topic))
|
|
188
194
|
.catch((error) => {
|
|
189
195
|
|
|
196
|
+
// if subscription fails, remove the topic from the current topics
|
|
190
197
|
__currentTopics.delete(topic);
|
|
191
198
|
|
|
192
199
|
if(error?.cause === -1) {
|
|
193
200
|
return Promise.reject('invalid_topic');
|
|
194
201
|
}
|
|
195
202
|
|
|
203
|
+
if(!shouldBeConnected || isReconnecting) {
|
|
204
|
+
return Promise.reject('subscription_failed');
|
|
205
|
+
}
|
|
206
|
+
|
|
196
207
|
if(shouldBeConnected && !isReconnecting && subscriptionFailureCount > 5) {
|
|
197
208
|
this.__privates.iot.log('Subscription failure exceeded, reconnecting...');
|
|
209
|
+
this.iot.__createNewWorker();
|
|
198
210
|
this.iot.__updateCredentials();
|
|
199
211
|
return Promise.reject('subscription_failed');
|
|
200
212
|
}
|
|
201
|
-
subscriptionFailureCount++;
|
|
202
213
|
|
|
214
|
+
subscriptionFailureCount++;
|
|
203
215
|
return this.subscribe(topic)
|
|
204
216
|
});
|
|
205
217
|
}
|
|
@@ -208,10 +220,10 @@ let iot = function () {
|
|
|
208
220
|
unsubscribe: (topic) => {
|
|
209
221
|
__currentTopics.delete(topic);
|
|
210
222
|
if(!this.iot.__promise) return Promise.reject('not_connected');
|
|
211
|
-
// if unsubscription fails add the topic back to the current topics
|
|
212
223
|
return this.iot.__promise
|
|
213
224
|
.then(() => this.__privates.iot.unsubscribe(topic))
|
|
214
225
|
.catch(() => {
|
|
226
|
+
// if unsubscription fails add the topic back to the current topics
|
|
215
227
|
__currentTopics.add(topic);
|
|
216
228
|
return Promise.reject('unsubscription_failed');
|
|
217
229
|
});
|
package/src/modules/wt-iot2.js
CHANGED
|
@@ -30,6 +30,10 @@ class Iot {
|
|
|
30
30
|
this.worker.onmessage = this.handleWorkerMessage.bind(this);
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
terminateWorker() {
|
|
34
|
+
this.worker.terminate();
|
|
35
|
+
}
|
|
36
|
+
|
|
33
37
|
connect(apiMqttUrl, apiMqttClientId, region, accessKeyId, secretAccessKey, sessionToken, expiration) {
|
|
34
38
|
this.log('iot connect called, we disconnect first just to be sure');
|
|
35
39
|
return this.disconnect()
|