@reactoo/watchtogether-sdk-js 2.7.36 → 2.7.37

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactoo/watchtogether-sdk-js",
3
- "version": "2.7.36",
3
+ "version": "2.7.37",
4
4
  "description": "Javascript SDK for Reactoo",
5
5
  "main": "src/index.js",
6
6
  "unpkg": "dist/watchtogether-sdk.min.js",
package/src/models/iot.js CHANGED
@@ -5,12 +5,14 @@ let iot = function () {
5
5
  let visibilityChangeHandler = null;
6
6
  let keepAliveIntervalId = null;
7
7
  let shouldBeConnected = false;
8
+ let isReconnecting = false;
8
9
 
9
10
  return {
10
11
 
11
12
  __promise: null,
12
13
 
13
14
  __updateCredentials: () => {
15
+ isReconnecting = true;
14
16
  return this.iot.getCredentials()
15
17
  .then(response => this.__privates.iot.updateWebSocketCredentials(
16
18
  response.data.credentials.accessKeyId,
@@ -22,6 +24,9 @@ let iot = function () {
22
24
  this.__privates.iot.log('Failed to update credentials:', error);
23
25
  // Let the error propagate to be handled by the Iot class
24
26
  throw error;
27
+ })
28
+ .finally(() => {
29
+ isReconnecting = false;
25
30
  });
26
31
  },
27
32
 
@@ -36,7 +41,7 @@ let iot = function () {
36
41
  },
37
42
  onClosed: () => {
38
43
  this.__privates.iot.log('MQTT client closed');
39
- if(shouldBeConnected) {
44
+ if(shouldBeConnected && !isReconnecting) {
40
45
  this.iot.__updateCredentials();
41
46
  }
42
47
  },
@@ -252,20 +252,21 @@ class Iot {
252
252
  this.log('iot updateWebSocketCredentials');
253
253
  this.lastConnectParams = {...this.lastConnectParams, accessKeyId, secretAccessKey, sessionToken, expiration };
254
254
  const currentTopics = new Set(this.subscribedTopics);
255
- return this.disconnect()
256
- .then(() => this.connect(
257
- this.lastConnectParams.apiMqttUrl,
258
- this.lastConnectParams.apiMqttClientId,
259
- this.lastConnectParams.region,
260
- accessKeyId,
261
- secretAccessKey,
262
- sessionToken,
263
- expiration
264
- ))
265
- .then(() => {
266
- // Resubscribe to topics
267
- currentTopics.forEach(topic => this.subscribe(topic));
268
- this.startCredentialsExpirationCheck(expiration);
255
+
256
+ // disconnect is part of connect process
257
+
258
+ return this.connect(
259
+ this.lastConnectParams.apiMqttUrl,
260
+ this.lastConnectParams.apiMqttClientId,
261
+ this.lastConnectParams.region,
262
+ accessKeyId,
263
+ secretAccessKey,
264
+ sessionToken,
265
+ expiration
266
+ ).then(() => {
267
+ // Resubscribe to topics
268
+ currentTopics.forEach(topic => this.subscribe(topic));
269
+ this.startCredentialsExpirationCheck(expiration);
269
270
  })
270
271
  }
271
272