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.
@@ -1356,6 +1356,12 @@ var Channel = /*#__PURE__*/function () {
1356
1356
  * Static state indicates that channel exists on backend, but is not being watched yet.
1357
1357
  */
1358
1358
 
1359
+ /**
1360
+ * Collects the incoming WS events before the channel is marked as initialized.
1361
+ * This prevents executing procedures that depend on channel being initialized.
1362
+ * Once the channel is marked as initialized the queue is flushed.
1363
+ */
1364
+
1359
1365
  /**
1360
1366
  * constructor - Create a channel
1361
1367
  *
@@ -1399,6 +1405,8 @@ var Channel = /*#__PURE__*/function () {
1399
1405
 
1400
1406
  _defineProperty(this, "disconnected", void 0);
1401
1407
 
1408
+ _defineProperty(this, "wsEventQueue", void 0);
1409
+
1402
1410
  _defineProperty(this, "create", /*#__PURE__*/function () {
1403
1411
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(options) {
1404
1412
  var defaultOptions;
@@ -1488,6 +1496,7 @@ var Channel = /*#__PURE__*/function () {
1488
1496
  this.lastTypingEvent = null;
1489
1497
  this.isTyping = false;
1490
1498
  this.disconnected = false;
1499
+ this.wsEventQueue = [];
1491
1500
  }
1492
1501
  /**
1493
1502
  * getClient - Get the chat client for this channel. If client.disconnect() was called, this function will error
@@ -2891,6 +2900,9 @@ var Channel = /*#__PURE__*/function () {
2891
2900
  case 7:
2892
2901
  state = _context28.sent;
2893
2902
  this.initialized = true;
2903
+
2904
+ this._flushWsEventQueue();
2905
+
2894
2906
  this.data = state.channel;
2895
2907
 
2896
2908
  this._client.logger('info', "channel:watch() - started watching channel ".concat(this.cid), {
@@ -2900,7 +2912,7 @@ var Channel = /*#__PURE__*/function () {
2900
2912
 
2901
2913
  return _context28.abrupt("return", state);
2902
2914
 
2903
- case 12:
2915
+ case 13:
2904
2916
  case "end":
2905
2917
  return _context28.stop();
2906
2918
  }
@@ -3625,6 +3637,11 @@ var Channel = /*#__PURE__*/function () {
3625
3637
 
3626
3638
  var channel = this;
3627
3639
 
3640
+ if (!this._isInitialized()) {
3641
+ this.wsEventQueue.push(event);
3642
+ return;
3643
+ }
3644
+
3628
3645
  this._client.logger('info', "channel:_handleChannelEvent - Received event of type { ".concat(event.type, " } on ").concat(this.cid), {
3629
3646
  tags: ['event', 'channel'],
3630
3647
  channel: this
@@ -3875,6 +3892,11 @@ var Channel = /*#__PURE__*/function () {
3875
3892
  channel.state.watcher_count = event.watcher_count;
3876
3893
  }
3877
3894
  }
3895
+ }, {
3896
+ key: "_isInitialized",
3897
+ value: function _isInitialized() {
3898
+ return this.initialized || this.offlineMode || this.getClient()._isUsingServerAuth();
3899
+ }
3878
3900
  }, {
3879
3901
  key: "_checkInitialized",
3880
3902
  value: function _checkInitialized() {
@@ -4036,6 +4058,14 @@ var Channel = /*#__PURE__*/function () {
4036
4058
  this.disconnected = true;
4037
4059
  this.state.setIsUpToDate(false);
4038
4060
  }
4061
+ }, {
4062
+ key: "_flushWsEventQueue",
4063
+ value: function _flushWsEventQueue() {
4064
+ while (this.wsEventQueue.length) {
4065
+ var event = this.wsEventQueue.shift();
4066
+ if (event) this.getClient().dispatchEvent(event);
4067
+ }
4068
+ }
4039
4069
  }]);
4040
4070
 
4041
4071
  return Channel;
@@ -10087,7 +10117,7 @@ var StreamChat = /*#__PURE__*/function () {
10087
10117
  }, {
10088
10118
  key: "getUserAgent",
10089
10119
  value: function getUserAgent() {
10090
- return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.12.2");
10120
+ return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.12.3");
10091
10121
  }
10092
10122
  }, {
10093
10123
  key: "setUserAgent",
@@ -11481,6 +11511,30 @@ var EVENT_MAP = {
11481
11511
  'connection.changed': true,
11482
11512
  'connection.recovered': true,
11483
11513
  'transport.changed': true
11514
+ }; // events handled by channel._handleChannelEvent
11515
+
11516
+ var CHANNEL_HANDLED_EVENTS = {
11517
+ 'typing.start': true,
11518
+ 'typing.stop': true,
11519
+ 'message.read': true,
11520
+ 'user.watching.start': true,
11521
+ 'user.updated': true,
11522
+ 'user.watching.stop': true,
11523
+ 'message.deleted': true,
11524
+ 'message.new': true,
11525
+ 'message.updated': true,
11526
+ 'channel.truncated': true,
11527
+ 'member.added': true,
11528
+ 'member.updated': true,
11529
+ 'member.removed': true,
11530
+ 'channel.updated': true,
11531
+ 'reaction.new': true,
11532
+ 'reaction.deleted': true,
11533
+ 'reaction.updated': true,
11534
+ 'channel.hidden': true,
11535
+ 'channel.visible': true,
11536
+ 'user.banned': true,
11537
+ 'user.unbanned': true
11484
11538
  };
11485
11539
 
11486
11540
  var Allow = 'Allow';
@@ -11557,5 +11611,5 @@ var BuiltinPermissions = {
11557
11611
  UseFrozenChannel: 'Send messages and reactions to frozen channels'
11558
11612
  };
11559
11613
 
11560
- export { Allow, AllowAll, AnyResource, AnyRole, BuiltinPermissions, BuiltinRoles, Channel, ChannelState, CheckSignature, ClientState, Deny, DenyAll, DevToken, EVENT_MAP, ErrorFromResponse, InsightMetrics, JWTServerToken, JWTUserToken, MaxPriority, MinPriority, Permission, StableWSConnection, StreamChat, TokenManager, UserFromToken, buildWsFatalInsight, buildWsSuccessAfterFailureInsight, chatCodes, decodeBase64, encodeBase64, isOwnUser, logChatPromiseExecution, postInsights };
11614
+ export { Allow, AllowAll, AnyResource, AnyRole, BuiltinPermissions, BuiltinRoles, CHANNEL_HANDLED_EVENTS, Channel, ChannelState, CheckSignature, ClientState, Deny, DenyAll, DevToken, EVENT_MAP, ErrorFromResponse, InsightMetrics, JWTServerToken, JWTUserToken, MaxPriority, MinPriority, Permission, StableWSConnection, StreamChat, TokenManager, UserFromToken, buildWsFatalInsight, buildWsSuccessAfterFailureInsight, chatCodes, decodeBase64, encodeBase64, isOwnUser, logChatPromiseExecution, postInsights };
11561
11615
  //# sourceMappingURL=browser.es.js.map