stream-chat 8.12.2 → 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
@@ -1385,6 +1385,12 @@ var Channel = /*#__PURE__*/function () {
1385
1385
  * Static state indicates that channel exists on backend, but is not being watched yet.
1386
1386
  */
1387
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
+
1388
1394
  /**
1389
1395
  * constructor - Create a channel
1390
1396
  *
@@ -1428,6 +1434,8 @@ var Channel = /*#__PURE__*/function () {
1428
1434
 
1429
1435
  _defineProperty__default['default'](this, "disconnected", void 0);
1430
1436
 
1437
+ _defineProperty__default['default'](this, "wsEventQueue", void 0);
1438
+
1431
1439
  _defineProperty__default['default'](this, "create", /*#__PURE__*/function () {
1432
1440
  var _ref = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee(options) {
1433
1441
  var defaultOptions;
@@ -1517,6 +1525,7 @@ var Channel = /*#__PURE__*/function () {
1517
1525
  this.lastTypingEvent = null;
1518
1526
  this.isTyping = false;
1519
1527
  this.disconnected = false;
1528
+ this.wsEventQueue = [];
1520
1529
  }
1521
1530
  /**
1522
1531
  * getClient - Get the chat client for this channel. If client.disconnect() was called, this function will error
@@ -2920,6 +2929,9 @@ var Channel = /*#__PURE__*/function () {
2920
2929
  case 7:
2921
2930
  state = _context28.sent;
2922
2931
  this.initialized = true;
2932
+
2933
+ this._flushWsEventQueue();
2934
+
2923
2935
  this.data = state.channel;
2924
2936
 
2925
2937
  this._client.logger('info', "channel:watch() - started watching channel ".concat(this.cid), {
@@ -2929,7 +2941,7 @@ var Channel = /*#__PURE__*/function () {
2929
2941
 
2930
2942
  return _context28.abrupt("return", state);
2931
2943
 
2932
- case 12:
2944
+ case 13:
2933
2945
  case "end":
2934
2946
  return _context28.stop();
2935
2947
  }
@@ -3654,6 +3666,11 @@ var Channel = /*#__PURE__*/function () {
3654
3666
 
3655
3667
  var channel = this;
3656
3668
 
3669
+ if (!this._isInitialized()) {
3670
+ this.wsEventQueue.push(event);
3671
+ return;
3672
+ }
3673
+
3657
3674
  this._client.logger('info', "channel:_handleChannelEvent - Received event of type { ".concat(event.type, " } on ").concat(this.cid), {
3658
3675
  tags: ['event', 'channel'],
3659
3676
  channel: this
@@ -3904,6 +3921,11 @@ var Channel = /*#__PURE__*/function () {
3904
3921
  channel.state.watcher_count = event.watcher_count;
3905
3922
  }
3906
3923
  }
3924
+ }, {
3925
+ key: "_isInitialized",
3926
+ value: function _isInitialized() {
3927
+ return this.initialized || this.offlineMode || this.getClient()._isUsingServerAuth();
3928
+ }
3907
3929
  }, {
3908
3930
  key: "_checkInitialized",
3909
3931
  value: function _checkInitialized() {
@@ -4065,6 +4087,14 @@ var Channel = /*#__PURE__*/function () {
4065
4087
  this.disconnected = true;
4066
4088
  this.state.setIsUpToDate(false);
4067
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
+ }
4068
4098
  }]);
4069
4099
 
4070
4100
  return Channel;
@@ -10118,7 +10148,7 @@ var StreamChat = /*#__PURE__*/function () {
10118
10148
  }, {
10119
10149
  key: "getUserAgent",
10120
10150
  value: function getUserAgent() {
10121
- return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.12.2");
10151
+ return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.12.3");
10122
10152
  }
10123
10153
  }, {
10124
10154
  key: "setUserAgent",
@@ -11512,6 +11542,30 @@ var EVENT_MAP = {
11512
11542
  'connection.changed': true,
11513
11543
  'connection.recovered': true,
11514
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
11515
11569
  };
11516
11570
 
11517
11571
  var Allow = 'Allow';
@@ -11594,6 +11648,7 @@ exports.AnyResource = AnyResource;
11594
11648
  exports.AnyRole = AnyRole;
11595
11649
  exports.BuiltinPermissions = BuiltinPermissions;
11596
11650
  exports.BuiltinRoles = BuiltinRoles;
11651
+ exports.CHANNEL_HANDLED_EVENTS = CHANNEL_HANDLED_EVENTS;
11597
11652
  exports.Channel = Channel;
11598
11653
  exports.ChannelState = ChannelState;
11599
11654
  exports.CheckSignature = CheckSignature;