stream-chat 4.4.3-dev.3 → 5.0.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.
Files changed (53) hide show
  1. package/README.md +4 -13
  2. package/dist/browser.es.js +1258 -722
  3. package/dist/browser.es.js.map +1 -1
  4. package/dist/browser.full-bundle.min.js +1 -1
  5. package/dist/browser.full-bundle.min.js.map +1 -1
  6. package/dist/browser.js +1258 -721
  7. package/dist/browser.js.map +1 -1
  8. package/dist/index.es.js +1258 -722
  9. package/dist/index.es.js.map +1 -1
  10. package/dist/index.js +1258 -721
  11. package/dist/index.js.map +1 -1
  12. package/dist/types/base64.d.ts.map +1 -1
  13. package/dist/types/channel.d.ts +19 -15
  14. package/dist/types/channel.d.ts.map +1 -1
  15. package/dist/types/channel_state.d.ts +2 -2
  16. package/dist/types/channel_state.d.ts.map +1 -1
  17. package/dist/types/client.d.ts +25 -42
  18. package/dist/types/client.d.ts.map +1 -1
  19. package/dist/types/client_state.d.ts +2 -2
  20. package/dist/types/client_state.d.ts.map +1 -1
  21. package/dist/types/connection.d.ts +14 -49
  22. package/dist/types/connection.d.ts.map +1 -1
  23. package/dist/types/connection_fallback.d.ts +41 -0
  24. package/dist/types/connection_fallback.d.ts.map +1 -0
  25. package/dist/types/errors.d.ts +14 -0
  26. package/dist/types/errors.d.ts.map +1 -0
  27. package/dist/types/insights.d.ts +16 -9
  28. package/dist/types/insights.d.ts.map +1 -1
  29. package/dist/types/permissions.d.ts.map +1 -1
  30. package/dist/types/signing.d.ts +3 -3
  31. package/dist/types/signing.d.ts.map +1 -1
  32. package/dist/types/token_manager.d.ts +2 -2
  33. package/dist/types/token_manager.d.ts.map +1 -1
  34. package/dist/types/types.d.ts +95 -89
  35. package/dist/types/types.d.ts.map +1 -1
  36. package/dist/types/utils.d.ts +13 -3
  37. package/dist/types/utils.d.ts.map +1 -1
  38. package/package.json +4 -4
  39. package/src/base64.ts +1 -4
  40. package/src/channel.ts +133 -461
  41. package/src/channel_state.ts +31 -158
  42. package/src/client.ts +298 -712
  43. package/src/client_state.ts +2 -2
  44. package/src/connection.ts +146 -395
  45. package/src/connection_fallback.ts +209 -0
  46. package/src/errors.ts +58 -0
  47. package/src/insights.ts +37 -31
  48. package/src/permissions.ts +3 -24
  49. package/src/signing.ts +6 -17
  50. package/src/token_manager.ts +6 -18
  51. package/src/types.ts +269 -512
  52. package/src/utils.ts +58 -24
  53. package/CHANGELOG.md +0 -844
@@ -88,9 +88,9 @@ var decodeBase64 = function decodeBase64(s) {
88
88
 
89
89
  var https = null;
90
90
 
91
- function ownKeys$5(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
91
+ function ownKeys$7(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
92
92
 
93
- function _objectSpread$5(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$5(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$5(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
93
+ function _objectSpread$7(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$7(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$7(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
94
94
 
95
95
  /**
96
96
  * ChannelState - A container class for the channel state.
@@ -158,7 +158,7 @@ var ChannelState = /*#__PURE__*/function () {
158
158
  var m = messages[i];
159
159
 
160
160
  if (((_m$user = m.user) === null || _m$user === void 0 ? void 0 : _m$user.id) === user.id) {
161
- messages[i] = _objectSpread$5(_objectSpread$5({}, m), {}, {
161
+ messages[i] = _objectSpread$7(_objectSpread$7({}, m), {}, {
162
162
  user: user
163
163
  });
164
164
  }
@@ -211,7 +211,7 @@ var ChannelState = /*#__PURE__*/function () {
211
211
  user: m.user
212
212
  };
213
213
  } else {
214
- messages[i] = _objectSpread$5(_objectSpread$5({}, m), {}, {
214
+ messages[i] = _objectSpread$7(_objectSpread$7({}, m), {}, {
215
215
  type: 'deleted',
216
216
  deleted_at: user.deleted_at
217
217
  });
@@ -279,7 +279,7 @@ var ChannelState = /*#__PURE__*/function () {
279
279
  }, {
280
280
  key: "formatMessage",
281
281
  value: function formatMessage(message) {
282
- return _objectSpread$5(_objectSpread$5({}, message), {}, {
282
+ return _objectSpread$7(_objectSpread$7({}, message), {}, {
283
283
  /**
284
284
  * @deprecated please use `html`
285
285
  */
@@ -469,7 +469,7 @@ var ChannelState = /*#__PURE__*/function () {
469
469
  var parseMessage = function parseMessage(m) {
470
470
  var _m$pinned_at, _m$updated_at;
471
471
 
472
- return _objectSpread$5(_objectSpread$5({}, m), {}, {
472
+ return _objectSpread$7(_objectSpread$7({}, m), {}, {
473
473
  created_at: m.created_at.toString(),
474
474
  pinned_at: (_m$pinned_at = m.pinned_at) === null || _m$pinned_at === void 0 ? void 0 : _m$pinned_at.toString(),
475
475
  updated_at: (_m$updated_at = m.updated_at) === null || _m$updated_at === void 0 ? void 0 : _m$updated_at.toString()
@@ -479,8 +479,8 @@ var ChannelState = /*#__PURE__*/function () {
479
479
  var updatedMessages = this.messages.filter(function (msg) {
480
480
  return msg.quoted_message_id === message.id;
481
481
  }).map(parseMessage).map(function (msg) {
482
- return _objectSpread$5(_objectSpread$5({}, msg), {}, {
483
- quoted_message: _objectSpread$5(_objectSpread$5({}, message), {}, {
482
+ return _objectSpread$7(_objectSpread$7({}, msg), {}, {
483
+ quoted_message: _objectSpread$7(_objectSpread$7({}, message), {}, {
484
484
  attachments: []
485
485
  })
486
486
  });
@@ -700,9 +700,9 @@ var ChannelState = /*#__PURE__*/function () {
700
700
  return ChannelState;
701
701
  }();
702
702
 
703
- function ownKeys$4(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
703
+ function ownKeys$6(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
704
704
 
705
- function _objectSpread$4(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$4(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$4(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
705
+ function _objectSpread$6(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$6(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$6(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
706
706
 
707
707
  var EVENT_MAP = {
708
708
  'channel.created': true,
@@ -749,7 +749,7 @@ var EVENT_MAP = {
749
749
  'connection.recovered': true
750
750
  };
751
751
 
752
- var IS_VALID_EVENT_MAP_TYPE = _objectSpread$4(_objectSpread$4({}, EVENT_MAP), {}, {
752
+ var IS_VALID_EVENT_MAP_TYPE = _objectSpread$6(_objectSpread$6({}, EVENT_MAP), {}, {
753
753
  all: true
754
754
  });
755
755
 
@@ -757,7 +757,7 @@ var isValidEventType = function isValidEventType(eventType) {
757
757
  return IS_VALID_EVENT_MAP_TYPE[eventType] || false;
758
758
  };
759
759
 
760
- function _createForOfIteratorHelper$3(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$3(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
760
+ function _createForOfIteratorHelper$3(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$3(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function (_e) { function e(_x) { return _e.apply(this, arguments); } e.toString = function () { return _e.toString(); }; return e; }(function (e) { throw e; }), f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function (_e2) { function e(_x2) { return _e2.apply(this, arguments); } e.toString = function () { return _e2.toString(); }; return e; }(function (e) { didErr = true; err = e; }), f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
761
761
 
762
762
  function _unsupportedIterableToArray$3(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$3(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$3(o, minLen); }
763
763
 
@@ -933,12 +933,55 @@ function getRandomBytes(length) {
933
933
  function convertErrorToJson(err) {
934
934
  var jsonObj = {};
935
935
  if (!err) return jsonObj;
936
- Object.getOwnPropertyNames(err).forEach(function (key) {
937
- // @ts-ignore
938
- jsonObj[key] = err[key];
939
- });
936
+
937
+ try {
938
+ Object.getOwnPropertyNames(err).forEach(function (key) {
939
+ jsonObj[key] = Object.getOwnPropertyDescriptor(err, key);
940
+ });
941
+ } catch (_) {
942
+ return {
943
+ error: 'failed to serialize the error'
944
+ };
945
+ }
946
+
940
947
  return jsonObj;
941
948
  }
949
+ /**
950
+ * isOnline safely return the navigator.online value for browser env
951
+ * if navigator is not in global object, it always return true
952
+ */
953
+
954
+ function isOnline() {
955
+ var nav = typeof navigator !== 'undefined' ? navigator : typeof window !== 'undefined' && window.navigator ? window.navigator : undefined;
956
+
957
+ if (!nav) {
958
+ console.warn('isOnline failed to access window.navigator and assume browser is online');
959
+ return true;
960
+ } // RN navigator has undefined for onLine
961
+
962
+
963
+ if (typeof nav.onLine !== 'boolean') {
964
+ return true;
965
+ }
966
+
967
+ return nav.onLine;
968
+ }
969
+ /**
970
+ * listenForConnectionChanges - Adds an event listener fired on browser going online or offline
971
+ */
972
+
973
+ function addConnectionEventListeners(cb) {
974
+ if (typeof window !== 'undefined' && window.addEventListener) {
975
+ window.addEventListener('offline', cb);
976
+ window.addEventListener('online', cb);
977
+ }
978
+ }
979
+ function removeConnectionEventListeners(cb) {
980
+ if (typeof window !== 'undefined' && window.removeEventListener) {
981
+ window.removeEventListener('offline', cb);
982
+ window.removeEventListener('online', cb);
983
+ }
984
+ }
942
985
 
943
986
  function _createForOfIteratorHelper$2(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$2(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
944
987
 
@@ -946,9 +989,9 @@ function _unsupportedIterableToArray$2(o, minLen) { if (!o) return; if (typeof o
946
989
 
947
990
  function _arrayLikeToArray$2(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
948
991
 
949
- function ownKeys$3(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
992
+ function ownKeys$5(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
950
993
 
951
- function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$3(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$3(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
994
+ function _objectSpread$5(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$5(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$5(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
952
995
 
953
996
  /**
954
997
  * Channel - The Channel class manages it's own state.
@@ -1068,7 +1111,7 @@ var Channel = /*#__PURE__*/function () {
1068
1111
 
1069
1112
  this.data = data; // this._data is used for the requests...
1070
1113
 
1071
- this._data = _objectSpread$3({}, data);
1114
+ this._data = _objectSpread$5({}, data);
1072
1115
  this.cid = "".concat(type, ":").concat(id);
1073
1116
  this.listeners = {}; // perhaps the state variable should be private
1074
1117
 
@@ -1126,7 +1169,7 @@ var Channel = /*#__PURE__*/function () {
1126
1169
  switch (_context2.prev = _context2.next) {
1127
1170
  case 0:
1128
1171
  _context2.next = 2;
1129
- return this.getClient().post(this._channelURL() + '/message', _objectSpread$3({
1172
+ return this.getClient().post(this._channelURL() + '/message', _objectSpread$5({
1130
1173
  message: message
1131
1174
  }, options));
1132
1175
 
@@ -1245,7 +1288,7 @@ var Channel = /*#__PURE__*/function () {
1245
1288
 
1246
1289
  case 3:
1247
1290
  // Return a list of channels
1248
- payload = _objectSpread$3(_objectSpread$3({
1291
+ payload = _objectSpread$5(_objectSpread$5({
1249
1292
  filter_conditions: {
1250
1293
  cid: this.cid
1251
1294
  }
@@ -1342,7 +1385,7 @@ var Channel = /*#__PURE__*/function () {
1342
1385
 
1343
1386
  _context5.next = 6;
1344
1387
  return this.getClient().get(this.getClient().baseURL + '/members', {
1345
- payload: _objectSpread$3({
1388
+ payload: _objectSpread$5({
1346
1389
  type: type,
1347
1390
  id: id,
1348
1391
  members: members,
@@ -1403,7 +1446,7 @@ var Channel = /*#__PURE__*/function () {
1403
1446
 
1404
1447
  case 4:
1405
1448
  _context6.next = 6;
1406
- return this.getClient().post(this.getClient().baseURL + "/messages/".concat(messageID, "/reaction"), _objectSpread$3({
1449
+ return this.getClient().post(this.getClient().baseURL + "/messages/".concat(messageID, "/reaction"), _objectSpread$5({
1407
1450
  reaction: reaction
1408
1451
  }, options));
1409
1452
 
@@ -1458,7 +1501,7 @@ var Channel = /*#__PURE__*/function () {
1458
1501
  *
1459
1502
  * @param {ChannelData<ChannelType>} channelData The object to update the custom properties of this channel with
1460
1503
  * @param {Message<AttachmentType, MessageType, UserType>} [updateMessage] Optional message object for channel members notification
1461
- * @param {{ skip_push?: boolean }} [options] Option object, {skip_push: true} to skip sending push notifications
1504
+ * @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
1462
1505
  * @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
1463
1506
  */
1464
1507
 
@@ -1484,7 +1527,7 @@ var Channel = /*#__PURE__*/function () {
1484
1527
  delete channelData[key];
1485
1528
  });
1486
1529
  _context7.next = 7;
1487
- return this._update(_objectSpread$3({
1530
+ return this._update(_objectSpread$5({
1488
1531
  message: updateMessage,
1489
1532
  data: channelData
1490
1533
  }, options));
@@ -1657,25 +1700,28 @@ var Channel = /*#__PURE__*/function () {
1657
1700
  }()
1658
1701
  /**
1659
1702
  * truncate - Removes all messages from the channel
1660
- *
1661
- * @return {Promise<TruncateChannelAPIResponse<ChannelType, CommandType, UserType>>} The server response
1703
+ * @param {TruncateOptions<AttachmentType, MessageType, UserType>} [options] Defines truncation options
1704
+ * @return {Promise<TruncateChannelAPIResponse<ChannelType, CommandType, UserType, MessageType, ReactionType>>} The server response
1662
1705
  */
1663
1706
 
1664
1707
  }, {
1665
1708
  key: "truncate",
1666
1709
  value: function () {
1667
1710
  var _truncate = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12() {
1711
+ var options,
1712
+ _args12 = arguments;
1668
1713
  return _regeneratorRuntime.wrap(function _callee12$(_context12) {
1669
1714
  while (1) {
1670
1715
  switch (_context12.prev = _context12.next) {
1671
1716
  case 0:
1672
- _context12.next = 2;
1673
- return this.getClient().post(this._channelURL() + '/truncate', {});
1717
+ options = _args12.length > 0 && _args12[0] !== undefined ? _args12[0] : {};
1718
+ _context12.next = 3;
1719
+ return this.getClient().post(this._channelURL() + '/truncate', options);
1674
1720
 
1675
- case 2:
1721
+ case 3:
1676
1722
  return _context12.abrupt("return", _context12.sent);
1677
1723
 
1678
- case 3:
1724
+ case 4:
1679
1725
  case "end":
1680
1726
  return _context12.stop();
1681
1727
  }
@@ -1709,7 +1755,7 @@ var Channel = /*#__PURE__*/function () {
1709
1755
  case 0:
1710
1756
  options = _args13.length > 0 && _args13[0] !== undefined ? _args13[0] : {};
1711
1757
  _context13.next = 3;
1712
- return this._update(_objectSpread$3({
1758
+ return this._update(_objectSpread$5({
1713
1759
  accept_invite: true
1714
1760
  }, options));
1715
1761
 
@@ -1750,7 +1796,7 @@ var Channel = /*#__PURE__*/function () {
1750
1796
  case 0:
1751
1797
  options = _args14.length > 0 && _args14[0] !== undefined ? _args14[0] : {};
1752
1798
  _context14.next = 3;
1753
- return this._update(_objectSpread$3({
1799
+ return this._update(_objectSpread$5({
1754
1800
  reject_invite: true
1755
1801
  }, options));
1756
1802
 
@@ -1776,6 +1822,7 @@ var Channel = /*#__PURE__*/function () {
1776
1822
  *
1777
1823
  * @param {{user_id: string, channel_role?: Role}[]} members An array of members to add to the channel
1778
1824
  * @param {Message<AttachmentType, MessageType, UserType>} [message] Optional message object for channel members notification
1825
+ * @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
1779
1826
  * @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
1780
1827
  */
1781
1828
 
@@ -1783,20 +1830,23 @@ var Channel = /*#__PURE__*/function () {
1783
1830
  key: "addMembers",
1784
1831
  value: function () {
1785
1832
  var _addMembers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(members, message) {
1833
+ var options,
1834
+ _args15 = arguments;
1786
1835
  return _regeneratorRuntime.wrap(function _callee15$(_context15) {
1787
1836
  while (1) {
1788
1837
  switch (_context15.prev = _context15.next) {
1789
1838
  case 0:
1790
- _context15.next = 2;
1791
- return this._update({
1839
+ options = _args15.length > 2 && _args15[2] !== undefined ? _args15[2] : {};
1840
+ _context15.next = 3;
1841
+ return this._update(_objectSpread$5({
1792
1842
  add_members: members,
1793
1843
  message: message
1794
- });
1844
+ }, options));
1795
1845
 
1796
- case 2:
1846
+ case 3:
1797
1847
  return _context15.abrupt("return", _context15.sent);
1798
1848
 
1799
- case 3:
1849
+ case 4:
1800
1850
  case "end":
1801
1851
  return _context15.stop();
1802
1852
  }
@@ -1815,6 +1865,7 @@ var Channel = /*#__PURE__*/function () {
1815
1865
  *
1816
1866
  * @param {string[]} members An array of member identifiers
1817
1867
  * @param {Message<AttachmentType, MessageType, UserType>} [message] Optional message object for channel members notification
1868
+ * @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
1818
1869
  * @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
1819
1870
  */
1820
1871
 
@@ -1822,20 +1873,23 @@ var Channel = /*#__PURE__*/function () {
1822
1873
  key: "addModerators",
1823
1874
  value: function () {
1824
1875
  var _addModerators = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16(members, message) {
1876
+ var options,
1877
+ _args16 = arguments;
1825
1878
  return _regeneratorRuntime.wrap(function _callee16$(_context16) {
1826
1879
  while (1) {
1827
1880
  switch (_context16.prev = _context16.next) {
1828
1881
  case 0:
1829
- _context16.next = 2;
1830
- return this._update({
1882
+ options = _args16.length > 2 && _args16[2] !== undefined ? _args16[2] : {};
1883
+ _context16.next = 3;
1884
+ return this._update(_objectSpread$5({
1831
1885
  add_moderators: members,
1832
1886
  message: message
1833
- });
1887
+ }, options));
1834
1888
 
1835
- case 2:
1889
+ case 3:
1836
1890
  return _context16.abrupt("return", _context16.sent);
1837
1891
 
1838
- case 3:
1892
+ case 4:
1839
1893
  case "end":
1840
1894
  return _context16.stop();
1841
1895
  }
@@ -1854,6 +1908,7 @@ var Channel = /*#__PURE__*/function () {
1854
1908
  *
1855
1909
  * @param {{channel_role: Role, user_id: string}[]} roles List of role assignments
1856
1910
  * @param {Message<AttachmentType, MessageType, UserType>} [message] Optional message object for channel members notification
1911
+ * @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
1857
1912
  * @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
1858
1913
  */
1859
1914
 
@@ -1861,20 +1916,23 @@ var Channel = /*#__PURE__*/function () {
1861
1916
  key: "assignRoles",
1862
1917
  value: function () {
1863
1918
  var _assignRoles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(roles, message) {
1919
+ var options,
1920
+ _args17 = arguments;
1864
1921
  return _regeneratorRuntime.wrap(function _callee17$(_context17) {
1865
1922
  while (1) {
1866
1923
  switch (_context17.prev = _context17.next) {
1867
1924
  case 0:
1868
- _context17.next = 2;
1869
- return this._update({
1925
+ options = _args17.length > 2 && _args17[2] !== undefined ? _args17[2] : {};
1926
+ _context17.next = 3;
1927
+ return this._update(_objectSpread$5({
1870
1928
  assign_roles: roles,
1871
1929
  message: message
1872
- });
1930
+ }, options));
1873
1931
 
1874
- case 2:
1932
+ case 3:
1875
1933
  return _context17.abrupt("return", _context17.sent);
1876
1934
 
1877
- case 3:
1935
+ case 4:
1878
1936
  case "end":
1879
1937
  return _context17.stop();
1880
1938
  }
@@ -1893,6 +1951,7 @@ var Channel = /*#__PURE__*/function () {
1893
1951
  *
1894
1952
  * @param {{user_id: string, channel_role?: Role}[]} members An array of members to invite to the channel
1895
1953
  * @param {Message<AttachmentType, MessageType, UserType>} [message] Optional message object for channel members notification
1954
+ * @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
1896
1955
  * @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
1897
1956
  */
1898
1957
 
@@ -1900,20 +1959,23 @@ var Channel = /*#__PURE__*/function () {
1900
1959
  key: "inviteMembers",
1901
1960
  value: function () {
1902
1961
  var _inviteMembers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18(members, message) {
1962
+ var options,
1963
+ _args18 = arguments;
1903
1964
  return _regeneratorRuntime.wrap(function _callee18$(_context18) {
1904
1965
  while (1) {
1905
1966
  switch (_context18.prev = _context18.next) {
1906
1967
  case 0:
1907
- _context18.next = 2;
1908
- return this._update({
1968
+ options = _args18.length > 2 && _args18[2] !== undefined ? _args18[2] : {};
1969
+ _context18.next = 3;
1970
+ return this._update(_objectSpread$5({
1909
1971
  invites: members,
1910
1972
  message: message
1911
- });
1973
+ }, options));
1912
1974
 
1913
- case 2:
1975
+ case 3:
1914
1976
  return _context18.abrupt("return", _context18.sent);
1915
1977
 
1916
- case 3:
1978
+ case 4:
1917
1979
  case "end":
1918
1980
  return _context18.stop();
1919
1981
  }
@@ -1932,6 +1994,7 @@ var Channel = /*#__PURE__*/function () {
1932
1994
  *
1933
1995
  * @param {string[]} members An array of member identifiers
1934
1996
  * @param {Message<AttachmentType, MessageType, UserType>} [message] Optional message object for channel members notification
1997
+ * @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
1935
1998
  * @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
1936
1999
  */
1937
2000
 
@@ -1939,20 +2002,23 @@ var Channel = /*#__PURE__*/function () {
1939
2002
  key: "removeMembers",
1940
2003
  value: function () {
1941
2004
  var _removeMembers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee19(members, message) {
2005
+ var options,
2006
+ _args19 = arguments;
1942
2007
  return _regeneratorRuntime.wrap(function _callee19$(_context19) {
1943
2008
  while (1) {
1944
2009
  switch (_context19.prev = _context19.next) {
1945
2010
  case 0:
1946
- _context19.next = 2;
1947
- return this._update({
2011
+ options = _args19.length > 2 && _args19[2] !== undefined ? _args19[2] : {};
2012
+ _context19.next = 3;
2013
+ return this._update(_objectSpread$5({
1948
2014
  remove_members: members,
1949
2015
  message: message
1950
- });
2016
+ }, options));
1951
2017
 
1952
- case 2:
2018
+ case 3:
1953
2019
  return _context19.abrupt("return", _context19.sent);
1954
2020
 
1955
- case 3:
2021
+ case 4:
1956
2022
  case "end":
1957
2023
  return _context19.stop();
1958
2024
  }
@@ -1971,6 +2037,7 @@ var Channel = /*#__PURE__*/function () {
1971
2037
  *
1972
2038
  * @param {string[]} members An array of member identifiers
1973
2039
  * @param {Message<AttachmentType, MessageType, UserType>} [message] Optional message object for channel members notification
2040
+ * @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
1974
2041
  * @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
1975
2042
  */
1976
2043
 
@@ -1978,20 +2045,23 @@ var Channel = /*#__PURE__*/function () {
1978
2045
  key: "demoteModerators",
1979
2046
  value: function () {
1980
2047
  var _demoteModerators = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee20(members, message) {
2048
+ var options,
2049
+ _args20 = arguments;
1981
2050
  return _regeneratorRuntime.wrap(function _callee20$(_context20) {
1982
2051
  while (1) {
1983
2052
  switch (_context20.prev = _context20.next) {
1984
2053
  case 0:
1985
- _context20.next = 2;
1986
- return this._update({
2054
+ options = _args20.length > 2 && _args20[2] !== undefined ? _args20[2] : {};
2055
+ _context20.next = 3;
2056
+ return this._update(_objectSpread$5({
1987
2057
  demote_moderators: members,
1988
2058
  message: message
1989
- });
2059
+ }, options));
1990
2060
 
1991
- case 2:
2061
+ case 3:
1992
2062
  return _context20.abrupt("return", _context20.sent);
1993
2063
 
1994
- case 3:
2064
+ case 4:
1995
2065
  case "end":
1996
2066
  return _context20.stop();
1997
2067
  }
@@ -2068,7 +2138,7 @@ var Channel = /*#__PURE__*/function () {
2068
2138
  case 0:
2069
2139
  opts = _args22.length > 0 && _args22[0] !== undefined ? _args22[0] : {};
2070
2140
  _context22.next = 3;
2071
- return this.getClient().post(this.getClient().baseURL + '/moderation/mute/channel', _objectSpread$3({
2141
+ return this.getClient().post(this.getClient().baseURL + '/moderation/mute/channel', _objectSpread$5({
2072
2142
  channel_cid: this.cid
2073
2143
  }, opts));
2074
2144
 
@@ -2110,7 +2180,7 @@ var Channel = /*#__PURE__*/function () {
2110
2180
  case 0:
2111
2181
  opts = _args23.length > 0 && _args23[0] !== undefined ? _args23[0] : {};
2112
2182
  _context23.next = 3;
2113
- return this.getClient().post(this.getClient().baseURL + '/moderation/unmute/channel', _objectSpread$3({
2183
+ return this.getClient().post(this.getClient().baseURL + '/moderation/unmute/channel', _objectSpread$5({
2114
2184
  channel_cid: this.cid
2115
2185
  }, opts));
2116
2186
 
@@ -2319,7 +2389,7 @@ var Channel = /*#__PURE__*/function () {
2319
2389
 
2320
2390
  case 4:
2321
2391
  _context26.next = 6;
2322
- return this.getClient().post(this._channelURL() + '/read', _objectSpread$3({}, data));
2392
+ return this.getClient().post(this._channelURL() + '/read', _objectSpread$5({}, data));
2323
2393
 
2324
2394
  case 6:
2325
2395
  return _context26.abrupt("return", _context26.sent);
@@ -2387,7 +2457,7 @@ var Channel = /*#__PURE__*/function () {
2387
2457
  defaultOptions.watch = false;
2388
2458
  }
2389
2459
 
2390
- combined = _objectSpread$3(_objectSpread$3({}, defaultOptions), options);
2460
+ combined = _objectSpread$5(_objectSpread$5({}, defaultOptions), options);
2391
2461
  _context27.next = 7;
2392
2462
  return this.query(combined);
2393
2463
 
@@ -2478,7 +2548,7 @@ var Channel = /*#__PURE__*/function () {
2478
2548
  switch (_context29.prev = _context29.next) {
2479
2549
  case 0:
2480
2550
  _context29.next = 2;
2481
- return this.getClient().get(this.getClient().baseURL + "/messages/".concat(parent_id, "/replies"), _objectSpread$3({}, options));
2551
+ return this.getClient().get(this.getClient().baseURL + "/messages/".concat(parent_id, "/replies"), _objectSpread$5({}, options));
2482
2552
 
2483
2553
  case 2:
2484
2554
  data = _context29.sent;
@@ -2516,7 +2586,7 @@ var Channel = /*#__PURE__*/function () {
2516
2586
  }, {
2517
2587
  key: "getReactions",
2518
2588
  value: function getReactions(message_id, options) {
2519
- return this.getClient().get(this.getClient().baseURL + "/messages/".concat(message_id, "/reactions"), _objectSpread$3({}, options));
2589
+ return this.getClient().get(this.getClient().baseURL + "/messages/".concat(message_id, "/reactions"), _objectSpread$5({}, options));
2520
2590
  }
2521
2591
  /**
2522
2592
  * getMessagesById - Retrieves a list of messages by ID
@@ -2648,7 +2718,7 @@ var Channel = /*#__PURE__*/function () {
2648
2718
  }
2649
2719
 
2650
2720
  _context30.next = 6;
2651
- return this.getClient().post(queryURL + '/query', _objectSpread$3({
2721
+ return this.getClient().post(queryURL + '/query', _objectSpread$5({
2652
2722
  data: this._data,
2653
2723
  state: true
2654
2724
  }, options));
@@ -2719,7 +2789,7 @@ var Channel = /*#__PURE__*/function () {
2719
2789
  this._checkInitialized();
2720
2790
 
2721
2791
  _context31.next = 3;
2722
- return this.getClient().banUser(targetUserID, _objectSpread$3(_objectSpread$3({}, options), {}, {
2792
+ return this.getClient().banUser(targetUserID, _objectSpread$5(_objectSpread$5({}, options), {}, {
2723
2793
  type: this.type,
2724
2794
  id: this.id
2725
2795
  }));
@@ -2891,7 +2961,7 @@ var Channel = /*#__PURE__*/function () {
2891
2961
  this._checkInitialized();
2892
2962
 
2893
2963
  _context35.next = 3;
2894
- return this.getClient().shadowBan(targetUserID, _objectSpread$3(_objectSpread$3({}, options), {}, {
2964
+ return this.getClient().shadowBan(targetUserID, _objectSpread$5(_objectSpread$5({}, options), {}, {
2895
2965
  type: this.type,
2896
2966
  id: this.id
2897
2967
  }));
@@ -3304,7 +3374,7 @@ var Channel = /*#__PURE__*/function () {
3304
3374
  for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
3305
3375
  var read = _step3.value;
3306
3376
 
3307
- var parsedRead = _objectSpread$3(_objectSpread$3({}, read), {}, {
3377
+ var parsedRead = _objectSpread$5(_objectSpread$5({}, read), {}, {
3308
3378
  last_read: new Date(read.last_read)
3309
3379
  });
3310
3380
 
@@ -3431,9 +3501,9 @@ var ClientState = /*#__PURE__*/function () {
3431
3501
  return ClientState;
3432
3502
  }();
3433
3503
 
3434
- function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
3504
+ function ownKeys$4(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
3435
3505
 
3436
- function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$2(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
3506
+ function _objectSpread$4(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$4(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$4(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
3437
3507
  var InsightMetrics = function InsightMetrics() {
3438
3508
  _classCallCheck(this, InsightMetrics);
3439
3509
 
@@ -3450,32 +3520,94 @@ var InsightMetrics = function InsightMetrics() {
3450
3520
  this.wsConsecutiveFailures = 0;
3451
3521
  this.instanceClientId = randomId();
3452
3522
  };
3523
+ /**
3524
+ * postInsights is not supposed to be used by end users directly within chat application, and thus is kept isolated
3525
+ * from all the client/connection code/logic.
3526
+ *
3527
+ * @param insightType
3528
+ * @param insights
3529
+ */
3530
+
3531
+ var postInsights = /*#__PURE__*/function () {
3532
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(insightType, insights) {
3533
+ var maxAttempts, i;
3534
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
3535
+ while (1) {
3536
+ switch (_context.prev = _context.next) {
3537
+ case 0:
3538
+ maxAttempts = 3;
3539
+ i = 0;
3540
+
3541
+ case 2:
3542
+ if (!(i < maxAttempts)) {
3543
+ _context.next = 17;
3544
+ break;
3545
+ }
3546
+
3547
+ _context.prev = 3;
3548
+ _context.next = 6;
3549
+ return axios.post("https://chat-insights.getstream.io/insights/".concat(insightType), insights);
3550
+
3551
+ case 6:
3552
+ _context.next = 13;
3553
+ break;
3554
+
3555
+ case 8:
3556
+ _context.prev = 8;
3557
+ _context.t0 = _context["catch"](3);
3558
+ _context.next = 12;
3559
+ return sleep((i + 1) * 3000);
3560
+
3561
+ case 12:
3562
+ return _context.abrupt("continue", 14);
3563
+
3564
+ case 13:
3565
+ return _context.abrupt("break", 17);
3566
+
3567
+ case 14:
3568
+ i++;
3569
+ _context.next = 2;
3570
+ break;
3571
+
3572
+ case 17:
3573
+ case "end":
3574
+ return _context.stop();
3575
+ }
3576
+ }
3577
+ }, _callee, null, [[3, 8]]);
3578
+ }));
3579
+
3580
+ return function postInsights(_x, _x2) {
3581
+ return _ref.apply(this, arguments);
3582
+ };
3583
+ }();
3453
3584
  function buildWsFatalInsight(connection, event) {
3454
- return _objectSpread$2(_objectSpread$2({}, event), buildWsBaseInsight(connection));
3585
+ return _objectSpread$4(_objectSpread$4({}, event), buildWsBaseInsight(connection));
3455
3586
  }
3456
3587
 
3457
3588
  function buildWsBaseInsight(connection) {
3458
3589
  var _connection$ws, _navigator, _navigator2;
3459
3590
 
3591
+ var client = connection.client;
3460
3592
  return {
3461
3593
  ready_state: (_connection$ws = connection.ws) === null || _connection$ws === void 0 ? void 0 : _connection$ws.readyState,
3462
- url: connection._buildUrl(connection.requestID),
3463
- api_key: connection.apiKey,
3464
- start_ts: connection.insightMetrics.connectionStartTimestamp,
3594
+ url: connection._buildUrl(),
3595
+ api_key: client.key,
3596
+ start_ts: client.insightMetrics.connectionStartTimestamp,
3465
3597
  end_ts: new Date().getTime(),
3466
- auth_type: connection.authType,
3467
- token: connection.tokenManager.token,
3468
- user_id: connection.userID,
3469
- user_details: connection.user,
3470
- device: connection.device,
3598
+ auth_type: client.getAuthType(),
3599
+ token: client.tokenManager.token,
3600
+ user_id: client.userID,
3601
+ user_details: client._user,
3602
+ device: client.options.device,
3471
3603
  client_id: connection.connectionID,
3472
3604
  ws_details: connection.ws,
3473
- ws_consecutive_failures: connection.insightMetrics.wsConsecutiveFailures,
3474
- ws_total_failures: connection.insightMetrics.wsTotalFailures,
3605
+ ws_consecutive_failures: client.insightMetrics.wsConsecutiveFailures,
3606
+ ws_total_failures: client.insightMetrics.wsTotalFailures,
3475
3607
  request_id: connection.requestID,
3476
3608
  online: typeof navigator !== 'undefined' ? (_navigator = navigator) === null || _navigator === void 0 ? void 0 : _navigator.onLine : null,
3477
3609
  user_agent: typeof navigator !== 'undefined' ? (_navigator2 = navigator) === null || _navigator2 === void 0 ? void 0 : _navigator2.userAgent : null,
3478
- instance_client_id: connection.insightMetrics.instanceClientId
3610
+ instance_client_id: client.insightMetrics.instanceClientId
3479
3611
  };
3480
3612
  }
3481
3613
 
@@ -3483,6 +3615,10 @@ function buildWsSuccessAfterFailureInsight(connection) {
3483
3615
  return buildWsBaseInsight(connection);
3484
3616
  }
3485
3617
 
3618
+ function ownKeys$3(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
3619
+
3620
+ function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$3(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$3(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
3621
+
3486
3622
  // Type guards to check WebSocket error type
3487
3623
  var isCloseEvent = function isCloseEvent(res) {
3488
3624
  return res.code !== undefined;
@@ -3491,7 +3627,6 @@ var isCloseEvent = function isCloseEvent(res) {
3491
3627
  var isErrorEvent = function isErrorEvent(res) {
3492
3628
  return res.error !== undefined;
3493
3629
  };
3494
-
3495
3630
  /**
3496
3631
  * StableWSConnection - A WS connection that reconnects upon failure.
3497
3632
  * - the browser will sometimes report that you're online or offline
@@ -3509,53 +3644,19 @@ var isErrorEvent = function isErrorEvent(res) {
3509
3644
  * - state can be recovered by querying the channel again
3510
3645
  * - if the servers fails to publish a message to the client, the WS connection is destroyed
3511
3646
  */
3647
+
3648
+
3512
3649
  var StableWSConnection = /*#__PURE__*/function () {
3650
+ // global from constructor
3651
+ // local vars
3513
3652
  function StableWSConnection(_ref) {
3514
3653
  var _this = this;
3515
3654
 
3516
- var apiKey = _ref.apiKey,
3517
- authType = _ref.authType,
3518
- clientID = _ref.clientID,
3519
- eventCallback = _ref.eventCallback,
3520
- logger = _ref.logger,
3521
- messageCallback = _ref.messageCallback,
3522
- recoverCallback = _ref.recoverCallback,
3523
- tokenManager = _ref.tokenManager,
3524
- user = _ref.user,
3525
- userAgent = _ref.userAgent,
3526
- userID = _ref.userID,
3527
- wsBaseURL = _ref.wsBaseURL,
3528
- device = _ref.device,
3529
- postInsights = _ref.postInsights,
3530
- insightMetrics = _ref.insightMetrics;
3655
+ var client = _ref.client;
3531
3656
 
3532
3657
  _classCallCheck(this, StableWSConnection);
3533
3658
 
3534
- _defineProperty(this, "apiKey", void 0);
3535
-
3536
- _defineProperty(this, "authType", void 0);
3537
-
3538
- _defineProperty(this, "clientID", void 0);
3539
-
3540
- _defineProperty(this, "eventCallback", void 0);
3541
-
3542
- _defineProperty(this, "logger", void 0);
3543
-
3544
- _defineProperty(this, "messageCallback", void 0);
3545
-
3546
- _defineProperty(this, "recoverCallback", void 0);
3547
-
3548
- _defineProperty(this, "tokenManager", void 0);
3549
-
3550
- _defineProperty(this, "user", void 0);
3551
-
3552
- _defineProperty(this, "userAgent", void 0);
3553
-
3554
- _defineProperty(this, "userID", void 0);
3555
-
3556
- _defineProperty(this, "wsBaseURL", void 0);
3557
-
3558
- _defineProperty(this, "device", void 0);
3659
+ _defineProperty(this, "client", void 0);
3559
3660
 
3560
3661
  _defineProperty(this, "connectionID", void 0);
3561
3662
 
@@ -3569,6 +3670,8 @@ var StableWSConnection = /*#__PURE__*/function () {
3569
3670
 
3570
3671
  _defineProperty(this, "isConnecting", void 0);
3571
3672
 
3673
+ _defineProperty(this, "isDisconnected", void 0);
3674
+
3572
3675
  _defineProperty(this, "isHealthy", void 0);
3573
3676
 
3574
3677
  _defineProperty(this, "isResolved", void 0);
@@ -3583,8 +3686,6 @@ var StableWSConnection = /*#__PURE__*/function () {
3583
3686
 
3584
3687
  _defineProperty(this, "requestID", void 0);
3585
3688
 
3586
- _defineProperty(this, "connectionStartTimestamp", void 0);
3587
-
3588
3689
  _defineProperty(this, "resolvePromise", void 0);
3589
3690
 
3590
3691
  _defineProperty(this, "totalFailures", void 0);
@@ -3593,32 +3694,18 @@ var StableWSConnection = /*#__PURE__*/function () {
3593
3694
 
3594
3695
  _defineProperty(this, "wsID", void 0);
3595
3696
 
3596
- _defineProperty(this, "postInsights", void 0);
3697
+ _defineProperty(this, "_buildUrl", function () {
3698
+ var qs = encodeURIComponent(_this.client._buildWSPayload(_this.requestID));
3597
3699
 
3598
- _defineProperty(this, "insightMetrics", void 0);
3700
+ var token = _this.client.tokenManager.getToken();
3599
3701
 
3600
- _defineProperty(this, "_buildUrl", function (reqID) {
3601
- var params = {
3602
- user_id: _this.user.id,
3603
- user_details: _this.user,
3604
- user_token: _this.tokenManager.getToken(),
3605
- server_determines_connection_id: true,
3606
- device: _this.device,
3607
- client_request_id: reqID
3608
- };
3609
- var qs = encodeURIComponent(JSON.stringify(params));
3610
-
3611
- var token = _this.tokenManager.getToken();
3612
-
3613
- return "".concat(_this.wsBaseURL, "/connect?json=").concat(qs, "&api_key=").concat(_this.apiKey, "&authorization=").concat(token, "&stream-auth-type=").concat(_this.authType, "&X-Stream-Client=").concat(_this.userAgent);
3702
+ return "".concat(_this.client.wsBaseURL, "/connect?json=").concat(qs, "&api_key=").concat(_this.client.key, "&authorization=").concat(token, "&stream-auth-type=").concat(_this.client.getAuthType(), "&X-Stream-Client=").concat(_this.client.getUserAgent());
3614
3703
  });
3615
3704
 
3616
3705
  _defineProperty(this, "onlineStatusChanged", function (event) {
3617
3706
  if (event.type === 'offline') {
3618
3707
  // mark the connection as down
3619
- _this.logger('info', 'connection:onlineStatusChanged() - Status changing to offline', {
3620
- tags: ['connection']
3621
- });
3708
+ _this._log('onlineStatusChanged() - Status changing to offline');
3622
3709
 
3623
3710
  _this._setHealth(false);
3624
3711
  } else if (event.type === 'online') {
@@ -3626,9 +3713,7 @@ var StableWSConnection = /*#__PURE__*/function () {
3626
3713
  // We check this.isHealthy, not sure if it's always
3627
3714
  // smart to create a new WS connection if the old one is still up and running.
3628
3715
  // it's possible we didn't miss any messages, so this process is just expensive and not needed.
3629
- _this.logger('info', "connection:onlineStatusChanged() - Status changing to online. isHealthy: ".concat(_this.isHealthy), {
3630
- tags: ['connection']
3631
- });
3716
+ _this._log("onlineStatusChanged() - Status changing to online. isHealthy: ".concat(_this.isHealthy));
3632
3717
 
3633
3718
  if (!_this.isHealthy) {
3634
3719
  _this._reconnect({
@@ -3641,8 +3726,7 @@ var StableWSConnection = /*#__PURE__*/function () {
3641
3726
  _defineProperty(this, "onopen", function (wsID) {
3642
3727
  if (_this.wsID !== wsID) return;
3643
3728
 
3644
- _this.logger('info', 'connection:onopen() - onopen callback', {
3645
- tags: ['connection'],
3729
+ _this._log('onopen() - onopen callback', {
3646
3730
  wsID: wsID
3647
3731
  });
3648
3732
  });
@@ -3654,27 +3738,26 @@ var StableWSConnection = /*#__PURE__*/function () {
3654
3738
  // after that a ws.onclose..
3655
3739
 
3656
3740
  if (!_this.isResolved && data) {
3741
+ var _this$resolvePromise;
3742
+
3657
3743
  _this.isResolved = true;
3658
3744
 
3659
- if (data.error != null) {
3745
+ if (data.error) {
3660
3746
  var _this$rejectPromise;
3661
3747
 
3662
3748
  (_this$rejectPromise = _this.rejectPromise) === null || _this$rejectPromise === void 0 ? void 0 : _this$rejectPromise.call(_this, _this._errorFromWSEvent(data, false));
3663
3749
  return;
3664
- } else {
3665
- var _this$resolvePromise;
3750
+ }
3666
3751
 
3667
- (_this$resolvePromise = _this.resolvePromise) === null || _this$resolvePromise === void 0 ? void 0 : _this$resolvePromise.call(_this, event);
3752
+ (_this$resolvePromise = _this.resolvePromise) === null || _this$resolvePromise === void 0 ? void 0 : _this$resolvePromise.call(_this, data);
3668
3753
 
3669
- _this._setHealth(true);
3670
- }
3754
+ _this._setHealth(true);
3671
3755
  } // trigger the event..
3672
3756
 
3673
3757
 
3674
3758
  _this.lastEvent = new Date();
3675
3759
 
3676
- _this.logger('info', 'connection:onmessage() - onmessage callback', {
3677
- tags: ['connection'],
3760
+ _this._log('onmessage() - onmessage callback', {
3678
3761
  event: event,
3679
3762
  wsID: wsID
3680
3763
  });
@@ -3683,7 +3766,7 @@ var StableWSConnection = /*#__PURE__*/function () {
3683
3766
  _this.scheduleNextPing();
3684
3767
  }
3685
3768
 
3686
- _this.messageCallback(event);
3769
+ _this.client.handleEvent(event);
3687
3770
 
3688
3771
  _this.scheduleConnectionCheck();
3689
3772
  });
@@ -3691,8 +3774,7 @@ var StableWSConnection = /*#__PURE__*/function () {
3691
3774
  _defineProperty(this, "onclose", function (wsID, event) {
3692
3775
  if (_this.wsID !== wsID) return;
3693
3776
 
3694
- _this.logger('info', 'connection:onclose() - onclose callback - ' + event.code, {
3695
- tags: ['connection'],
3777
+ _this._log('onclose() - onclose callback - ' + event.code, {
3696
3778
  event: event,
3697
3779
  wsID: wsID
3698
3780
  });
@@ -3709,8 +3791,7 @@ var StableWSConnection = /*#__PURE__*/function () {
3709
3791
  error.target = event.target;
3710
3792
  (_this$rejectPromise2 = _this.rejectPromise) === null || _this$rejectPromise2 === void 0 ? void 0 : _this$rejectPromise2.call(_this, error);
3711
3793
 
3712
- _this.logger('info', "connection:onclose() - WS connection reject with error ".concat(event.reason), {
3713
- tags: ['connection'],
3794
+ _this._log("onclose() - WS connection reject with error ".concat(event.reason), {
3714
3795
  event: event
3715
3796
  });
3716
3797
  } else {
@@ -3724,8 +3805,7 @@ var StableWSConnection = /*#__PURE__*/function () {
3724
3805
  _this.isConnecting = false;
3725
3806
  (_this$rejectPromise3 = _this.rejectPromise) === null || _this$rejectPromise3 === void 0 ? void 0 : _this$rejectPromise3.call(_this, _this._errorFromWSEvent(event));
3726
3807
 
3727
- _this.logger('info', "connection:onclose() - WS connection closed. Calling reconnect ...", {
3728
- tags: ['connection'],
3808
+ _this._log("onclose() - WS connection closed. Calling reconnect ...", {
3729
3809
  event: event
3730
3810
  }); // reconnect if its an abnormal failure
3731
3811
 
@@ -3746,8 +3826,7 @@ var StableWSConnection = /*#__PURE__*/function () {
3746
3826
  _this.isConnecting = false;
3747
3827
  (_this$rejectPromise4 = _this.rejectPromise) === null || _this$rejectPromise4 === void 0 ? void 0 : _this$rejectPromise4.call(_this, _this._errorFromWSEvent(event));
3748
3828
 
3749
- _this.logger('info', "connection:onerror() - WS connection resulted into error", {
3750
- tags: ['connection'],
3829
+ _this._log("onerror() - WS connection resulted into error", {
3751
3830
  event: event
3752
3831
  });
3753
3832
 
@@ -3755,28 +3834,28 @@ var StableWSConnection = /*#__PURE__*/function () {
3755
3834
  });
3756
3835
 
3757
3836
  _defineProperty(this, "_setHealth", function (healthy) {
3758
- if (healthy && !_this.isHealthy) {
3759
- // yes we are online:
3760
- _this.isHealthy = true;
3837
+ if (healthy === _this.isHealthy) return;
3838
+ _this.isHealthy = healthy;
3761
3839
 
3762
- _this.eventCallback({
3840
+ if (_this.isHealthy) {
3841
+ //@ts-expect-error
3842
+ _this.client.dispatchEvent({
3763
3843
  type: 'connection.changed',
3764
- online: true
3844
+ online: _this.isHealthy
3765
3845
  });
3766
- }
3767
3846
 
3768
- if (!healthy && _this.isHealthy) {
3769
- // bummer we are offline
3770
- _this.isHealthy = false;
3771
- setTimeout(function () {
3772
- if (!_this.isHealthy) {
3773
- _this.eventCallback({
3774
- type: 'connection.changed',
3775
- online: false
3776
- });
3777
- }
3778
- }, 5000);
3779
- }
3847
+ return;
3848
+ } // we're offline, wait few seconds and fire and event if still offline
3849
+
3850
+
3851
+ setTimeout(function () {
3852
+ if (_this.isHealthy) return; //@ts-expect-error
3853
+
3854
+ _this.client.dispatchEvent({
3855
+ type: 'connection.changed',
3856
+ online: _this.isHealthy
3857
+ });
3858
+ }, 5000);
3780
3859
  });
3781
3860
 
3782
3861
  _defineProperty(this, "_errorFromWSEvent", function (event) {
@@ -3798,10 +3877,9 @@ var StableWSConnection = /*#__PURE__*/function () {
3798
3877
  } // Keeping this `warn` level log, to avoid cluttering of error logs from ws failures.
3799
3878
 
3800
3879
 
3801
- _this.logger('warn', "connection:_errorFromWSEvent() - WS failed with code ".concat(code), {
3802
- tags: ['connection'],
3880
+ _this._log("_errorFromWSEvent() - WS failed with code ".concat(code), {
3803
3881
  event: event
3804
- });
3882
+ }, 'warn');
3805
3883
 
3806
3884
  var error = new Error("WS failed with code ".concat(code, " and reason - ").concat(message));
3807
3885
  error.code = code;
@@ -3815,50 +3893,13 @@ var StableWSConnection = /*#__PURE__*/function () {
3815
3893
  return error;
3816
3894
  });
3817
3895
 
3818
- _defineProperty(this, "_listenForConnectionChanges", function () {
3819
- var _window;
3820
-
3821
- // (typeof window !== 'undefined') check is for environments where window is not defined, such as nextjs environment,
3822
- // and thus (window === undefined) will result in ReferenceError.
3823
- if (typeof window !== 'undefined' && (_window = window) !== null && _window !== void 0 && _window.addEventListener) {
3824
- window.addEventListener('offline', _this.onlineStatusChanged);
3825
- window.addEventListener('online', _this.onlineStatusChanged);
3826
- }
3827
- });
3828
-
3829
- _defineProperty(this, "_removeConnectionListeners", function () {
3830
- var _window2;
3831
-
3832
- // (typeof window !== 'undefined') check is for environments where window is not defined, such as nextjs environment,
3833
- // and thus (window === undefined) will result in ReferenceError.
3834
- if (typeof window !== 'undefined' && (_window2 = window) !== null && _window2 !== void 0 && _window2.removeEventListener) {
3835
- window.removeEventListener('offline', _this.onlineStatusChanged);
3836
- window.removeEventListener('online', _this.onlineStatusChanged);
3837
- }
3838
- });
3839
-
3840
3896
  _defineProperty(this, "_setupConnectionPromise", function () {
3841
- var that = _this;
3842
3897
  _this.isResolved = false;
3843
3898
  /** a promise that is resolved once ws.open is called */
3844
3899
 
3845
3900
  _this.connectionOpen = new Promise(function (resolve, reject) {
3846
- that.resolvePromise = resolve;
3847
- that.rejectPromise = reject;
3848
- }).then(function (e) {
3849
- if (e.data && typeof e.data === 'string') {
3850
- var data = JSON.parse(e.data);
3851
-
3852
- if (data && data.error != null) {
3853
- throw new Error(JSON.stringify(data.error));
3854
- }
3855
-
3856
- return data;
3857
- } else {
3858
- return undefined;
3859
- }
3860
- }, function (error) {
3861
- throw error;
3901
+ _this.resolvePromise = resolve;
3902
+ _this.rejectPromise = reject;
3862
3903
  });
3863
3904
  });
3864
3905
 
@@ -3872,7 +3913,7 @@ var StableWSConnection = /*#__PURE__*/function () {
3872
3913
  // send the healthcheck.., server replies with a health check event
3873
3914
  var data = [{
3874
3915
  type: 'health.check',
3875
- client_id: _this.clientID
3916
+ client_id: _this.client.clientID
3876
3917
  }]; // try to send on the connection
3877
3918
 
3878
3919
  try {
@@ -3893,9 +3934,7 @@ var StableWSConnection = /*#__PURE__*/function () {
3893
3934
  var now = new Date();
3894
3935
 
3895
3936
  if (_this.lastEvent && now.getTime() - _this.lastEvent.getTime() > _this.connectionCheckTimeout) {
3896
- _this.logger('info', 'connection:scheduleConnectionCheck - going to reconnect', {
3897
- tags: ['connection']
3898
- });
3937
+ _this._log('scheduleConnectionCheck - going to reconnect');
3899
3938
 
3900
3939
  _this._setHealth(false);
3901
3940
 
@@ -3904,15 +3943,8 @@ var StableWSConnection = /*#__PURE__*/function () {
3904
3943
  }, _this.connectionCheckTimeout);
3905
3944
  });
3906
3945
 
3907
- this.wsBaseURL = wsBaseURL;
3908
- this.clientID = clientID;
3909
- this.userID = userID;
3910
- this.user = user;
3911
- this.authType = authType;
3912
- this.userAgent = userAgent;
3913
- this.apiKey = apiKey;
3914
- this.tokenManager = tokenManager;
3915
- this.device = device;
3946
+ /** StreamChat client */
3947
+ this.client = client;
3916
3948
  /** consecutive failures influence the duration of the timeout */
3917
3949
 
3918
3950
  this.consecutiveFailures = 0;
@@ -3922,18 +3954,15 @@ var StableWSConnection = /*#__PURE__*/function () {
3922
3954
  /** We only make 1 attempt to reconnect at the same time.. */
3923
3955
 
3924
3956
  this.isConnecting = false;
3957
+ /** To avoid reconnect if client is disconnected */
3958
+
3959
+ this.isDisconnected = false;
3925
3960
  /** Boolean that indicates if the connection promise is resolved */
3926
3961
 
3927
3962
  this.isResolved = false;
3928
3963
  /** Boolean that indicates if we have a working connection to the server */
3929
3964
 
3930
3965
  this.isHealthy = false;
3931
- /** Callback when the connection fails and recovers */
3932
-
3933
- this.recoverCallback = recoverCallback;
3934
- this.messageCallback = messageCallback;
3935
- this.eventCallback = eventCallback;
3936
- this.logger = logger;
3937
3966
  /** Incremented when a new WS connection is made */
3938
3967
 
3939
3968
  this.wsID = 1;
@@ -3944,74 +3973,82 @@ var StableWSConnection = /*#__PURE__*/function () {
3944
3973
 
3945
3974
  this.pingInterval = 25 * 1000;
3946
3975
  this.connectionCheckTimeout = this.pingInterval + 10 * 1000;
3947
-
3948
- this._listenForConnectionChanges();
3949
-
3950
- this.postInsights = postInsights;
3951
- this.insightMetrics = insightMetrics;
3976
+ addConnectionEventListeners(this.onlineStatusChanged);
3952
3977
  }
3953
- /**
3954
- * connect - Connect to the WS URL
3955
- *
3956
- * @return {ConnectAPIResponse<ChannelType, CommandType, UserType>} Promise that completes once the first health check message is received
3957
- */
3958
-
3959
3978
 
3960
3979
  _createClass(StableWSConnection, [{
3980
+ key: "_log",
3981
+ value: function _log(msg) {
3982
+ var extra = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3983
+ var level = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'info';
3984
+ this.client.logger(level, 'connection:' + msg, _objectSpread$3({
3985
+ tags: ['connection']
3986
+ }, extra));
3987
+ }
3988
+ /**
3989
+ * connect - Connect to the WS URL
3990
+ * the default 15s timeout allows between 2~3 tries
3991
+ * @return {ConnectAPIResponse<ChannelType, CommandType, UserType>} Promise that completes once the first health check message is received
3992
+ */
3993
+
3994
+ }, {
3961
3995
  key: "connect",
3962
3996
  value: function () {
3963
3997
  var _connect2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
3964
- var healthCheck;
3998
+ var timeout,
3999
+ healthCheck,
4000
+ _args = arguments;
3965
4001
  return _regeneratorRuntime.wrap(function _callee$(_context) {
3966
4002
  while (1) {
3967
4003
  switch (_context.prev = _context.next) {
3968
4004
  case 0:
4005
+ timeout = _args.length > 0 && _args[0] !== undefined ? _args[0] : 15000;
4006
+
3969
4007
  if (!this.isConnecting) {
3970
- _context.next = 2;
4008
+ _context.next = 3;
3971
4009
  break;
3972
4010
  }
3973
4011
 
3974
4012
  throw Error("You've called connect twice, can only attempt 1 connection at the time");
3975
4013
 
3976
- case 2:
3977
- _context.prev = 2;
3978
- _context.next = 5;
4014
+ case 3:
4015
+ this.isDisconnected = false;
4016
+ _context.prev = 4;
4017
+ _context.next = 7;
3979
4018
  return this._connect();
3980
4019
 
3981
- case 5:
4020
+ case 7:
3982
4021
  healthCheck = _context.sent;
3983
4022
  this.consecutiveFailures = 0;
3984
- this.logger('info', "connection:connect() - Established ws connection with healthcheck: ".concat(healthCheck), {
3985
- tags: ['connection']
3986
- });
3987
- _context.next = 21;
4023
+
4024
+ this._log("connect() - Established ws connection with healthcheck: ".concat(healthCheck));
4025
+
4026
+ _context.next = 23;
3988
4027
  break;
3989
4028
 
3990
- case 10:
3991
- _context.prev = 10;
3992
- _context.t0 = _context["catch"](2);
4029
+ case 12:
4030
+ _context.prev = 12;
4031
+ _context.t0 = _context["catch"](4);
3993
4032
  this.isHealthy = false;
3994
4033
  this.consecutiveFailures += 1;
3995
4034
 
3996
- if (!(_context.t0.code === chatCodes.TOKEN_EXPIRED && !this.tokenManager.isStatic())) {
3997
- _context.next = 19;
4035
+ if (!(_context.t0.code === chatCodes.TOKEN_EXPIRED && !this.client.tokenManager.isStatic())) {
4036
+ _context.next = 21;
3998
4037
  break;
3999
4038
  }
4000
4039
 
4001
- this.logger('info', 'connection:connect() - WS failure due to expired token, so going to try to reload token and reconnect', {
4002
- tags: ['connection']
4003
- });
4040
+ this._log('connect() - WS failure due to expired token, so going to try to reload token and reconnect');
4004
4041
 
4005
4042
  this._reconnect({
4006
4043
  refreshToken: true
4007
4044
  });
4008
4045
 
4009
- _context.next = 21;
4046
+ _context.next = 23;
4010
4047
  break;
4011
4048
 
4012
- case 19:
4049
+ case 21:
4013
4050
  if (_context.t0.isWSFailure) {
4014
- _context.next = 21;
4051
+ _context.next = 23;
4015
4052
  break;
4016
4053
  }
4017
4054
 
@@ -4022,19 +4059,19 @@ var StableWSConnection = /*#__PURE__*/function () {
4022
4059
  isWSFailure: _context.t0.isWSFailure
4023
4060
  }));
4024
4061
 
4025
- case 21:
4026
- _context.next = 23;
4027
- return this._waitForHealthy();
4028
-
4029
4062
  case 23:
4063
+ _context.next = 25;
4064
+ return this._waitForHealthy(timeout);
4065
+
4066
+ case 25:
4030
4067
  return _context.abrupt("return", _context.sent);
4031
4068
 
4032
- case 24:
4069
+ case 26:
4033
4070
  case "end":
4034
4071
  return _context.stop();
4035
4072
  }
4036
4073
  }
4037
- }, _callee, this, [[2, 10]]);
4074
+ }, _callee, this, [[4, 12]]);
4038
4075
  }));
4039
4076
 
4040
4077
  function connect() {
@@ -4125,6 +4162,7 @@ var StableWSConnection = /*#__PURE__*/function () {
4125
4162
  return sleep(timeout);
4126
4163
 
4127
4164
  case 2:
4165
+ _this2.isConnecting = false;
4128
4166
  throw new Error(JSON.stringify({
4129
4167
  code: '',
4130
4168
  StatusCode: '',
@@ -4132,7 +4170,7 @@ var StableWSConnection = /*#__PURE__*/function () {
4132
4170
  isWSFailure: true
4133
4171
  }));
4134
4172
 
4135
- case 3:
4173
+ case 4:
4136
4174
  case "end":
4137
4175
  return _context3.stop();
4138
4176
  }
@@ -4156,7 +4194,7 @@ var StableWSConnection = /*#__PURE__*/function () {
4156
4194
  }()
4157
4195
  /**
4158
4196
  * Builds and returns the url for websocket.
4159
- * @param reqID Unique identifier generated on client side, to help tracking apis on backend.
4197
+ * @private
4160
4198
  * @returns url string
4161
4199
  */
4162
4200
 
@@ -4170,10 +4208,11 @@ var StableWSConnection = /*#__PURE__*/function () {
4170
4208
  function disconnect(timeout) {
4171
4209
  var _this3 = this;
4172
4210
 
4173
- this.logger('info', "connection:disconnect() - Closing the websocket connection for wsID ".concat(this.wsID), {
4174
- tags: ['connection']
4175
- });
4176
- this.wsID += 1; // start by removing all the listeners
4211
+ this._log("disconnect() - Closing the websocket connection for wsID ".concat(this.wsID));
4212
+
4213
+ this.wsID += 1;
4214
+ this.isConnecting = false;
4215
+ this.isDisconnected = true; // start by removing all the listeners
4177
4216
 
4178
4217
  if (this.healthCheckTimeoutRef) {
4179
4218
  clearInterval(this.healthCheckTimeoutRef);
@@ -4183,8 +4222,7 @@ var StableWSConnection = /*#__PURE__*/function () {
4183
4222
  clearInterval(this.connectionCheckTimeoutRef);
4184
4223
  }
4185
4224
 
4186
- this._removeConnectionListeners();
4187
-
4225
+ removeConnectionEventListeners(this.onlineStatusChanged);
4188
4226
  this.isHealthy = false; // remove ws handlers...
4189
4227
 
4190
4228
  if (this.ws && this.ws.removeAllListeners) {
@@ -4200,8 +4238,7 @@ var StableWSConnection = /*#__PURE__*/function () {
4200
4238
  if (ws && ws.close && ws.readyState === ws.OPEN) {
4201
4239
  isClosedPromise = new Promise(function (resolve) {
4202
4240
  var onclose = function onclose(event) {
4203
- _this3.logger('info', "connection:disconnect() - resolving isClosedPromise ".concat(event ? 'with' : 'without', " close frame"), {
4204
- tags: ['connection'],
4241
+ _this3._log("disconnect() - resolving isClosedPromise ".concat(event ? 'with' : 'without', " close frame"), {
4205
4242
  event: event
4206
4243
  });
4207
4244
 
@@ -4213,14 +4250,13 @@ var StableWSConnection = /*#__PURE__*/function () {
4213
4250
 
4214
4251
  setTimeout(onclose, timeout != null ? timeout : 1000);
4215
4252
  });
4216
- this.logger('info', "connection:disconnect() - Manually closed connection by calling client.disconnect()", {
4217
- tags: ['connection']
4218
- });
4253
+
4254
+ this._log("disconnect() - Manually closed connection by calling client.disconnect()");
4255
+
4219
4256
  ws.close(chatCodes.WS_CLOSED_SUCCESS, 'Manually closed connection by calling client.disconnect()');
4220
4257
  } else {
4221
- this.logger('info', "connection:disconnect() - ws connection doesn't exist or it is already closed.", {
4222
- tags: ['connection']
4223
- });
4258
+ this._log("disconnect() - ws connection doesn't exist or it is already closed.");
4259
+
4224
4260
  isClosedPromise = Promise.resolve();
4225
4261
  }
4226
4262
 
@@ -4237,13 +4273,12 @@ var StableWSConnection = /*#__PURE__*/function () {
4237
4273
  key: "_connect",
4238
4274
  value: function () {
4239
4275
  var _connect3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
4240
- var wsURL, response, _this$postInsights, insights;
4241
-
4276
+ var wsURL, response, insights;
4242
4277
  return _regeneratorRuntime.wrap(function _callee5$(_context5) {
4243
4278
  while (1) {
4244
4279
  switch (_context5.prev = _context5.next) {
4245
4280
  case 0:
4246
- if (!this.isConnecting) {
4281
+ if (!(this.isConnecting || this.isDisconnected)) {
4247
4282
  _context5.next = 2;
4248
4283
  break;
4249
4284
  }
@@ -4254,15 +4289,15 @@ var StableWSConnection = /*#__PURE__*/function () {
4254
4289
  // simply ignore _connect if it's currently trying to connect
4255
4290
  this.isConnecting = true;
4256
4291
  this.requestID = randomId();
4257
- this.insightMetrics.connectionStartTimestamp = new Date().getTime();
4292
+ this.client.insightMetrics.connectionStartTimestamp = new Date().getTime();
4258
4293
  _context5.prev = 5;
4259
4294
  _context5.next = 8;
4260
- return this.tokenManager.tokenReady();
4295
+ return this.client.tokenManager.tokenReady();
4261
4296
 
4262
4297
  case 8:
4263
4298
  this._setupConnectionPromise();
4264
4299
 
4265
- wsURL = this._buildUrl(this.requestID);
4300
+ wsURL = this._buildUrl();
4266
4301
  this.ws = new WebSocket(wsURL);
4267
4302
  this.ws.onopen = this.onopen.bind(this, this.wsID);
4268
4303
  this.ws.onclose = this.onclose.bind(this, this.wsID);
@@ -4282,9 +4317,9 @@ var StableWSConnection = /*#__PURE__*/function () {
4282
4317
 
4283
4318
  this.connectionID = response.connection_id;
4284
4319
 
4285
- if (this.insightMetrics.wsConsecutiveFailures > 0 && this.postInsights) {
4286
- this.postInsights('ws_success_after_failure', buildWsSuccessAfterFailureInsight(this));
4287
- this.insightMetrics.wsConsecutiveFailures = 0;
4320
+ if (this.client.insightMetrics.wsConsecutiveFailures > 0 && this.client.options.enableInsights) {
4321
+ postInsights('ws_success_after_failure', buildWsSuccessAfterFailureInsight(this));
4322
+ this.client.insightMetrics.wsConsecutiveFailures = 0;
4288
4323
  }
4289
4324
 
4290
4325
  return _context5.abrupt("return", response);
@@ -4298,12 +4333,11 @@ var StableWSConnection = /*#__PURE__*/function () {
4298
4333
  _context5.t0 = _context5["catch"](5);
4299
4334
  this.isConnecting = false;
4300
4335
 
4301
- if (this.postInsights) {
4302
- this.insightMetrics.wsConsecutiveFailures++;
4303
- this.insightMetrics.wsTotalFailures++; // @ts-ignore
4304
-
4336
+ if (this.client.options.enableInsights) {
4337
+ this.client.insightMetrics.wsConsecutiveFailures++;
4338
+ this.client.insightMetrics.wsTotalFailures++;
4305
4339
  insights = buildWsFatalInsight(this, convertErrorToJson(_context5.t0));
4306
- (_this$postInsights = this.postInsights) === null || _this$postInsights === void 0 ? void 0 : _this$postInsights.call(this, 'ws_fatal', insights);
4340
+ postInsights === null || postInsights === void 0 ? void 0 : postInsights('ws_fatal', insights);
4307
4341
  }
4308
4342
 
4309
4343
  throw _context5.t0;
@@ -4337,26 +4371,23 @@ var StableWSConnection = /*#__PURE__*/function () {
4337
4371
  var _reconnect2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
4338
4372
  var options,
4339
4373
  interval,
4340
- _open,
4341
4374
  _args6 = arguments;
4342
-
4343
4375
  return _regeneratorRuntime.wrap(function _callee6$(_context6) {
4344
4376
  while (1) {
4345
4377
  switch (_context6.prev = _context6.next) {
4346
4378
  case 0:
4347
4379
  options = _args6.length > 0 && _args6[0] !== undefined ? _args6[0] : {};
4348
- this.logger('info', 'connection:_reconnect() - Initiating the reconnect', {
4349
- tags: ['connection']
4350
- }); // only allow 1 connection at the time
4380
+
4381
+ this._log('_reconnect() - Initiating the reconnect'); // only allow 1 connection at the time
4382
+
4351
4383
 
4352
4384
  if (!(this.isConnecting || this.isHealthy)) {
4353
4385
  _context6.next = 5;
4354
4386
  break;
4355
4387
  }
4356
4388
 
4357
- this.logger('info', 'connection:_reconnect() - Abort (1) since already connecting or healthy', {
4358
- tags: ['connection']
4359
- });
4389
+ this._log('_reconnect() - Abort (1) since already connecting or healthy');
4390
+
4360
4391
  return _context6.abrupt("return");
4361
4392
 
4362
4393
  case 5:
@@ -4378,95 +4409,86 @@ var StableWSConnection = /*#__PURE__*/function () {
4378
4409
  break;
4379
4410
  }
4380
4411
 
4381
- this.logger('info', 'connection:_reconnect() - Abort (2) since already connecting or healthy', {
4382
- tags: ['connection']
4383
- });
4412
+ this._log('_reconnect() - Abort (2) since already connecting or healthy');
4413
+
4384
4414
  return _context6.abrupt("return");
4385
4415
 
4386
4416
  case 12:
4387
- // cleanup the old connection
4388
- this.logger('info', 'connection:_reconnect() - Destroying current WS connection', {
4389
- tags: ['connection']
4390
- });
4417
+ if (!this.isDisconnected) {
4418
+ _context6.next = 15;
4419
+ break;
4420
+ }
4421
+
4422
+ this._log('_reconnect() - Abort (3) since disconnect() is called');
4423
+
4424
+ return _context6.abrupt("return");
4425
+
4426
+ case 15:
4427
+ this._log('_reconnect() - Destroying current WS connection'); // cleanup the old connection
4428
+
4391
4429
 
4392
4430
  this._destroyCurrentWSConnection();
4393
4431
 
4394
4432
  if (!options.refreshToken) {
4395
- _context6.next = 17;
4433
+ _context6.next = 20;
4396
4434
  break;
4397
4435
  }
4398
4436
 
4399
- _context6.next = 17;
4400
- return this.tokenManager.loadToken();
4401
-
4402
- case 17:
4403
- _context6.prev = 17;
4404
4437
  _context6.next = 20;
4405
- return this._connect();
4438
+ return this.client.tokenManager.loadToken();
4406
4439
 
4407
4440
  case 20:
4408
- _open = _context6.sent;
4409
-
4410
- if (!this.recoverCallback) {
4411
- _context6.next = 26;
4412
- break;
4413
- }
4441
+ _context6.prev = 20;
4442
+ _context6.next = 23;
4443
+ return this._connect();
4414
4444
 
4415
- this.logger('info', 'connection:_reconnect() - Waiting for recoverCallBack', {
4416
- tags: ['connection']
4417
- });
4418
- _context6.next = 25;
4419
- return this.recoverCallback(_open);
4445
+ case 23:
4446
+ this._log('_reconnect() - Waiting for recoverCallBack');
4420
4447
 
4421
- case 25:
4422
- this.logger('info', 'connection:_reconnect() - Finished recoverCallBack', {
4423
- tags: ['connection']
4424
- });
4448
+ _context6.next = 26;
4449
+ return this.client.recoverState();
4425
4450
 
4426
4451
  case 26:
4452
+ this._log('_reconnect() - Finished recoverCallBack');
4453
+
4427
4454
  this.consecutiveFailures = 0;
4428
- _context6.next = 37;
4455
+ _context6.next = 38;
4429
4456
  break;
4430
4457
 
4431
- case 29:
4432
- _context6.prev = 29;
4433
- _context6.t0 = _context6["catch"](17);
4458
+ case 30:
4459
+ _context6.prev = 30;
4460
+ _context6.t0 = _context6["catch"](20);
4434
4461
  this.isHealthy = false;
4435
4462
  this.consecutiveFailures += 1;
4436
4463
 
4437
- if (!(_context6.t0.code === chatCodes.TOKEN_EXPIRED && !this.tokenManager.isStatic())) {
4438
- _context6.next = 36;
4464
+ if (!(_context6.t0.code === chatCodes.TOKEN_EXPIRED && !this.client.tokenManager.isStatic())) {
4465
+ _context6.next = 37;
4439
4466
  break;
4440
4467
  }
4441
4468
 
4442
- this.logger('info', 'connection:_reconnect() - WS failure due to expired token, so going to try to reload token and reconnect', {
4443
- tags: ['connection']
4444
- });
4469
+ this._log('_reconnect() - WS failure due to expired token, so going to try to reload token and reconnect');
4470
+
4445
4471
  return _context6.abrupt("return", this._reconnect({
4446
4472
  refreshToken: true
4447
4473
  }));
4448
4474
 
4449
- case 36:
4475
+ case 37:
4450
4476
  // reconnect on WS failures, don't reconnect if there is a code bug
4451
4477
  if (_context6.t0.isWSFailure) {
4452
- this.logger('info', 'connection:_reconnect() - WS failure, so going to try to reconnect', {
4453
- tags: ['connection']
4454
- });
4478
+ this._log('_reconnect() - WS failure, so going to try to reconnect');
4455
4479
 
4456
4480
  this._reconnect();
4457
4481
  }
4458
4482
 
4459
- case 37:
4460
- this.logger('info', 'connection:_reconnect() - == END ==', {
4461
- tags: ['connection']
4462
- });
4463
-
4464
4483
  case 38:
4484
+ this._log('_reconnect() - == END ==');
4485
+
4486
+ case 39:
4465
4487
  case "end":
4466
4488
  return _context6.stop();
4467
4489
  }
4468
4490
  }
4469
- }, _callee6, this, [[17, 29]]);
4491
+ }, _callee6, this, [[20, 30]]);
4470
4492
  }));
4471
4493
 
4472
4494
  function _reconnect() {
@@ -4495,13 +4517,10 @@ var StableWSConnection = /*#__PURE__*/function () {
4495
4517
  this.wsID += 1;
4496
4518
 
4497
4519
  try {
4498
- if (this.ws && this.ws.removeAllListeners) {
4499
- this.ws.removeAllListeners();
4500
- }
4520
+ var _this$ws2, _this$ws3;
4501
4521
 
4502
- if (this.ws && this.ws.close) {
4503
- this.ws.close();
4504
- }
4522
+ this === null || this === void 0 ? void 0 : (_this$ws2 = this.ws) === null || _this$ws2 === void 0 ? void 0 : _this$ws2.removeAllListeners();
4523
+ this === null || this === void 0 ? void 0 : (_this$ws3 = this.ws) === null || _this$ws3 === void 0 ? void 0 : _this$ws3.close();
4505
4524
  } catch (e) {// we don't care
4506
4525
  }
4507
4526
  }
@@ -4518,9 +4537,9 @@ var jwt = null;
4518
4537
 
4519
4538
  var crypto$1 = null;
4520
4539
 
4521
- function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
4540
+ function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
4522
4541
 
4523
- function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$1(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
4542
+ function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$2(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
4524
4543
 
4525
4544
  /**
4526
4545
  * Creates the JWT token that can be used for a UserSession
@@ -4529,7 +4548,7 @@ function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) {
4529
4548
  * @private
4530
4549
  * @param {Secret} apiSecret - API Secret key
4531
4550
  * @param {string} userId - The user_id key in the JWT payload
4532
- * @param {UnknownType} [extraData] - Extra that should be part of the JWT token
4551
+ * @param {UR} [extraData] - Extra that should be part of the JWT token
4533
4552
  * @param {SignOptions} [jwtOptions] - Options that can be past to jwt.sign
4534
4553
  * @return {string} JWT Token
4535
4554
  */
@@ -4541,7 +4560,7 @@ function JWTUserToken(apiSecret, userId) {
4541
4560
  throw new TypeError('userId should be a string');
4542
4561
  }
4543
4562
 
4544
- var payload = _objectSpread$1({
4563
+ var payload = _objectSpread$2({
4545
4564
  user_id: userId
4546
4565
  }, extraData); // make sure we return a clear error when jwt is shimmed (ie. browser build)
4547
4566
 
@@ -4722,76 +4741,586 @@ function TokenManager(secret) {
4722
4741
  break;
4723
4742
  }
4724
4743
 
4725
- return _context2.abrupt("return", resolve(_this.token));
4744
+ return _context2.abrupt("return", resolve(_this.token));
4745
+
4746
+ case 2:
4747
+ if (!(_this.tokenProvider && typeof _this.tokenProvider !== 'string')) {
4748
+ _context2.next = 7;
4749
+ break;
4750
+ }
4751
+
4752
+ _context2.next = 5;
4753
+ return _this.tokenProvider();
4754
+
4755
+ case 5:
4756
+ _this.token = _context2.sent;
4757
+ resolve(_this.token);
4758
+
4759
+ case 7:
4760
+ case "end":
4761
+ return _context2.stop();
4762
+ }
4763
+ }
4764
+ }, _callee2);
4765
+ }));
4766
+
4767
+ return function (_x3) {
4768
+ return _ref2.apply(this, arguments);
4769
+ };
4770
+ }());
4771
+ return _this.loadTokenPromise;
4772
+ });
4773
+
4774
+ _defineProperty(this, "getToken", function () {
4775
+ if (_this.token) {
4776
+ return _this.token;
4777
+ }
4778
+
4779
+ if (_this.user && _this.user.anon && !_this.token) {
4780
+ return _this.token;
4781
+ }
4782
+
4783
+ if (_this.secret) {
4784
+ return JWTServerToken(_this.secret);
4785
+ }
4786
+
4787
+ throw new Error("Both secret and user tokens are not set. Either client.connectUser wasn't called or client.disconnect was called");
4788
+ });
4789
+
4790
+ _defineProperty(this, "isStatic", function () {
4791
+ return _this.type === 'static';
4792
+ });
4793
+
4794
+ this.loadTokenPromise = null;
4795
+
4796
+ if (secret) {
4797
+ this.secret = secret;
4798
+ }
4799
+
4800
+ this.type = 'static';
4801
+
4802
+ if (this.secret) {
4803
+ this.token = JWTServerToken(this.secret);
4804
+ }
4805
+ }
4806
+ /**
4807
+ * Set the static string token or token provider.
4808
+ * Token provider should return a token string or a promise which resolves to string token.
4809
+ *
4810
+ * @param {TokenOrProvider} tokenOrProvider
4811
+ * @param {UserResponse<UserType>} user
4812
+ */
4813
+ ;
4814
+
4815
+ var APIErrorCodes = {
4816
+ '-1': {
4817
+ name: 'InternalSystemError',
4818
+ retryable: true
4819
+ },
4820
+ '2': {
4821
+ name: 'AccessKeyError',
4822
+ retryable: false
4823
+ },
4824
+ '3': {
4825
+ name: 'AuthenticationFailedError',
4826
+ retryable: true
4827
+ },
4828
+ '4': {
4829
+ name: 'InputError',
4830
+ retryable: false
4831
+ },
4832
+ '6': {
4833
+ name: 'DuplicateUsernameError',
4834
+ retryable: false
4835
+ },
4836
+ '9': {
4837
+ name: 'RateLimitError',
4838
+ retryable: true
4839
+ },
4840
+ '16': {
4841
+ name: 'DoesNotExistError',
4842
+ retryable: false
4843
+ },
4844
+ '17': {
4845
+ name: 'NotAllowedError',
4846
+ retryable: false
4847
+ },
4848
+ '18': {
4849
+ name: 'EventNotSupportedError',
4850
+ retryable: false
4851
+ },
4852
+ '19': {
4853
+ name: 'ChannelFeatureNotSupportedError',
4854
+ retryable: false
4855
+ },
4856
+ '20': {
4857
+ name: 'MessageTooLongError',
4858
+ retryable: false
4859
+ },
4860
+ '21': {
4861
+ name: 'MultipleNestingLevelError',
4862
+ retryable: false
4863
+ },
4864
+ '22': {
4865
+ name: 'PayloadTooBigError',
4866
+ retryable: false
4867
+ },
4868
+ '23': {
4869
+ name: 'RequestTimeoutError',
4870
+ retryable: true
4871
+ },
4872
+ '24': {
4873
+ name: 'MaxHeaderSizeExceededError',
4874
+ retryable: false
4875
+ },
4876
+ '40': {
4877
+ name: 'AuthErrorTokenExpired',
4878
+ retryable: false
4879
+ },
4880
+ '41': {
4881
+ name: 'AuthErrorTokenNotValidYet',
4882
+ retryable: false
4883
+ },
4884
+ '42': {
4885
+ name: 'AuthErrorTokenUsedBeforeIssuedAt',
4886
+ retryable: false
4887
+ },
4888
+ '43': {
4889
+ name: 'AuthErrorTokenSignatureInvalid',
4890
+ retryable: false
4891
+ },
4892
+ '44': {
4893
+ name: 'CustomCommandEndpointMissingError',
4894
+ retryable: false
4895
+ },
4896
+ '45': {
4897
+ name: 'CustomCommandEndpointCallError',
4898
+ retryable: true
4899
+ },
4900
+ '46': {
4901
+ name: 'ConnectionIDNotFoundError',
4902
+ retryable: false
4903
+ },
4904
+ '60': {
4905
+ name: 'CoolDownError',
4906
+ retryable: true
4907
+ },
4908
+ '69': {
4909
+ name: 'ErrWrongRegion',
4910
+ retryable: false
4911
+ },
4912
+ '70': {
4913
+ name: 'ErrQueryChannelPermissions',
4914
+ retryable: false
4915
+ },
4916
+ '71': {
4917
+ name: 'ErrTooManyConnections',
4918
+ retryable: true
4919
+ },
4920
+ '99': {
4921
+ name: 'AppSuspendedError',
4922
+ retryable: false
4923
+ }
4924
+ };
4925
+ function isAPIError(error) {
4926
+ return error.code !== undefined;
4927
+ }
4928
+ function isErrorRetryable(error) {
4929
+ if (!error.code) return false;
4930
+ var err = APIErrorCodes["".concat(error.code)];
4931
+ if (!err) return false;
4932
+ return err.retryable;
4933
+ }
4934
+ function isConnectionIDError(error) {
4935
+ return error.code === 46; // ConnectionIDNotFoundError
4936
+ }
4937
+ function isWSFailure(err) {
4938
+ if (typeof err.isWSFailure === 'boolean') {
4939
+ return err.isWSFailure;
4940
+ }
4941
+
4942
+ try {
4943
+ return JSON.parse(err.message).isWSFailure;
4944
+ } catch (_) {
4945
+ return false;
4946
+ }
4947
+ }
4948
+
4949
+ function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
4950
+
4951
+ function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$1(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
4952
+ var ConnectionState;
4953
+
4954
+ (function (ConnectionState) {
4955
+ ConnectionState["Closed"] = "CLOSED";
4956
+ ConnectionState["Connected"] = "CONNECTED";
4957
+ ConnectionState["Connecting"] = "CONNECTING";
4958
+ ConnectionState["Disconnected"] = "DISCONNECTED";
4959
+ ConnectionState["Init"] = "INIT";
4960
+ })(ConnectionState || (ConnectionState = {}));
4961
+
4962
+ var WSConnectionFallback = /*#__PURE__*/function () {
4963
+ function WSConnectionFallback(_ref) {
4964
+ var _this = this;
4965
+
4966
+ var client = _ref.client;
4967
+
4968
+ _classCallCheck(this, WSConnectionFallback);
4969
+
4970
+ _defineProperty(this, "client", void 0);
4971
+
4972
+ _defineProperty(this, "state", void 0);
4973
+
4974
+ _defineProperty(this, "consecutiveFailures", void 0);
4975
+
4976
+ _defineProperty(this, "connectionID", void 0);
4977
+
4978
+ _defineProperty(this, "cancelToken", void 0);
4979
+
4980
+ _defineProperty(this, "_onlineStatusChanged", function (event) {
4981
+ _this._log("_onlineStatusChanged() - ".concat(event.type));
4982
+
4983
+ if (event.type === 'offline') {
4984
+ var _this$cancelToken;
4985
+
4986
+ _this._setState(ConnectionState.Closed);
4987
+
4988
+ (_this$cancelToken = _this.cancelToken) === null || _this$cancelToken === void 0 ? void 0 : _this$cancelToken.cancel('disconnect() is called');
4989
+ _this.cancelToken = undefined;
4990
+ return;
4991
+ }
4992
+
4993
+ if (event.type === 'online' && _this.state === ConnectionState.Closed) {
4994
+ _this.connect(true);
4995
+ }
4996
+ });
4997
+
4998
+ _defineProperty(this, "_req", /*#__PURE__*/function () {
4999
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params, config, retry) {
5000
+ var _this$cancelToken2, res;
5001
+
5002
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
5003
+ while (1) {
5004
+ switch (_context.prev = _context.next) {
5005
+ case 0:
5006
+ if (!_this.cancelToken && !params.close) {
5007
+ _this.cancelToken = axios.CancelToken.source();
5008
+ }
5009
+
5010
+ _context.prev = 1;
5011
+ _context.next = 4;
5012
+ return _this.client.doAxiosRequest('get', _this.client.baseURL.replace(':3030', ':8900') + '/longpoll', // replace port if present for testing with local API
5013
+ undefined, {
5014
+ config: _objectSpread$1(_objectSpread$1({}, config), {}, {
5015
+ cancelToken: (_this$cancelToken2 = _this.cancelToken) === null || _this$cancelToken2 === void 0 ? void 0 : _this$cancelToken2.token
5016
+ }),
5017
+ params: params
5018
+ });
5019
+
5020
+ case 4:
5021
+ res = _context.sent;
5022
+ _this.consecutiveFailures = 0; // always reset in case of no error
5023
+
5024
+ return _context.abrupt("return", res);
5025
+
5026
+ case 9:
5027
+ _context.prev = 9;
5028
+ _context.t0 = _context["catch"](1);
5029
+ _this.consecutiveFailures += 1;
5030
+
5031
+ if (!(retry && isErrorRetryable(_context.t0))) {
5032
+ _context.next = 17;
5033
+ break;
5034
+ }
5035
+
5036
+ _this._log("_req() - Retryable error, retrying request");
5037
+
5038
+ _context.next = 16;
5039
+ return sleep(retryInterval(_this.consecutiveFailures));
5040
+
5041
+ case 16:
5042
+ return _context.abrupt("return", _this._req(params, config, retry));
5043
+
5044
+ case 17:
5045
+ throw _context.t0;
5046
+
5047
+ case 18:
5048
+ case "end":
5049
+ return _context.stop();
5050
+ }
5051
+ }
5052
+ }, _callee, null, [[1, 9]]);
5053
+ }));
5054
+
5055
+ return function (_x, _x2, _x3) {
5056
+ return _ref2.apply(this, arguments);
5057
+ };
5058
+ }());
5059
+
5060
+ _defineProperty(this, "_poll", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
5061
+ var _data$events, data, i;
5062
+
5063
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
5064
+ while (1) {
5065
+ switch (_context2.prev = _context2.next) {
5066
+ case 0:
5067
+ if (!(_this.state === ConnectionState.Connected)) {
5068
+ _context2.next = 25;
5069
+ break;
5070
+ }
5071
+
5072
+ _context2.prev = 1;
5073
+ _context2.next = 4;
5074
+ return _this._req({}, {
5075
+ timeout: 30000
5076
+ }, true);
5077
+
5078
+ case 4:
5079
+ data = _context2.sent;
5080
+
5081
+ // 30s => API responds in 20s if there is no event
5082
+ if ((_data$events = data.events) !== null && _data$events !== void 0 && _data$events.length) {
5083
+ for (i = 0; i < data.events.length; i++) {
5084
+ _this.client.dispatchEvent(data.events[i]);
5085
+ }
5086
+ }
5087
+
5088
+ _context2.next = 23;
5089
+ break;
5090
+
5091
+ case 8:
5092
+ _context2.prev = 8;
5093
+ _context2.t0 = _context2["catch"](1);
5094
+
5095
+ if (!axios.isCancel(_context2.t0)) {
5096
+ _context2.next = 13;
5097
+ break;
5098
+ }
5099
+
5100
+ _this._log("_poll() - axios canceled request");
5101
+
5102
+ return _context2.abrupt("return");
5103
+
5104
+ case 13:
5105
+ if (!isConnectionIDError(_context2.t0)) {
5106
+ _context2.next = 18;
5107
+ break;
5108
+ }
5109
+
5110
+ _this._log("_poll() - ConnectionID error, connecting without ID...");
5111
+
5112
+ _this._setState(ConnectionState.Disconnected);
5113
+
5114
+ _this.connect(true);
5115
+
5116
+ return _context2.abrupt("return");
5117
+
5118
+ case 18:
5119
+ if (!(isAPIError(_context2.t0) && !isErrorRetryable(_context2.t0))) {
5120
+ _context2.next = 21;
5121
+ break;
5122
+ }
5123
+
5124
+ _this._setState(ConnectionState.Closed);
5125
+
5126
+ return _context2.abrupt("return");
5127
+
5128
+ case 21:
5129
+ _context2.next = 23;
5130
+ return sleep(retryInterval(_this.consecutiveFailures));
5131
+
5132
+ case 23:
5133
+ _context2.next = 0;
5134
+ break;
5135
+
5136
+ case 25:
5137
+ case "end":
5138
+ return _context2.stop();
5139
+ }
5140
+ }
5141
+ }, _callee2, null, [[1, 8]]);
5142
+ })));
5143
+
5144
+ _defineProperty(this, "connect", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
5145
+ var reconnect,
5146
+ _yield$_this$_req,
5147
+ event,
5148
+ _args3 = arguments;
5149
+
5150
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
5151
+ while (1) {
5152
+ switch (_context3.prev = _context3.next) {
5153
+ case 0:
5154
+ reconnect = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : false;
5155
+
5156
+ if (!(_this.state === ConnectionState.Connecting)) {
5157
+ _context3.next = 4;
5158
+ break;
5159
+ }
5160
+
5161
+ _this._log('connect() - connecting already in progress', {
5162
+ reconnect: reconnect
5163
+ }, 'warn');
5164
+
5165
+ return _context3.abrupt("return");
5166
+
5167
+ case 4:
5168
+ if (!(_this.state === ConnectionState.Connected)) {
5169
+ _context3.next = 7;
5170
+ break;
5171
+ }
5172
+
5173
+ _this._log('connect() - already connected and polling', {
5174
+ reconnect: reconnect
5175
+ }, 'warn');
5176
+
5177
+ return _context3.abrupt("return");
5178
+
5179
+ case 7:
5180
+ _this._setState(ConnectionState.Connecting);
5181
+
5182
+ _this.connectionID = undefined; // connect should be sent with empty connection_id so API creates one
5183
+
5184
+ _context3.prev = 9;
5185
+ _context3.next = 12;
5186
+ return _this._req({
5187
+ json: _this.client._buildWSPayload()
5188
+ }, {
5189
+ timeout: 8000
5190
+ }, // 8s
5191
+ reconnect);
5192
+
5193
+ case 12:
5194
+ _yield$_this$_req = _context3.sent;
5195
+ event = _yield$_this$_req.event;
5196
+
5197
+ _this._setState(ConnectionState.Connected);
5198
+
5199
+ _this.connectionID = event.connection_id;
5200
+
5201
+ _this._poll();
5202
+
5203
+ if (reconnect) {
5204
+ _this.client.recoverState();
5205
+ }
5206
+
5207
+ return _context3.abrupt("return", event);
5208
+
5209
+ case 21:
5210
+ _context3.prev = 21;
5211
+ _context3.t0 = _context3["catch"](9);
5212
+
5213
+ _this._setState(ConnectionState.Closed);
5214
+
5215
+ throw _context3.t0;
5216
+
5217
+ case 25:
5218
+ case "end":
5219
+ return _context3.stop();
5220
+ }
5221
+ }
5222
+ }, _callee3, null, [[9, 21]]);
5223
+ })));
5224
+
5225
+ _defineProperty(this, "isHealthy", function () {
5226
+ return _this.connectionID && _this.state === ConnectionState.Connected;
5227
+ });
4726
5228
 
4727
- case 2:
4728
- if (!(_this.tokenProvider && typeof _this.tokenProvider !== 'string')) {
4729
- _context2.next = 7;
4730
- break;
4731
- }
5229
+ _defineProperty(this, "disconnect", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
5230
+ var _this$cancelToken3;
4732
5231
 
4733
- _context2.next = 5;
4734
- return _this.tokenProvider();
5232
+ var timeout,
5233
+ connection_id,
5234
+ _args4 = arguments;
5235
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
5236
+ while (1) {
5237
+ switch (_context4.prev = _context4.next) {
5238
+ case 0:
5239
+ timeout = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : 2000;
5240
+ removeConnectionEventListeners(_this._onlineStatusChanged);
5241
+
5242
+ _this._setState(ConnectionState.Disconnected);
5243
+
5244
+ (_this$cancelToken3 = _this.cancelToken) === null || _this$cancelToken3 === void 0 ? void 0 : _this$cancelToken3.cancel('disconnect() is called');
5245
+ _this.cancelToken = undefined;
5246
+ connection_id = _this.connectionID;
5247
+ _this.connectionID = undefined;
5248
+ _context4.prev = 7;
5249
+ _context4.next = 10;
5250
+ return _this._req({
5251
+ close: true,
5252
+ connection_id: connection_id
5253
+ }, {
5254
+ timeout: timeout
5255
+ }, false);
4735
5256
 
4736
- case 5:
4737
- _this.token = _context2.sent;
4738
- resolve(_this.token);
5257
+ case 10:
5258
+ _this._log("disconnect() - Closed connectionID");
4739
5259
 
4740
- case 7:
4741
- case "end":
4742
- return _context2.stop();
4743
- }
4744
- }
4745
- }, _callee2);
4746
- }));
5260
+ _context4.next = 16;
5261
+ break;
4747
5262
 
4748
- return function (_x3) {
4749
- return _ref2.apply(this, arguments);
4750
- };
4751
- }());
4752
- return _this.loadTokenPromise;
4753
- });
5263
+ case 13:
5264
+ _context4.prev = 13;
5265
+ _context4.t0 = _context4["catch"](7);
4754
5266
 
4755
- _defineProperty(this, "getToken", function () {
4756
- if (_this.token) {
4757
- return _this.token;
4758
- }
5267
+ _this._log("disconnect() - Failed", {
5268
+ err: _context4.t0
5269
+ }, 'error');
4759
5270
 
4760
- if (_this.user && _this.user.anon && !_this.token) {
4761
- return _this.token;
4762
- }
5271
+ case 16:
5272
+ case "end":
5273
+ return _context4.stop();
5274
+ }
5275
+ }
5276
+ }, _callee4, null, [[7, 13]]);
5277
+ })));
4763
5278
 
4764
- if (_this.secret) {
4765
- return JWTServerToken(_this.secret);
5279
+ this.client = client;
5280
+ this.state = ConnectionState.Init;
5281
+ this.consecutiveFailures = 0;
5282
+ addConnectionEventListeners(this._onlineStatusChanged);
5283
+ }
5284
+
5285
+ _createClass(WSConnectionFallback, [{
5286
+ key: "_log",
5287
+ value: function _log(msg) {
5288
+ var extra = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
5289
+ var level = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'info';
5290
+ this.client.logger(level, 'WSConnectionFallback:' + msg, _objectSpread$1({
5291
+ tags: ['connection_fallback', 'connection']
5292
+ }, extra));
4766
5293
  }
5294
+ }, {
5295
+ key: "_setState",
5296
+ value: function _setState(state) {
5297
+ this._log("_setState() - ".concat(state)); // transition from connecting => connected
4767
5298
 
4768
- throw new Error("Both secret and user tokens are not set. Either client.connectUser wasn't called or client.disconnect was called");
4769
- });
4770
5299
 
4771
- _defineProperty(this, "isStatic", function () {
4772
- return _this.type === 'static';
4773
- });
5300
+ if (this.state === ConnectionState.Connecting && state === ConnectionState.Connected) {
5301
+ //@ts-expect-error
5302
+ this.client.dispatchEvent({
5303
+ type: 'connection.changed',
5304
+ online: true
5305
+ });
5306
+ }
4774
5307
 
4775
- this.loadTokenPromise = null;
5308
+ if (state === ConnectionState.Closed || state === ConnectionState.Disconnected) {
5309
+ //@ts-expect-error
5310
+ this.client.dispatchEvent({
5311
+ type: 'connection.changed',
5312
+ online: false
5313
+ });
5314
+ }
4776
5315
 
4777
- if (secret) {
4778
- this.secret = secret;
4779
- }
5316
+ this.state = state;
5317
+ }
5318
+ /** @private */
4780
5319
 
4781
- this.type = 'static';
5320
+ }]);
4782
5321
 
4783
- if (this.secret) {
4784
- this.token = JWTServerToken(this.secret);
4785
- }
4786
- }
4787
- /**
4788
- * Set the static string token or token provider.
4789
- * Token provider should return a token string or a promise which resolves to string token.
4790
- *
4791
- * @param {TokenOrProvider} tokenOrProvider
4792
- * @param {UserResponse<UserType>} user
4793
- */
4794
- ;
5322
+ return WSConnectionFallback;
5323
+ }();
4795
5324
 
4796
5325
  function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
4797
5326
 
@@ -4831,10 +5360,6 @@ var StreamChat = /*#__PURE__*/function () {
4831
5360
 
4832
5361
  _defineProperty(this, "configs", void 0);
4833
5362
 
4834
- _defineProperty(this, "connectionID", void 0);
4835
-
4836
- _defineProperty(this, "failures", void 0);
4837
-
4838
5363
  _defineProperty(this, "key", void 0);
4839
5364
 
4840
5365
  _defineProperty(this, "listeners", void 0);
@@ -4869,16 +5394,26 @@ var StreamChat = /*#__PURE__*/function () {
4869
5394
 
4870
5395
  _defineProperty(this, "wsConnection", void 0);
4871
5396
 
5397
+ _defineProperty(this, "wsFallback", void 0);
5398
+
4872
5399
  _defineProperty(this, "wsPromise", void 0);
4873
5400
 
4874
5401
  _defineProperty(this, "consecutiveFailures", void 0);
4875
5402
 
4876
5403
  _defineProperty(this, "insightMetrics", void 0);
4877
5404
 
4878
- _defineProperty(this, "_hasConnectionID", function () {
4879
- var _this$wsConnection;
5405
+ _defineProperty(this, "defaultWSTimeoutWithFallback", void 0);
4880
5406
 
4881
- return Boolean((_this$wsConnection = _this.wsConnection) === null || _this$wsConnection === void 0 ? void 0 : _this$wsConnection.connectionID);
5407
+ _defineProperty(this, "defaultWSTimeout", void 0);
5408
+
5409
+ _defineProperty(this, "_getConnectionID", function () {
5410
+ var _this$wsConnection, _this$wsFallback;
5411
+
5412
+ return ((_this$wsConnection = _this.wsConnection) === null || _this$wsConnection === void 0 ? void 0 : _this$wsConnection.connectionID) || ((_this$wsFallback = _this.wsFallback) === null || _this$wsFallback === void 0 ? void 0 : _this$wsFallback.connectionID);
5413
+ });
5414
+
5415
+ _defineProperty(this, "_hasConnectionID", function () {
5416
+ return Boolean(_this._getConnectionID());
4882
5417
  });
4883
5418
 
4884
5419
  _defineProperty(this, "connectUser", /*#__PURE__*/function () {
@@ -4964,36 +5499,55 @@ var StreamChat = /*#__PURE__*/function () {
4964
5499
  return _this.tokenManager.setTokenOrProvider(userTokenOrProvider, user);
4965
5500
  });
4966
5501
 
4967
- _defineProperty(this, "closeConnection", function (timeout) {
4968
- if (_this.cleaningIntervalRef != null) {
4969
- clearInterval(_this.cleaningIntervalRef);
4970
- _this.cleaningIntervalRef = undefined;
4971
- }
5502
+ _defineProperty(this, "closeConnection", /*#__PURE__*/function () {
5503
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(timeout) {
5504
+ var _this$wsConnection2, _this$wsFallback2;
4972
5505
 
4973
- if (!_this.wsConnection) {
4974
- return Promise.resolve();
4975
- }
5506
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
5507
+ while (1) {
5508
+ switch (_context2.prev = _context2.next) {
5509
+ case 0:
5510
+ if (_this.cleaningIntervalRef != null) {
5511
+ clearInterval(_this.cleaningIntervalRef);
5512
+ _this.cleaningIntervalRef = undefined;
5513
+ }
4976
5514
 
4977
- return _this.wsConnection.disconnect(timeout);
4978
- });
5515
+ _context2.next = 3;
5516
+ return Promise.all([(_this$wsConnection2 = _this.wsConnection) === null || _this$wsConnection2 === void 0 ? void 0 : _this$wsConnection2.disconnect(timeout), (_this$wsFallback2 = _this.wsFallback) === null || _this$wsFallback2 === void 0 ? void 0 : _this$wsFallback2.disconnect(timeout)]);
4979
5517
 
4980
- _defineProperty(this, "openConnection", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
4981
- var _this$wsConnection2;
5518
+ case 3:
5519
+ return _context2.abrupt("return", Promise.resolve());
4982
5520
 
4983
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
5521
+ case 4:
5522
+ case "end":
5523
+ return _context2.stop();
5524
+ }
5525
+ }
5526
+ }, _callee2);
5527
+ }));
5528
+
5529
+ return function (_x3) {
5530
+ return _ref2.apply(this, arguments);
5531
+ };
5532
+ }());
5533
+
5534
+ _defineProperty(this, "openConnection", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
5535
+ var _this$wsConnection3, _this$wsFallback3;
5536
+
5537
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
4984
5538
  while (1) {
4985
- switch (_context2.prev = _context2.next) {
5539
+ switch (_context3.prev = _context3.next) {
4986
5540
  case 0:
4987
5541
  if (_this.userID) {
4988
- _context2.next = 2;
5542
+ _context3.next = 2;
4989
5543
  break;
4990
5544
  }
4991
5545
 
4992
5546
  throw Error('User is not set on client, use client.connectUser or client.connectAnonymousUser instead');
4993
5547
 
4994
5548
  case 2:
4995
- if (!((_this$wsConnection2 = _this.wsConnection) !== null && _this$wsConnection2 !== void 0 && _this$wsConnection2.isHealthy && _this._hasConnectionID())) {
4996
- _context2.next = 5;
5549
+ if (!(((_this$wsConnection3 = _this.wsConnection) !== null && _this$wsConnection3 !== void 0 && _this$wsConnection3.isHealthy || (_this$wsFallback3 = _this.wsFallback) !== null && _this$wsFallback3 !== void 0 && _this$wsFallback3.isHealthy()) && _this._hasConnectionID())) {
5550
+ _context3.next = 5;
4997
5551
  break;
4998
5552
  }
4999
5553
 
@@ -5001,7 +5555,7 @@ var StreamChat = /*#__PURE__*/function () {
5001
5555
  tags: ['connection', 'client']
5002
5556
  });
5003
5557
 
5004
- return _context2.abrupt("return", Promise.resolve());
5558
+ return _context3.abrupt("return", Promise.resolve());
5005
5559
 
5006
5560
  case 5:
5007
5561
  _this.clientID = "".concat(_this.userID, "--").concat(randomId());
@@ -5009,14 +5563,14 @@ var StreamChat = /*#__PURE__*/function () {
5009
5563
 
5010
5564
  _this._startCleaning();
5011
5565
 
5012
- return _context2.abrupt("return", _this.wsPromise);
5566
+ return _context3.abrupt("return", _this.wsPromise);
5013
5567
 
5014
5568
  case 9:
5015
5569
  case "end":
5016
- return _context2.stop();
5570
+ return _context3.stop();
5017
5571
  }
5018
5572
  }
5019
- }, _callee2);
5573
+ }, _callee3);
5020
5574
  })));
5021
5575
 
5022
5576
  _defineProperty(this, "_setupConnection", this.openConnection);
@@ -5034,12 +5588,12 @@ var StreamChat = /*#__PURE__*/function () {
5034
5588
  });
5035
5589
 
5036
5590
  _defineProperty(this, "disconnectUser", /*#__PURE__*/function () {
5037
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(timeout) {
5591
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(timeout) {
5038
5592
  var closePromise, _i, _Object$values, _channel;
5039
5593
 
5040
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
5594
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
5041
5595
  while (1) {
5042
- switch (_context3.prev = _context3.next) {
5596
+ switch (_context4.prev = _context4.next) {
5043
5597
  case 0:
5044
5598
  _this.logger('info', 'client:disconnect() - Disconnecting the client', {
5045
5599
  tags: ['connection', 'client']
@@ -5063,21 +5617,21 @@ var StreamChat = /*#__PURE__*/function () {
5063
5617
 
5064
5618
  _this.state = new ClientState(); // reset token manager
5065
5619
 
5066
- _this.tokenManager.reset(); // close the WS connection
5067
-
5620
+ setTimeout(_this.tokenManager.reset); // delay reseting to use token for disconnect calls
5621
+ // close the WS connection
5068
5622
 
5069
- return _context3.abrupt("return", closePromise);
5623
+ return _context4.abrupt("return", closePromise);
5070
5624
 
5071
5625
  case 11:
5072
5626
  case "end":
5073
- return _context3.stop();
5627
+ return _context4.stop();
5074
5628
  }
5075
5629
  }
5076
- }, _callee3);
5630
+ }, _callee4);
5077
5631
  }));
5078
5632
 
5079
- return function (_x3) {
5080
- return _ref3.apply(this, arguments);
5633
+ return function (_x4) {
5634
+ return _ref4.apply(this, arguments);
5081
5635
  };
5082
5636
  }());
5083
5637
 
@@ -5105,78 +5659,78 @@ var StreamChat = /*#__PURE__*/function () {
5105
5659
  _defineProperty(this, "setAnonymousUser", this.connectAnonymousUser);
5106
5660
 
5107
5661
  _defineProperty(this, "doAxiosRequest", /*#__PURE__*/function () {
5108
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(type, url, data) {
5662
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(type, url, data) {
5109
5663
  var options,
5110
5664
  requestConfig,
5111
5665
  response,
5112
5666
  _requestConfig$header,
5113
- _args4 = arguments;
5667
+ _args5 = arguments;
5114
5668
 
5115
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
5669
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
5116
5670
  while (1) {
5117
- switch (_context4.prev = _context4.next) {
5671
+ switch (_context5.prev = _context5.next) {
5118
5672
  case 0:
5119
- options = _args4.length > 3 && _args4[3] !== undefined ? _args4[3] : {};
5120
- _context4.next = 3;
5673
+ options = _args5.length > 3 && _args5[3] !== undefined ? _args5[3] : {};
5674
+ _context5.next = 3;
5121
5675
  return _this.tokenManager.tokenReady();
5122
5676
 
5123
5677
  case 3:
5124
5678
  requestConfig = _this._enrichAxiosOptions(options);
5125
- _context4.prev = 4;
5679
+ _context5.prev = 4;
5126
5680
 
5127
5681
  _this._logApiRequest(type, url, data, requestConfig);
5128
5682
 
5129
- _context4.t0 = type;
5130
- _context4.next = _context4.t0 === 'get' ? 9 : _context4.t0 === 'delete' ? 13 : _context4.t0 === 'post' ? 17 : _context4.t0 === 'put' ? 21 : _context4.t0 === 'patch' ? 25 : _context4.t0 === 'options' ? 29 : 33;
5683
+ _context5.t0 = type;
5684
+ _context5.next = _context5.t0 === 'get' ? 9 : _context5.t0 === 'delete' ? 13 : _context5.t0 === 'post' ? 17 : _context5.t0 === 'put' ? 21 : _context5.t0 === 'patch' ? 25 : _context5.t0 === 'options' ? 29 : 33;
5131
5685
  break;
5132
5686
 
5133
5687
  case 9:
5134
- _context4.next = 11;
5688
+ _context5.next = 11;
5135
5689
  return _this.axiosInstance.get(url, requestConfig);
5136
5690
 
5137
5691
  case 11:
5138
- response = _context4.sent;
5139
- return _context4.abrupt("break", 34);
5692
+ response = _context5.sent;
5693
+ return _context5.abrupt("break", 34);
5140
5694
 
5141
5695
  case 13:
5142
- _context4.next = 15;
5696
+ _context5.next = 15;
5143
5697
  return _this.axiosInstance.delete(url, requestConfig);
5144
5698
 
5145
5699
  case 15:
5146
- response = _context4.sent;
5147
- return _context4.abrupt("break", 34);
5700
+ response = _context5.sent;
5701
+ return _context5.abrupt("break", 34);
5148
5702
 
5149
5703
  case 17:
5150
- _context4.next = 19;
5704
+ _context5.next = 19;
5151
5705
  return _this.axiosInstance.post(url, data, requestConfig);
5152
5706
 
5153
5707
  case 19:
5154
- response = _context4.sent;
5155
- return _context4.abrupt("break", 34);
5708
+ response = _context5.sent;
5709
+ return _context5.abrupt("break", 34);
5156
5710
 
5157
5711
  case 21:
5158
- _context4.next = 23;
5712
+ _context5.next = 23;
5159
5713
  return _this.axiosInstance.put(url, data, requestConfig);
5160
5714
 
5161
5715
  case 23:
5162
- response = _context4.sent;
5163
- return _context4.abrupt("break", 34);
5716
+ response = _context5.sent;
5717
+ return _context5.abrupt("break", 34);
5164
5718
 
5165
5719
  case 25:
5166
- _context4.next = 27;
5720
+ _context5.next = 27;
5167
5721
  return _this.axiosInstance.patch(url, data, requestConfig);
5168
5722
 
5169
5723
  case 27:
5170
- response = _context4.sent;
5171
- return _context4.abrupt("break", 34);
5724
+ response = _context5.sent;
5725
+ return _context5.abrupt("break", 34);
5172
5726
 
5173
5727
  case 29:
5174
- _context4.next = 31;
5728
+ _context5.next = 31;
5175
5729
  return _this.axiosInstance.options(url, requestConfig);
5176
5730
 
5177
5731
  case 31:
5178
- response = _context4.sent;
5179
- return _context4.abrupt("break", 34);
5732
+ response = _context5.sent;
5733
+ return _context5.abrupt("break", 34);
5180
5734
 
5181
5735
  case 33:
5182
5736
  throw new Error('Invalid request type');
@@ -5185,65 +5739,66 @@ var StreamChat = /*#__PURE__*/function () {
5185
5739
  _this._logApiResponse(type, url, response);
5186
5740
 
5187
5741
  _this.consecutiveFailures = 0;
5188
- return _context4.abrupt("return", _this.handleResponse(response));
5742
+ return _context5.abrupt("return", _this.handleResponse(response));
5189
5743
 
5190
5744
  case 39:
5191
- _context4.prev = 39;
5192
- _context4.t1 = _context4["catch"](4);
5193
- _context4.t1.client_request_id = (_requestConfig$header = requestConfig.headers) === null || _requestConfig$header === void 0 ? void 0 : _requestConfig$header['x-client-request-id'];
5745
+ _context5.prev = 39;
5746
+ _context5.t1 = _context5["catch"](4);
5747
+ _context5.t1.client_request_id = (_requestConfig$header = requestConfig.headers) === null || _requestConfig$header === void 0 ? void 0 : _requestConfig$header['x-client-request-id'];
5194
5748
 
5195
- _this._logApiError(type, url, _context4.t1);
5749
+ _this._logApiError(type, url, _context5.t1);
5196
5750
 
5197
5751
  _this.consecutiveFailures += 1;
5198
5752
 
5199
- if (!_context4.t1.response) {
5200
- _context4.next = 56;
5753
+ if (!_context5.t1.response) {
5754
+ _context5.next = 56;
5201
5755
  break;
5202
5756
  }
5203
5757
 
5204
- if (!(_context4.t1.response.data.code === chatCodes.TOKEN_EXPIRED && !_this.tokenManager.isStatic())) {
5205
- _context4.next = 53;
5758
+ if (!(_context5.t1.response.data.code === chatCodes.TOKEN_EXPIRED && !_this.tokenManager.isStatic())) {
5759
+ _context5.next = 53;
5206
5760
  break;
5207
5761
  }
5208
5762
 
5209
5763
  if (!(_this.consecutiveFailures > 1)) {
5210
- _context4.next = 49;
5764
+ _context5.next = 49;
5211
5765
  break;
5212
5766
  }
5213
5767
 
5214
- _context4.next = 49;
5768
+ _context5.next = 49;
5215
5769
  return sleep(retryInterval(_this.consecutiveFailures));
5216
5770
 
5217
5771
  case 49:
5218
5772
  _this.tokenManager.loadToken();
5219
5773
 
5220
- _context4.next = 52;
5774
+ _context5.next = 52;
5221
5775
  return _this.doAxiosRequest(type, url, data, options);
5222
5776
 
5223
5777
  case 52:
5224
- return _context4.abrupt("return", _context4.sent);
5778
+ return _context5.abrupt("return", _context5.sent);
5225
5779
 
5226
5780
  case 53:
5227
- return _context4.abrupt("return", _this.handleResponse(_context4.t1.response));
5781
+ return _context5.abrupt("return", _this.handleResponse(_context5.t1.response));
5228
5782
 
5229
5783
  case 56:
5230
- throw _context4.t1;
5784
+ throw _context5.t1;
5231
5785
 
5232
5786
  case 57:
5233
5787
  case "end":
5234
- return _context4.stop();
5788
+ return _context5.stop();
5235
5789
  }
5236
5790
  }
5237
- }, _callee4, null, [[4, 39]]);
5791
+ }, _callee5, null, [[4, 39]]);
5238
5792
  }));
5239
5793
 
5240
- return function (_x4, _x5, _x6) {
5241
- return _ref4.apply(this, arguments);
5794
+ return function (_x5, _x6, _x7) {
5795
+ return _ref5.apply(this, arguments);
5242
5796
  };
5243
5797
  }());
5244
5798
 
5245
5799
  _defineProperty(this, "dispatchEvent", function (event) {
5246
- // client event handlers
5800
+ if (!event.received_at) event.received_at = new Date(); // client event handlers
5801
+
5247
5802
  var postListenerCallbacks = _this._handleClientEvent(event); // channel event handlers
5248
5803
 
5249
5804
 
@@ -5269,7 +5824,6 @@ var StreamChat = /*#__PURE__*/function () {
5269
5824
  // dispatch the event to the channel listeners
5270
5825
  var jsonString = messageEvent.data;
5271
5826
  var event = JSON.parse(jsonString);
5272
- event.received_at = new Date();
5273
5827
 
5274
5828
  _this.dispatchEvent(event);
5275
5829
  });
@@ -5390,22 +5944,20 @@ var StreamChat = /*#__PURE__*/function () {
5390
5944
  }
5391
5945
  });
5392
5946
 
5393
- _defineProperty(this, "recoverState", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
5394
- var _this$wsConnection3;
5395
-
5947
+ _defineProperty(this, "recoverState", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
5396
5948
  var cids;
5397
- return _regeneratorRuntime.wrap(function _callee5$(_context5) {
5949
+ return _regeneratorRuntime.wrap(function _callee6$(_context6) {
5398
5950
  while (1) {
5399
- switch (_context5.prev = _context5.next) {
5951
+ switch (_context6.prev = _context6.next) {
5400
5952
  case 0:
5401
- _this.logger('info', "client:recoverState() - Start of recoverState with connectionID ".concat((_this$wsConnection3 = _this.wsConnection) === null || _this$wsConnection3 === void 0 ? void 0 : _this$wsConnection3.connectionID), {
5953
+ _this.logger('info', "client:recoverState() - Start of recoverState with connectionID ".concat(_this._getConnectionID()), {
5402
5954
  tags: ['connection']
5403
5955
  });
5404
5956
 
5405
5957
  cids = Object.keys(_this.activeChannels);
5406
5958
 
5407
5959
  if (!(cids.length && _this.recoverStateOnReconnect)) {
5408
- _context5.next = 10;
5960
+ _context6.next = 10;
5409
5961
  break;
5410
5962
  }
5411
5963
 
@@ -5413,7 +5965,7 @@ var StreamChat = /*#__PURE__*/function () {
5413
5965
  tags: ['connection', 'client']
5414
5966
  });
5415
5967
 
5416
- _context5.next = 6;
5968
+ _context6.next = 6;
5417
5969
  return _this.queryChannels({
5418
5970
  cid: {
5419
5971
  $in: cids
@@ -5433,7 +5985,7 @@ var StreamChat = /*#__PURE__*/function () {
5433
5985
  type: 'connection.recovered'
5434
5986
  });
5435
5987
 
5436
- _context5.next = 11;
5988
+ _context6.next = 11;
5437
5989
  break;
5438
5990
 
5439
5991
  case 10:
@@ -5447,10 +5999,10 @@ var StreamChat = /*#__PURE__*/function () {
5447
5999
 
5448
6000
  case 13:
5449
6001
  case "end":
5450
- return _context5.stop();
6002
+ return _context6.stop();
5451
6003
  }
5452
6004
  }
5453
- }, _callee5);
6005
+ }, _callee6);
5454
6006
  })));
5455
6007
 
5456
6008
  _defineProperty(this, "getChannelByMembers", function (channelType, custom) {
@@ -5530,66 +6082,14 @@ var StreamChat = /*#__PURE__*/function () {
5530
6082
  return !!_this.secret;
5531
6083
  });
5532
6084
 
5533
- _defineProperty(this, "postInsights", /*#__PURE__*/function () {
5534
- var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(insightType, insights) {
5535
- var maxAttempts, i;
5536
- return _regeneratorRuntime.wrap(function _callee6$(_context6) {
5537
- while (1) {
5538
- switch (_context6.prev = _context6.next) {
5539
- case 0:
5540
- maxAttempts = 3;
5541
- i = 0;
5542
-
5543
- case 2:
5544
- if (!(i < maxAttempts)) {
5545
- _context6.next = 18;
5546
- break;
5547
- }
5548
-
5549
- _context6.prev = 3;
5550
- _context6.next = 6;
5551
- return _this.axiosInstance.post("https://chat-insights.getstream.io/insights/".concat(insightType), insights);
5552
-
5553
- case 6:
5554
- _context6.next = 14;
5555
- break;
5556
-
5557
- case 8:
5558
- _context6.prev = 8;
5559
- _context6.t0 = _context6["catch"](3);
5560
-
5561
- _this.logger('warn', "failed to send insights event ".concat(insightType), {
5562
- tags: ['insights', 'connection'],
5563
- error: _context6.t0,
5564
- insights: insights
5565
- });
5566
-
5567
- _context6.next = 13;
5568
- return sleep((i + 1) * 3000);
5569
-
5570
- case 13:
5571
- return _context6.abrupt("continue", 15);
5572
-
5573
- case 14:
5574
- return _context6.abrupt("break", 18);
5575
-
5576
- case 15:
5577
- i++;
5578
- _context6.next = 2;
5579
- break;
5580
-
5581
- case 18:
5582
- case "end":
5583
- return _context6.stop();
5584
- }
5585
- }
5586
- }, _callee6, null, [[3, 8]]);
5587
- }));
5588
-
5589
- return function (_x7, _x8) {
5590
- return _ref6.apply(this, arguments);
5591
- };
5592
- }());
6085
+ _defineProperty(this, "_buildWSPayload", function (client_request_id) {
6086
+ return JSON.stringify({
6087
+ user_id: _this.userID,
6088
+ user_details: _this._user,
6089
+ device: _this.options.device,
6090
+ client_request_id: client_request_id
6091
+ });
6092
+ });
5593
6093
 
5594
6094
  // set the key
5595
6095
  this.key = _key;
@@ -5647,6 +6147,8 @@ var StreamChat = /*#__PURE__*/function () {
5647
6147
  this.tokenManager = new TokenManager(this.secret);
5648
6148
  this.consecutiveFailures = 0;
5649
6149
  this.insightMetrics = new InsightMetrics();
6150
+ this.defaultWSTimeoutWithFallback = 6000;
6151
+ this.defaultWSTimeout = 15000;
5650
6152
  /**
5651
6153
  * logger function should accept 3 parameters:
5652
6154
  * @param logLevel string
@@ -5820,7 +6322,7 @@ var StreamChat = /*#__PURE__*/function () {
5820
6322
  }, _callee7, this);
5821
6323
  }));
5822
6324
 
5823
- function updateAppSettings(_x9) {
6325
+ function updateAppSettings(_x8) {
5824
6326
  return _updateAppSettings.apply(this, arguments);
5825
6327
  }
5826
6328
 
@@ -5854,7 +6356,7 @@ var StreamChat = /*#__PURE__*/function () {
5854
6356
  }, _callee8, this);
5855
6357
  }));
5856
6358
 
5857
- function revokeTokens(_x10) {
6359
+ function revokeTokens(_x9) {
5858
6360
  return _revokeTokens.apply(this, arguments);
5859
6361
  }
5860
6362
 
@@ -5886,7 +6388,7 @@ var StreamChat = /*#__PURE__*/function () {
5886
6388
  }, _callee9, this);
5887
6389
  }));
5888
6390
 
5889
- function revokeUserToken(_x11, _x12) {
6391
+ function revokeUserToken(_x10, _x11) {
5890
6392
  return _revokeUserToken.apply(this, arguments);
5891
6393
  }
5892
6394
 
@@ -5945,7 +6447,7 @@ var StreamChat = /*#__PURE__*/function () {
5945
6447
  }, _callee10, this);
5946
6448
  }));
5947
6449
 
5948
- function revokeUsersToken(_x13, _x14) {
6450
+ function revokeUsersToken(_x12, _x13) {
5949
6451
  return _revokeUsersToken.apply(this, arguments);
5950
6452
  }
5951
6453
 
@@ -6037,7 +6539,7 @@ var StreamChat = /*#__PURE__*/function () {
6037
6539
  }, _callee12, this);
6038
6540
  }));
6039
6541
 
6040
- function testPushSettings(_x15) {
6542
+ function testPushSettings(_x14) {
6041
6543
  return _testPushSettings.apply(this, arguments);
6042
6544
  }
6043
6545
 
@@ -6146,7 +6648,7 @@ var StreamChat = /*#__PURE__*/function () {
6146
6648
  }, _callee14, this, [[1, 7]]);
6147
6649
  }));
6148
6650
 
6149
- function setGuestUser(_x16) {
6651
+ function setGuestUser(_x15) {
6150
6652
  return _setGuestUser.apply(this, arguments);
6151
6653
  }
6152
6654
 
@@ -6457,72 +6959,102 @@ var StreamChat = /*#__PURE__*/function () {
6457
6959
  */
6458
6960
  function () {
6459
6961
  var _connect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15() {
6460
- var client;
6461
6962
  return _regeneratorRuntime.wrap(function _callee15$(_context15) {
6462
6963
  while (1) {
6463
6964
  switch (_context15.prev = _context15.next) {
6464
6965
  case 0:
6465
- client = this;
6466
- this.failures = 0;
6467
-
6468
- if (!(client.userID == null || this._user == null)) {
6469
- _context15.next = 4;
6966
+ if (!(!this.userID || !this._user)) {
6967
+ _context15.next = 2;
6470
6968
  break;
6471
6969
  }
6472
6970
 
6473
6971
  throw Error('Call connectUser or connectAnonymousUser before starting the connection');
6474
6972
 
6475
- case 4:
6476
- if (!(client.wsBaseURL == null)) {
6477
- _context15.next = 6;
6973
+ case 2:
6974
+ if (this.wsBaseURL) {
6975
+ _context15.next = 4;
6478
6976
  break;
6479
6977
  }
6480
6978
 
6481
6979
  throw Error('Websocket base url not set');
6482
6980
 
6483
- case 6:
6484
- if (!(client.clientID == null)) {
6485
- _context15.next = 8;
6981
+ case 4:
6982
+ if (this.clientID) {
6983
+ _context15.next = 6;
6486
6984
  break;
6487
6985
  }
6488
6986
 
6489
6987
  throw Error('clientID is not set');
6490
6988
 
6491
- case 8:
6989
+ case 6:
6492
6990
  if (!this.wsConnection && (this.options.warmUp || this.options.enableInsights)) {
6493
- this.sayHi();
6991
+ this._sayHi();
6494
6992
  } // The StableWSConnection handles all the reconnection logic.
6495
6993
 
6496
6994
 
6497
6995
  this.wsConnection = new StableWSConnection({
6498
- wsBaseURL: client.wsBaseURL,
6499
- clientID: client.clientID,
6500
- userID: client.userID,
6501
- tokenManager: client.tokenManager,
6502
- user: this._user,
6503
- authType: this.getAuthType(),
6504
- userAgent: this.getUserAgent(),
6505
- apiKey: this.key,
6506
- recoverCallback: this.recoverState,
6507
- messageCallback: this.handleEvent,
6508
- eventCallback: this.dispatchEvent,
6509
- logger: this.logger,
6510
- device: this.options.device,
6511
- postInsights: this.options.enableInsights ? this.postInsights : undefined,
6512
- insightMetrics: this.insightMetrics
6996
+ client: this
6513
6997
  });
6998
+ _context15.prev = 8;
6999
+
7000
+ if (!this.wsFallback) {
7001
+ _context15.next = 13;
7002
+ break;
7003
+ }
7004
+
6514
7005
  _context15.next = 12;
6515
- return this.wsConnection.connect();
7006
+ return this.wsFallback.connect();
6516
7007
 
6517
7008
  case 12:
6518
7009
  return _context15.abrupt("return", _context15.sent);
6519
7010
 
6520
7011
  case 13:
7012
+ _context15.next = 15;
7013
+ return this.wsConnection.connect(this.options.enableWSFallback ? this.defaultWSTimeoutWithFallback : this.defaultWSTimeout);
7014
+
7015
+ case 15:
7016
+ return _context15.abrupt("return", _context15.sent);
7017
+
7018
+ case 18:
7019
+ _context15.prev = 18;
7020
+ _context15.t0 = _context15["catch"](8);
7021
+
7022
+ if (!(this.options.enableWSFallback && isWSFailure(_context15.t0) && isOnline())) {
7023
+ _context15.next = 29;
7024
+ break;
7025
+ }
7026
+
7027
+ this.logger('info', 'client:connect() - WS failed, fallback to longpoll', {
7028
+ tags: ['connection', 'client']
7029
+ }); // @ts-expect-error
7030
+
7031
+ this.dispatchEvent({
7032
+ type: 'transport.changed',
7033
+ mode: 'longpoll'
7034
+ });
7035
+
7036
+ this.wsConnection._destroyCurrentWSConnection();
7037
+
7038
+ this.wsConnection.disconnect().then(); // close WS so no retry
7039
+
7040
+ this.wsFallback = new WSConnectionFallback({
7041
+ client: this
7042
+ });
7043
+ _context15.next = 28;
7044
+ return this.wsFallback.connect();
7045
+
7046
+ case 28:
7047
+ return _context15.abrupt("return", _context15.sent);
7048
+
7049
+ case 29:
7050
+ throw _context15.t0;
7051
+
7052
+ case 30:
6521
7053
  case "end":
6522
7054
  return _context15.stop();
6523
7055
  }
6524
7056
  }
6525
- }, _callee15, this);
7057
+ }, _callee15, this, [[8, 18]]);
6526
7058
  }));
6527
7059
 
6528
7060
  function connect() {
@@ -6531,9 +7063,15 @@ var StreamChat = /*#__PURE__*/function () {
6531
7063
 
6532
7064
  return connect;
6533
7065
  }()
7066
+ /**
7067
+ * Check the connectivity with server for warmup purpose.
7068
+ *
7069
+ * @private
7070
+ */
7071
+
6534
7072
  }, {
6535
- key: "sayHi",
6536
- value: function sayHi() {
7073
+ key: "_sayHi",
7074
+ value: function _sayHi() {
6537
7075
  var _this4 = this;
6538
7076
 
6539
7077
  var client_request_id = randomId();
@@ -6543,11 +7081,13 @@ var StreamChat = /*#__PURE__*/function () {
6543
7081
  }
6544
7082
  };
6545
7083
  this.doAxiosRequest('get', this.baseURL + '/hi', null, opts).catch(function (e) {
6546
- _this4.postInsights('http_hi_failed', {
6547
- api_key: _this4.key,
6548
- err: e,
6549
- client_request_id: client_request_id
6550
- });
7084
+ if (_this4.options.enableInsights) {
7085
+ postInsights('http_hi_failed', {
7086
+ api_key: _this4.key,
7087
+ err: e,
7088
+ client_request_id: client_request_id
7089
+ });
7090
+ }
6551
7091
  });
6552
7092
  }
6553
7093
  /**
@@ -6610,7 +7150,7 @@ var StreamChat = /*#__PURE__*/function () {
6610
7150
  }, _callee16, this);
6611
7151
  }));
6612
7152
 
6613
- function queryUsers(_x17) {
7153
+ function queryUsers(_x16) {
6614
7154
  return _queryUsers.apply(this, arguments);
6615
7155
  }
6616
7156
 
@@ -6829,7 +7369,7 @@ var StreamChat = /*#__PURE__*/function () {
6829
7369
  }, _callee19, this);
6830
7370
  }));
6831
7371
 
6832
- function queryChannels(_x18) {
7372
+ function queryChannels(_x17) {
6833
7373
  return _queryChannels.apply(this, arguments);
6834
7374
  }
6835
7375
 
@@ -6915,7 +7455,7 @@ var StreamChat = /*#__PURE__*/function () {
6915
7455
  }, _callee20, this);
6916
7456
  }));
6917
7457
 
6918
- function search(_x19, _x20) {
7458
+ function search(_x18, _x19) {
6919
7459
  return _search.apply(this, arguments);
6920
7460
  }
6921
7461
 
@@ -6933,7 +7473,7 @@ var StreamChat = /*#__PURE__*/function () {
6933
7473
  }, {
6934
7474
  key: "setLocalDevice",
6935
7475
  value: function setLocalDevice(device) {
6936
- if (this.wsConnection) {
7476
+ if (this.wsConnection || this.wsFallback) {
6937
7477
  throw new Error('you can only set device before opening a websocket connection');
6938
7478
  }
6939
7479
 
@@ -6975,7 +7515,7 @@ var StreamChat = /*#__PURE__*/function () {
6975
7515
  }, _callee21, this);
6976
7516
  }));
6977
7517
 
6978
- function addDevice(_x21, _x22, _x23) {
7518
+ function addDevice(_x20, _x21, _x22) {
6979
7519
  return _addDevice.apply(this, arguments);
6980
7520
  }
6981
7521
 
@@ -7013,7 +7553,7 @@ var StreamChat = /*#__PURE__*/function () {
7013
7553
  }, _callee22, this);
7014
7554
  }));
7015
7555
 
7016
- function getDevices(_x24) {
7556
+ function getDevices(_x23) {
7017
7557
  return _getDevices.apply(this, arguments);
7018
7558
  }
7019
7559
 
@@ -7053,7 +7593,7 @@ var StreamChat = /*#__PURE__*/function () {
7053
7593
  }, _callee23, this);
7054
7594
  }));
7055
7595
 
7056
- function removeDevice(_x25, _x26) {
7596
+ function removeDevice(_x24, _x25) {
7057
7597
  return _removeDevice.apply(this, arguments);
7058
7598
  }
7059
7599
 
@@ -7094,7 +7634,7 @@ var StreamChat = /*#__PURE__*/function () {
7094
7634
  }, _callee24, this);
7095
7635
  }));
7096
7636
 
7097
- function getRateLimits(_x27) {
7637
+ function getRateLimits(_x26) {
7098
7638
  return _getRateLimits.apply(this, arguments);
7099
7639
  }
7100
7640
 
@@ -7195,7 +7735,7 @@ var StreamChat = /*#__PURE__*/function () {
7195
7735
  }, _callee25, this);
7196
7736
  }));
7197
7737
 
7198
- function partialUpdateUser(_x28) {
7738
+ function partialUpdateUser(_x27) {
7199
7739
  return _partialUpdateUser.apply(this, arguments);
7200
7740
  }
7201
7741
 
@@ -7281,7 +7821,7 @@ var StreamChat = /*#__PURE__*/function () {
7281
7821
  }, _callee26, this, [[2, 13, 16, 19]]);
7282
7822
  }));
7283
7823
 
7284
- function upsertUsers(_x29) {
7824
+ function upsertUsers(_x28) {
7285
7825
  return _upsertUsers.apply(this, arguments);
7286
7826
  }
7287
7827
 
@@ -7394,7 +7934,7 @@ var StreamChat = /*#__PURE__*/function () {
7394
7934
  }, _callee27, this, [[1, 11, 14, 17]]);
7395
7935
  }));
7396
7936
 
7397
- function partialUpdateUsers(_x30) {
7937
+ function partialUpdateUsers(_x29) {
7398
7938
  return _partialUpdateUsers.apply(this, arguments);
7399
7939
  }
7400
7940
 
@@ -7422,7 +7962,7 @@ var StreamChat = /*#__PURE__*/function () {
7422
7962
  }, _callee28, this);
7423
7963
  }));
7424
7964
 
7425
- function deleteUser(_x31, _x32) {
7965
+ function deleteUser(_x30, _x31) {
7426
7966
  return _deleteUser.apply(this, arguments);
7427
7967
  }
7428
7968
 
@@ -7450,7 +7990,7 @@ var StreamChat = /*#__PURE__*/function () {
7450
7990
  }, _callee29, this);
7451
7991
  }));
7452
7992
 
7453
- function reactivateUser(_x33, _x34) {
7993
+ function reactivateUser(_x32, _x33) {
7454
7994
  return _reactivateUser.apply(this, arguments);
7455
7995
  }
7456
7996
 
@@ -7478,7 +8018,7 @@ var StreamChat = /*#__PURE__*/function () {
7478
8018
  }, _callee30, this);
7479
8019
  }));
7480
8020
 
7481
- function deactivateUser(_x35, _x36) {
8021
+ function deactivateUser(_x34, _x35) {
7482
8022
  return _deactivateUser.apply(this, arguments);
7483
8023
  }
7484
8024
 
@@ -7506,7 +8046,7 @@ var StreamChat = /*#__PURE__*/function () {
7506
8046
  }, _callee31, this);
7507
8047
  }));
7508
8048
 
7509
- function exportUser(_x37, _x38) {
8049
+ function exportUser(_x36, _x37) {
7510
8050
  return _exportUser.apply(this, arguments);
7511
8051
  }
7512
8052
 
@@ -7527,27 +8067,15 @@ var StreamChat = /*#__PURE__*/function () {
7527
8067
  while (1) {
7528
8068
  switch (_context32.prev = _context32.next) {
7529
8069
  case 0:
7530
- if ((options === null || options === void 0 ? void 0 : options.user_id) !== undefined) {
7531
- options.banned_by_id = options.user_id;
7532
- delete options.user_id;
7533
- console.warn("banUser: 'user_id' is deprecated, please consider switching to 'banned_by_id'");
7534
- }
7535
-
7536
- if ((options === null || options === void 0 ? void 0 : options.user) !== undefined) {
7537
- options.banned_by = options.user;
7538
- delete options.user;
7539
- console.warn("banUser: 'user' is deprecated, please consider switching to 'banned_by'");
7540
- }
7541
-
7542
- _context32.next = 4;
8070
+ _context32.next = 2;
7543
8071
  return this.post(this.baseURL + '/moderation/ban', _objectSpread({
7544
8072
  target_user_id: targetUserID
7545
8073
  }, options));
7546
8074
 
7547
- case 4:
8075
+ case 2:
7548
8076
  return _context32.abrupt("return", _context32.sent);
7549
8077
 
7550
- case 5:
8078
+ case 3:
7551
8079
  case "end":
7552
8080
  return _context32.stop();
7553
8081
  }
@@ -7555,7 +8083,7 @@ var StreamChat = /*#__PURE__*/function () {
7555
8083
  }, _callee32, this);
7556
8084
  }));
7557
8085
 
7558
- function banUser(_x39, _x40) {
8086
+ function banUser(_x38, _x39) {
7559
8087
  return _banUser.apply(this, arguments);
7560
8088
  }
7561
8089
 
@@ -7592,7 +8120,7 @@ var StreamChat = /*#__PURE__*/function () {
7592
8120
  }, _callee33, this);
7593
8121
  }));
7594
8122
 
7595
- function unbanUser(_x41, _x42) {
8123
+ function unbanUser(_x40, _x41) {
7596
8124
  return _unbanUser.apply(this, arguments);
7597
8125
  }
7598
8126
 
@@ -7629,7 +8157,7 @@ var StreamChat = /*#__PURE__*/function () {
7629
8157
  }, _callee34, this);
7630
8158
  }));
7631
8159
 
7632
- function shadowBan(_x43, _x44) {
8160
+ function shadowBan(_x42, _x43) {
7633
8161
  return _shadowBan.apply(this, arguments);
7634
8162
  }
7635
8163
 
@@ -7666,7 +8194,7 @@ var StreamChat = /*#__PURE__*/function () {
7666
8194
  }, _callee35, this);
7667
8195
  }));
7668
8196
 
7669
- function removeShadowBan(_x45, _x46) {
8197
+ function removeShadowBan(_x44, _x45) {
7670
8198
  return _removeShadowBan.apply(this, arguments);
7671
8199
  }
7672
8200
 
@@ -7709,7 +8237,7 @@ var StreamChat = /*#__PURE__*/function () {
7709
8237
  }, _callee36, this);
7710
8238
  }));
7711
8239
 
7712
- function muteUser(_x47, _x48) {
8240
+ function muteUser(_x46, _x47) {
7713
8241
  return _muteUser.apply(this, arguments);
7714
8242
  }
7715
8243
 
@@ -7748,7 +8276,7 @@ var StreamChat = /*#__PURE__*/function () {
7748
8276
  }, _callee37, this);
7749
8277
  }));
7750
8278
 
7751
- function unmuteUser(_x49, _x50) {
8279
+ function unmuteUser(_x48, _x49) {
7752
8280
  return _unmuteUser.apply(this, arguments);
7753
8281
  }
7754
8282
 
@@ -7807,7 +8335,7 @@ var StreamChat = /*#__PURE__*/function () {
7807
8335
  }, _callee38, this);
7808
8336
  }));
7809
8337
 
7810
- function flagMessage(_x51) {
8338
+ function flagMessage(_x50) {
7811
8339
  return _flagMessage.apply(this, arguments);
7812
8340
  }
7813
8341
 
@@ -7847,7 +8375,7 @@ var StreamChat = /*#__PURE__*/function () {
7847
8375
  }, _callee39, this);
7848
8376
  }));
7849
8377
 
7850
- function flagUser(_x52) {
8378
+ function flagUser(_x51) {
7851
8379
  return _flagUser.apply(this, arguments);
7852
8380
  }
7853
8381
 
@@ -7887,7 +8415,7 @@ var StreamChat = /*#__PURE__*/function () {
7887
8415
  }, _callee40, this);
7888
8416
  }));
7889
8417
 
7890
- function unflagMessage(_x53) {
8418
+ function unflagMessage(_x52) {
7891
8419
  return _unflagMessage.apply(this, arguments);
7892
8420
  }
7893
8421
 
@@ -7927,7 +8455,7 @@ var StreamChat = /*#__PURE__*/function () {
7927
8455
  }, _callee41, this);
7928
8456
  }));
7929
8457
 
7930
- function unflagUser(_x54) {
8458
+ function unflagUser(_x53) {
7931
8459
  return _unflagUser.apply(this, arguments);
7932
8460
  }
7933
8461
 
@@ -8066,7 +8594,7 @@ var StreamChat = /*#__PURE__*/function () {
8066
8594
  }, _callee43, this);
8067
8595
  }));
8068
8596
 
8069
- function translateMessage(_x55, _x56) {
8597
+ function translateMessage(_x54, _x55) {
8070
8598
  return _translateMessage.apply(this, arguments);
8071
8599
  }
8072
8600
 
@@ -8182,7 +8710,7 @@ var StreamChat = /*#__PURE__*/function () {
8182
8710
  case 2:
8183
8711
  clonedMessage = _extends({}, message);
8184
8712
  delete clonedMessage.id;
8185
- reservedMessageFields = ['command', 'created_at', 'html', 'latest_reactions', 'own_reactions', 'reaction_counts', 'reply_count', 'type', 'updated_at', 'user', '__html'];
8713
+ reservedMessageFields = ['command', 'created_at', 'html', 'latest_reactions', 'own_reactions', 'quoted_message', 'reaction_counts', 'reply_count', 'type', 'updated_at', 'user', '__html'];
8186
8714
  reservedMessageFields.forEach(function (item) {
8187
8715
  if (clonedMessage[item] != null) {
8188
8716
  delete clonedMessage[item];
@@ -8226,7 +8754,7 @@ var StreamChat = /*#__PURE__*/function () {
8226
8754
  }, _callee44, this);
8227
8755
  }));
8228
8756
 
8229
- function updateMessage(_x57, _x58, _x59) {
8757
+ function updateMessage(_x56, _x57, _x58) {
8230
8758
  return _updateMessage.apply(this, arguments);
8231
8759
  }
8232
8760
 
@@ -8287,7 +8815,7 @@ var StreamChat = /*#__PURE__*/function () {
8287
8815
  }, _callee45, this);
8288
8816
  }));
8289
8817
 
8290
- function partialUpdateMessage(_x60, _x61, _x62, _x63) {
8818
+ function partialUpdateMessage(_x59, _x60, _x61, _x62) {
8291
8819
  return _partialUpdateMessage.apply(this, arguments);
8292
8820
  }
8293
8821
 
@@ -8324,7 +8852,7 @@ var StreamChat = /*#__PURE__*/function () {
8324
8852
  }, _callee46, this);
8325
8853
  }));
8326
8854
 
8327
- function deleteMessage(_x64, _x65) {
8855
+ function deleteMessage(_x63, _x64) {
8328
8856
  return _deleteMessage.apply(this, arguments);
8329
8857
  }
8330
8858
 
@@ -8352,7 +8880,7 @@ var StreamChat = /*#__PURE__*/function () {
8352
8880
  }, _callee47, this);
8353
8881
  }));
8354
8882
 
8355
- function getMessage(_x66) {
8883
+ function getMessage(_x65) {
8356
8884
  return _getMessage.apply(this, arguments);
8357
8885
  }
8358
8886
 
@@ -8361,7 +8889,7 @@ var StreamChat = /*#__PURE__*/function () {
8361
8889
  }, {
8362
8890
  key: "getUserAgent",
8363
8891
  value: function getUserAgent() {
8364
- return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "4.4.3-dev.3");
8892
+ return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "5.0.1");
8365
8893
  }
8366
8894
  }, {
8367
8895
  key: "setUserAgent",
@@ -8375,7 +8903,7 @@ var StreamChat = /*#__PURE__*/function () {
8375
8903
  }, {
8376
8904
  key: "_enrichAxiosOptions",
8377
8905
  value: function _enrichAxiosOptions() {
8378
- var _options$headers, _this$wsConnection4;
8906
+ var _options$headers;
8379
8907
 
8380
8908
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
8381
8909
  params: {},
@@ -8385,21 +8913,23 @@ var StreamChat = /*#__PURE__*/function () {
8385
8913
 
8386
8914
  var token = this._getToken();
8387
8915
 
8916
+ var authorization = token ? {
8917
+ Authorization: token
8918
+ } : undefined;
8919
+
8388
8920
  if (!((_options$headers = options.headers) !== null && _options$headers !== void 0 && _options$headers['x-client-request-id'])) {
8389
- options.headers = {
8921
+ options.headers = _objectSpread(_objectSpread({}, options.headers), {}, {
8390
8922
  'x-client-request-id': randomId()
8391
- };
8923
+ });
8392
8924
  }
8393
8925
 
8394
8926
  return _objectSpread({
8395
- params: _objectSpread(_objectSpread({
8396
- user_id: this.userID
8397
- }, options.params), {}, {
8398
- api_key: this.key,
8399
- connection_id: (_this$wsConnection4 = this.wsConnection) === null || _this$wsConnection4 === void 0 ? void 0 : _this$wsConnection4.connectionID
8400
- }),
8401
- headers: _objectSpread({
8402
- Authorization: token,
8927
+ params: _objectSpread({
8928
+ user_id: this.userID,
8929
+ connection_id: this._getConnectionID(),
8930
+ api_key: this.key
8931
+ }, options.params),
8932
+ headers: _objectSpread(_objectSpread({}, authorization), {}, {
8403
8933
  'stream-auth-type': this.getAuthType(),
8404
8934
  'X-Stream-Client': this.getUserAgent()
8405
8935
  }, options.headers)
@@ -8429,6 +8959,12 @@ var StreamChat = /*#__PURE__*/function () {
8429
8959
  }
8430
8960
  }, 500);
8431
8961
  }
8962
+ /**
8963
+ * encode ws url payload
8964
+ * @private
8965
+ * @returns json string
8966
+ */
8967
+
8432
8968
  }, {
8433
8969
  key: "verifyWebhook",
8434
8970
  value: function verifyWebhook(requestBody, xSignature) {
@@ -8569,7 +9105,7 @@ var StreamChat = /*#__PURE__*/function () {
8569
9105
  }, _callee48, this);
8570
9106
  }));
8571
9107
 
8572
- function sendUserCustomEvent(_x67, _x68) {
9108
+ function sendUserCustomEvent(_x66, _x67) {
8573
9109
  return _sendUserCustomEvent.apply(this, arguments);
8574
9110
  }
8575
9111
 
@@ -8657,7 +9193,7 @@ var StreamChat = /*#__PURE__*/function () {
8657
9193
  }, _callee49, this);
8658
9194
  }));
8659
9195
 
8660
- function createSegment(_x69) {
9196
+ function createSegment(_x68) {
8661
9197
  return _createSegment.apply(this, arguments);
8662
9198
  }
8663
9199
 
@@ -8697,7 +9233,7 @@ var StreamChat = /*#__PURE__*/function () {
8697
9233
  }, _callee50, this);
8698
9234
  }));
8699
9235
 
8700
- function getSegment(_x70) {
9236
+ function getSegment(_x69) {
8701
9237
  return _getSegment.apply(this, arguments);
8702
9238
  }
8703
9239
 
@@ -8736,7 +9272,7 @@ var StreamChat = /*#__PURE__*/function () {
8736
9272
  }, _callee51, this);
8737
9273
  }));
8738
9274
 
8739
- function listSegments(_x71) {
9275
+ function listSegments(_x70) {
8740
9276
  return _listSegments.apply(this, arguments);
8741
9277
  }
8742
9278
 
@@ -8779,7 +9315,7 @@ var StreamChat = /*#__PURE__*/function () {
8779
9315
  }, _callee52, this);
8780
9316
  }));
8781
9317
 
8782
- function updateSegment(_x72, _x73) {
9318
+ function updateSegment(_x71, _x72) {
8783
9319
  return _updateSegment.apply(this, arguments);
8784
9320
  }
8785
9321
 
@@ -8811,7 +9347,7 @@ var StreamChat = /*#__PURE__*/function () {
8811
9347
  }, _callee53, this);
8812
9348
  }));
8813
9349
 
8814
- function deleteSegment(_x74) {
9350
+ function deleteSegment(_x73) {
8815
9351
  return _deleteSegment.apply(this, arguments);
8816
9352
  }
8817
9353
 
@@ -8853,7 +9389,7 @@ var StreamChat = /*#__PURE__*/function () {
8853
9389
  }, _callee54, this);
8854
9390
  }));
8855
9391
 
8856
- function createCampaign(_x75) {
9392
+ function createCampaign(_x74) {
8857
9393
  return _createCampaign.apply(this, arguments);
8858
9394
  }
8859
9395
 
@@ -8893,7 +9429,7 @@ var StreamChat = /*#__PURE__*/function () {
8893
9429
  }, _callee55, this);
8894
9430
  }));
8895
9431
 
8896
- function getCampaign(_x76) {
9432
+ function getCampaign(_x75) {
8897
9433
  return _getCampaign.apply(this, arguments);
8898
9434
  }
8899
9435
 
@@ -8932,7 +9468,7 @@ var StreamChat = /*#__PURE__*/function () {
8932
9468
  }, _callee56, this);
8933
9469
  }));
8934
9470
 
8935
- function listCampaigns(_x77) {
9471
+ function listCampaigns(_x76) {
8936
9472
  return _listCampaigns.apply(this, arguments);
8937
9473
  }
8938
9474
 
@@ -8975,7 +9511,7 @@ var StreamChat = /*#__PURE__*/function () {
8975
9511
  }, _callee57, this);
8976
9512
  }));
8977
9513
 
8978
- function updateCampaign(_x78, _x79) {
9514
+ function updateCampaign(_x77, _x78) {
8979
9515
  return _updateCampaign.apply(this, arguments);
8980
9516
  }
8981
9517
 
@@ -9007,7 +9543,7 @@ var StreamChat = /*#__PURE__*/function () {
9007
9543
  }, _callee58, this);
9008
9544
  }));
9009
9545
 
9010
- function deleteCampaign(_x80) {
9546
+ function deleteCampaign(_x79) {
9011
9547
  return _deleteCampaign.apply(this, arguments);
9012
9548
  }
9013
9549
 
@@ -9051,7 +9587,7 @@ var StreamChat = /*#__PURE__*/function () {
9051
9587
  }, _callee59, this);
9052
9588
  }));
9053
9589
 
9054
- function scheduleCampaign(_x81, _x82) {
9590
+ function scheduleCampaign(_x80, _x81) {
9055
9591
  return _scheduleCampaign.apply(this, arguments);
9056
9592
  }
9057
9593
 
@@ -9091,7 +9627,7 @@ var StreamChat = /*#__PURE__*/function () {
9091
9627
  }, _callee60, this);
9092
9628
  }));
9093
9629
 
9094
- function stopCampaign(_x83) {
9630
+ function stopCampaign(_x82) {
9095
9631
  return _stopCampaign.apply(this, arguments);
9096
9632
  }
9097
9633
 
@@ -9131,7 +9667,7 @@ var StreamChat = /*#__PURE__*/function () {
9131
9667
  }, _callee61, this);
9132
9668
  }));
9133
9669
 
9134
- function resumeCampaign(_x84) {
9670
+ function resumeCampaign(_x83) {
9135
9671
  return _resumeCampaign.apply(this, arguments);
9136
9672
  }
9137
9673
 
@@ -9174,7 +9710,7 @@ var StreamChat = /*#__PURE__*/function () {
9174
9710
  }, _callee62, this);
9175
9711
  }));
9176
9712
 
9177
- function testCampaign(_x85, _x86) {
9713
+ function testCampaign(_x84, _x85) {
9178
9714
  return _testCampaign.apply(this, arguments);
9179
9715
  }
9180
9716
 
@@ -9207,7 +9743,7 @@ var StreamChat = /*#__PURE__*/function () {
9207
9743
  }, _callee63, this);
9208
9744
  }));
9209
9745
 
9210
- function enrichURL(_x87) {
9746
+ function enrichURL(_x86) {
9211
9747
  return _enrichURL.apply(this, arguments);
9212
9748
  }
9213
9749
 
@@ -9239,7 +9775,7 @@ var StreamChat = /*#__PURE__*/function () {
9239
9775
  }, _callee64, this);
9240
9776
  }));
9241
9777
 
9242
- function getTask(_x88) {
9778
+ function getTask(_x87) {
9243
9779
  return _getTask.apply(this, arguments);
9244
9780
  }
9245
9781
 
@@ -9281,15 +9817,12 @@ var StreamChat = /*#__PURE__*/function () {
9281
9817
  }, _callee65, this);
9282
9818
  }));
9283
9819
 
9284
- function deleteChannels(_x89) {
9820
+ function deleteChannels(_x88) {
9285
9821
  return _deleteChannels.apply(this, arguments);
9286
9822
  }
9287
9823
 
9288
9824
  return deleteChannels;
9289
9825
  }()
9290
- }, {
9291
- key: "deleteUsers",
9292
- value:
9293
9826
  /**
9294
9827
  * deleteUsers - Batch Delete Users
9295
9828
  *
@@ -9298,7 +9831,10 @@ var StreamChat = /*#__PURE__*/function () {
9298
9831
  *
9299
9832
  * @return {APIResponse} A task ID
9300
9833
  */
9301
- function () {
9834
+
9835
+ }, {
9836
+ key: "deleteUsers",
9837
+ value: function () {
9302
9838
  var _deleteUsers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee66(user_ids, options) {
9303
9839
  return _regeneratorRuntime.wrap(function _callee66$(_context66) {
9304
9840
  while (1) {
@@ -9344,7 +9880,7 @@ var StreamChat = /*#__PURE__*/function () {
9344
9880
  }, _callee66, this);
9345
9881
  }));
9346
9882
 
9347
- function deleteUsers(_x90, _x91) {
9883
+ function deleteUsers(_x89, _x90) {
9348
9884
  return _deleteUsers.apply(this, arguments);
9349
9885
  }
9350
9886
 
@@ -9444,5 +9980,5 @@ var BuiltinPermissions = {
9444
9980
  UseFrozenChannel: 'Send messages and reactions to frozen channels'
9445
9981
  };
9446
9982
 
9447
- export { Allow, AllowAll, AnyResource, AnyRole, BuiltinPermissions, BuiltinRoles, Channel, ChannelState, CheckSignature, ClientState, Deny, DenyAll, DevToken, EVENT_MAP, InsightMetrics, JWTServerToken, JWTUserToken, MaxPriority, MinPriority, Permission, StableWSConnection, StreamChat, TokenManager, UserFromToken, buildWsFatalInsight, buildWsSuccessAfterFailureInsight, chatCodes, decodeBase64, encodeBase64, isOwnUser, isValidEventType, logChatPromiseExecution };
9983
+ export { Allow, AllowAll, AnyResource, AnyRole, BuiltinPermissions, BuiltinRoles, Channel, ChannelState, CheckSignature, ClientState, Deny, DenyAll, DevToken, EVENT_MAP, InsightMetrics, JWTServerToken, JWTUserToken, MaxPriority, MinPriority, Permission, StableWSConnection, StreamChat, TokenManager, UserFromToken, buildWsFatalInsight, buildWsSuccessAfterFailureInsight, chatCodes, decodeBase64, encodeBase64, isOwnUser, isValidEventType, logChatPromiseExecution, postInsights };
9448
9984
  //# sourceMappingURL=browser.es.js.map