@reactoo/watchtogether-sdk-js 2.7.42 → 2.7.44-beta.1

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;
@@ -16807,9 +16820,9 @@ let iot = function () {
16807
16820
  }
16808
16821
  interruptCount = 0;
16809
16822
  shouldBeConnected = false;
16823
+ _this.iot.disableVisibilityChangeListener();
16824
+ _this.iot.disableKeepAliveInterval();
16810
16825
  return _this.__privates.iot.disconnect().then(() => {
16811
- _this.iot.disableVisibilityChangeListener();
16812
- _this.iot.disableKeepAliveInterval();
16813
16826
  _this.iot.$off('connect', _this.iot.onConnect, _this);
16814
16827
  _this.iot.$off('closed', _this.iot.onClosed, _this);
16815
16828
  _this.iot.$off('error', _this.iot.onError, _this);
@@ -16829,16 +16842,22 @@ let iot = function () {
16829
16842
  subscribe: topic => {
16830
16843
  if (!__currentTopics.has(topic)) {
16831
16844
  __currentTopics.add(topic);
16832
- if (!this.iot.__promise) return Promise.resolve('not_connected');
16845
+ if (!this.iot.__promise) return Promise.reject('not_connected');
16833
16846
  // if subscription fails, remove the topic from the current topics
16834
- return this.iot.__promise.then(() => !this.__privates.iot.subscribe(topic) && __currentTopics.delete(topic));
16847
+ return this.iot.__promise.then(() => this.__privates.iot.subscribe(topic)).catch(() => {
16848
+ __currentTopics.delete(topic);
16849
+ return Promise.reject('subscription_failed');
16850
+ });
16835
16851
  }
16836
16852
  },
16837
16853
  unsubscribe: topic => {
16838
16854
  __currentTopics.delete(topic);
16839
- if (!this.iot.__promise) return Promise.resolve('not_connected');
16855
+ if (!this.iot.__promise) return Promise.reject('not_connected');
16840
16856
  // 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));
16857
+ return this.iot.__promise.then(() => this.__privates.iot.unsubscribe(topic)).catch(() => {
16858
+ __currentTopics.add(topic);
16859
+ return Promise.reject('unsubscription_failed');
16860
+ });
16842
16861
  },
16843
16862
  send: (topic, message) => {
16844
16863
  return this.iot.__promise.then(() => this.__privates.iot.send(topic, message));
@@ -16855,9 +16874,15 @@ let iot = function () {
16855
16874
  $clear: () => {
16856
16875
  return this.__privates.iot.clear();
16857
16876
  },
16877
+ $emit: function (key) {
16878
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
16879
+ args[_key - 1] = arguments[_key];
16880
+ }
16881
+ return _this.__privates.iot.emit(key, ...args);
16882
+ },
16858
16883
  checkConnection: () => {
16859
16884
  return this.__privates.iot.checkConnection().catch(error => {
16860
- if (!shouldBeConnected || isReconnecting) {
16885
+ if (!shouldBeConnected) {
16861
16886
  this.__privates.iot.log('Ignoring connection check failure, not connected');
16862
16887
  return Promise.resolve();
16863
16888
  }
@@ -25338,23 +25363,29 @@ class Iot {
25338
25363
  subscribe(topic) {
25339
25364
  this.log('iot subscribe', topic);
25340
25365
  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
25366
  this.subscribedTopics.add(topic);
25343
- return true;
25367
+ return this.connection.subscribe(topic, aws_iot_device_sdk_v2__WEBPACK_IMPORTED_MODULE_2__.mqtt.QoS.AtLeastOnce).catch(err => {
25368
+ this.log('Error subscribing to topic:', err);
25369
+ this.subscribedTopics.delete(topic);
25370
+ return Promise.reject(err);
25371
+ });
25344
25372
  } else {
25345
25373
  this.log('Invalid topic or not connected:', topic);
25346
- return false;
25374
+ return Promise.reject(new Error('Invalid topic or not connected'));
25347
25375
  }
25348
25376
  }
25349
25377
  unsubscribe(topic) {
25350
25378
  this.log('iot unsubscribe', topic);
25351
25379
  if (this.connection && this.connection.currentState === 0 && this.connection.desiredState === 0 && typeof topic === 'string' && topic.trim() !== '') {
25352
- this.connection.unsubscribe(topic);
25353
25380
  this.subscribedTopics.delete(topic);
25354
- return true;
25381
+ return this.connection.unsubscribe(topic).catch(err => {
25382
+ this.log('Error unsubscribing from topic:', err);
25383
+ this.subscribedTopics.add(topic);
25384
+ return Promise.reject(err);
25385
+ });
25355
25386
  } else {
25356
25387
  this.log('Invalid topic or not connected:', topic);
25357
- return false;
25388
+ return Promise.reject(new Error('Invalid topic or not connected'));
25358
25389
  }
25359
25390
  }
25360
25391
  send(topic, message) {
@@ -25487,6 +25518,7 @@ class Iot {
25487
25518
  return this.connect(this.lastConnectParams.apiMqttUrl, this.lastConnectParams.apiMqttClientId, this.lastConnectParams.region, accessKeyId, secretAccessKey, sessionToken, expiration).then(() => {
25488
25519
  // Resubscribe to topics
25489
25520
  currentTopics.forEach(topic => this.subscribe(topic));
25521
+ return true;
25490
25522
  });
25491
25523
  }
25492
25524
  checkConnection() {