@reactoo/watchtogether-sdk-js 2.7.43 → 2.7.44-beta.2

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.40
3
+ * @version 2.7.43
4
4
  */
5
5
  (function webpackUniversalModuleDefinition(root, factory) {
6
6
  if(typeof exports === 'object' && typeof module === 'object')
@@ -16718,10 +16718,22 @@ let iot = function () {
16718
16718
  this.__privates.iot.log('Updating Credentials...');
16719
16719
  interruptCount = 0;
16720
16720
  isReconnecting = true;
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 => {
16722
- this.__privates.iot.log('Failed to update credentials:', error);
16721
+ this.iot.$emit('isReconnecting', isReconnecting);
16722
+ return new Promise((resolve, reject) => {
16723
+ const timeoutId = setTimeout(() => {
16724
+ reject(new Error('Updating Credentials Timeout...'));
16725
+ }, 10000); // 10 seconds timeout is enough
16726
+ 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)).then(() => {
16727
+ clearTimeout(timeoutId);
16728
+ resolve();
16729
+ }).catch(error => {
16730
+ clearTimeout(timeoutId);
16731
+ this.__privates.iot.log('Failed to update credentials:', error);
16732
+ reject(error);
16733
+ });
16723
16734
  }).finally(() => {
16724
16735
  isReconnecting = false;
16736
+ this.iot.$emit('isReconnecting', isReconnecting);
16725
16737
  });
16726
16738
  },
16727
16739
  getCredentials: () => {
@@ -16774,10 +16786,7 @@ let iot = function () {
16774
16786
  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)]);
16775
16787
  }).then(resolve).catch(reject);
16776
16788
  });
16777
- let __currentTopicsCopy = new Set(__currentTopics); // Keep this line
16778
16789
  __currentTopics.clear();
16779
- _this.iot.setupVisibilityChangeListener();
16780
- _this.iot.setupKeepAliveInterval();
16781
16790
  _this.iot.$on('connect', _this.iot.onConnect, _this);
16782
16791
  _this.iot.$on('closed', _this.iot.onClosed, _this);
16783
16792
  _this.iot.$on('error', _this.iot.onError, _this);
@@ -16792,8 +16801,12 @@ let iot = function () {
16792
16801
  if (!subscribeToSuggestedTopics) {
16793
16802
  return Promise.resolve(instance);
16794
16803
  }
16795
- let topics = new Set([...suggestedTopic, ...__currentTopicsCopy]); // Filter out any undefined or null topics
16804
+ let topics = new Set([...suggestedTopic]); // Filter out any undefined or null topics
16796
16805
  return Promise.all(Array.from(topics).map(topic => _this.iot.subscribe(topic))).then(() => instance);
16806
+ }).then(instance => {
16807
+ _this.iot.setupVisibilityChangeListener();
16808
+ _this.iot.setupKeepAliveInterval();
16809
+ return instance;
16797
16810
  }).catch(error => {
16798
16811
  _this.__privates.iot.log('MQTT Login Error:', error);
16799
16812
  throw error;
@@ -16804,12 +16817,13 @@ let iot = function () {
16804
16817
  let keepCurrentTopics = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
16805
16818
  if (!keepCurrentTopics) {
16806
16819
  __currentTopics.clear();
16820
+ _this.__privates.iot.clearTopics();
16807
16821
  }
16808
16822
  interruptCount = 0;
16809
16823
  shouldBeConnected = false;
16824
+ _this.iot.disableVisibilityChangeListener();
16825
+ _this.iot.disableKeepAliveInterval();
16810
16826
  return _this.__privates.iot.disconnect().then(() => {
16811
- _this.iot.disableVisibilityChangeListener();
16812
- _this.iot.disableKeepAliveInterval();
16813
16827
  _this.iot.$off('connect', _this.iot.onConnect, _this);
16814
16828
  _this.iot.$off('closed', _this.iot.onClosed, _this);
16815
16829
  _this.iot.$off('error', _this.iot.onError, _this);
@@ -16829,16 +16843,22 @@ let iot = function () {
16829
16843
  subscribe: topic => {
16830
16844
  if (!__currentTopics.has(topic)) {
16831
16845
  __currentTopics.add(topic);
16832
- if (!this.iot.__promise) return Promise.resolve('not_connected');
16846
+ if (!this.iot.__promise) return Promise.reject('not_connected');
16833
16847
  // if subscription fails, remove the topic from the current topics
16834
- return this.iot.__promise.then(() => !this.__privates.iot.subscribe(topic) && __currentTopics.delete(topic));
16848
+ return this.iot.__promise.then(() => this.__privates.iot.subscribe(topic)).catch(() => {
16849
+ __currentTopics.delete(topic);
16850
+ return Promise.reject('subscription_failed');
16851
+ });
16835
16852
  }
16836
16853
  },
16837
16854
  unsubscribe: topic => {
16838
16855
  __currentTopics.delete(topic);
16839
- if (!this.iot.__promise) return Promise.resolve('not_connected');
16856
+ if (!this.iot.__promise) return Promise.reject('not_connected');
16840
16857
  // if unsubscription fails add the topic back to the current topics
16841
- return this.iot.__promise.then(() => !this.__privates.iot.unsubscribe(topic) && __currentTopics.add(topic));
16858
+ return this.iot.__promise.then(() => this.__privates.iot.unsubscribe(topic)).catch(() => {
16859
+ __currentTopics.add(topic);
16860
+ return Promise.reject('unsubscription_failed');
16861
+ });
16842
16862
  },
16843
16863
  send: (topic, message) => {
16844
16864
  return this.iot.__promise.then(() => this.__privates.iot.send(topic, message));
@@ -16855,9 +16875,15 @@ let iot = function () {
16855
16875
  $clear: () => {
16856
16876
  return this.__privates.iot.clear();
16857
16877
  },
16878
+ $emit: function (key) {
16879
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
16880
+ args[_key - 1] = arguments[_key];
16881
+ }
16882
+ return _this.__privates.iot.emit(key, ...args);
16883
+ },
16858
16884
  checkConnection: () => {
16859
16885
  return this.__privates.iot.checkConnection().catch(error => {
16860
- if (!shouldBeConnected || isReconnecting) {
16886
+ if (!shouldBeConnected) {
16861
16887
  this.__privates.iot.log('Ignoring connection check failure, not connected');
16862
16888
  return Promise.resolve();
16863
16889
  }
@@ -25335,26 +25361,35 @@ class Iot {
25335
25361
  isConnected() {
25336
25362
  return this.connection && this.connection.currentState === 0 && this.connection.desiredState === 0;
25337
25363
  }
25364
+ clearTopics() {
25365
+ this.subscribedTopics.clear();
25366
+ }
25338
25367
  subscribe(topic) {
25339
25368
  this.log('iot subscribe', topic);
25340
25369
  if (this.connection && this.connection.currentState === 0 && this.connection.desiredState === 0 && typeof topic === 'string' && topic.trim() !== '') {
25341
- this.connection.subscribe(topic, aws_iot_device_sdk_v2__WEBPACK_IMPORTED_MODULE_2__.mqtt.QoS.AtLeastOnce);
25342
25370
  this.subscribedTopics.add(topic);
25343
- return true;
25371
+ return this.connection.subscribe(topic, aws_iot_device_sdk_v2__WEBPACK_IMPORTED_MODULE_2__.mqtt.QoS.AtLeastOnce).catch(err => {
25372
+ this.log('Error subscribing to topic:', err);
25373
+ this.subscribedTopics.delete(topic);
25374
+ return Promise.reject(err);
25375
+ });
25344
25376
  } else {
25345
25377
  this.log('Invalid topic or not connected:', topic);
25346
- return false;
25378
+ return Promise.reject(new Error('Invalid topic or not connected'));
25347
25379
  }
25348
25380
  }
25349
25381
  unsubscribe(topic) {
25350
25382
  this.log('iot unsubscribe', topic);
25351
25383
  if (this.connection && this.connection.currentState === 0 && this.connection.desiredState === 0 && typeof topic === 'string' && topic.trim() !== '') {
25352
- this.connection.unsubscribe(topic);
25353
25384
  this.subscribedTopics.delete(topic);
25354
- return true;
25385
+ return this.connection.unsubscribe(topic).catch(err => {
25386
+ this.log('Error unsubscribing from topic:', err);
25387
+ this.subscribedTopics.add(topic);
25388
+ return Promise.reject(err);
25389
+ });
25355
25390
  } else {
25356
25391
  this.log('Invalid topic or not connected:', topic);
25357
- return false;
25392
+ return Promise.reject(new Error('Invalid topic or not connected'));
25358
25393
  }
25359
25394
  }
25360
25395
  send(topic, message) {
@@ -25487,6 +25522,7 @@ class Iot {
25487
25522
  return this.connect(this.lastConnectParams.apiMqttUrl, this.lastConnectParams.apiMqttClientId, this.lastConnectParams.region, accessKeyId, secretAccessKey, sessionToken, expiration).then(() => {
25488
25523
  // Resubscribe to topics
25489
25524
  currentTopics.forEach(topic => this.subscribe(topic));
25525
+ return true;
25490
25526
  });
25491
25527
  }
25492
25528
  checkConnection() {