stream-chat 4.4.2 → 4.4.3-dev.0

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/browser.js CHANGED
@@ -950,6 +950,16 @@ function getRandomBytes(length) {
950
950
  return bytes;
951
951
  }
952
952
 
953
+ function convertErrorToJson(err) {
954
+ var jsonObj = {};
955
+ if (!err) return jsonObj;
956
+ Object.getOwnPropertyNames(err).forEach(function (key) {
957
+ // @ts-ignore
958
+ jsonObj[key] = err[key];
959
+ });
960
+ return jsonObj;
961
+ }
962
+
953
963
  function _createForOfIteratorHelper$2(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { 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 = o[Symbol.iterator](); }, 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; } } }; }
954
964
 
955
965
  function _unsupportedIterableToArray$2(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$2(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$2(o, minLen); }
@@ -3461,13 +3471,7 @@ var InsightMetrics = function InsightMetrics() {
3461
3471
  this.instanceClientId = randomId();
3462
3472
  };
3463
3473
  function buildWsFatalInsight(connection, event) {
3464
- return _objectSpread$2({
3465
- err: {
3466
- wasClean: event.wasClean,
3467
- code: event.code,
3468
- reason: event.reason
3469
- }
3470
- }, buildWsBaseInsight(connection));
3474
+ return _objectSpread$2(_objectSpread$2({}, event), buildWsBaseInsight(connection));
3471
3475
  }
3472
3476
 
3473
3477
  function buildWsBaseInsight(connection) {
@@ -3705,13 +3709,7 @@ var StableWSConnection = /*#__PURE__*/function () {
3705
3709
  });
3706
3710
 
3707
3711
  _defineProperty__default['default'](this, "onclose", function (wsID, event) {
3708
- if (event.code !== chatCodes.WS_CLOSED_SUCCESS) {
3709
- var _this$postInsights;
3710
-
3711
- _this.insightMetrics.wsConsecutiveFailures++;
3712
- _this.insightMetrics.wsTotalFailures++;
3713
- (_this$postInsights = _this.postInsights) === null || _this$postInsights === void 0 ? void 0 : _this$postInsights.call(_this, 'ws_fatal', buildWsFatalInsight(_this, event));
3714
- }
3712
+ if (_this.wsID !== wsID) return;
3715
3713
 
3716
3714
  _this.logger('info', 'connection:onclose() - onclose callback - ' + event.code, {
3717
3715
  tags: ['connection'],
@@ -3719,8 +3717,6 @@ var StableWSConnection = /*#__PURE__*/function () {
3719
3717
  wsID: wsID
3720
3718
  });
3721
3719
 
3722
- if (_this.wsID !== wsID) return;
3723
-
3724
3720
  if (event.code === chatCodes.WS_CLOSED_SUCCESS) {
3725
3721
  var _this$rejectPromise2;
3726
3722
 
@@ -3728,6 +3724,9 @@ var StableWSConnection = /*#__PURE__*/function () {
3728
3724
  // usually caused by invalid auth details
3729
3725
  var error = new Error("WS connection reject with error ".concat(event.reason));
3730
3726
  error.reason = event.reason;
3727
+ error.code = event.code;
3728
+ error.wasClean = event.wasClean;
3729
+ error.target = event.target;
3731
3730
  (_this$rejectPromise2 = _this.rejectPromise) === null || _this$rejectPromise2 === void 0 ? void 0 : _this$rejectPromise2.call(_this, error);
3732
3731
 
3733
3732
  _this.logger('info', "connection:onclose() - WS connection reject with error ".concat(event.reason), {
@@ -4258,7 +4257,7 @@ var StableWSConnection = /*#__PURE__*/function () {
4258
4257
  key: "_connect",
4259
4258
  value: function () {
4260
4259
  var _connect3 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee5() {
4261
- var wsURL, response, _this$postInsights2;
4260
+ var wsURL, response, _this$postInsights, insights;
4262
4261
 
4263
4262
  return _regeneratorRuntime__default['default'].wrap(function _callee5$(_context5) {
4264
4263
  while (1) {
@@ -4303,24 +4302,33 @@ var StableWSConnection = /*#__PURE__*/function () {
4303
4302
 
4304
4303
  this.connectionID = response.connection_id;
4305
4304
 
4306
- if (this.insightMetrics.wsConsecutiveFailures > 0) {
4307
- (_this$postInsights2 = this.postInsights) === null || _this$postInsights2 === void 0 ? void 0 : _this$postInsights2.call(this, 'ws_success_after_failure', buildWsSuccessAfterFailureInsight(this));
4305
+ if (this.insightMetrics.wsConsecutiveFailures > 0 && this.postInsights) {
4306
+ this.postInsights('ws_success_after_failure', buildWsSuccessAfterFailureInsight(this));
4308
4307
  this.insightMetrics.wsConsecutiveFailures = 0;
4309
4308
  }
4310
4309
 
4311
4310
  return _context5.abrupt("return", response);
4312
4311
 
4313
4312
  case 23:
4314
- _context5.next = 29;
4313
+ _context5.next = 30;
4315
4314
  break;
4316
4315
 
4317
4316
  case 25:
4318
4317
  _context5.prev = 25;
4319
4318
  _context5.t0 = _context5["catch"](5);
4320
4319
  this.isConnecting = false;
4320
+
4321
+ if (this.postInsights) {
4322
+ this.insightMetrics.wsConsecutiveFailures++;
4323
+ this.insightMetrics.wsTotalFailures++; // @ts-ignore
4324
+
4325
+ insights = buildWsFatalInsight(this, convertErrorToJson(_context5.t0));
4326
+ (_this$postInsights = this.postInsights) === null || _this$postInsights === void 0 ? void 0 : _this$postInsights.call(this, 'ws_fatal', insights);
4327
+ }
4328
+
4321
4329
  throw _context5.t0;
4322
4330
 
4323
- case 29:
4331
+ case 30:
4324
4332
  case "end":
4325
4333
  return _context5.stop();
4326
4334
  }
@@ -8369,7 +8377,7 @@ var StreamChat = /*#__PURE__*/function () {
8369
8377
  }, {
8370
8378
  key: "getUserAgent",
8371
8379
  value: function getUserAgent() {
8372
- return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "4.4.2");
8380
+ return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "4.4.3-dev.0");
8373
8381
  }
8374
8382
  }, {
8375
8383
  key: "setUserAgent",