stream-chat 8.12.1 → 8.12.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1340,6 +1340,19 @@ function removeConnectionEventListeners(cb) {
1340
1340
  window.removeEventListener('online', cb);
1341
1341
  }
1342
1342
  }
1343
+ var axiosParamsSerializer = function axiosParamsSerializer(params) {
1344
+ var newParams = [];
1345
+
1346
+ for (var k in params) {
1347
+ if (Array.isArray(params[k]) || _typeof__default['default'](params[k]) === 'object') {
1348
+ newParams.push("".concat(k, "=").concat(encodeURIComponent(JSON.stringify(params[k]))));
1349
+ } else {
1350
+ newParams.push("".concat(k, "=").concat(encodeURIComponent(params[k])));
1351
+ }
1352
+ }
1353
+
1354
+ return newParams.join('&');
1355
+ };
1343
1356
 
1344
1357
  function _createForOfIteratorHelper$2(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { 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 = it.call(o); }, 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; } } }; }
1345
1358
 
@@ -1372,6 +1385,12 @@ var Channel = /*#__PURE__*/function () {
1372
1385
  * Static state indicates that channel exists on backend, but is not being watched yet.
1373
1386
  */
1374
1387
 
1388
+ /**
1389
+ * Collects the incoming WS events before the channel is marked as initialized.
1390
+ * This prevents executing procedures that depend on channel being initialized.
1391
+ * Once the channel is marked as initialized the queue is flushed.
1392
+ */
1393
+
1375
1394
  /**
1376
1395
  * constructor - Create a channel
1377
1396
  *
@@ -1415,6 +1434,8 @@ var Channel = /*#__PURE__*/function () {
1415
1434
 
1416
1435
  _defineProperty__default['default'](this, "disconnected", void 0);
1417
1436
 
1437
+ _defineProperty__default['default'](this, "wsEventQueue", void 0);
1438
+
1418
1439
  _defineProperty__default['default'](this, "create", /*#__PURE__*/function () {
1419
1440
  var _ref = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee(options) {
1420
1441
  var defaultOptions;
@@ -1504,6 +1525,7 @@ var Channel = /*#__PURE__*/function () {
1504
1525
  this.lastTypingEvent = null;
1505
1526
  this.isTyping = false;
1506
1527
  this.disconnected = false;
1528
+ this.wsEventQueue = [];
1507
1529
  }
1508
1530
  /**
1509
1531
  * getClient - Get the chat client for this channel. If client.disconnect() was called, this function will error
@@ -2907,6 +2929,9 @@ var Channel = /*#__PURE__*/function () {
2907
2929
  case 7:
2908
2930
  state = _context28.sent;
2909
2931
  this.initialized = true;
2932
+
2933
+ this._flushWsEventQueue();
2934
+
2910
2935
  this.data = state.channel;
2911
2936
 
2912
2937
  this._client.logger('info', "channel:watch() - started watching channel ".concat(this.cid), {
@@ -2916,7 +2941,7 @@ var Channel = /*#__PURE__*/function () {
2916
2941
 
2917
2942
  return _context28.abrupt("return", state);
2918
2943
 
2919
- case 12:
2944
+ case 13:
2920
2945
  case "end":
2921
2946
  return _context28.stop();
2922
2947
  }
@@ -3641,6 +3666,11 @@ var Channel = /*#__PURE__*/function () {
3641
3666
 
3642
3667
  var channel = this;
3643
3668
 
3669
+ if (!this._isInitialized()) {
3670
+ this.wsEventQueue.push(event);
3671
+ return;
3672
+ }
3673
+
3644
3674
  this._client.logger('info', "channel:_handleChannelEvent - Received event of type { ".concat(event.type, " } on ").concat(this.cid), {
3645
3675
  tags: ['event', 'channel'],
3646
3676
  channel: this
@@ -3891,6 +3921,11 @@ var Channel = /*#__PURE__*/function () {
3891
3921
  channel.state.watcher_count = event.watcher_count;
3892
3922
  }
3893
3923
  }
3924
+ }, {
3925
+ key: "_isInitialized",
3926
+ value: function _isInitialized() {
3927
+ return this.initialized || this.offlineMode || this.getClient()._isUsingServerAuth();
3928
+ }
3894
3929
  }, {
3895
3930
  key: "_checkInitialized",
3896
3931
  value: function _checkInitialized() {
@@ -4052,6 +4087,14 @@ var Channel = /*#__PURE__*/function () {
4052
4087
  this.disconnected = true;
4053
4088
  this.state.setIsUpToDate(false);
4054
4089
  }
4090
+ }, {
4091
+ key: "_flushWsEventQueue",
4092
+ value: function _flushWsEventQueue() {
4093
+ while (this.wsEventQueue.length) {
4094
+ var event = this.wsEventQueue.shift();
4095
+ if (event) this.getClient().dispatchEvent(event);
4096
+ }
4097
+ }
4055
4098
  }]);
4056
4099
 
4057
4100
  return Channel;
@@ -6944,6 +6987,7 @@ var StreamChat = /*#__PURE__*/function () {
6944
6987
  this.insightMetrics = new InsightMetrics();
6945
6988
  this.defaultWSTimeoutWithFallback = 6000;
6946
6989
  this.defaultWSTimeout = 15000;
6990
+ this.axiosInstance.defaults.paramsSerializer = axiosParamsSerializer;
6947
6991
  /**
6948
6992
  * logger function should accept 3 parameters:
6949
6993
  * @param logLevel string
@@ -10104,7 +10148,7 @@ var StreamChat = /*#__PURE__*/function () {
10104
10148
  }, {
10105
10149
  key: "getUserAgent",
10106
10150
  value: function getUserAgent() {
10107
- return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.12.1");
10151
+ return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.12.3");
10108
10152
  }
10109
10153
  }, {
10110
10154
  key: "setUserAgent",
@@ -11498,6 +11542,30 @@ var EVENT_MAP = {
11498
11542
  'connection.changed': true,
11499
11543
  'connection.recovered': true,
11500
11544
  'transport.changed': true
11545
+ }; // events handled by channel._handleChannelEvent
11546
+
11547
+ var CHANNEL_HANDLED_EVENTS = {
11548
+ 'typing.start': true,
11549
+ 'typing.stop': true,
11550
+ 'message.read': true,
11551
+ 'user.watching.start': true,
11552
+ 'user.updated': true,
11553
+ 'user.watching.stop': true,
11554
+ 'message.deleted': true,
11555
+ 'message.new': true,
11556
+ 'message.updated': true,
11557
+ 'channel.truncated': true,
11558
+ 'member.added': true,
11559
+ 'member.updated': true,
11560
+ 'member.removed': true,
11561
+ 'channel.updated': true,
11562
+ 'reaction.new': true,
11563
+ 'reaction.deleted': true,
11564
+ 'reaction.updated': true,
11565
+ 'channel.hidden': true,
11566
+ 'channel.visible': true,
11567
+ 'user.banned': true,
11568
+ 'user.unbanned': true
11501
11569
  };
11502
11570
 
11503
11571
  var Allow = 'Allow';
@@ -11580,6 +11648,7 @@ exports.AnyResource = AnyResource;
11580
11648
  exports.AnyRole = AnyRole;
11581
11649
  exports.BuiltinPermissions = BuiltinPermissions;
11582
11650
  exports.BuiltinRoles = BuiltinRoles;
11651
+ exports.CHANNEL_HANDLED_EVENTS = CHANNEL_HANDLED_EVENTS;
11583
11652
  exports.Channel = Channel;
11584
11653
  exports.ChannelState = ChannelState;
11585
11654
  exports.CheckSignature = CheckSignature;