stream-chat 4.4.3-dev.2 → 5.0.0

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 +1229 -720
  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 +1229 -719
  7. package/dist/browser.js.map +1 -1
  8. package/dist/index.es.js +1229 -720
  9. package/dist/index.es.js.map +1 -1
  10. package/dist/index.js +1229 -719
  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 +17 -10
  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 +94 -88
  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 +291 -712
  43. package/src/client_state.ts +2 -2
  44. package/src/connection.ts +146 -395
  45. package/src/connection_fallback.ts +205 -0
  46. package/src/errors.ts +58 -0
  47. package/src/insights.ts +38 -32
  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 +268 -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);
3597
-
3598
- _defineProperty(this, "insightMetrics", void 0);
3599
-
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));
3697
+ _defineProperty(this, "_buildUrl", function () {
3698
+ var qs = encodeURIComponent(_this.client._buildWSPayload(_this.requestID));
3610
3699
 
3611
- var token = _this.tokenManager.getToken();
3700
+ var token = _this.client.tokenManager.getToken();
3612
3701
 
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,576 @@ 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 = 3;
5158
+ break;
5159
+ }
5160
+
5161
+ throw new Error('connecting already in progress');
5162
+
5163
+ case 3:
5164
+ if (!(_this.state === ConnectionState.Connected)) {
5165
+ _context3.next = 5;
5166
+ break;
5167
+ }
5168
+
5169
+ throw new Error('already connected and polling');
5170
+
5171
+ case 5:
5172
+ _this._setState(ConnectionState.Connecting);
5173
+
5174
+ _this.connectionID = undefined; // connect should be sent with empty connection_id so API creates one
5175
+
5176
+ _context3.prev = 7;
5177
+ _context3.next = 10;
5178
+ return _this._req({
5179
+ json: _this.client._buildWSPayload()
5180
+ }, {
5181
+ timeout: 8000
5182
+ }, // 8s
5183
+ reconnect);
5184
+
5185
+ case 10:
5186
+ _yield$_this$_req = _context3.sent;
5187
+ event = _yield$_this$_req.event;
5188
+
5189
+ _this._setState(ConnectionState.Connected);
5190
+
5191
+ _this.connectionID = event.connection_id;
5192
+
5193
+ _this._poll();
5194
+
5195
+ if (reconnect) {
5196
+ _this.client.recoverState();
5197
+ }
5198
+
5199
+ return _context3.abrupt("return", event);
4726
5200
 
4727
- case 2:
4728
- if (!(_this.tokenProvider && typeof _this.tokenProvider !== 'string')) {
4729
- _context2.next = 7;
4730
- break;
4731
- }
5201
+ case 19:
5202
+ _context3.prev = 19;
5203
+ _context3.t0 = _context3["catch"](7);
4732
5204
 
4733
- _context2.next = 5;
4734
- return _this.tokenProvider();
5205
+ _this._setState(ConnectionState.Closed);
4735
5206
 
4736
- case 5:
4737
- _this.token = _context2.sent;
4738
- resolve(_this.token);
5207
+ throw _context3.t0;
4739
5208
 
4740
- case 7:
4741
- case "end":
4742
- return _context2.stop();
4743
- }
5209
+ case 23:
5210
+ case "end":
5211
+ return _context3.stop();
4744
5212
  }
4745
- }, _callee2);
4746
- }));
5213
+ }
5214
+ }, _callee3, null, [[7, 19]]);
5215
+ })));
4747
5216
 
4748
- return function (_x3) {
4749
- return _ref2.apply(this, arguments);
4750
- };
4751
- }());
4752
- return _this.loadTokenPromise;
4753
- });
5217
+ _defineProperty(this, "isHealthy", function () {
5218
+ return _this.connectionID && _this.state === ConnectionState.Connected;
5219
+ });
4754
5220
 
4755
- _defineProperty(this, "getToken", function () {
4756
- if (_this.token) {
4757
- return _this.token;
4758
- }
5221
+ _defineProperty(this, "disconnect", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
5222
+ var _this$cancelToken3;
4759
5223
 
4760
- if (_this.user && _this.user.anon && !_this.token) {
4761
- return _this.token;
4762
- }
5224
+ var timeout,
5225
+ _args4 = arguments;
5226
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
5227
+ while (1) {
5228
+ switch (_context4.prev = _context4.next) {
5229
+ case 0:
5230
+ timeout = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : 2000;
5231
+ removeConnectionEventListeners(_this._onlineStatusChanged);
4763
5232
 
4764
- if (_this.secret) {
4765
- return JWTServerToken(_this.secret);
4766
- }
5233
+ _this._setState(ConnectionState.Disconnected);
4767
5234
 
4768
- throw new Error("Both secret and user tokens are not set. Either client.connectUser wasn't called or client.disconnect was called");
4769
- });
5235
+ (_this$cancelToken3 = _this.cancelToken) === null || _this$cancelToken3 === void 0 ? void 0 : _this$cancelToken3.cancel('disconnect() is called');
5236
+ _this.cancelToken = undefined;
5237
+ _context4.prev = 5;
5238
+ _context4.next = 8;
5239
+ return _this._req({
5240
+ close: true
5241
+ }, {
5242
+ timeout: timeout
5243
+ }, false);
4770
5244
 
4771
- _defineProperty(this, "isStatic", function () {
4772
- return _this.type === 'static';
4773
- });
5245
+ case 8:
5246
+ _this.connectionID = undefined;
4774
5247
 
4775
- this.loadTokenPromise = null;
5248
+ _this._log("disconnect() - Closed connectionID");
4776
5249
 
4777
- if (secret) {
4778
- this.secret = secret;
4779
- }
5250
+ _context4.next = 15;
5251
+ break;
4780
5252
 
4781
- this.type = 'static';
5253
+ case 12:
5254
+ _context4.prev = 12;
5255
+ _context4.t0 = _context4["catch"](5);
4782
5256
 
4783
- if (this.secret) {
4784
- this.token = JWTServerToken(this.secret);
5257
+ _this._log("disconnect() - Failed", {
5258
+ err: _context4.t0
5259
+ }, 'error');
5260
+
5261
+ case 15:
5262
+ case "end":
5263
+ return _context4.stop();
5264
+ }
5265
+ }
5266
+ }, _callee4, null, [[5, 12]]);
5267
+ })));
5268
+
5269
+ this.client = client;
5270
+ this.state = ConnectionState.Init;
5271
+ this.consecutiveFailures = 0;
5272
+ addConnectionEventListeners(this._onlineStatusChanged);
4785
5273
  }
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
- ;
5274
+
5275
+ _createClass(WSConnectionFallback, [{
5276
+ key: "_log",
5277
+ value: function _log(msg) {
5278
+ var extra = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
5279
+ var level = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'info';
5280
+ this.client.logger(level, 'WSConnectionFallback:' + msg, _objectSpread$1({
5281
+ tags: ['connection_fallback', 'connection']
5282
+ }, extra));
5283
+ }
5284
+ }, {
5285
+ key: "_setState",
5286
+ value: function _setState(state) {
5287
+ this._log("_setState() - ".concat(state)); // transition from connecting => connected
5288
+
5289
+
5290
+ if (this.state === ConnectionState.Connecting && state === ConnectionState.Connected) {
5291
+ //@ts-expect-error
5292
+ this.client.dispatchEvent({
5293
+ type: 'connection.changed',
5294
+ online: true
5295
+ });
5296
+ }
5297
+
5298
+ if (state === ConnectionState.Closed || state === ConnectionState.Disconnected) {
5299
+ //@ts-expect-error
5300
+ this.client.dispatchEvent({
5301
+ type: 'connection.changed',
5302
+ online: false
5303
+ });
5304
+ }
5305
+
5306
+ this.state = state;
5307
+ }
5308
+ /** @private */
5309
+
5310
+ }]);
5311
+
5312
+ return WSConnectionFallback;
5313
+ }();
4795
5314
 
4796
5315
  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
5316
 
@@ -4831,10 +5350,6 @@ var StreamChat = /*#__PURE__*/function () {
4831
5350
 
4832
5351
  _defineProperty(this, "configs", void 0);
4833
5352
 
4834
- _defineProperty(this, "connectionID", void 0);
4835
-
4836
- _defineProperty(this, "failures", void 0);
4837
-
4838
5353
  _defineProperty(this, "key", void 0);
4839
5354
 
4840
5355
  _defineProperty(this, "listeners", void 0);
@@ -4869,16 +5384,26 @@ var StreamChat = /*#__PURE__*/function () {
4869
5384
 
4870
5385
  _defineProperty(this, "wsConnection", void 0);
4871
5386
 
5387
+ _defineProperty(this, "wsFallback", void 0);
5388
+
4872
5389
  _defineProperty(this, "wsPromise", void 0);
4873
5390
 
4874
5391
  _defineProperty(this, "consecutiveFailures", void 0);
4875
5392
 
4876
5393
  _defineProperty(this, "insightMetrics", void 0);
4877
5394
 
4878
- _defineProperty(this, "_hasConnectionID", function () {
4879
- var _this$wsConnection;
5395
+ _defineProperty(this, "defaultWSTimeoutWithFallback", void 0);
5396
+
5397
+ _defineProperty(this, "defaultWSTimeout", void 0);
5398
+
5399
+ _defineProperty(this, "_getConnectionID", function () {
5400
+ var _this$wsConnection, _this$wsFallback;
5401
+
5402
+ 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);
5403
+ });
4880
5404
 
4881
- return Boolean((_this$wsConnection = _this.wsConnection) === null || _this$wsConnection === void 0 ? void 0 : _this$wsConnection.connectionID);
5405
+ _defineProperty(this, "_hasConnectionID", function () {
5406
+ return Boolean(_this._getConnectionID());
4882
5407
  });
4883
5408
 
4884
5409
  _defineProperty(this, "connectUser", /*#__PURE__*/function () {
@@ -4964,36 +5489,55 @@ var StreamChat = /*#__PURE__*/function () {
4964
5489
  return _this.tokenManager.setTokenOrProvider(userTokenOrProvider, user);
4965
5490
  });
4966
5491
 
4967
- _defineProperty(this, "closeConnection", function (timeout) {
4968
- if (_this.cleaningIntervalRef != null) {
4969
- clearInterval(_this.cleaningIntervalRef);
4970
- _this.cleaningIntervalRef = undefined;
4971
- }
5492
+ _defineProperty(this, "closeConnection", /*#__PURE__*/function () {
5493
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(timeout) {
5494
+ var _this$wsConnection2, _this$wsFallback2;
4972
5495
 
4973
- if (!_this.wsConnection) {
4974
- return Promise.resolve();
4975
- }
5496
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
5497
+ while (1) {
5498
+ switch (_context2.prev = _context2.next) {
5499
+ case 0:
5500
+ if (_this.cleaningIntervalRef != null) {
5501
+ clearInterval(_this.cleaningIntervalRef);
5502
+ _this.cleaningIntervalRef = undefined;
5503
+ }
4976
5504
 
4977
- return _this.wsConnection.disconnect(timeout);
4978
- });
5505
+ _context2.next = 3;
5506
+ 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
5507
 
4980
- _defineProperty(this, "openConnection", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
4981
- var _this$wsConnection2;
5508
+ case 3:
5509
+ return _context2.abrupt("return", Promise.resolve());
4982
5510
 
4983
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
5511
+ case 4:
5512
+ case "end":
5513
+ return _context2.stop();
5514
+ }
5515
+ }
5516
+ }, _callee2);
5517
+ }));
5518
+
5519
+ return function (_x3) {
5520
+ return _ref2.apply(this, arguments);
5521
+ };
5522
+ }());
5523
+
5524
+ _defineProperty(this, "openConnection", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
5525
+ var _this$wsConnection3, _this$wsFallback3;
5526
+
5527
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
4984
5528
  while (1) {
4985
- switch (_context2.prev = _context2.next) {
5529
+ switch (_context3.prev = _context3.next) {
4986
5530
  case 0:
4987
5531
  if (_this.userID) {
4988
- _context2.next = 2;
5532
+ _context3.next = 2;
4989
5533
  break;
4990
5534
  }
4991
5535
 
4992
5536
  throw Error('User is not set on client, use client.connectUser or client.connectAnonymousUser instead');
4993
5537
 
4994
5538
  case 2:
4995
- if (!((_this$wsConnection2 = _this.wsConnection) !== null && _this$wsConnection2 !== void 0 && _this$wsConnection2.isHealthy && _this._hasConnectionID())) {
4996
- _context2.next = 5;
5539
+ 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())) {
5540
+ _context3.next = 5;
4997
5541
  break;
4998
5542
  }
4999
5543
 
@@ -5001,7 +5545,7 @@ var StreamChat = /*#__PURE__*/function () {
5001
5545
  tags: ['connection', 'client']
5002
5546
  });
5003
5547
 
5004
- return _context2.abrupt("return", Promise.resolve());
5548
+ return _context3.abrupt("return", Promise.resolve());
5005
5549
 
5006
5550
  case 5:
5007
5551
  _this.clientID = "".concat(_this.userID, "--").concat(randomId());
@@ -5009,14 +5553,14 @@ var StreamChat = /*#__PURE__*/function () {
5009
5553
 
5010
5554
  _this._startCleaning();
5011
5555
 
5012
- return _context2.abrupt("return", _this.wsPromise);
5556
+ return _context3.abrupt("return", _this.wsPromise);
5013
5557
 
5014
5558
  case 9:
5015
5559
  case "end":
5016
- return _context2.stop();
5560
+ return _context3.stop();
5017
5561
  }
5018
5562
  }
5019
- }, _callee2);
5563
+ }, _callee3);
5020
5564
  })));
5021
5565
 
5022
5566
  _defineProperty(this, "_setupConnection", this.openConnection);
@@ -5034,12 +5578,12 @@ var StreamChat = /*#__PURE__*/function () {
5034
5578
  });
5035
5579
 
5036
5580
  _defineProperty(this, "disconnectUser", /*#__PURE__*/function () {
5037
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(timeout) {
5581
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(timeout) {
5038
5582
  var closePromise, _i, _Object$values, _channel;
5039
5583
 
5040
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
5584
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
5041
5585
  while (1) {
5042
- switch (_context3.prev = _context3.next) {
5586
+ switch (_context4.prev = _context4.next) {
5043
5587
  case 0:
5044
5588
  _this.logger('info', 'client:disconnect() - Disconnecting the client', {
5045
5589
  tags: ['connection', 'client']
@@ -5063,21 +5607,21 @@ var StreamChat = /*#__PURE__*/function () {
5063
5607
 
5064
5608
  _this.state = new ClientState(); // reset token manager
5065
5609
 
5066
- _this.tokenManager.reset(); // close the WS connection
5610
+ setTimeout(_this.tokenManager.reset); // delay reseting to use token for disconnect calls
5611
+ // close the WS connection
5067
5612
 
5068
-
5069
- return _context3.abrupt("return", closePromise);
5613
+ return _context4.abrupt("return", closePromise);
5070
5614
 
5071
5615
  case 11:
5072
5616
  case "end":
5073
- return _context3.stop();
5617
+ return _context4.stop();
5074
5618
  }
5075
5619
  }
5076
- }, _callee3);
5620
+ }, _callee4);
5077
5621
  }));
5078
5622
 
5079
- return function (_x3) {
5080
- return _ref3.apply(this, arguments);
5623
+ return function (_x4) {
5624
+ return _ref4.apply(this, arguments);
5081
5625
  };
5082
5626
  }());
5083
5627
 
@@ -5105,78 +5649,78 @@ var StreamChat = /*#__PURE__*/function () {
5105
5649
  _defineProperty(this, "setAnonymousUser", this.connectAnonymousUser);
5106
5650
 
5107
5651
  _defineProperty(this, "doAxiosRequest", /*#__PURE__*/function () {
5108
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(type, url, data) {
5652
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(type, url, data) {
5109
5653
  var options,
5110
5654
  requestConfig,
5111
5655
  response,
5112
5656
  _requestConfig$header,
5113
- _args4 = arguments;
5657
+ _args5 = arguments;
5114
5658
 
5115
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
5659
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
5116
5660
  while (1) {
5117
- switch (_context4.prev = _context4.next) {
5661
+ switch (_context5.prev = _context5.next) {
5118
5662
  case 0:
5119
- options = _args4.length > 3 && _args4[3] !== undefined ? _args4[3] : {};
5120
- _context4.next = 3;
5663
+ options = _args5.length > 3 && _args5[3] !== undefined ? _args5[3] : {};
5664
+ _context5.next = 3;
5121
5665
  return _this.tokenManager.tokenReady();
5122
5666
 
5123
5667
  case 3:
5124
5668
  requestConfig = _this._enrichAxiosOptions(options);
5125
- _context4.prev = 4;
5669
+ _context5.prev = 4;
5126
5670
 
5127
5671
  _this._logApiRequest(type, url, data, requestConfig);
5128
5672
 
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;
5673
+ _context5.t0 = type;
5674
+ _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
5675
  break;
5132
5676
 
5133
5677
  case 9:
5134
- _context4.next = 11;
5678
+ _context5.next = 11;
5135
5679
  return _this.axiosInstance.get(url, requestConfig);
5136
5680
 
5137
5681
  case 11:
5138
- response = _context4.sent;
5139
- return _context4.abrupt("break", 34);
5682
+ response = _context5.sent;
5683
+ return _context5.abrupt("break", 34);
5140
5684
 
5141
5685
  case 13:
5142
- _context4.next = 15;
5686
+ _context5.next = 15;
5143
5687
  return _this.axiosInstance.delete(url, requestConfig);
5144
5688
 
5145
5689
  case 15:
5146
- response = _context4.sent;
5147
- return _context4.abrupt("break", 34);
5690
+ response = _context5.sent;
5691
+ return _context5.abrupt("break", 34);
5148
5692
 
5149
5693
  case 17:
5150
- _context4.next = 19;
5694
+ _context5.next = 19;
5151
5695
  return _this.axiosInstance.post(url, data, requestConfig);
5152
5696
 
5153
5697
  case 19:
5154
- response = _context4.sent;
5155
- return _context4.abrupt("break", 34);
5698
+ response = _context5.sent;
5699
+ return _context5.abrupt("break", 34);
5156
5700
 
5157
5701
  case 21:
5158
- _context4.next = 23;
5702
+ _context5.next = 23;
5159
5703
  return _this.axiosInstance.put(url, data, requestConfig);
5160
5704
 
5161
5705
  case 23:
5162
- response = _context4.sent;
5163
- return _context4.abrupt("break", 34);
5706
+ response = _context5.sent;
5707
+ return _context5.abrupt("break", 34);
5164
5708
 
5165
5709
  case 25:
5166
- _context4.next = 27;
5710
+ _context5.next = 27;
5167
5711
  return _this.axiosInstance.patch(url, data, requestConfig);
5168
5712
 
5169
5713
  case 27:
5170
- response = _context4.sent;
5171
- return _context4.abrupt("break", 34);
5714
+ response = _context5.sent;
5715
+ return _context5.abrupt("break", 34);
5172
5716
 
5173
5717
  case 29:
5174
- _context4.next = 31;
5718
+ _context5.next = 31;
5175
5719
  return _this.axiosInstance.options(url, requestConfig);
5176
5720
 
5177
5721
  case 31:
5178
- response = _context4.sent;
5179
- return _context4.abrupt("break", 34);
5722
+ response = _context5.sent;
5723
+ return _context5.abrupt("break", 34);
5180
5724
 
5181
5725
  case 33:
5182
5726
  throw new Error('Invalid request type');
@@ -5185,65 +5729,66 @@ var StreamChat = /*#__PURE__*/function () {
5185
5729
  _this._logApiResponse(type, url, response);
5186
5730
 
5187
5731
  _this.consecutiveFailures = 0;
5188
- return _context4.abrupt("return", _this.handleResponse(response));
5732
+ return _context5.abrupt("return", _this.handleResponse(response));
5189
5733
 
5190
5734
  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'];
5735
+ _context5.prev = 39;
5736
+ _context5.t1 = _context5["catch"](4);
5737
+ _context5.t1.client_request_id = (_requestConfig$header = requestConfig.headers) === null || _requestConfig$header === void 0 ? void 0 : _requestConfig$header['x-client-request-id'];
5194
5738
 
5195
- _this._logApiError(type, url, _context4.t1);
5739
+ _this._logApiError(type, url, _context5.t1);
5196
5740
 
5197
5741
  _this.consecutiveFailures += 1;
5198
5742
 
5199
- if (!_context4.t1.response) {
5200
- _context4.next = 56;
5743
+ if (!_context5.t1.response) {
5744
+ _context5.next = 56;
5201
5745
  break;
5202
5746
  }
5203
5747
 
5204
- if (!(_context4.t1.response.data.code === chatCodes.TOKEN_EXPIRED && !_this.tokenManager.isStatic())) {
5205
- _context4.next = 53;
5748
+ if (!(_context5.t1.response.data.code === chatCodes.TOKEN_EXPIRED && !_this.tokenManager.isStatic())) {
5749
+ _context5.next = 53;
5206
5750
  break;
5207
5751
  }
5208
5752
 
5209
5753
  if (!(_this.consecutiveFailures > 1)) {
5210
- _context4.next = 49;
5754
+ _context5.next = 49;
5211
5755
  break;
5212
5756
  }
5213
5757
 
5214
- _context4.next = 49;
5758
+ _context5.next = 49;
5215
5759
  return sleep(retryInterval(_this.consecutiveFailures));
5216
5760
 
5217
5761
  case 49:
5218
5762
  _this.tokenManager.loadToken();
5219
5763
 
5220
- _context4.next = 52;
5764
+ _context5.next = 52;
5221
5765
  return _this.doAxiosRequest(type, url, data, options);
5222
5766
 
5223
5767
  case 52:
5224
- return _context4.abrupt("return", _context4.sent);
5768
+ return _context5.abrupt("return", _context5.sent);
5225
5769
 
5226
5770
  case 53:
5227
- return _context4.abrupt("return", _this.handleResponse(_context4.t1.response));
5771
+ return _context5.abrupt("return", _this.handleResponse(_context5.t1.response));
5228
5772
 
5229
5773
  case 56:
5230
- throw _context4.t1;
5774
+ throw _context5.t1;
5231
5775
 
5232
5776
  case 57:
5233
5777
  case "end":
5234
- return _context4.stop();
5778
+ return _context5.stop();
5235
5779
  }
5236
5780
  }
5237
- }, _callee4, null, [[4, 39]]);
5781
+ }, _callee5, null, [[4, 39]]);
5238
5782
  }));
5239
5783
 
5240
- return function (_x4, _x5, _x6) {
5241
- return _ref4.apply(this, arguments);
5784
+ return function (_x5, _x6, _x7) {
5785
+ return _ref5.apply(this, arguments);
5242
5786
  };
5243
5787
  }());
5244
5788
 
5245
5789
  _defineProperty(this, "dispatchEvent", function (event) {
5246
- // client event handlers
5790
+ if (!event.received_at) event.received_at = new Date(); // client event handlers
5791
+
5247
5792
  var postListenerCallbacks = _this._handleClientEvent(event); // channel event handlers
5248
5793
 
5249
5794
 
@@ -5269,7 +5814,6 @@ var StreamChat = /*#__PURE__*/function () {
5269
5814
  // dispatch the event to the channel listeners
5270
5815
  var jsonString = messageEvent.data;
5271
5816
  var event = JSON.parse(jsonString);
5272
- event.received_at = new Date();
5273
5817
 
5274
5818
  _this.dispatchEvent(event);
5275
5819
  });
@@ -5390,22 +5934,20 @@ var StreamChat = /*#__PURE__*/function () {
5390
5934
  }
5391
5935
  });
5392
5936
 
5393
- _defineProperty(this, "recoverState", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
5394
- var _this$wsConnection3;
5395
-
5937
+ _defineProperty(this, "recoverState", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
5396
5938
  var cids;
5397
- return _regeneratorRuntime.wrap(function _callee5$(_context5) {
5939
+ return _regeneratorRuntime.wrap(function _callee6$(_context6) {
5398
5940
  while (1) {
5399
- switch (_context5.prev = _context5.next) {
5941
+ switch (_context6.prev = _context6.next) {
5400
5942
  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), {
5943
+ _this.logger('info', "client:recoverState() - Start of recoverState with connectionID ".concat(_this._getConnectionID()), {
5402
5944
  tags: ['connection']
5403
5945
  });
5404
5946
 
5405
5947
  cids = Object.keys(_this.activeChannels);
5406
5948
 
5407
5949
  if (!(cids.length && _this.recoverStateOnReconnect)) {
5408
- _context5.next = 10;
5950
+ _context6.next = 10;
5409
5951
  break;
5410
5952
  }
5411
5953
 
@@ -5413,7 +5955,7 @@ var StreamChat = /*#__PURE__*/function () {
5413
5955
  tags: ['connection', 'client']
5414
5956
  });
5415
5957
 
5416
- _context5.next = 6;
5958
+ _context6.next = 6;
5417
5959
  return _this.queryChannels({
5418
5960
  cid: {
5419
5961
  $in: cids
@@ -5433,7 +5975,7 @@ var StreamChat = /*#__PURE__*/function () {
5433
5975
  type: 'connection.recovered'
5434
5976
  });
5435
5977
 
5436
- _context5.next = 11;
5978
+ _context6.next = 11;
5437
5979
  break;
5438
5980
 
5439
5981
  case 10:
@@ -5447,10 +5989,10 @@ var StreamChat = /*#__PURE__*/function () {
5447
5989
 
5448
5990
  case 13:
5449
5991
  case "end":
5450
- return _context5.stop();
5992
+ return _context6.stop();
5451
5993
  }
5452
5994
  }
5453
- }, _callee5);
5995
+ }, _callee6);
5454
5996
  })));
5455
5997
 
5456
5998
  _defineProperty(this, "getChannelByMembers", function (channelType, custom) {
@@ -5530,66 +6072,14 @@ var StreamChat = /*#__PURE__*/function () {
5530
6072
  return !!_this.secret;
5531
6073
  });
5532
6074
 
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
- }());
6075
+ _defineProperty(this, "_buildWSPayload", function (client_request_id) {
6076
+ return JSON.stringify({
6077
+ user_id: _this.userID,
6078
+ user_details: _this._user,
6079
+ device: _this.options.device,
6080
+ client_request_id: client_request_id
6081
+ });
6082
+ });
5593
6083
 
5594
6084
  // set the key
5595
6085
  this.key = _key;
@@ -5647,6 +6137,8 @@ var StreamChat = /*#__PURE__*/function () {
5647
6137
  this.tokenManager = new TokenManager(this.secret);
5648
6138
  this.consecutiveFailures = 0;
5649
6139
  this.insightMetrics = new InsightMetrics();
6140
+ this.defaultWSTimeoutWithFallback = 6000;
6141
+ this.defaultWSTimeout = 15000;
5650
6142
  /**
5651
6143
  * logger function should accept 3 parameters:
5652
6144
  * @param logLevel string
@@ -5820,7 +6312,7 @@ var StreamChat = /*#__PURE__*/function () {
5820
6312
  }, _callee7, this);
5821
6313
  }));
5822
6314
 
5823
- function updateAppSettings(_x9) {
6315
+ function updateAppSettings(_x8) {
5824
6316
  return _updateAppSettings.apply(this, arguments);
5825
6317
  }
5826
6318
 
@@ -5854,7 +6346,7 @@ var StreamChat = /*#__PURE__*/function () {
5854
6346
  }, _callee8, this);
5855
6347
  }));
5856
6348
 
5857
- function revokeTokens(_x10) {
6349
+ function revokeTokens(_x9) {
5858
6350
  return _revokeTokens.apply(this, arguments);
5859
6351
  }
5860
6352
 
@@ -5886,7 +6378,7 @@ var StreamChat = /*#__PURE__*/function () {
5886
6378
  }, _callee9, this);
5887
6379
  }));
5888
6380
 
5889
- function revokeUserToken(_x11, _x12) {
6381
+ function revokeUserToken(_x10, _x11) {
5890
6382
  return _revokeUserToken.apply(this, arguments);
5891
6383
  }
5892
6384
 
@@ -5945,7 +6437,7 @@ var StreamChat = /*#__PURE__*/function () {
5945
6437
  }, _callee10, this);
5946
6438
  }));
5947
6439
 
5948
- function revokeUsersToken(_x13, _x14) {
6440
+ function revokeUsersToken(_x12, _x13) {
5949
6441
  return _revokeUsersToken.apply(this, arguments);
5950
6442
  }
5951
6443
 
@@ -6037,7 +6529,7 @@ var StreamChat = /*#__PURE__*/function () {
6037
6529
  }, _callee12, this);
6038
6530
  }));
6039
6531
 
6040
- function testPushSettings(_x15) {
6532
+ function testPushSettings(_x14) {
6041
6533
  return _testPushSettings.apply(this, arguments);
6042
6534
  }
6043
6535
 
@@ -6146,7 +6638,7 @@ var StreamChat = /*#__PURE__*/function () {
6146
6638
  }, _callee14, this, [[1, 7]]);
6147
6639
  }));
6148
6640
 
6149
- function setGuestUser(_x16) {
6641
+ function setGuestUser(_x15) {
6150
6642
  return _setGuestUser.apply(this, arguments);
6151
6643
  }
6152
6644
 
@@ -6457,72 +6949,84 @@ var StreamChat = /*#__PURE__*/function () {
6457
6949
  */
6458
6950
  function () {
6459
6951
  var _connect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15() {
6460
- var client;
6461
6952
  return _regeneratorRuntime.wrap(function _callee15$(_context15) {
6462
6953
  while (1) {
6463
6954
  switch (_context15.prev = _context15.next) {
6464
6955
  case 0:
6465
- client = this;
6466
- this.failures = 0;
6467
-
6468
- if (!(client.userID == null || this._user == null)) {
6469
- _context15.next = 4;
6956
+ if (!(!this.userID || !this._user)) {
6957
+ _context15.next = 2;
6470
6958
  break;
6471
6959
  }
6472
6960
 
6473
6961
  throw Error('Call connectUser or connectAnonymousUser before starting the connection');
6474
6962
 
6475
- case 4:
6476
- if (!(client.wsBaseURL == null)) {
6477
- _context15.next = 6;
6963
+ case 2:
6964
+ if (this.wsBaseURL) {
6965
+ _context15.next = 4;
6478
6966
  break;
6479
6967
  }
6480
6968
 
6481
6969
  throw Error('Websocket base url not set');
6482
6970
 
6483
- case 6:
6484
- if (!(client.clientID == null)) {
6485
- _context15.next = 8;
6971
+ case 4:
6972
+ if (this.clientID) {
6973
+ _context15.next = 6;
6486
6974
  break;
6487
6975
  }
6488
6976
 
6489
6977
  throw Error('clientID is not set');
6490
6978
 
6491
- case 8:
6979
+ case 6:
6492
6980
  if (!this.wsConnection && (this.options.warmUp || this.options.enableInsights)) {
6493
- this.sendBeacon();
6981
+ this._sayHi();
6494
6982
  } // The StableWSConnection handles all the reconnection logic.
6495
6983
 
6496
6984
 
6497
6985
  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
6986
+ client: this
6513
6987
  });
6514
- _context15.next = 12;
6515
- return this.wsConnection.connect();
6988
+ _context15.prev = 8;
6989
+ _context15.next = 11;
6990
+ return this.wsConnection.connect(this.options.enableWSFallback ? this.defaultWSTimeoutWithFallback : this.defaultWSTimeout);
6516
6991
 
6517
- case 12:
6992
+ case 11:
6518
6993
  return _context15.abrupt("return", _context15.sent);
6519
6994
 
6520
- case 13:
6995
+ case 14:
6996
+ _context15.prev = 14;
6997
+ _context15.t0 = _context15["catch"](8);
6998
+
6999
+ if (!(this.options.enableWSFallback && isWSFailure(_context15.t0) && isOnline())) {
7000
+ _context15.next = 24;
7001
+ break;
7002
+ }
7003
+
7004
+ this.logger('info', 'client:connect() - WS failed, fallback to longpoll', {
7005
+ tags: ['connection', 'client']
7006
+ });
7007
+
7008
+ this.wsConnection._destroyCurrentWSConnection();
7009
+
7010
+ this.wsConnection.disconnect().then(); // close WS so no retry
7011
+
7012
+ this.wsFallback = new WSConnectionFallback({
7013
+ client: this
7014
+ });
7015
+ _context15.next = 23;
7016
+ return this.wsFallback.connect();
7017
+
7018
+ case 23:
7019
+ return _context15.abrupt("return", _context15.sent);
7020
+
7021
+ case 24:
7022
+ throw _context15.t0;
7023
+
7024
+ case 25:
6521
7025
  case "end":
6522
7026
  return _context15.stop();
6523
7027
  }
6524
7028
  }
6525
- }, _callee15, this);
7029
+ }, _callee15, this, [[8, 14]]);
6526
7030
  }));
6527
7031
 
6528
7032
  function connect() {
@@ -6531,9 +7035,15 @@ var StreamChat = /*#__PURE__*/function () {
6531
7035
 
6532
7036
  return connect;
6533
7037
  }()
7038
+ /**
7039
+ * Check the connectivity with server for warmup purpose.
7040
+ *
7041
+ * @private
7042
+ */
7043
+
6534
7044
  }, {
6535
- key: "sendBeacon",
6536
- value: function sendBeacon() {
7045
+ key: "_sayHi",
7046
+ value: function _sayHi() {
6537
7047
  var _this4 = this;
6538
7048
 
6539
7049
  var client_request_id = randomId();
@@ -6542,12 +7052,14 @@ var StreamChat = /*#__PURE__*/function () {
6542
7052
  'x-client-request-id': client_request_id
6543
7053
  }
6544
7054
  };
6545
- this.doAxiosRequest('get', this.baseURL + '/beacon', null, opts).catch(function (e) {
6546
- _this4.postInsights('http_beacon_failed', {
6547
- api_key: _this4.key,
6548
- err: e,
6549
- client_request_id: client_request_id
6550
- });
7055
+ this.doAxiosRequest('get', this.baseURL + '/hi', null, opts).catch(function (e) {
7056
+ if (_this4.options.enableInsights) {
7057
+ postInsights('http_hi_failed', {
7058
+ api_key: _this4.key,
7059
+ err: e,
7060
+ client_request_id: client_request_id
7061
+ });
7062
+ }
6551
7063
  });
6552
7064
  }
6553
7065
  /**
@@ -6610,7 +7122,7 @@ var StreamChat = /*#__PURE__*/function () {
6610
7122
  }, _callee16, this);
6611
7123
  }));
6612
7124
 
6613
- function queryUsers(_x17) {
7125
+ function queryUsers(_x16) {
6614
7126
  return _queryUsers.apply(this, arguments);
6615
7127
  }
6616
7128
 
@@ -6829,7 +7341,7 @@ var StreamChat = /*#__PURE__*/function () {
6829
7341
  }, _callee19, this);
6830
7342
  }));
6831
7343
 
6832
- function queryChannels(_x18) {
7344
+ function queryChannels(_x17) {
6833
7345
  return _queryChannels.apply(this, arguments);
6834
7346
  }
6835
7347
 
@@ -6915,7 +7427,7 @@ var StreamChat = /*#__PURE__*/function () {
6915
7427
  }, _callee20, this);
6916
7428
  }));
6917
7429
 
6918
- function search(_x19, _x20) {
7430
+ function search(_x18, _x19) {
6919
7431
  return _search.apply(this, arguments);
6920
7432
  }
6921
7433
 
@@ -6933,7 +7445,7 @@ var StreamChat = /*#__PURE__*/function () {
6933
7445
  }, {
6934
7446
  key: "setLocalDevice",
6935
7447
  value: function setLocalDevice(device) {
6936
- if (this.wsConnection) {
7448
+ if (this.wsConnection || this.wsFallback) {
6937
7449
  throw new Error('you can only set device before opening a websocket connection');
6938
7450
  }
6939
7451
 
@@ -6975,7 +7487,7 @@ var StreamChat = /*#__PURE__*/function () {
6975
7487
  }, _callee21, this);
6976
7488
  }));
6977
7489
 
6978
- function addDevice(_x21, _x22, _x23) {
7490
+ function addDevice(_x20, _x21, _x22) {
6979
7491
  return _addDevice.apply(this, arguments);
6980
7492
  }
6981
7493
 
@@ -7013,7 +7525,7 @@ var StreamChat = /*#__PURE__*/function () {
7013
7525
  }, _callee22, this);
7014
7526
  }));
7015
7527
 
7016
- function getDevices(_x24) {
7528
+ function getDevices(_x23) {
7017
7529
  return _getDevices.apply(this, arguments);
7018
7530
  }
7019
7531
 
@@ -7053,7 +7565,7 @@ var StreamChat = /*#__PURE__*/function () {
7053
7565
  }, _callee23, this);
7054
7566
  }));
7055
7567
 
7056
- function removeDevice(_x25, _x26) {
7568
+ function removeDevice(_x24, _x25) {
7057
7569
  return _removeDevice.apply(this, arguments);
7058
7570
  }
7059
7571
 
@@ -7094,7 +7606,7 @@ var StreamChat = /*#__PURE__*/function () {
7094
7606
  }, _callee24, this);
7095
7607
  }));
7096
7608
 
7097
- function getRateLimits(_x27) {
7609
+ function getRateLimits(_x26) {
7098
7610
  return _getRateLimits.apply(this, arguments);
7099
7611
  }
7100
7612
 
@@ -7195,7 +7707,7 @@ var StreamChat = /*#__PURE__*/function () {
7195
7707
  }, _callee25, this);
7196
7708
  }));
7197
7709
 
7198
- function partialUpdateUser(_x28) {
7710
+ function partialUpdateUser(_x27) {
7199
7711
  return _partialUpdateUser.apply(this, arguments);
7200
7712
  }
7201
7713
 
@@ -7281,7 +7793,7 @@ var StreamChat = /*#__PURE__*/function () {
7281
7793
  }, _callee26, this, [[2, 13, 16, 19]]);
7282
7794
  }));
7283
7795
 
7284
- function upsertUsers(_x29) {
7796
+ function upsertUsers(_x28) {
7285
7797
  return _upsertUsers.apply(this, arguments);
7286
7798
  }
7287
7799
 
@@ -7394,7 +7906,7 @@ var StreamChat = /*#__PURE__*/function () {
7394
7906
  }, _callee27, this, [[1, 11, 14, 17]]);
7395
7907
  }));
7396
7908
 
7397
- function partialUpdateUsers(_x30) {
7909
+ function partialUpdateUsers(_x29) {
7398
7910
  return _partialUpdateUsers.apply(this, arguments);
7399
7911
  }
7400
7912
 
@@ -7422,7 +7934,7 @@ var StreamChat = /*#__PURE__*/function () {
7422
7934
  }, _callee28, this);
7423
7935
  }));
7424
7936
 
7425
- function deleteUser(_x31, _x32) {
7937
+ function deleteUser(_x30, _x31) {
7426
7938
  return _deleteUser.apply(this, arguments);
7427
7939
  }
7428
7940
 
@@ -7450,7 +7962,7 @@ var StreamChat = /*#__PURE__*/function () {
7450
7962
  }, _callee29, this);
7451
7963
  }));
7452
7964
 
7453
- function reactivateUser(_x33, _x34) {
7965
+ function reactivateUser(_x32, _x33) {
7454
7966
  return _reactivateUser.apply(this, arguments);
7455
7967
  }
7456
7968
 
@@ -7478,7 +7990,7 @@ var StreamChat = /*#__PURE__*/function () {
7478
7990
  }, _callee30, this);
7479
7991
  }));
7480
7992
 
7481
- function deactivateUser(_x35, _x36) {
7993
+ function deactivateUser(_x34, _x35) {
7482
7994
  return _deactivateUser.apply(this, arguments);
7483
7995
  }
7484
7996
 
@@ -7506,7 +8018,7 @@ var StreamChat = /*#__PURE__*/function () {
7506
8018
  }, _callee31, this);
7507
8019
  }));
7508
8020
 
7509
- function exportUser(_x37, _x38) {
8021
+ function exportUser(_x36, _x37) {
7510
8022
  return _exportUser.apply(this, arguments);
7511
8023
  }
7512
8024
 
@@ -7527,27 +8039,15 @@ var StreamChat = /*#__PURE__*/function () {
7527
8039
  while (1) {
7528
8040
  switch (_context32.prev = _context32.next) {
7529
8041
  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;
8042
+ _context32.next = 2;
7543
8043
  return this.post(this.baseURL + '/moderation/ban', _objectSpread({
7544
8044
  target_user_id: targetUserID
7545
8045
  }, options));
7546
8046
 
7547
- case 4:
8047
+ case 2:
7548
8048
  return _context32.abrupt("return", _context32.sent);
7549
8049
 
7550
- case 5:
8050
+ case 3:
7551
8051
  case "end":
7552
8052
  return _context32.stop();
7553
8053
  }
@@ -7555,7 +8055,7 @@ var StreamChat = /*#__PURE__*/function () {
7555
8055
  }, _callee32, this);
7556
8056
  }));
7557
8057
 
7558
- function banUser(_x39, _x40) {
8058
+ function banUser(_x38, _x39) {
7559
8059
  return _banUser.apply(this, arguments);
7560
8060
  }
7561
8061
 
@@ -7592,7 +8092,7 @@ var StreamChat = /*#__PURE__*/function () {
7592
8092
  }, _callee33, this);
7593
8093
  }));
7594
8094
 
7595
- function unbanUser(_x41, _x42) {
8095
+ function unbanUser(_x40, _x41) {
7596
8096
  return _unbanUser.apply(this, arguments);
7597
8097
  }
7598
8098
 
@@ -7629,7 +8129,7 @@ var StreamChat = /*#__PURE__*/function () {
7629
8129
  }, _callee34, this);
7630
8130
  }));
7631
8131
 
7632
- function shadowBan(_x43, _x44) {
8132
+ function shadowBan(_x42, _x43) {
7633
8133
  return _shadowBan.apply(this, arguments);
7634
8134
  }
7635
8135
 
@@ -7666,7 +8166,7 @@ var StreamChat = /*#__PURE__*/function () {
7666
8166
  }, _callee35, this);
7667
8167
  }));
7668
8168
 
7669
- function removeShadowBan(_x45, _x46) {
8169
+ function removeShadowBan(_x44, _x45) {
7670
8170
  return _removeShadowBan.apply(this, arguments);
7671
8171
  }
7672
8172
 
@@ -7709,7 +8209,7 @@ var StreamChat = /*#__PURE__*/function () {
7709
8209
  }, _callee36, this);
7710
8210
  }));
7711
8211
 
7712
- function muteUser(_x47, _x48) {
8212
+ function muteUser(_x46, _x47) {
7713
8213
  return _muteUser.apply(this, arguments);
7714
8214
  }
7715
8215
 
@@ -7748,7 +8248,7 @@ var StreamChat = /*#__PURE__*/function () {
7748
8248
  }, _callee37, this);
7749
8249
  }));
7750
8250
 
7751
- function unmuteUser(_x49, _x50) {
8251
+ function unmuteUser(_x48, _x49) {
7752
8252
  return _unmuteUser.apply(this, arguments);
7753
8253
  }
7754
8254
 
@@ -7807,7 +8307,7 @@ var StreamChat = /*#__PURE__*/function () {
7807
8307
  }, _callee38, this);
7808
8308
  }));
7809
8309
 
7810
- function flagMessage(_x51) {
8310
+ function flagMessage(_x50) {
7811
8311
  return _flagMessage.apply(this, arguments);
7812
8312
  }
7813
8313
 
@@ -7847,7 +8347,7 @@ var StreamChat = /*#__PURE__*/function () {
7847
8347
  }, _callee39, this);
7848
8348
  }));
7849
8349
 
7850
- function flagUser(_x52) {
8350
+ function flagUser(_x51) {
7851
8351
  return _flagUser.apply(this, arguments);
7852
8352
  }
7853
8353
 
@@ -7887,7 +8387,7 @@ var StreamChat = /*#__PURE__*/function () {
7887
8387
  }, _callee40, this);
7888
8388
  }));
7889
8389
 
7890
- function unflagMessage(_x53) {
8390
+ function unflagMessage(_x52) {
7891
8391
  return _unflagMessage.apply(this, arguments);
7892
8392
  }
7893
8393
 
@@ -7927,7 +8427,7 @@ var StreamChat = /*#__PURE__*/function () {
7927
8427
  }, _callee41, this);
7928
8428
  }));
7929
8429
 
7930
- function unflagUser(_x54) {
8430
+ function unflagUser(_x53) {
7931
8431
  return _unflagUser.apply(this, arguments);
7932
8432
  }
7933
8433
 
@@ -8066,7 +8566,7 @@ var StreamChat = /*#__PURE__*/function () {
8066
8566
  }, _callee43, this);
8067
8567
  }));
8068
8568
 
8069
- function translateMessage(_x55, _x56) {
8569
+ function translateMessage(_x54, _x55) {
8070
8570
  return _translateMessage.apply(this, arguments);
8071
8571
  }
8072
8572
 
@@ -8182,7 +8682,7 @@ var StreamChat = /*#__PURE__*/function () {
8182
8682
  case 2:
8183
8683
  clonedMessage = _extends({}, message);
8184
8684
  delete clonedMessage.id;
8185
- reservedMessageFields = ['command', 'created_at', 'html', 'latest_reactions', 'own_reactions', 'reaction_counts', 'reply_count', 'type', 'updated_at', 'user', '__html'];
8685
+ reservedMessageFields = ['command', 'created_at', 'html', 'latest_reactions', 'own_reactions', 'quoted_message', 'reaction_counts', 'reply_count', 'type', 'updated_at', 'user', '__html'];
8186
8686
  reservedMessageFields.forEach(function (item) {
8187
8687
  if (clonedMessage[item] != null) {
8188
8688
  delete clonedMessage[item];
@@ -8226,7 +8726,7 @@ var StreamChat = /*#__PURE__*/function () {
8226
8726
  }, _callee44, this);
8227
8727
  }));
8228
8728
 
8229
- function updateMessage(_x57, _x58, _x59) {
8729
+ function updateMessage(_x56, _x57, _x58) {
8230
8730
  return _updateMessage.apply(this, arguments);
8231
8731
  }
8232
8732
 
@@ -8287,7 +8787,7 @@ var StreamChat = /*#__PURE__*/function () {
8287
8787
  }, _callee45, this);
8288
8788
  }));
8289
8789
 
8290
- function partialUpdateMessage(_x60, _x61, _x62, _x63) {
8790
+ function partialUpdateMessage(_x59, _x60, _x61, _x62) {
8291
8791
  return _partialUpdateMessage.apply(this, arguments);
8292
8792
  }
8293
8793
 
@@ -8324,7 +8824,7 @@ var StreamChat = /*#__PURE__*/function () {
8324
8824
  }, _callee46, this);
8325
8825
  }));
8326
8826
 
8327
- function deleteMessage(_x64, _x65) {
8827
+ function deleteMessage(_x63, _x64) {
8328
8828
  return _deleteMessage.apply(this, arguments);
8329
8829
  }
8330
8830
 
@@ -8352,7 +8852,7 @@ var StreamChat = /*#__PURE__*/function () {
8352
8852
  }, _callee47, this);
8353
8853
  }));
8354
8854
 
8355
- function getMessage(_x66) {
8855
+ function getMessage(_x65) {
8356
8856
  return _getMessage.apply(this, arguments);
8357
8857
  }
8358
8858
 
@@ -8361,7 +8861,7 @@ var StreamChat = /*#__PURE__*/function () {
8361
8861
  }, {
8362
8862
  key: "getUserAgent",
8363
8863
  value: function getUserAgent() {
8364
- return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "4.4.3-dev.2");
8864
+ return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "5.0.0");
8365
8865
  }
8366
8866
  }, {
8367
8867
  key: "setUserAgent",
@@ -8375,7 +8875,7 @@ var StreamChat = /*#__PURE__*/function () {
8375
8875
  }, {
8376
8876
  key: "_enrichAxiosOptions",
8377
8877
  value: function _enrichAxiosOptions() {
8378
- var _options$headers, _this$wsConnection4;
8878
+ var _options$headers;
8379
8879
 
8380
8880
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
8381
8881
  params: {},
@@ -8385,10 +8885,14 @@ var StreamChat = /*#__PURE__*/function () {
8385
8885
 
8386
8886
  var token = this._getToken();
8387
8887
 
8888
+ var authorization = token ? {
8889
+ Authorization: token
8890
+ } : undefined;
8891
+
8388
8892
  if (!((_options$headers = options.headers) !== null && _options$headers !== void 0 && _options$headers['x-client-request-id'])) {
8389
- options.headers = {
8893
+ options.headers = _objectSpread(_objectSpread({}, options.headers), {}, {
8390
8894
  'x-client-request-id': randomId()
8391
- };
8895
+ });
8392
8896
  }
8393
8897
 
8394
8898
  return _objectSpread({
@@ -8396,10 +8900,9 @@ var StreamChat = /*#__PURE__*/function () {
8396
8900
  user_id: this.userID
8397
8901
  }, options.params), {}, {
8398
8902
  api_key: this.key,
8399
- connection_id: (_this$wsConnection4 = this.wsConnection) === null || _this$wsConnection4 === void 0 ? void 0 : _this$wsConnection4.connectionID
8903
+ connection_id: this._getConnectionID()
8400
8904
  }),
8401
- headers: _objectSpread({
8402
- Authorization: token,
8905
+ headers: _objectSpread(_objectSpread({}, authorization), {}, {
8403
8906
  'stream-auth-type': this.getAuthType(),
8404
8907
  'X-Stream-Client': this.getUserAgent()
8405
8908
  }, options.headers)
@@ -8429,6 +8932,12 @@ var StreamChat = /*#__PURE__*/function () {
8429
8932
  }
8430
8933
  }, 500);
8431
8934
  }
8935
+ /**
8936
+ * encode ws url payload
8937
+ * @private
8938
+ * @returns json string
8939
+ */
8940
+
8432
8941
  }, {
8433
8942
  key: "verifyWebhook",
8434
8943
  value: function verifyWebhook(requestBody, xSignature) {
@@ -8569,7 +9078,7 @@ var StreamChat = /*#__PURE__*/function () {
8569
9078
  }, _callee48, this);
8570
9079
  }));
8571
9080
 
8572
- function sendUserCustomEvent(_x67, _x68) {
9081
+ function sendUserCustomEvent(_x66, _x67) {
8573
9082
  return _sendUserCustomEvent.apply(this, arguments);
8574
9083
  }
8575
9084
 
@@ -8657,7 +9166,7 @@ var StreamChat = /*#__PURE__*/function () {
8657
9166
  }, _callee49, this);
8658
9167
  }));
8659
9168
 
8660
- function createSegment(_x69) {
9169
+ function createSegment(_x68) {
8661
9170
  return _createSegment.apply(this, arguments);
8662
9171
  }
8663
9172
 
@@ -8697,7 +9206,7 @@ var StreamChat = /*#__PURE__*/function () {
8697
9206
  }, _callee50, this);
8698
9207
  }));
8699
9208
 
8700
- function getSegment(_x70) {
9209
+ function getSegment(_x69) {
8701
9210
  return _getSegment.apply(this, arguments);
8702
9211
  }
8703
9212
 
@@ -8736,7 +9245,7 @@ var StreamChat = /*#__PURE__*/function () {
8736
9245
  }, _callee51, this);
8737
9246
  }));
8738
9247
 
8739
- function listSegments(_x71) {
9248
+ function listSegments(_x70) {
8740
9249
  return _listSegments.apply(this, arguments);
8741
9250
  }
8742
9251
 
@@ -8779,7 +9288,7 @@ var StreamChat = /*#__PURE__*/function () {
8779
9288
  }, _callee52, this);
8780
9289
  }));
8781
9290
 
8782
- function updateSegment(_x72, _x73) {
9291
+ function updateSegment(_x71, _x72) {
8783
9292
  return _updateSegment.apply(this, arguments);
8784
9293
  }
8785
9294
 
@@ -8811,7 +9320,7 @@ var StreamChat = /*#__PURE__*/function () {
8811
9320
  }, _callee53, this);
8812
9321
  }));
8813
9322
 
8814
- function deleteSegment(_x74) {
9323
+ function deleteSegment(_x73) {
8815
9324
  return _deleteSegment.apply(this, arguments);
8816
9325
  }
8817
9326
 
@@ -8853,7 +9362,7 @@ var StreamChat = /*#__PURE__*/function () {
8853
9362
  }, _callee54, this);
8854
9363
  }));
8855
9364
 
8856
- function createCampaign(_x75) {
9365
+ function createCampaign(_x74) {
8857
9366
  return _createCampaign.apply(this, arguments);
8858
9367
  }
8859
9368
 
@@ -8893,7 +9402,7 @@ var StreamChat = /*#__PURE__*/function () {
8893
9402
  }, _callee55, this);
8894
9403
  }));
8895
9404
 
8896
- function getCampaign(_x76) {
9405
+ function getCampaign(_x75) {
8897
9406
  return _getCampaign.apply(this, arguments);
8898
9407
  }
8899
9408
 
@@ -8932,7 +9441,7 @@ var StreamChat = /*#__PURE__*/function () {
8932
9441
  }, _callee56, this);
8933
9442
  }));
8934
9443
 
8935
- function listCampaigns(_x77) {
9444
+ function listCampaigns(_x76) {
8936
9445
  return _listCampaigns.apply(this, arguments);
8937
9446
  }
8938
9447
 
@@ -8975,7 +9484,7 @@ var StreamChat = /*#__PURE__*/function () {
8975
9484
  }, _callee57, this);
8976
9485
  }));
8977
9486
 
8978
- function updateCampaign(_x78, _x79) {
9487
+ function updateCampaign(_x77, _x78) {
8979
9488
  return _updateCampaign.apply(this, arguments);
8980
9489
  }
8981
9490
 
@@ -9007,7 +9516,7 @@ var StreamChat = /*#__PURE__*/function () {
9007
9516
  }, _callee58, this);
9008
9517
  }));
9009
9518
 
9010
- function deleteCampaign(_x80) {
9519
+ function deleteCampaign(_x79) {
9011
9520
  return _deleteCampaign.apply(this, arguments);
9012
9521
  }
9013
9522
 
@@ -9051,7 +9560,7 @@ var StreamChat = /*#__PURE__*/function () {
9051
9560
  }, _callee59, this);
9052
9561
  }));
9053
9562
 
9054
- function scheduleCampaign(_x81, _x82) {
9563
+ function scheduleCampaign(_x80, _x81) {
9055
9564
  return _scheduleCampaign.apply(this, arguments);
9056
9565
  }
9057
9566
 
@@ -9091,7 +9600,7 @@ var StreamChat = /*#__PURE__*/function () {
9091
9600
  }, _callee60, this);
9092
9601
  }));
9093
9602
 
9094
- function stopCampaign(_x83) {
9603
+ function stopCampaign(_x82) {
9095
9604
  return _stopCampaign.apply(this, arguments);
9096
9605
  }
9097
9606
 
@@ -9131,7 +9640,7 @@ var StreamChat = /*#__PURE__*/function () {
9131
9640
  }, _callee61, this);
9132
9641
  }));
9133
9642
 
9134
- function resumeCampaign(_x84) {
9643
+ function resumeCampaign(_x83) {
9135
9644
  return _resumeCampaign.apply(this, arguments);
9136
9645
  }
9137
9646
 
@@ -9174,7 +9683,7 @@ var StreamChat = /*#__PURE__*/function () {
9174
9683
  }, _callee62, this);
9175
9684
  }));
9176
9685
 
9177
- function testCampaign(_x85, _x86) {
9686
+ function testCampaign(_x84, _x85) {
9178
9687
  return _testCampaign.apply(this, arguments);
9179
9688
  }
9180
9689
 
@@ -9207,7 +9716,7 @@ var StreamChat = /*#__PURE__*/function () {
9207
9716
  }, _callee63, this);
9208
9717
  }));
9209
9718
 
9210
- function enrichURL(_x87) {
9719
+ function enrichURL(_x86) {
9211
9720
  return _enrichURL.apply(this, arguments);
9212
9721
  }
9213
9722
 
@@ -9239,7 +9748,7 @@ var StreamChat = /*#__PURE__*/function () {
9239
9748
  }, _callee64, this);
9240
9749
  }));
9241
9750
 
9242
- function getTask(_x88) {
9751
+ function getTask(_x87) {
9243
9752
  return _getTask.apply(this, arguments);
9244
9753
  }
9245
9754
 
@@ -9281,15 +9790,12 @@ var StreamChat = /*#__PURE__*/function () {
9281
9790
  }, _callee65, this);
9282
9791
  }));
9283
9792
 
9284
- function deleteChannels(_x89) {
9793
+ function deleteChannels(_x88) {
9285
9794
  return _deleteChannels.apply(this, arguments);
9286
9795
  }
9287
9796
 
9288
9797
  return deleteChannels;
9289
9798
  }()
9290
- }, {
9291
- key: "deleteUsers",
9292
- value:
9293
9799
  /**
9294
9800
  * deleteUsers - Batch Delete Users
9295
9801
  *
@@ -9298,7 +9804,10 @@ var StreamChat = /*#__PURE__*/function () {
9298
9804
  *
9299
9805
  * @return {APIResponse} A task ID
9300
9806
  */
9301
- function () {
9807
+
9808
+ }, {
9809
+ key: "deleteUsers",
9810
+ value: function () {
9302
9811
  var _deleteUsers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee66(user_ids, options) {
9303
9812
  return _regeneratorRuntime.wrap(function _callee66$(_context66) {
9304
9813
  while (1) {
@@ -9344,7 +9853,7 @@ var StreamChat = /*#__PURE__*/function () {
9344
9853
  }, _callee66, this);
9345
9854
  }));
9346
9855
 
9347
- function deleteUsers(_x90, _x91) {
9856
+ function deleteUsers(_x89, _x90) {
9348
9857
  return _deleteUsers.apply(this, arguments);
9349
9858
  }
9350
9859
 
@@ -9444,5 +9953,5 @@ var BuiltinPermissions = {
9444
9953
  UseFrozenChannel: 'Send messages and reactions to frozen channels'
9445
9954
  };
9446
9955
 
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 };
9956
+ 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
9957
  //# sourceMappingURL=browser.es.js.map