@reactoo/watchtogether-sdk-js 2.7.34 → 2.7.36

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.32
3
+ * @version 2.7.35
4
4
  */
5
5
  (function webpackUniversalModuleDefinition(root, factory) {
6
6
  if(typeof exports === 'object' && typeof module === 'object')
@@ -16502,6 +16502,7 @@ let asset = function () {
16502
16502
  uploadAsset: function (file, roomIds) {
16503
16503
  let id = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
16504
16504
  let initiationData = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
16505
+ let assetData = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
16505
16506
  return _this.__privates.auth.__client.then(client => Promise.all([client, initiationData ? Promise.resolve(initiationData) : client.apis.asset.initiateAssetUpload({
16506
16507
  id: id || (0,_modules_wt_utils__WEBPACK_IMPORTED_MODULE_0__.generateUUID)()
16507
16508
  })])).then(_ref2 => {
@@ -16523,7 +16524,8 @@ let asset = function () {
16523
16524
  title: file.name,
16524
16525
  ...(roomIds ? {
16525
16526
  roomIds
16526
- } : {})
16527
+ } : {}),
16528
+ ...(assetData ? assetData : {})
16527
16529
  }
16528
16530
  }), idn]);
16529
16531
  });
@@ -16706,6 +16708,8 @@ let iot = function () {
16706
16708
  var _this = this;
16707
16709
  let __currentTopics = new Set();
16708
16710
  let visibilityChangeHandler = null;
16711
+ let keepAliveIntervalId = null;
16712
+ let shouldBeConnected = false;
16709
16713
  return {
16710
16714
  __promise: null,
16711
16715
  __updateCredentials: () => {
@@ -16725,11 +16729,12 @@ let iot = function () {
16725
16729
  },
16726
16730
  onConnect: () => {
16727
16731
  this.__privates.iot.log('MQTT client connected');
16728
- this.iot.setupVisibilityChangeListener();
16729
16732
  },
16730
16733
  onClosed: () => {
16731
16734
  this.__privates.iot.log('MQTT client closed');
16732
- this.iot.disableVisibilityChangeListener();
16735
+ if (shouldBeConnected) {
16736
+ this.iot.__updateCredentials();
16737
+ }
16733
16738
  },
16734
16739
  onError: () => {
16735
16740
  this.__privates.iot.log('MQTT client error');
@@ -16758,6 +16763,9 @@ let iot = function () {
16758
16763
  });
16759
16764
  let __currentTopicsCopy = new Set(__currentTopics); // Keep this line
16760
16765
  __currentTopics.clear();
16766
+ shouldBeConnected = true;
16767
+ _this.iot.setupVisibilityChangeListener();
16768
+ //this.iot.setupKeepAliveInterval();
16761
16769
  _this.iot.$on('connect', _this.iot.onConnect, _this);
16762
16770
  _this.iot.$on('closed', _this.iot.onClosed, _this);
16763
16771
  _this.iot.$on('error', _this.iot.onError, _this);
@@ -16788,6 +16796,9 @@ let iot = function () {
16788
16796
  __currentTopics.clear();
16789
16797
  }
16790
16798
  return _this.__privates.iot.disconnect().then(() => {
16799
+ shouldBeConnected = false;
16800
+ _this.iot.disableVisibilityChangeListener();
16801
+ //this.iot.disableKeepAliveInterval();
16791
16802
  _this.iot.$off('connect', _this.iot.onConnect, _this);
16792
16803
  _this.iot.$off('closed', _this.iot.onClosed, _this);
16793
16804
  _this.iot.$off('error', _this.iot.onError, _this);
@@ -16838,6 +16849,14 @@ let iot = function () {
16838
16849
  return this.iot.__updateCredentials();
16839
16850
  });
16840
16851
  },
16852
+ setupKeepAliveInterval: () => {
16853
+ clearInterval(keepAliveIntervalId);
16854
+ keepAliveIntervalId = setInterval(this.iot.checkConnection, 30000);
16855
+ },
16856
+ disableKeepAliveInterval: () => {
16857
+ clearInterval(keepAliveIntervalId);
16858
+ keepAliveIntervalId = null;
16859
+ },
16841
16860
  setupVisibilityChangeListener: () => {
16842
16861
  if (visibilityChangeHandler) {
16843
16862
  // Listener is already set up
@@ -25213,7 +25232,6 @@ class Iot {
25213
25232
  constructor(enableDebugFlag) {
25214
25233
  Object.assign(this, (0,_wt_emitter__WEBPACK_IMPORTED_MODULE_0__["default"])());
25215
25234
  this.decoder = new TextDecoder('utf-8');
25216
- this.connectionActive = false;
25217
25235
  this.log = Iot.noop;
25218
25236
  // Remove: this.debugFlag = enableDebugFlag;
25219
25237
  this.credentialsExpirationCheckIntervalId = null;
@@ -25229,41 +25247,6 @@ class Iot {
25229
25247
  enableDebug() {
25230
25248
  this.log = console.log.bind(console);
25231
25249
  }
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
- }
25267
25250
  connect(apiMqttUrl, apiMqttClientId, region, accessKeyId, secretAccessKey, sessionToken, expiration) {
25268
25251
  this.log('iot connect called, we disconnect first just to be sure');
25269
25252
  return this.disconnect().finally(() => {
@@ -25289,15 +25272,33 @@ class Iot {
25289
25272
  const config = configBuilder.build();
25290
25273
  const client = new aws_iot_device_sdk_v2__WEBPACK_IMPORTED_MODULE_2__.mqtt.MqttClient();
25291
25274
  this.connection = client.new_connection(config);
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);
25275
+ this.connection.on('connect', () => {
25276
+ this.emit('connect');
25277
+ });
25278
+ this.connection.on('closed', error => {
25279
+ this.emit('closed', error);
25280
+ });
25281
+ this.connection.on('disconnect', () => {
25282
+ this.emit('disconnect');
25283
+ });
25284
+ this.connection.on('error', error => {
25285
+ this.emit('error', error);
25286
+ });
25287
+ this.connection.on('interrupt', error => {
25288
+ this.emit('interrupt', error);
25289
+ });
25290
+ this.connection.on('resume', error => {
25291
+ this.emit('resume', error);
25292
+ });
25293
+ this.connection.on('message', (topic, payload) => {
25294
+ this.handleMessage(topic, new Uint8Array(payload));
25295
+ });
25296
+ this.connection.on('connection_success', error => {
25297
+ this.emit('connection_success', error);
25298
+ });
25299
+ this.connection.on('connection_failure', error => {
25300
+ this.emit('connection_failure', error);
25301
+ });
25301
25302
  return this.connection.connect().then(() => {
25302
25303
  this.startCredentialsExpirationCheck(expiration);
25303
25304
  });
@@ -25307,12 +25308,11 @@ class Iot {
25307
25308
  this.log('iot disconnect');
25308
25309
  this.stopCredentialsExpirationCheck();
25309
25310
  if (this.connection) {
25310
- this.connectionActive = false;
25311
25311
  return this.connection.disconnect();
25312
25312
  } else return Promise.resolve();
25313
25313
  }
25314
25314
  isConnected() {
25315
- return this.connectionActive;
25315
+ return this.connection && this.connection.currentState === 0 && this.connection.desiredState === 0;
25316
25316
  }
25317
25317
  subscribe(topic) {
25318
25318
  this.log('iot subscribe', topic);
@@ -25380,7 +25380,7 @@ class Iot {
25380
25380
  // room
25381
25381
  if (event === 'message' || event === 'template_updated' || event === 'record_start' || event === 'record_stop' || event === 'record_configured' || event === 'record_livestream_available' || event === 'record_livestream_kick' || event === 'user_update_displayname' || event === 'user_update_avatar' || event === 'user_update_bio' || event === 'user_update_customattributes' || event === 'user_update_privateattributes' || event === 'channel_changed' || event === "instance_homepage_changed" || event === "instance_settings_changed" || event === "externalmix_changed" || event === "video_uploaded" || event === "change_user_devices" || event === "queue" || event === "title_changed" || event === "videowall_changed" || event === 'left' ||
25382
25382
  //user removed room a.k.a. left the room
25383
- event === 'kicked' || event === 'banned' || event === 'unbanned' || event === 'approved' || event === 'muted' || event === 'unmuted' || event === 'messageRemoved' || event === 'messageReported' || event === 'chatClear' || event === 'handRaised' || event === 'handLowered' || event === 'handsCleared' || event === 'volume_set') {
25383
+ event === 'kicked' || event === 'banned' || event === 'unbanned' || event === 'approved' || event === 'muted' || event === 'unmuted' || event === 'messageRemoved' || event === 'messageReported' || event === 'chatClear' || event === 'handRaised' || event === 'handLowered' || event === 'handsCleared' || event === 'volume_set' || event === 'asset_created') {
25384
25384
  this.emit('message', {
25385
25385
  event,
25386
25386
  ...message,
@@ -25441,7 +25441,8 @@ class Iot {
25441
25441
  this.currentCredentialsExpirationStamp = new Date(expiration).getTime();
25442
25442
  this.credentialsExpirationCheckIntervalId = setInterval(() => {
25443
25443
  const currentTimeStamp = new Date().getTime();
25444
- if (this.currentCredentialsExpirationStamp - currentTimeStamp <= 300000) {
25444
+ // update 15 minutes before expiration
25445
+ if (this.currentCredentialsExpirationStamp - currentTimeStamp <= 900000) {
25445
25446
  this.emit('updateCredentials');
25446
25447
  }
25447
25448
  }, 5000);
@@ -25468,7 +25469,7 @@ class Iot {
25468
25469
  }
25469
25470
  checkConnection() {
25470
25471
  return new Promise((resolve, reject) => {
25471
- if (!this.connection || !this.connectionActive) {
25472
+ if (!this.connection || !(this.connection.currentState === 0 && this.connection.desiredState === 0)) {
25472
25473
  reject(new Error('Not connected'));
25473
25474
  return;
25474
25475
  }