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