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.es.js CHANGED
@@ -1312,6 +1312,19 @@ function removeConnectionEventListeners(cb) {
1312
1312
  window.removeEventListener('online', cb);
1313
1313
  }
1314
1314
  }
1315
+ var axiosParamsSerializer = function axiosParamsSerializer(params) {
1316
+ var newParams = [];
1317
+
1318
+ for (var k in params) {
1319
+ if (Array.isArray(params[k]) || _typeof(params[k]) === 'object') {
1320
+ newParams.push("".concat(k, "=").concat(encodeURIComponent(JSON.stringify(params[k]))));
1321
+ } else {
1322
+ newParams.push("".concat(k, "=").concat(encodeURIComponent(params[k])));
1323
+ }
1324
+ }
1325
+
1326
+ return newParams.join('&');
1327
+ };
1315
1328
 
1316
1329
  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; } } }; }
1317
1330
 
@@ -1344,6 +1357,12 @@ var Channel = /*#__PURE__*/function () {
1344
1357
  * Static state indicates that channel exists on backend, but is not being watched yet.
1345
1358
  */
1346
1359
 
1360
+ /**
1361
+ * Collects the incoming WS events before the channel is marked as initialized.
1362
+ * This prevents executing procedures that depend on channel being initialized.
1363
+ * Once the channel is marked as initialized the queue is flushed.
1364
+ */
1365
+
1347
1366
  /**
1348
1367
  * constructor - Create a channel
1349
1368
  *
@@ -1387,6 +1406,8 @@ var Channel = /*#__PURE__*/function () {
1387
1406
 
1388
1407
  _defineProperty(this, "disconnected", void 0);
1389
1408
 
1409
+ _defineProperty(this, "wsEventQueue", void 0);
1410
+
1390
1411
  _defineProperty(this, "create", /*#__PURE__*/function () {
1391
1412
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(options) {
1392
1413
  var defaultOptions;
@@ -1476,6 +1497,7 @@ var Channel = /*#__PURE__*/function () {
1476
1497
  this.lastTypingEvent = null;
1477
1498
  this.isTyping = false;
1478
1499
  this.disconnected = false;
1500
+ this.wsEventQueue = [];
1479
1501
  }
1480
1502
  /**
1481
1503
  * getClient - Get the chat client for this channel. If client.disconnect() was called, this function will error
@@ -2879,6 +2901,9 @@ var Channel = /*#__PURE__*/function () {
2879
2901
  case 7:
2880
2902
  state = _context28.sent;
2881
2903
  this.initialized = true;
2904
+
2905
+ this._flushWsEventQueue();
2906
+
2882
2907
  this.data = state.channel;
2883
2908
 
2884
2909
  this._client.logger('info', "channel:watch() - started watching channel ".concat(this.cid), {
@@ -2888,7 +2913,7 @@ var Channel = /*#__PURE__*/function () {
2888
2913
 
2889
2914
  return _context28.abrupt("return", state);
2890
2915
 
2891
- case 12:
2916
+ case 13:
2892
2917
  case "end":
2893
2918
  return _context28.stop();
2894
2919
  }
@@ -3613,6 +3638,11 @@ var Channel = /*#__PURE__*/function () {
3613
3638
 
3614
3639
  var channel = this;
3615
3640
 
3641
+ if (!this._isInitialized()) {
3642
+ this.wsEventQueue.push(event);
3643
+ return;
3644
+ }
3645
+
3616
3646
  this._client.logger('info', "channel:_handleChannelEvent - Received event of type { ".concat(event.type, " } on ").concat(this.cid), {
3617
3647
  tags: ['event', 'channel'],
3618
3648
  channel: this
@@ -3863,6 +3893,11 @@ var Channel = /*#__PURE__*/function () {
3863
3893
  channel.state.watcher_count = event.watcher_count;
3864
3894
  }
3865
3895
  }
3896
+ }, {
3897
+ key: "_isInitialized",
3898
+ value: function _isInitialized() {
3899
+ return this.initialized || this.offlineMode || this.getClient()._isUsingServerAuth();
3900
+ }
3866
3901
  }, {
3867
3902
  key: "_checkInitialized",
3868
3903
  value: function _checkInitialized() {
@@ -4024,6 +4059,14 @@ var Channel = /*#__PURE__*/function () {
4024
4059
  this.disconnected = true;
4025
4060
  this.state.setIsUpToDate(false);
4026
4061
  }
4062
+ }, {
4063
+ key: "_flushWsEventQueue",
4064
+ value: function _flushWsEventQueue() {
4065
+ while (this.wsEventQueue.length) {
4066
+ var event = this.wsEventQueue.shift();
4067
+ if (event) this.getClient().dispatchEvent(event);
4068
+ }
4069
+ }
4027
4070
  }]);
4028
4071
 
4029
4072
  return Channel;
@@ -6916,6 +6959,7 @@ var StreamChat = /*#__PURE__*/function () {
6916
6959
  this.insightMetrics = new InsightMetrics();
6917
6960
  this.defaultWSTimeoutWithFallback = 6000;
6918
6961
  this.defaultWSTimeout = 15000;
6962
+ this.axiosInstance.defaults.paramsSerializer = axiosParamsSerializer;
6919
6963
  /**
6920
6964
  * logger function should accept 3 parameters:
6921
6965
  * @param logLevel string
@@ -10076,7 +10120,7 @@ var StreamChat = /*#__PURE__*/function () {
10076
10120
  }, {
10077
10121
  key: "getUserAgent",
10078
10122
  value: function getUserAgent() {
10079
- return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.12.1");
10123
+ return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.12.3");
10080
10124
  }
10081
10125
  }, {
10082
10126
  key: "setUserAgent",
@@ -11470,6 +11514,30 @@ var EVENT_MAP = {
11470
11514
  'connection.changed': true,
11471
11515
  'connection.recovered': true,
11472
11516
  'transport.changed': true
11517
+ }; // events handled by channel._handleChannelEvent
11518
+
11519
+ var CHANNEL_HANDLED_EVENTS = {
11520
+ 'typing.start': true,
11521
+ 'typing.stop': true,
11522
+ 'message.read': true,
11523
+ 'user.watching.start': true,
11524
+ 'user.updated': true,
11525
+ 'user.watching.stop': true,
11526
+ 'message.deleted': true,
11527
+ 'message.new': true,
11528
+ 'message.updated': true,
11529
+ 'channel.truncated': true,
11530
+ 'member.added': true,
11531
+ 'member.updated': true,
11532
+ 'member.removed': true,
11533
+ 'channel.updated': true,
11534
+ 'reaction.new': true,
11535
+ 'reaction.deleted': true,
11536
+ 'reaction.updated': true,
11537
+ 'channel.hidden': true,
11538
+ 'channel.visible': true,
11539
+ 'user.banned': true,
11540
+ 'user.unbanned': true
11473
11541
  };
11474
11542
 
11475
11543
  var Allow = 'Allow';
@@ -11546,5 +11614,5 @@ var BuiltinPermissions = {
11546
11614
  UseFrozenChannel: 'Send messages and reactions to frozen channels'
11547
11615
  };
11548
11616
 
11549
- 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 };
11617
+ 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 };
11550
11618
  //# sourceMappingURL=index.es.js.map