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/browser.js CHANGED
@@ -1336,6 +1336,19 @@ function removeConnectionEventListeners(cb) {
1336
1336
  window.removeEventListener('online', cb);
1337
1337
  }
1338
1338
  }
1339
+ var axiosParamsSerializer = function axiosParamsSerializer(params) {
1340
+ var newParams = [];
1341
+
1342
+ for (var k in params) {
1343
+ if (Array.isArray(params[k]) || _typeof__default['default'](params[k]) === 'object') {
1344
+ newParams.push("".concat(k, "=").concat(encodeURIComponent(JSON.stringify(params[k]))));
1345
+ } else {
1346
+ newParams.push("".concat(k, "=").concat(encodeURIComponent(params[k])));
1347
+ }
1348
+ }
1349
+
1350
+ return newParams.join('&');
1351
+ };
1339
1352
 
1340
1353
  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; } } }; }
1341
1354
 
@@ -1368,6 +1381,12 @@ var Channel = /*#__PURE__*/function () {
1368
1381
  * Static state indicates that channel exists on backend, but is not being watched yet.
1369
1382
  */
1370
1383
 
1384
+ /**
1385
+ * Collects the incoming WS events before the channel is marked as initialized.
1386
+ * This prevents executing procedures that depend on channel being initialized.
1387
+ * Once the channel is marked as initialized the queue is flushed.
1388
+ */
1389
+
1371
1390
  /**
1372
1391
  * constructor - Create a channel
1373
1392
  *
@@ -1411,6 +1430,8 @@ var Channel = /*#__PURE__*/function () {
1411
1430
 
1412
1431
  _defineProperty__default['default'](this, "disconnected", void 0);
1413
1432
 
1433
+ _defineProperty__default['default'](this, "wsEventQueue", void 0);
1434
+
1414
1435
  _defineProperty__default['default'](this, "create", /*#__PURE__*/function () {
1415
1436
  var _ref = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee(options) {
1416
1437
  var defaultOptions;
@@ -1500,6 +1521,7 @@ var Channel = /*#__PURE__*/function () {
1500
1521
  this.lastTypingEvent = null;
1501
1522
  this.isTyping = false;
1502
1523
  this.disconnected = false;
1524
+ this.wsEventQueue = [];
1503
1525
  }
1504
1526
  /**
1505
1527
  * getClient - Get the chat client for this channel. If client.disconnect() was called, this function will error
@@ -2903,6 +2925,9 @@ var Channel = /*#__PURE__*/function () {
2903
2925
  case 7:
2904
2926
  state = _context28.sent;
2905
2927
  this.initialized = true;
2928
+
2929
+ this._flushWsEventQueue();
2930
+
2906
2931
  this.data = state.channel;
2907
2932
 
2908
2933
  this._client.logger('info', "channel:watch() - started watching channel ".concat(this.cid), {
@@ -2912,7 +2937,7 @@ var Channel = /*#__PURE__*/function () {
2912
2937
 
2913
2938
  return _context28.abrupt("return", state);
2914
2939
 
2915
- case 12:
2940
+ case 13:
2916
2941
  case "end":
2917
2942
  return _context28.stop();
2918
2943
  }
@@ -3637,6 +3662,11 @@ var Channel = /*#__PURE__*/function () {
3637
3662
 
3638
3663
  var channel = this;
3639
3664
 
3665
+ if (!this._isInitialized()) {
3666
+ this.wsEventQueue.push(event);
3667
+ return;
3668
+ }
3669
+
3640
3670
  this._client.logger('info', "channel:_handleChannelEvent - Received event of type { ".concat(event.type, " } on ").concat(this.cid), {
3641
3671
  tags: ['event', 'channel'],
3642
3672
  channel: this
@@ -3887,6 +3917,11 @@ var Channel = /*#__PURE__*/function () {
3887
3917
  channel.state.watcher_count = event.watcher_count;
3888
3918
  }
3889
3919
  }
3920
+ }, {
3921
+ key: "_isInitialized",
3922
+ value: function _isInitialized() {
3923
+ return this.initialized || this.offlineMode || this.getClient()._isUsingServerAuth();
3924
+ }
3890
3925
  }, {
3891
3926
  key: "_checkInitialized",
3892
3927
  value: function _checkInitialized() {
@@ -4048,6 +4083,14 @@ var Channel = /*#__PURE__*/function () {
4048
4083
  this.disconnected = true;
4049
4084
  this.state.setIsUpToDate(false);
4050
4085
  }
4086
+ }, {
4087
+ key: "_flushWsEventQueue",
4088
+ value: function _flushWsEventQueue() {
4089
+ while (this.wsEventQueue.length) {
4090
+ var event = this.wsEventQueue.shift();
4091
+ if (event) this.getClient().dispatchEvent(event);
4092
+ }
4093
+ }
4051
4094
  }]);
4052
4095
 
4053
4096
  return Channel;
@@ -6938,6 +6981,7 @@ var StreamChat = /*#__PURE__*/function () {
6938
6981
  this.insightMetrics = new InsightMetrics();
6939
6982
  this.defaultWSTimeoutWithFallback = 6000;
6940
6983
  this.defaultWSTimeout = 15000;
6984
+ this.axiosInstance.defaults.paramsSerializer = axiosParamsSerializer;
6941
6985
  /**
6942
6986
  * logger function should accept 3 parameters:
6943
6987
  * @param logLevel string
@@ -10098,7 +10142,7 @@ var StreamChat = /*#__PURE__*/function () {
10098
10142
  }, {
10099
10143
  key: "getUserAgent",
10100
10144
  value: function getUserAgent() {
10101
- return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.12.1");
10145
+ return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.12.3");
10102
10146
  }
10103
10147
  }, {
10104
10148
  key: "setUserAgent",
@@ -11492,6 +11536,30 @@ var EVENT_MAP = {
11492
11536
  'connection.changed': true,
11493
11537
  'connection.recovered': true,
11494
11538
  'transport.changed': true
11539
+ }; // events handled by channel._handleChannelEvent
11540
+
11541
+ var CHANNEL_HANDLED_EVENTS = {
11542
+ 'typing.start': true,
11543
+ 'typing.stop': true,
11544
+ 'message.read': true,
11545
+ 'user.watching.start': true,
11546
+ 'user.updated': true,
11547
+ 'user.watching.stop': true,
11548
+ 'message.deleted': true,
11549
+ 'message.new': true,
11550
+ 'message.updated': true,
11551
+ 'channel.truncated': true,
11552
+ 'member.added': true,
11553
+ 'member.updated': true,
11554
+ 'member.removed': true,
11555
+ 'channel.updated': true,
11556
+ 'reaction.new': true,
11557
+ 'reaction.deleted': true,
11558
+ 'reaction.updated': true,
11559
+ 'channel.hidden': true,
11560
+ 'channel.visible': true,
11561
+ 'user.banned': true,
11562
+ 'user.unbanned': true
11495
11563
  };
11496
11564
 
11497
11565
  var Allow = 'Allow';
@@ -11574,6 +11642,7 @@ exports.AnyResource = AnyResource;
11574
11642
  exports.AnyRole = AnyRole;
11575
11643
  exports.BuiltinPermissions = BuiltinPermissions;
11576
11644
  exports.BuiltinRoles = BuiltinRoles;
11645
+ exports.CHANNEL_HANDLED_EVENTS = CHANNEL_HANDLED_EVENTS;
11577
11646
  exports.Channel = Channel;
11578
11647
  exports.ChannelState = ChannelState;
11579
11648
  exports.CheckSignature = CheckSignature;