@reactoo/watchtogether-sdk-js 2.7.40 → 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.
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @reactoo/watchtogether-sdk-js
3
- * @version 2.7.39
3
+ * @version 2.7.40
4
4
  */
5
5
  (function webpackUniversalModuleDefinition(root, factory) {
6
6
  if(typeof exports === 'object' && typeof module === 'object')
@@ -16715,13 +16715,11 @@ let iot = function () {
16715
16715
  return {
16716
16716
  __promise: null,
16717
16717
  __updateCredentials: () => {
16718
+ this.__privates.iot.log('Updating Credentials...');
16718
16719
  interruptCount = 0;
16719
16720
  isReconnecting = true;
16720
16721
  return this.iot.getCredentials().then(response => this.__privates.iot.updateWebSocketCredentials(response.data.credentials.accessKeyId, response.data.credentials.secretAccessKey, response.data.credentials.sessionToken, response.data.credentials.expiration)).catch(error => {
16721
- console.log('Failed to update credentials:', error);
16722
16722
  this.__privates.iot.log('Failed to update credentials:', error);
16723
- // Let the error propagate to be handled by the Iot class
16724
- throw error;
16725
16723
  }).finally(() => {
16726
16724
  isReconnecting = false;
16727
16725
  });
@@ -16740,6 +16738,7 @@ let iot = function () {
16740
16738
  onClosed: () => {
16741
16739
  this.__privates.iot.log('MQTT client closed');
16742
16740
  if (shouldBeConnected && !isReconnecting) {
16741
+ this.__privates.iot.log('Connection unexpectedly closed, reconnecting...');
16743
16742
  this.iot.__updateCredentials();
16744
16743
  }
16745
16744
  },
@@ -16751,6 +16750,7 @@ let iot = function () {
16751
16750
  },
16752
16751
  onInterrupt: () => {
16753
16752
  if (shouldBeConnected && !isReconnecting && !document.hidden && interruptCount > 10) {
16753
+ this.__privates.iot.log('Interrupt count exceeded, reconnecting...');
16754
16754
  this.iot.__updateCredentials();
16755
16755
  }
16756
16756
  interruptCount++;
@@ -16786,6 +16786,7 @@ let iot = function () {
16786
16786
  _this.iot.$on('resume', _this.iot.onResume, _this);
16787
16787
  _this.iot.$on('connection_success', _this.iot.onConnectionSuccess, _this);
16788
16788
  _this.iot.$on('connection_failure', _this.iot.onConnectionFailure, _this);
16789
+ _this.iot.$on('updateCredentials', _this.iot.__updateCredentials, _this);
16789
16790
  _this.iot.__promise.then(_ref => {
16790
16791
  let [suggestedTopic, instance] = _ref;
16791
16792
  if (!subscribeToSuggestedTopics) {
@@ -16793,9 +16794,6 @@ let iot = function () {
16793
16794
  }
16794
16795
  let topics = new Set([...suggestedTopic, ...__currentTopicsCopy]); // Filter out any undefined or null topics
16795
16796
  return Promise.all(Array.from(topics).map(topic => _this.iot.subscribe(topic))).then(() => instance);
16796
- }).then(instance => {
16797
- _this.iot.$on('updateCredentials', _this.iot.__updateCredentials, _this);
16798
- return instance;
16799
16797
  }).catch(error => {
16800
16798
  _this.__privates.iot.log('MQTT Login Error:', error);
16801
16799
  throw error;
@@ -16820,6 +16818,7 @@ let iot = function () {
16820
16818
  _this.iot.$off('resume', _this.iot.onResume, _this);
16821
16819
  _this.iot.$off('connection_success', _this.iot.onConnectionSuccess, _this);
16822
16820
  _this.iot.$off('connection_failure', _this.iot.onConnectionFailure, _this);
16821
+ _this.iot.$off('updateCredentials', _this.iot.__updateCredentials, _this);
16823
16822
  _this.iot.__promise = null;
16824
16823
  return true;
16825
16824
  });
@@ -16858,6 +16857,10 @@ let iot = function () {
16858
16857
  },
16859
16858
  checkConnection: () => {
16860
16859
  return this.__privates.iot.checkConnection().catch(error => {
16860
+ if (!shouldBeConnected || isReconnecting) {
16861
+ this.__privates.iot.log('Ignoring connection check failure, not connected');
16862
+ return Promise.resolve();
16863
+ }
16861
16864
  this.__privates.iot.log('Connection check failed:', error);
16862
16865
  return this.iot.__updateCredentials();
16863
16866
  });
@@ -16865,8 +16868,13 @@ let iot = function () {
16865
16868
  setupKeepAliveInterval: () => {
16866
16869
  clearInterval(keepAliveIntervalId);
16867
16870
  keepAliveIntervalId = setInterval(() => {
16868
- this.__privates.iot.keepAliveMessage();
16869
- }, 30000);
16871
+ this.__privates.iot.checkConnection().catch(error => {
16872
+ if (!document.hidden && shouldBeConnected && !isReconnecting) {
16873
+ this.__privates.iot.log('Keepalive failed:', error);
16874
+ this.iot.__updateCredentials();
16875
+ }
16876
+ });
16877
+ }, 15000);
16870
16878
  },
16871
16879
  disableKeepAliveInterval: () => {
16872
16880
  clearInterval(keepAliveIntervalId);
@@ -25265,6 +25273,7 @@ class Iot {
25265
25273
  this.log('iot connect called, we disconnect first just to be sure');
25266
25274
  return this.disconnect().finally(() => {
25267
25275
  this.log('iot connect');
25276
+ this.startCredentialsExpirationCheck(expiration);
25268
25277
  this.lastConnectParams = {
25269
25278
  apiMqttUrl,
25270
25279
  apiMqttClientId,
@@ -25313,9 +25322,7 @@ class Iot {
25313
25322
  this.connection.on('connection_failure', error => {
25314
25323
  this.emit('connection_failure', error);
25315
25324
  });
25316
- return this.connection.connect().then(() => {
25317
- this.startCredentialsExpirationCheck(expiration);
25318
- });
25325
+ return this.connection.connect();
25319
25326
  });
25320
25327
  }
25321
25328
  disconnect() {
@@ -25457,6 +25464,7 @@ class Iot {
25457
25464
  const currentTimeStamp = new Date().getTime();
25458
25465
  // update 15 minutes before expiration
25459
25466
  if (this.currentCredentialsExpirationStamp - currentTimeStamp <= 900000) {
25467
+ this.log('iot credentials expired, updating');
25460
25468
  this.emit('updateCredentials');
25461
25469
  }
25462
25470
  }, 5000);
@@ -25479,7 +25487,6 @@ class Iot {
25479
25487
  return this.connect(this.lastConnectParams.apiMqttUrl, this.lastConnectParams.apiMqttClientId, this.lastConnectParams.region, accessKeyId, secretAccessKey, sessionToken, expiration).then(() => {
25480
25488
  // Resubscribe to topics
25481
25489
  currentTopics.forEach(topic => this.subscribe(topic));
25482
- this.startCredentialsExpirationCheck(expiration);
25483
25490
  });
25484
25491
  }
25485
25492
  checkConnection() {
@@ -25503,7 +25510,7 @@ class Iot {
25503
25510
  return;
25504
25511
  }
25505
25512
  const testMessage = {
25506
- type: 'connection_check',
25513
+ type: 'keep_alive',
25507
25514
  timestamp: Date.now()
25508
25515
  };
25509
25516
  const timeoutId = setTimeout(() => {
@@ -25512,7 +25519,7 @@ class Iot {
25512
25519
  }, 5000); // 5 seconds timeout
25513
25520
 
25514
25521
  const checkMessageHandler = message => {
25515
- if (message.type === 'connection_check' && message.timestamp === testMessage.timestamp) {
25522
+ if (message.type === 'keep_alive' && message.timestamp === testMessage.timestamp) {
25516
25523
  clearTimeout(timeoutId);
25517
25524
  this.off('message', checkMessageHandler);
25518
25525
  resolve();
@@ -25528,30 +25535,6 @@ class Iot {
25528
25535
  }
25529
25536
  });
25530
25537
  }
25531
- keepAliveMessage() {
25532
- if (this.subscribedTopics.size === 0) {
25533
- this.log('No subscribed topics available for keep alive message');
25534
- return;
25535
- }
25536
- // Find a suitable topic for the connection check
25537
- let suitableTopic = Array.from(this.subscribedTopics).find(topic => topic.indexOf('user') > -1);
25538
- if (!suitableTopic) {
25539
- suitableTopic = Array.from(this.subscribedTopics).find(topic => topic.indexOf('room') > -1 && topic !== 'wt/instanceroom/reactooDemo');
25540
- }
25541
- if (!suitableTopic) {
25542
- this.log('No suitable topic found for keep alive message');
25543
- return;
25544
- }
25545
- const testMessage = {
25546
- type: 'keep_alive',
25547
- timestamp: Date.now()
25548
- };
25549
- try {
25550
- this.send(suitableTopic, testMessage);
25551
- } catch (error) {
25552
- this.log(`Keep-alive error: ${error.message}`);
25553
- }
25554
- }
25555
25538
  }
25556
25539
  /* harmony default export */ __webpack_exports__["default"] = (Iot);
25557
25540