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.
@@ -1311,6 +1311,19 @@ function removeConnectionEventListeners(cb) {
1311
1311
  window.removeEventListener('online', cb);
1312
1312
  }
1313
1313
  }
1314
+ var axiosParamsSerializer = function axiosParamsSerializer(params) {
1315
+ var newParams = [];
1316
+
1317
+ for (var k in params) {
1318
+ if (Array.isArray(params[k]) || _typeof(params[k]) === 'object') {
1319
+ newParams.push("".concat(k, "=").concat(encodeURIComponent(JSON.stringify(params[k]))));
1320
+ } else {
1321
+ newParams.push("".concat(k, "=").concat(encodeURIComponent(params[k])));
1322
+ }
1323
+ }
1324
+
1325
+ return newParams.join('&');
1326
+ };
1314
1327
 
1315
1328
  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; } } }; }
1316
1329
 
@@ -1343,6 +1356,12 @@ var Channel = /*#__PURE__*/function () {
1343
1356
  * Static state indicates that channel exists on backend, but is not being watched yet.
1344
1357
  */
1345
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
+
1346
1365
  /**
1347
1366
  * constructor - Create a channel
1348
1367
  *
@@ -1386,6 +1405,8 @@ var Channel = /*#__PURE__*/function () {
1386
1405
 
1387
1406
  _defineProperty(this, "disconnected", void 0);
1388
1407
 
1408
+ _defineProperty(this, "wsEventQueue", void 0);
1409
+
1389
1410
  _defineProperty(this, "create", /*#__PURE__*/function () {
1390
1411
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(options) {
1391
1412
  var defaultOptions;
@@ -1475,6 +1496,7 @@ var Channel = /*#__PURE__*/function () {
1475
1496
  this.lastTypingEvent = null;
1476
1497
  this.isTyping = false;
1477
1498
  this.disconnected = false;
1499
+ this.wsEventQueue = [];
1478
1500
  }
1479
1501
  /**
1480
1502
  * getClient - Get the chat client for this channel. If client.disconnect() was called, this function will error
@@ -2878,6 +2900,9 @@ var Channel = /*#__PURE__*/function () {
2878
2900
  case 7:
2879
2901
  state = _context28.sent;
2880
2902
  this.initialized = true;
2903
+
2904
+ this._flushWsEventQueue();
2905
+
2881
2906
  this.data = state.channel;
2882
2907
 
2883
2908
  this._client.logger('info', "channel:watch() - started watching channel ".concat(this.cid), {
@@ -2887,7 +2912,7 @@ var Channel = /*#__PURE__*/function () {
2887
2912
 
2888
2913
  return _context28.abrupt("return", state);
2889
2914
 
2890
- case 12:
2915
+ case 13:
2891
2916
  case "end":
2892
2917
  return _context28.stop();
2893
2918
  }
@@ -3612,6 +3637,11 @@ var Channel = /*#__PURE__*/function () {
3612
3637
 
3613
3638
  var channel = this;
3614
3639
 
3640
+ if (!this._isInitialized()) {
3641
+ this.wsEventQueue.push(event);
3642
+ return;
3643
+ }
3644
+
3615
3645
  this._client.logger('info', "channel:_handleChannelEvent - Received event of type { ".concat(event.type, " } on ").concat(this.cid), {
3616
3646
  tags: ['event', 'channel'],
3617
3647
  channel: this
@@ -3862,6 +3892,11 @@ var Channel = /*#__PURE__*/function () {
3862
3892
  channel.state.watcher_count = event.watcher_count;
3863
3893
  }
3864
3894
  }
3895
+ }, {
3896
+ key: "_isInitialized",
3897
+ value: function _isInitialized() {
3898
+ return this.initialized || this.offlineMode || this.getClient()._isUsingServerAuth();
3899
+ }
3865
3900
  }, {
3866
3901
  key: "_checkInitialized",
3867
3902
  value: function _checkInitialized() {
@@ -4023,6 +4058,14 @@ var Channel = /*#__PURE__*/function () {
4023
4058
  this.disconnected = true;
4024
4059
  this.state.setIsUpToDate(false);
4025
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
+ }
4026
4069
  }]);
4027
4070
 
4028
4071
  return Channel;
@@ -6913,6 +6956,7 @@ var StreamChat = /*#__PURE__*/function () {
6913
6956
  this.insightMetrics = new InsightMetrics();
6914
6957
  this.defaultWSTimeoutWithFallback = 6000;
6915
6958
  this.defaultWSTimeout = 15000;
6959
+ this.axiosInstance.defaults.paramsSerializer = axiosParamsSerializer;
6916
6960
  /**
6917
6961
  * logger function should accept 3 parameters:
6918
6962
  * @param logLevel string
@@ -10073,7 +10117,7 @@ var StreamChat = /*#__PURE__*/function () {
10073
10117
  }, {
10074
10118
  key: "getUserAgent",
10075
10119
  value: function getUserAgent() {
10076
- return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.12.1");
10120
+ return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.12.3");
10077
10121
  }
10078
10122
  }, {
10079
10123
  key: "setUserAgent",
@@ -11467,6 +11511,30 @@ var EVENT_MAP = {
11467
11511
  'connection.changed': true,
11468
11512
  'connection.recovered': true,
11469
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
11470
11538
  };
11471
11539
 
11472
11540
  var Allow = 'Allow';
@@ -11543,5 +11611,5 @@ var BuiltinPermissions = {
11543
11611
  UseFrozenChannel: 'Send messages and reactions to frozen channels'
11544
11612
  };
11545
11613
 
11546
- 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 };
11547
11615
  //# sourceMappingURL=browser.es.js.map