@reactoo/watchtogether-sdk-js 2.7.32 → 2.7.34

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.30
3
+ * @version 2.7.32
4
4
  */
5
5
  (function webpackUniversalModuleDefinition(root, factory) {
6
6
  if(typeof exports === 'object' && typeof module === 'object')
@@ -16723,6 +16723,32 @@ let iot = function () {
16723
16723
  }
16724
16724
  }));
16725
16725
  },
16726
+ onConnect: () => {
16727
+ this.__privates.iot.log('MQTT client connected');
16728
+ this.iot.setupVisibilityChangeListener();
16729
+ },
16730
+ onClosed: () => {
16731
+ this.__privates.iot.log('MQTT client closed');
16732
+ this.iot.disableVisibilityChangeListener();
16733
+ },
16734
+ onError: () => {
16735
+ this.__privates.iot.log('MQTT client error');
16736
+ },
16737
+ onDisconnect: () => {
16738
+ this.__privates.iot.log('MQTT client disconnect');
16739
+ },
16740
+ onInterrupt: () => {
16741
+ this.__privates.iot.log('MQTT client interrupt');
16742
+ },
16743
+ onResume: () => {
16744
+ this.__privates.iot.log('MQTT client resume');
16745
+ },
16746
+ onConnectionSuccess: () => {
16747
+ this.__privates.iot.log('MQTT client connection_success');
16748
+ },
16749
+ onConnectionFailure: () => {
16750
+ this.__privates.iot.log('MQTT client connection_failure');
16751
+ },
16726
16752
  iotLogin: function () {
16727
16753
  let subscribeToSuggestedTopics = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
16728
16754
  _this.iot.__promise = new Promise((resolve, reject) => {
@@ -16732,32 +16758,14 @@ let iot = function () {
16732
16758
  });
16733
16759
  let __currentTopicsCopy = new Set(__currentTopics); // Keep this line
16734
16760
  __currentTopics.clear();
16735
- _this.iot.$on('connect', () => {
16736
- _this.__privates.iot.log('MQTT client connected');
16737
- _this.iot.setupVisibilityChangeListener();
16738
- });
16739
- _this.iot.$on('closed', () => {
16740
- _this.__privates.iot.log('MQTT client closed');
16741
- _this.iot.disableVisibilityChangeListener();
16742
- });
16743
- _this.iot.$on('error', () => {
16744
- _this.__privates.iot.log('MQTT client error');
16745
- });
16746
- _this.iot.$on('disconnect', () => {
16747
- _this.__privates.iot.log('MQTT client disconnect');
16748
- });
16749
- _this.iot.$on('interrupt', () => {
16750
- _this.__privates.iot.log('MQTT client interrupt');
16751
- });
16752
- _this.iot.$on('resume', () => {
16753
- _this.__privates.iot.log('MQTT client resume');
16754
- });
16755
- _this.iot.$on('connection_success', () => {
16756
- _this.__privates.iot.log('MQTT client connection_success');
16757
- });
16758
- _this.iot.$on('connection_failure', () => {
16759
- _this.__privates.iot.log('MQTT client connection_failure');
16760
- });
16761
+ _this.iot.$on('connect', _this.iot.onConnect, _this);
16762
+ _this.iot.$on('closed', _this.iot.onClosed, _this);
16763
+ _this.iot.$on('error', _this.iot.onError, _this);
16764
+ _this.iot.$on('disconnect', _this.iot.onDisconnect, _this);
16765
+ _this.iot.$on('interrupt', _this.iot.onInterrupt, _this);
16766
+ _this.iot.$on('resume', _this.iot.onResume, _this);
16767
+ _this.iot.$on('connection_success', _this.iot.onConnectionSuccess, _this);
16768
+ _this.iot.$on('connection_failure', _this.iot.onConnectionFailure, _this);
16761
16769
  _this.iot.__promise.then(_ref => {
16762
16770
  let [suggestedTopic, instance] = _ref;
16763
16771
  if (!subscribeToSuggestedTopics) {
@@ -16780,8 +16788,15 @@ let iot = function () {
16780
16788
  __currentTopics.clear();
16781
16789
  }
16782
16790
  return _this.__privates.iot.disconnect().then(() => {
16791
+ _this.iot.$off('connect', _this.iot.onConnect, _this);
16792
+ _this.iot.$off('closed', _this.iot.onClosed, _this);
16793
+ _this.iot.$off('error', _this.iot.onError, _this);
16794
+ _this.iot.$off('disconnect', _this.iot.onDisconnect, _this);
16795
+ _this.iot.$off('interrupt', _this.iot.onInterrupt, _this);
16796
+ _this.iot.$off('resume', _this.iot.onResume, _this);
16797
+ _this.iot.$off('connection_success', _this.iot.onConnectionSuccess, _this);
16798
+ _this.iot.$off('connection_failure', _this.iot.onConnectionFailure, _this);
16783
16799
  _this.iot.__promise = null;
16784
- _this.iot.$clear();
16785
16800
  return true;
16786
16801
  });
16787
16802
  },
@@ -25214,6 +25229,41 @@ class Iot {
25214
25229
  enableDebug() {
25215
25230
  this.log = console.log.bind(console);
25216
25231
  }
25232
+ onConnect() {
25233
+ this.connectionActive = true;
25234
+ this.emit('connect');
25235
+ }
25236
+ onClosed(error) {
25237
+ this.connectionActive = false;
25238
+ this.emit('closed', error);
25239
+ }
25240
+ onDisconnect() {
25241
+ this.connectionActive = false;
25242
+ this.emit('disconnect');
25243
+ }
25244
+ onError(error) {
25245
+ this.connectionActive = false;
25246
+ this.emit('error', error);
25247
+ }
25248
+ onInterrupt(error) {
25249
+ this.connectionActive = false;
25250
+ this.emit('interrupt', error);
25251
+ }
25252
+ onResume(r) {
25253
+ this.connectionActive = true;
25254
+ this.emit('resume', r);
25255
+ }
25256
+ onMessage(topic, payload) {
25257
+ this.handleMessage(topic, new Uint8Array(payload));
25258
+ }
25259
+ onConnectionSuccess(r) {
25260
+ this.connectionActive = true;
25261
+ this.emit('connection_success', r);
25262
+ }
25263
+ onConnectionFailure(error) {
25264
+ this.connectionActive = false;
25265
+ this.emit('connection_failure', error);
25266
+ }
25217
25267
  connect(apiMqttUrl, apiMqttClientId, region, accessKeyId, secretAccessKey, sessionToken, expiration) {
25218
25268
  this.log('iot connect called, we disconnect first just to be sure');
25219
25269
  return this.disconnect().finally(() => {
@@ -25239,41 +25289,15 @@ class Iot {
25239
25289
  const config = configBuilder.build();
25240
25290
  const client = new aws_iot_device_sdk_v2__WEBPACK_IMPORTED_MODULE_2__.mqtt.MqttClient();
25241
25291
  this.connection = client.new_connection(config);
25242
- this.connection.on('connect', () => {
25243
- this.connectionActive = true;
25244
- this.emit('connect');
25245
- });
25246
- this.connection.on('disconnect', () => {
25247
- this.connectionActive = false;
25248
- this.emit('disconnect');
25249
- });
25250
- this.connection.on('error', error => {
25251
- this.connectionActive = false;
25252
- this.emit('error', error);
25253
- });
25254
- this.connection.on('interrupt', error => {
25255
- this.connectionActive = false;
25256
- this.emit('interrupt', error);
25257
- });
25258
- this.connection.on('resume', error => {
25259
- this.connectionActive = true;
25260
- this.emit('resume', error);
25261
- });
25262
- this.connection.on('message', (topic, payload) => {
25263
- this.handleMessage(topic, new Uint8Array(payload));
25264
- });
25265
- this.connection.on('connection_success', error => {
25266
- this.connectionActive = true;
25267
- this.emit('connection_success', error);
25268
- });
25269
- this.connection.on('connection_failure', error => {
25270
- this.connectionActive = false;
25271
- this.emit('connection_failure', error);
25272
- });
25273
- this.connection.on('closed', error => {
25274
- this.connectionActive = false;
25275
- this.emit('closed', error);
25276
- });
25292
+ this.connection.on('connect', this.onConnect, this);
25293
+ this.connection.on('closed', this.onClosed, this);
25294
+ this.connection.on('disconnect', this.onDisconnect, this);
25295
+ this.connection.on('error', this.onError, this);
25296
+ this.connection.on('interrupt', this.onInterrupt, this);
25297
+ this.connection.on('resume', this.onResume, this);
25298
+ this.connection.on('message', this.onMessage, this);
25299
+ this.connection.on('connection_success', this.onConnectionSuccess, this);
25300
+ this.connection.on('connection_failure', this.onConnectionFailure, this);
25277
25301
  return this.connection.connect().then(() => {
25278
25302
  this.startCredentialsExpirationCheck(expiration);
25279
25303
  });