stream-chat 4.4.3-dev.1 → 4.4.3-dev.2

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
@@ -3605,7 +3605,7 @@ var StableWSConnection = /*#__PURE__*/function () {
3605
3605
  user_token: _this.tokenManager.getToken(),
3606
3606
  server_determines_connection_id: true,
3607
3607
  device: _this.device,
3608
- request_id: reqID
3608
+ client_request_id: reqID
3609
3609
  };
3610
3610
  var qs = encodeURIComponent(JSON.stringify(params));
3611
3611
 
@@ -5112,7 +5112,9 @@ var StreamChat = /*#__PURE__*/function () {
5112
5112
  var options,
5113
5113
  requestConfig,
5114
5114
  response,
5115
+ _requestConfig$header,
5115
5116
  _args4 = arguments;
5117
+
5116
5118
  return _regeneratorRuntime.wrap(function _callee4$(_context4) {
5117
5119
  while (1) {
5118
5120
  switch (_context4.prev = _context4.next) {
@@ -5191,45 +5193,46 @@ var StreamChat = /*#__PURE__*/function () {
5191
5193
  case 39:
5192
5194
  _context4.prev = 39;
5193
5195
  _context4.t1 = _context4["catch"](4);
5196
+ _context4.t1.client_request_id = (_requestConfig$header = requestConfig.headers) === null || _requestConfig$header === void 0 ? void 0 : _requestConfig$header['x-client-request-id'];
5194
5197
 
5195
5198
  _this._logApiError(type, url, _context4.t1);
5196
5199
 
5197
5200
  _this.consecutiveFailures += 1;
5198
5201
 
5199
5202
  if (!_context4.t1.response) {
5200
- _context4.next = 55;
5203
+ _context4.next = 56;
5201
5204
  break;
5202
5205
  }
5203
5206
 
5204
5207
  if (!(_context4.t1.response.data.code === chatCodes.TOKEN_EXPIRED && !_this.tokenManager.isStatic())) {
5205
- _context4.next = 52;
5208
+ _context4.next = 53;
5206
5209
  break;
5207
5210
  }
5208
5211
 
5209
5212
  if (!(_this.consecutiveFailures > 1)) {
5210
- _context4.next = 48;
5213
+ _context4.next = 49;
5211
5214
  break;
5212
5215
  }
5213
5216
 
5214
- _context4.next = 48;
5217
+ _context4.next = 49;
5215
5218
  return sleep(retryInterval(_this.consecutiveFailures));
5216
5219
 
5217
- case 48:
5220
+ case 49:
5218
5221
  _this.tokenManager.loadToken();
5219
5222
 
5220
- _context4.next = 51;
5223
+ _context4.next = 52;
5221
5224
  return _this.doAxiosRequest(type, url, data, options);
5222
5225
 
5223
- case 51:
5226
+ case 52:
5224
5227
  return _context4.abrupt("return", _context4.sent);
5225
5228
 
5226
- case 52:
5229
+ case 53:
5227
5230
  return _context4.abrupt("return", _this.handleResponse(_context4.t1.response));
5228
5231
 
5229
- case 55:
5232
+ case 56:
5230
5233
  throw _context4.t1;
5231
5234
 
5232
- case 56:
5235
+ case 57:
5233
5236
  case "end":
5234
5237
  return _context4.stop();
5235
5238
  }
@@ -5623,7 +5626,7 @@ var StreamChat = /*#__PURE__*/function () {
5623
5626
  }
5624
5627
 
5625
5628
  this.axiosInstance = axios.create(this.options);
5626
- this.setBaseURL(this.options.baseURL || 'https://chat-us-east-1.stream-io-api.com');
5629
+ this.setBaseURL(this.options.baseURL || 'https://chat.stream-io-api.com');
5627
5630
 
5628
5631
  if (typeof process !== 'undefined' && process.env.STREAM_LOCAL_TEST_RUN) {
5629
5632
  this.setBaseURL('http://localhost:3030');
@@ -6457,7 +6460,7 @@ var StreamChat = /*#__PURE__*/function () {
6457
6460
  */
6458
6461
  function () {
6459
6462
  var _connect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15() {
6460
- var client, warmUpPromise, handshake;
6463
+ var client;
6461
6464
  return _regeneratorRuntime.wrap(function _callee15$(_context15) {
6462
6465
  while (1) {
6463
6466
  switch (_context15.prev = _context15.next) {
@@ -6489,7 +6492,11 @@ var StreamChat = /*#__PURE__*/function () {
6489
6492
  throw Error('clientID is not set');
6490
6493
 
6491
6494
  case 8:
6492
- // The StableWSConnection handles all the reconnection logic.
6495
+ if (!this.wsConnection && (this.options.warmUp || this.options.enableInsights)) {
6496
+ this.sendBeacon();
6497
+ } // The StableWSConnection handles all the reconnection logic.
6498
+
6499
+
6493
6500
  this.wsConnection = new StableWSConnection({
6494
6501
  wsBaseURL: client.wsBaseURL,
6495
6502
  clientID: client.clientID,
@@ -6507,40 +6514,18 @@ var StreamChat = /*#__PURE__*/function () {
6507
6514
  postInsights: this.options.enableInsights ? this.postInsights : undefined,
6508
6515
  insightMetrics: this.insightMetrics
6509
6516
  });
6510
-
6511
- if (this.options.warmUp) {
6512
- warmUpPromise = this.doAxiosRequest('options', this.baseURL + '/connect');
6513
- }
6514
-
6515
6517
  _context15.next = 12;
6516
6518
  return this.wsConnection.connect();
6517
6519
 
6518
6520
  case 12:
6519
- handshake = _context15.sent;
6520
- _context15.prev = 13;
6521
- _context15.next = 16;
6522
- return warmUpPromise;
6523
-
6524
- case 16:
6525
- _context15.next = 21;
6526
- break;
6527
-
6528
- case 18:
6529
- _context15.prev = 18;
6530
- _context15.t0 = _context15["catch"](13);
6531
- this.logger('error', 'Warmup request failed', {
6532
- error: _context15.t0
6533
- });
6534
-
6535
- case 21:
6536
- return _context15.abrupt("return", handshake);
6521
+ return _context15.abrupt("return", _context15.sent);
6537
6522
 
6538
- case 22:
6523
+ case 13:
6539
6524
  case "end":
6540
6525
  return _context15.stop();
6541
6526
  }
6542
6527
  }
6543
- }, _callee15, this, [[13, 18]]);
6528
+ }, _callee15, this);
6544
6529
  }));
6545
6530
 
6546
6531
  function connect() {
@@ -6549,6 +6534,25 @@ var StreamChat = /*#__PURE__*/function () {
6549
6534
 
6550
6535
  return connect;
6551
6536
  }()
6537
+ }, {
6538
+ key: "sendBeacon",
6539
+ value: function sendBeacon() {
6540
+ var _this4 = this;
6541
+
6542
+ var client_request_id = randomId();
6543
+ var opts = {
6544
+ headers: {
6545
+ 'x-client-request-id': client_request_id
6546
+ }
6547
+ };
6548
+ this.doAxiosRequest('get', this.baseURL + '/beacon', null, opts).catch(function (e) {
6549
+ _this4.postInsights('http_beacon_failed', {
6550
+ api_key: _this4.key,
6551
+ err: e,
6552
+ client_request_id: client_request_id
6553
+ });
6554
+ });
6555
+ }
6552
6556
  /**
6553
6557
  * queryUsers - Query users and watch user presence
6554
6558
  *
@@ -8360,7 +8364,7 @@ var StreamChat = /*#__PURE__*/function () {
8360
8364
  }, {
8361
8365
  key: "getUserAgent",
8362
8366
  value: function getUserAgent() {
8363
- return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "4.4.3-dev.1");
8367
+ return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "4.4.3-dev.2");
8364
8368
  }
8365
8369
  }, {
8366
8370
  key: "setUserAgent",
@@ -8374,7 +8378,7 @@ var StreamChat = /*#__PURE__*/function () {
8374
8378
  }, {
8375
8379
  key: "_enrichAxiosOptions",
8376
8380
  value: function _enrichAxiosOptions() {
8377
- var _this$wsConnection4;
8381
+ var _options$headers, _this$wsConnection4;
8378
8382
 
8379
8383
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
8380
8384
  params: {},
@@ -8384,6 +8388,12 @@ var StreamChat = /*#__PURE__*/function () {
8384
8388
 
8385
8389
  var token = this._getToken();
8386
8390
 
8391
+ if (!((_options$headers = options.headers) !== null && _options$headers !== void 0 && _options$headers['x-client-request-id'])) {
8392
+ options.headers = {
8393
+ 'x-client-request-id': randomId()
8394
+ };
8395
+ }
8396
+
8387
8397
  return _objectSpread({
8388
8398
  params: _objectSpread(_objectSpread({
8389
8399
  user_id: this.userID