@reactoo/watchtogether-sdk-js 2.7.38-beta.2 → 2.7.38-beta.4

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.35
3
+ * @version 2.7.38-beta.3
4
4
  */
5
5
  (function webpackUniversalModuleDefinition(root, factory) {
6
6
  if(typeof exports === 'object' && typeof module === 'object')
@@ -16711,11 +16711,14 @@ let iot = function () {
16711
16711
  let keepAliveIntervalId = null;
16712
16712
  let shouldBeConnected = false;
16713
16713
  let isReconnecting = false;
16714
+ let interruptCount = 0;
16714
16715
  return {
16715
16716
  __promise: null,
16716
16717
  __updateCredentials: () => {
16718
+ interruptCount = 0;
16717
16719
  isReconnecting = true;
16718
16720
  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);
16719
16722
  this.__privates.iot.log('Failed to update credentials:', error);
16720
16723
  // Let the error propagate to be handled by the Iot class
16721
16724
  throw error;
@@ -16741,25 +16744,37 @@ let iot = function () {
16741
16744
  }
16742
16745
  },
16743
16746
  onError: () => {
16747
+ console.log('MQTT client error');
16744
16748
  this.__privates.iot.log('MQTT client error');
16745
16749
  },
16746
16750
  onDisconnect: () => {
16751
+ console.log('MQTT client disconnect');
16747
16752
  this.__privates.iot.log('MQTT client disconnect');
16748
16753
  },
16749
16754
  onInterrupt: () => {
16755
+ if (shouldBeConnected && !isReconnecting && !document.hidden && interruptCount > 10) {
16756
+ this.iot.__updateCredentials();
16757
+ }
16758
+ interruptCount++;
16759
+ console.log('MQTT client interrupt');
16750
16760
  this.__privates.iot.log('MQTT client interrupt');
16751
16761
  },
16752
16762
  onResume: () => {
16763
+ console.log('MQTT client resume');
16753
16764
  this.__privates.iot.log('MQTT client resume');
16754
16765
  },
16755
16766
  onConnectionSuccess: () => {
16767
+ console.log('MQTT client connection_success');
16756
16768
  this.__privates.iot.log('MQTT client connection_success');
16757
16769
  },
16758
16770
  onConnectionFailure: () => {
16771
+ console.log('MQTT client connection_failure');
16759
16772
  this.__privates.iot.log('MQTT client connection_failure');
16760
16773
  },
16761
16774
  iotLogin: function () {
16762
16775
  let subscribeToSuggestedTopics = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
16776
+ interruptCount = 0;
16777
+ shouldBeConnected = true;
16763
16778
  _this.iot.__promise = new Promise((resolve, reject) => {
16764
16779
  _this.iot.getCredentials().then(response => {
16765
16780
  return Promise.all([response.data.suggestedTopics, _this.__privates.iot.connect(response.data.endpoint, response.data.clientId, response.data.region, response.data.credentials.accessKeyId, response.data.credentials.secretAccessKey, response.data.credentials.sessionToken, response.data.credentials.expiration)]);
@@ -16767,9 +16782,8 @@ let iot = function () {
16767
16782
  });
16768
16783
  let __currentTopicsCopy = new Set(__currentTopics); // Keep this line
16769
16784
  __currentTopics.clear();
16770
- shouldBeConnected = true;
16771
16785
  _this.iot.setupVisibilityChangeListener();
16772
- //this.iot.setupKeepAliveInterval();
16786
+ _this.iot.setupKeepAliveInterval();
16773
16787
  _this.iot.$on('connect', _this.iot.onConnect, _this);
16774
16788
  _this.iot.$on('closed', _this.iot.onClosed, _this);
16775
16789
  _this.iot.$on('error', _this.iot.onError, _this);
@@ -16799,10 +16813,11 @@ let iot = function () {
16799
16813
  if (!keepCurrentTopics) {
16800
16814
  __currentTopics.clear();
16801
16815
  }
16816
+ interruptCount = 0;
16817
+ shouldBeConnected = false;
16802
16818
  return _this.__privates.iot.disconnect().then(() => {
16803
- shouldBeConnected = false;
16804
16819
  _this.iot.disableVisibilityChangeListener();
16805
- //this.iot.disableKeepAliveInterval();
16820
+ _this.iot.disableKeepAliveInterval();
16806
16821
  _this.iot.$off('connect', _this.iot.onConnect, _this);
16807
16822
  _this.iot.$off('closed', _this.iot.onClosed, _this);
16808
16823
  _this.iot.$off('error', _this.iot.onError, _this);
@@ -16855,7 +16870,9 @@ let iot = function () {
16855
16870
  },
16856
16871
  setupKeepAliveInterval: () => {
16857
16872
  clearInterval(keepAliveIntervalId);
16858
- keepAliveIntervalId = setInterval(this.iot.checkConnection, 30000);
16873
+ keepAliveIntervalId = setInterval(() => {
16874
+ this.__privates.iot.keepAliveMessage();
16875
+ }, 30000);
16859
16876
  },
16860
16877
  disableKeepAliveInterval: () => {
16861
16878
  clearInterval(keepAliveIntervalId);
@@ -25237,7 +25254,6 @@ class Iot {
25237
25254
  Object.assign(this, (0,_wt_emitter__WEBPACK_IMPORTED_MODULE_0__["default"])());
25238
25255
  this.decoder = new TextDecoder('utf-8');
25239
25256
  this.log = Iot.noop;
25240
- // Remove: this.debugFlag = enableDebugFlag;
25241
25257
  this.credentialsExpirationCheckIntervalId = null;
25242
25258
  this.currentCredentialsExpirationStamp = null;
25243
25259
  this.lastConnectParams = null;
@@ -25465,9 +25481,7 @@ class Iot {
25465
25481
  expiration
25466
25482
  };
25467
25483
  const currentTopics = new Set(this.subscribedTopics);
25468
-
25469
25484
  // disconnect is part of connect process
25470
-
25471
25485
  return this.connect(this.lastConnectParams.apiMqttUrl, this.lastConnectParams.apiMqttClientId, this.lastConnectParams.region, accessKeyId, secretAccessKey, sessionToken, expiration).then(() => {
25472
25486
  // Resubscribe to topics
25473
25487
  currentTopics.forEach(topic => this.subscribe(topic));
@@ -25517,6 +25531,23 @@ class Iot {
25517
25531
  }
25518
25532
  });
25519
25533
  }
25534
+ keepAliveMessage() {
25535
+ if (this.subscribedTopics.size === 0) {
25536
+ this.log('No subscribed topics available for keep alive message');
25537
+ return;
25538
+ }
25539
+ // Find a suitable topic for the connection check
25540
+ const suitableTopic = Array.from(this.subscribedTopics).find(topic => topic.indexOf('user') > -1);
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
+ this.send(suitableTopic, testMessage);
25550
+ }
25520
25551
  }
25521
25552
  /* harmony default export */ __webpack_exports__["default"] = (Iot);
25522
25553