@reactoo/watchtogether-sdk-js 2.7.39 → 2.7.41

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.39",
3
+ "version": "2.7.41",
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
@@ -13,6 +13,7 @@ let iot = function () {
13
13
  __promise: null,
14
14
 
15
15
  __updateCredentials: () => {
16
+ this.__privates.iot.log('Updating Credentials...');
16
17
  interruptCount = 0;
17
18
  isReconnecting = true;
18
19
  return this.iot.getCredentials()
@@ -23,10 +24,7 @@ let iot = function () {
23
24
  response.data.credentials.expiration
24
25
  ))
25
26
  .catch(error => {
26
- console.log('Failed to update credentials:', error);
27
27
  this.__privates.iot.log('Failed to update credentials:', error);
28
- // Let the error propagate to be handled by the Iot class
29
- throw error;
30
28
  })
31
29
  .finally(() => {
32
30
  isReconnecting = false;
@@ -45,6 +43,7 @@ let iot = function () {
45
43
  onClosed: () => {
46
44
  this.__privates.iot.log('MQTT client closed');
47
45
  if(shouldBeConnected && !isReconnecting) {
46
+ this.__privates.iot.log('Connection unexpectedly closed, reconnecting...');
48
47
  this.iot.__updateCredentials();
49
48
  }
50
49
  },
@@ -56,6 +55,7 @@ let iot = function () {
56
55
  },
57
56
  onInterrupt: () => {
58
57
  if(shouldBeConnected && !isReconnecting && !document.hidden && interruptCount > 10) {
58
+ this.__privates.iot.log('Interrupt count exceeded, reconnecting...');
59
59
  this.iot.__updateCredentials();
60
60
  }
61
61
  interruptCount++;
@@ -109,6 +109,7 @@ let iot = function () {
109
109
  this.iot.$on('resume', this.iot.onResume, this);
110
110
  this.iot.$on('connection_success', this.iot.onConnectionSuccess, this);
111
111
  this.iot.$on('connection_failure', this.iot.onConnectionFailure, this);
112
+ this.iot.$on('updateCredentials', this.iot.__updateCredentials, this);
112
113
 
113
114
  this.iot.__promise
114
115
  .then(([suggestedTopic, instance]) => {
@@ -118,10 +119,6 @@ let iot = function () {
118
119
  let topics = new Set([...suggestedTopic, ...__currentTopicsCopy]); // Filter out any undefined or null topics
119
120
  return Promise.all(Array.from(topics).map(topic => this.iot.subscribe(topic))).then(() => instance)
120
121
  })
121
- .then((instance) => {
122
- this.iot.$on('updateCredentials', this.iot.__updateCredentials, this);
123
- return instance;
124
- })
125
122
  .catch((error) => {
126
123
  this.__privates.iot.log('MQTT Login Error:', error);
127
124
  throw error;
@@ -151,6 +148,7 @@ let iot = function () {
151
148
  this.iot.$off('resume', this.iot.onResume, this);
152
149
  this.iot.$off('connection_success', this.iot.onConnectionSuccess, this);
153
150
  this.iot.$off('connection_failure', this.iot.onConnectionFailure, this);
151
+ this.iot.$off('updateCredentials', this.iot.__updateCredentials, this);
154
152
 
155
153
  this.iot.__promise = null;
156
154
  return true;
@@ -200,6 +198,12 @@ let iot = function () {
200
198
  checkConnection: () => {
201
199
  return this.__privates.iot.checkConnection()
202
200
  .catch(error => {
201
+
202
+ if(!shouldBeConnected || isReconnecting) {
203
+ this.__privates.iot.log('Ignoring connection check failure, not connected');
204
+ return Promise.resolve();
205
+ }
206
+
203
207
  this.__privates.iot.log('Connection check failed:', error);
204
208
  return this.iot.__updateCredentials();
205
209
  });
@@ -208,8 +212,14 @@ let iot = function () {
208
212
  setupKeepAliveInterval: () => {
209
213
  clearInterval(keepAliveIntervalId);
210
214
  keepAliveIntervalId = setInterval(() => {
211
- this.__privates.iot.keepAliveMessage();
212
- }, 30000);
215
+ this.__privates.iot.checkConnection()
216
+ .catch(error => {
217
+ if(!document.hidden && shouldBeConnected && !isReconnecting) {
218
+ this.__privates.iot.log('Keepalive failed:', error);
219
+ this.iot.__updateCredentials();
220
+ }
221
+ });
222
+ }, 15000);
213
223
  },
214
224
 
215
225
  disableKeepAliveInterval: () => {
@@ -29,6 +29,7 @@ class Iot {
29
29
  return this.disconnect()
30
30
  .finally(() => {
31
31
  this.log('iot connect');
32
+ this.startCredentialsExpirationCheck(expiration);
32
33
  this.lastConnectParams = { apiMqttUrl, apiMqttClientId, region, accessKeyId, secretAccessKey, sessionToken, expiration };
33
34
 
34
35
  const configBuilder = iot.AwsIotMqttConnectionConfigBuilder.new_with_websockets();
@@ -83,11 +84,7 @@ class Iot {
83
84
  this.emit('connection_failure', error);
84
85
  });
85
86
 
86
- return this.connection.connect()
87
- .then(() => {
88
- this.startCredentialsExpirationCheck(expiration);
89
- });
90
-
87
+ return this.connection.connect();
91
88
  });
92
89
  }
93
90
 
@@ -237,6 +234,7 @@ class Iot {
237
234
  const currentTimeStamp = new Date().getTime();
238
235
  // update 15 minutes before expiration
239
236
  if(this.currentCredentialsExpirationStamp - currentTimeStamp <= 900000) {
237
+ this.log('iot credentials expired, updating');
240
238
  this.emit('updateCredentials');
241
239
  }
242
240
  }, 5000);
@@ -263,7 +261,6 @@ class Iot {
263
261
  ).then(() => {
264
262
  // Resubscribe to topics
265
263
  currentTopics.forEach(topic => this.subscribe(topic));
266
- this.startCredentialsExpirationCheck(expiration);
267
264
  })
268
265
  }
269
266
 
@@ -280,7 +277,11 @@ class Iot {
280
277
  }
281
278
 
282
279
  // Find a suitable topic for the connection check
283
- const suitableTopic = Array.from(this.subscribedTopics).find(topic => topic.indexOf('user') > -1);
280
+ let suitableTopic = Array.from(this.subscribedTopics).find(topic => topic.indexOf('user') > -1);
281
+
282
+ if(!suitableTopic) {
283
+ suitableTopic = Array.from(this.subscribedTopics).find(topic => topic.indexOf('room') > -1 && topic !== 'wt/instanceroom/reactooDemo');
284
+ }
284
285
 
285
286
  if (!suitableTopic) {
286
287
  reject(new Error('No suitable topic found for connection check'));
@@ -288,7 +289,7 @@ class Iot {
288
289
  }
289
290
 
290
291
  const testMessage = {
291
- type: 'connection_check',
292
+ type: 'keep_alive',
292
293
  timestamp: Date.now()
293
294
  };
294
295
 
@@ -298,7 +299,7 @@ class Iot {
298
299
  }, 5000); // 5 seconds timeout
299
300
 
300
301
  const checkMessageHandler = (message) => {
301
- if (message.type === 'connection_check' && message.timestamp === testMessage.timestamp) {
302
+ if (message.type === 'keep_alive' && message.timestamp === testMessage.timestamp) {
302
303
  clearTimeout(timeoutId);
303
304
  this.off('message', checkMessageHandler);
304
305
  resolve();
@@ -316,29 +317,6 @@ class Iot {
316
317
  }
317
318
  });
318
319
  }
319
-
320
- keepAliveMessage() {
321
- if (this.subscribedTopics.size === 0) {
322
- this.log('No subscribed topics available for keep alive message');
323
- return;
324
- }
325
- // Find a suitable topic for the connection check
326
- const suitableTopic = Array.from(this.subscribedTopics).find(topic => topic.indexOf('user') > -1);
327
- if (!suitableTopic) {
328
- this.log('No suitable topic found for keep alive message');
329
- return;
330
- }
331
- const testMessage = {
332
- type: 'keep_alive',
333
- timestamp: Date.now()
334
- };
335
- try {
336
- this.send(suitableTopic, testMessage);
337
- }
338
- catch (error) {
339
- this.log(`Keep-alive error: ${error.message}`);
340
- }
341
- }
342
320
  }
343
321
 
344
322
  export default Iot;
@@ -2311,7 +2311,6 @@ class RoomSession {
2311
2311
  config.isIceRestarting = false;
2312
2312
  });
2313
2313
  }
2314
-
2315
2314
  }
2316
2315
 
2317
2316
  _setupTransceivers(handleId, [audioSend, audioRecv, videoSend, videoRecv, audioTransceiver = null, videoTransceiver = null]) {