@reactoo/watchtogether-sdk-js 2.7.65 → 2.7.67-beta.0
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 +14 -2
- package/src/modules/wt-iot2.js +18 -2
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;
|
|
@@ -53,6 +58,7 @@ let iot = function () {
|
|
|
53
58
|
this.__privates.iot.log('MQTT client closed');
|
|
54
59
|
if(shouldBeConnected && !isReconnecting) {
|
|
55
60
|
this.__privates.iot.log('Connection unexpectedly closed, reconnecting...');
|
|
61
|
+
this.iot.__createNewWorker();
|
|
56
62
|
this.iot.__updateCredentials();
|
|
57
63
|
}
|
|
58
64
|
},
|
|
@@ -65,6 +71,7 @@ let iot = function () {
|
|
|
65
71
|
onInterrupt: (data, connectionId) => {
|
|
66
72
|
if(shouldBeConnected && !isReconnecting && interruptCount > 10) {
|
|
67
73
|
this.__privates.iot.log('Interrupt count exceeded, reconnecting...');
|
|
74
|
+
this.iot.__createNewWorker();
|
|
68
75
|
this.iot.__updateCredentials();
|
|
69
76
|
}
|
|
70
77
|
interruptCount++;
|
|
@@ -79,6 +86,7 @@ let iot = function () {
|
|
|
79
86
|
onConnectionFailure: (data, connectionId) => {
|
|
80
87
|
if(shouldBeConnected && !isReconnecting && interruptCount > 10) {
|
|
81
88
|
this.__privates.iot.log('Interrupt count exceeded, reconnecting...');
|
|
89
|
+
this.iot.__createNewWorker();
|
|
82
90
|
this.iot.__updateCredentials();
|
|
83
91
|
}
|
|
84
92
|
interruptCount++;
|
|
@@ -149,6 +157,7 @@ let iot = function () {
|
|
|
149
157
|
if(!keepCurrentTopics) {
|
|
150
158
|
__currentTopics.clear();
|
|
151
159
|
this.__privates.iot.clearTopics();
|
|
160
|
+
this.__privates.iot.terminateWorker();
|
|
152
161
|
}
|
|
153
162
|
|
|
154
163
|
interruptCount = 0;
|
|
@@ -199,6 +208,7 @@ let iot = function () {
|
|
|
199
208
|
|
|
200
209
|
if(shouldBeConnected && !isReconnecting && subscriptionFailureCount > 5) {
|
|
201
210
|
this.__privates.iot.log('Subscription failure exceeded, reconnecting...');
|
|
211
|
+
this.iot.__createNewWorker();
|
|
202
212
|
this.iot.__updateCredentials();
|
|
203
213
|
return Promise.reject('subscription_failed');
|
|
204
214
|
}
|
|
@@ -263,6 +273,7 @@ let iot = function () {
|
|
|
263
273
|
}
|
|
264
274
|
|
|
265
275
|
this.__privates.iot.log('Connection check failed:', error);
|
|
276
|
+
this.iot.__createNewWorker();
|
|
266
277
|
return this.iot.__updateCredentials();
|
|
267
278
|
});
|
|
268
279
|
},
|
|
@@ -277,12 +288,13 @@ let iot = function () {
|
|
|
277
288
|
.catch(error => {
|
|
278
289
|
|
|
279
290
|
if(error?.cause === -1) {
|
|
280
|
-
this.__privates.iot.log("We don't have a topic to check connection with");
|
|
291
|
+
this.__privates.iot.log("We don't have a topic to check connection with or check was aborted");
|
|
281
292
|
return;
|
|
282
293
|
}
|
|
283
294
|
|
|
284
|
-
if(
|
|
295
|
+
if(shouldBeConnected && !isReconnecting) {
|
|
285
296
|
this.__privates.iot.log('Keepalive failed:', error);
|
|
297
|
+
this.iot.__createNewWorker();
|
|
286
298
|
this.iot.__updateCredentials();
|
|
287
299
|
}
|
|
288
300
|
});
|
package/src/modules/wt-iot2.js
CHANGED
|
@@ -11,7 +11,7 @@ class Iot {
|
|
|
11
11
|
this.currentCredentialsExpirationStamp = null;
|
|
12
12
|
this.lastConnectParams = null;
|
|
13
13
|
this.subscribedTopics = new Set();
|
|
14
|
-
this.
|
|
14
|
+
this.abortController = null;
|
|
15
15
|
this.initWorker();
|
|
16
16
|
|
|
17
17
|
if (enableDebugFlag) {
|
|
@@ -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()
|
|
@@ -39,6 +43,7 @@ class Iot {
|
|
|
39
43
|
})
|
|
40
44
|
.then(() => {
|
|
41
45
|
this.log('iot connect');
|
|
46
|
+
this.abortController = new AbortController();
|
|
42
47
|
this.startCredentialsExpirationCheck(expiration);
|
|
43
48
|
this.lastConnectParams = { apiMqttUrl, apiMqttClientId, region, accessKeyId, secretAccessKey, sessionToken, expiration };
|
|
44
49
|
|
|
@@ -56,7 +61,6 @@ class Iot {
|
|
|
56
61
|
clearTimeout(timeoutId);
|
|
57
62
|
this.off('worker:connect_result', handleConnectResult);
|
|
58
63
|
if (event.success) {
|
|
59
|
-
this.currentConnectionId = event.connectionId;
|
|
60
64
|
resolve();
|
|
61
65
|
} else {
|
|
62
66
|
reject(new Error(event.error));
|
|
@@ -82,6 +86,7 @@ class Iot {
|
|
|
82
86
|
disconnect() {
|
|
83
87
|
this.log('iot disconnect');
|
|
84
88
|
this.stopCredentialsExpirationCheck();
|
|
89
|
+
this.abortController?.abort();
|
|
85
90
|
return new Promise((resolve, reject) => {
|
|
86
91
|
|
|
87
92
|
const stamp = new Date().getTime();
|
|
@@ -373,12 +378,23 @@ class Iot {
|
|
|
373
378
|
|
|
374
379
|
const timeoutId = setTimeout(() => {
|
|
375
380
|
this.off('message', checkMessageHandler);
|
|
381
|
+
this.abortController.signal.removeEventListener('abort', abort);
|
|
376
382
|
reject(new Error('Connection check timeout'));
|
|
377
383
|
}, 5000);
|
|
378
384
|
|
|
385
|
+
const abort = () => {
|
|
386
|
+
clearTimeout(timeoutId);
|
|
387
|
+
this.off('message', checkMessageHandler);
|
|
388
|
+
this.abortController.signal.removeEventListener('abort', abort);
|
|
389
|
+
reject(new Error('Connection check aborted', {cause: -1}));
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
this.abortController.signal.addEventListener('abort', abort);
|
|
393
|
+
|
|
379
394
|
const checkMessageHandler = (message) => {
|
|
380
395
|
if (message.type === 'keep_alive' && message.timestamp === testMessage.timestamp) {
|
|
381
396
|
clearTimeout(timeoutId);
|
|
397
|
+
this.abortController.signal.removeEventListener('abort', abort);
|
|
382
398
|
this.off('message', checkMessageHandler);
|
|
383
399
|
resolve();
|
|
384
400
|
}
|