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

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.
@@ -16718,22 +16718,17 @@ let iot = function () {
16718
16718
  this.__privates.iot.log('Updating Credentials...');
16719
16719
  interruptCount = 0;
16720
16720
  isReconnecting = true;
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
- });
16734
- }).finally(() => {
16721
+ this.iot.$emit('isReconnecting', isReconnecting, true);
16722
+ 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)).then(r => {
16723
+ isReconnecting = false;
16724
+ this.iot.$emit('isReconnecting', isReconnecting, false);
16725
+ this.__privates.iot.log('Credentials updated');
16726
+ return Promise.resolve(r);
16727
+ }).catch(error => {
16735
16728
  isReconnecting = false;
16736
- this.iot.$emit('isReconnecting', isReconnecting);
16729
+ this.iot.$emit('isReconnecting', isReconnecting, true);
16730
+ this.__privates.iot.log('Failed to update credentials:', error);
16731
+ return Promise.reject(error);
16737
16732
  });
16738
16733
  },
16739
16734
  getCredentials: () => {
@@ -16817,6 +16812,7 @@ let iot = function () {
16817
16812
  let keepCurrentTopics = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
16818
16813
  if (!keepCurrentTopics) {
16819
16814
  __currentTopics.clear();
16815
+ _this.__privates.iot.clearTopics();
16820
16816
  }
16821
16817
  interruptCount = 0;
16822
16818
  shouldBeConnected = false;
@@ -25347,19 +25343,44 @@ class Iot {
25347
25343
  this.connection.on('connection_failure', error => {
25348
25344
  this.emit('connection_failure', error);
25349
25345
  });
25350
- return this.connection.connect();
25346
+ return new Promise((resolve, reject) => {
25347
+ const timeoutId = setTimeout(() => {
25348
+ reject(new Error('Connection timeout'));
25349
+ }, 10000); // 10 seconds timeout is enough
25350
+ this.connection.connect().then(r => {
25351
+ clearTimeout(timeoutId);
25352
+ resolve(r);
25353
+ }).catch(error => {
25354
+ clearTimeout(timeoutId);
25355
+ reject(error);
25356
+ });
25357
+ });
25351
25358
  });
25352
25359
  }
25353
25360
  disconnect() {
25354
25361
  this.log('iot disconnect');
25355
25362
  this.stopCredentialsExpirationCheck();
25356
25363
  if (this.connection) {
25357
- return this.connection.disconnect();
25364
+ return new Promise((resolve, reject) => {
25365
+ const timeoutId = setTimeout(() => {
25366
+ reject(new Error('Disconnect timeout'));
25367
+ }, 10000); // 10 seconds timeout is enough
25368
+ this.connection.disconnect().then(r => {
25369
+ clearTimeout(timeoutId);
25370
+ resolve(r);
25371
+ }).catch(error => {
25372
+ clearTimeout(timeoutId);
25373
+ reject(error);
25374
+ });
25375
+ });
25358
25376
  } else return Promise.resolve();
25359
25377
  }
25360
25378
  isConnected() {
25361
25379
  return this.connection && this.connection.currentState === 0 && this.connection.desiredState === 0;
25362
25380
  }
25381
+ clearTopics() {
25382
+ this.subscribedTopics.clear();
25383
+ }
25363
25384
  subscribe(topic) {
25364
25385
  this.log('iot subscribe', topic);
25365
25386
  if (this.connection && this.connection.currentState === 0 && this.connection.desiredState === 0 && typeof topic === 'string' && topic.trim() !== '') {