polfan-server-js-client 0.2.106 → 0.2.107

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.
@@ -4,7 +4,7 @@
4
4
  <option name="autoReloadType" value="SELECTIVE" />
5
5
  </component>
6
6
  <component name="ChangeListManager">
7
- <list default="true" id="831dae43-0da1-47fd-a5f7-33dd5eec2992" name="Changes" comment="Fix jumpTo when window is in LIVE state" />
7
+ <list default="true" id="831dae43-0da1-47fd-a5f7-33dd5eec2992" name="Changes" comment="Bump version" />
8
8
  <option name="SHOW_DIALOG" value="false" />
9
9
  <option name="HIGHLIGHT_CONFLICTS" value="true" />
10
10
  <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@@ -28,6 +28,7 @@
28
28
  </option>
29
29
  <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
30
30
  <option name="ROOT_SYNC" value="DONT_SYNC" />
31
+ <option name="UPDATE_TYPE" value="REBASE" />
31
32
  </component>
32
33
  <component name="GitHubPullRequestSearchHistory">{
33
34
  &quot;lastFilter&quot;: {
@@ -68,7 +69,7 @@
68
69
  "codeWithMe.voiceChat.enabledByDefault": "false",
69
70
  "com.intellij.ml.llm.matterhorn.ej.ui.settings.DefaultModelSelectionForGA.v1": "true",
70
71
  "git-widget-placeholder": "claude/chat-state-tracker-reconnect-6s4eha",
71
- "git.auto.fetch.suggestion.counter": "2",
72
+ "git.auto.fetch.suggestion.counter": "3",
72
73
  "ignore.virus.scanning.warn.message": "true",
73
74
  "junie.onboarding.icon.badge.shown": "true",
74
75
  "last_opened_file_path": "//wsl.localhost/Debian/home/jarek/polfan-js-client-library",
@@ -226,15 +227,7 @@
226
227
  <workItem from="1783939298935" duration="21428000" />
227
228
  <workItem from="1784102649250" duration="12484000" />
228
229
  <workItem from="1784524117686" duration="79000" />
229
- <workItem from="1784562428378" duration="8399000" />
230
- </task>
231
- <task id="LOCAL-00057" summary="Ephemeral room history support">
232
- <option name="closed" value="true" />
233
- <created>1756051989192</created>
234
- <option name="number" value="00057" />
235
- <option name="presentableId" value="LOCAL-00057" />
236
- <option name="project" value="LOCAL" />
237
- <updated>1756051989192</updated>
230
+ <workItem from="1784562428378" duration="10671000" />
238
231
  </task>
239
232
  <task id="LOCAL-00058" summary="Protocol version support">
240
233
  <option name="closed" value="true" />
@@ -620,7 +613,15 @@
620
613
  <option name="project" value="LOCAL" />
621
614
  <updated>1784734559954</updated>
622
615
  </task>
623
- <option name="localTasksCounter" value="106" />
616
+ <task id="LOCAL-00106" summary="Bump version">
617
+ <option name="closed" value="true" />
618
+ <created>1784995701121</created>
619
+ <option name="number" value="00106" />
620
+ <option name="presentableId" value="LOCAL-00106" />
621
+ <option name="project" value="LOCAL" />
622
+ <updated>1784995701121</updated>
623
+ </task>
624
+ <option name="localTasksCounter" value="107" />
624
625
  <servers />
625
626
  </component>
626
627
  <component name="TypeScriptGeneratedFilesManager">
@@ -670,7 +671,6 @@
670
671
  </option>
671
672
  </component>
672
673
  <component name="VcsManagerConfiguration">
673
- <MESSAGE value="Remove unused exports" />
674
674
  <MESSAGE value="Added abuse reports and message redaction types" />
675
675
  <MESSAGE value="Added new permission" />
676
676
  <MESSAGE value="WIP: delete redacted messages" />
@@ -695,7 +695,8 @@
695
695
  <MESSAGE value="Fixes in WebApiChatClient" />
696
696
  <MESSAGE value="Fix resolve window status after jump to message" />
697
697
  <MESSAGE value="Fix jumpTo when window is in LIVE state" />
698
- <option name="LAST_COMMIT_MESSAGE" value="Fix jumpTo when window is in LIVE state" />
698
+ <MESSAGE value="Bump version" />
699
+ <option name="LAST_COMMIT_MESSAGE" value="Bump version" />
699
700
  </component>
700
701
  <component name="XSLT-Support.FileAssociations.UIState">
701
702
  <expand />
@@ -118,6 +118,12 @@ var EventTarget = /*#__PURE__*/function () {
118
118
  }();
119
119
  ;// ./src/AbstractChatClient.ts
120
120
  function AbstractChatClient_typeof(o) { "@babel/helpers - typeof"; return AbstractChatClient_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, AbstractChatClient_typeof(o); }
121
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
122
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
123
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
124
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
125
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
126
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
121
127
  function AbstractChatClient_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
122
128
  function AbstractChatClient_defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, AbstractChatClient_toPropertyKey(o.key), o); } }
123
129
  function AbstractChatClient_createClass(e, r, t) { return r && AbstractChatClient_defineProperties(e.prototype, r), t && AbstractChatClient_defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
@@ -187,6 +193,30 @@ var AbstractChatClient = /*#__PURE__*/function (_EventTarget) {
187
193
  this.awaitingResponse.get(envelope.ref)[1](error);
188
194
  this.awaitingResponse["delete"](envelope.ref);
189
195
  }
196
+
197
+ /**
198
+ * Reject every command that is still waiting for a response.
199
+ *
200
+ * Call this whenever the transport can no longer deliver an answer (the
201
+ * connection dropped). The server will never reply to those commands, so
202
+ * leaving them pending would hang every caller awaiting them forever -
203
+ * including cached lookups in the state tracker, which would then keep a
204
+ * view stuck on a loader even after a successful reconnect.
205
+ */
206
+ }, {
207
+ key: "failAwaitingResponses",
208
+ value: function failAwaitingResponses(error) {
209
+ if (!this.awaitingResponse.size) {
210
+ return;
211
+ }
212
+ var pending = Array.from(this.awaitingResponse.values());
213
+ this.awaitingResponse.clear();
214
+ for (var _i = 0, _pending = pending; _i < _pending.length; _i++) {
215
+ var _pending$_i = _slicedToArray(_pending[_i], 2),
216
+ reject = _pending$_i[1];
217
+ reject(error);
218
+ }
219
+ }
190
220
  }]);
191
221
  }(EventTarget);
192
222
 
@@ -209,17 +239,17 @@ function _superPropBase(t, o) { for (; !{}.hasOwnProperty.call(t, o) && null !==
209
239
  function IndexedObjectCollection_getPrototypeOf(t) { return IndexedObjectCollection_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, IndexedObjectCollection_getPrototypeOf(t); }
210
240
  function IndexedObjectCollection_inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && IndexedObjectCollection_setPrototypeOf(t, e); }
211
241
  function IndexedObjectCollection_setPrototypeOf(t, e) { return IndexedObjectCollection_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, IndexedObjectCollection_setPrototypeOf(t, e); }
212
- function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
213
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
214
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
215
- function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
216
- function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
217
- function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
242
+ function IndexedObjectCollection_slicedToArray(r, e) { return IndexedObjectCollection_arrayWithHoles(r) || IndexedObjectCollection_iterableToArrayLimit(r, e) || IndexedObjectCollection_unsupportedIterableToArray(r, e) || IndexedObjectCollection_nonIterableRest(); }
243
+ function IndexedObjectCollection_nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
244
+ function IndexedObjectCollection_iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
245
+ function IndexedObjectCollection_arrayWithHoles(r) { if (Array.isArray(r)) return r; }
246
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = IndexedObjectCollection_unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
247
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || IndexedObjectCollection_unsupportedIterableToArray(r) || _nonIterableSpread(); }
218
248
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
219
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
249
+ function IndexedObjectCollection_unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return IndexedObjectCollection_arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? IndexedObjectCollection_arrayLikeToArray(r, a) : void 0; } }
220
250
  function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
221
- function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
222
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
251
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return IndexedObjectCollection_arrayLikeToArray(r); }
252
+ function IndexedObjectCollection_arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
223
253
  function IndexedObjectCollection_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
224
254
  function IndexedObjectCollection_defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, IndexedObjectCollection_toPropertyKey(o.key), o); } }
225
255
  function IndexedObjectCollection_createClass(e, r, t) { return r && IndexedObjectCollection_defineProperties(e.prototype, r), t && IndexedObjectCollection_defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
@@ -290,7 +320,7 @@ var IndexedCollection = /*#__PURE__*/function () {
290
320
  _step;
291
321
  try {
292
322
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
293
- var _step$value = _slicedToArray(_step.value, 2),
323
+ var _step$value = IndexedObjectCollection_slicedToArray(_step.value, 2),
294
324
  key = _step$value[0],
295
325
  value = _step$value[1];
296
326
  if (result.length >= limit) {
@@ -648,7 +678,19 @@ var PromiseRegistry = /*#__PURE__*/function () {
648
678
  return AsyncUtils_createClass(PromiseRegistry, [{
649
679
  key: "register",
650
680
  value: function register(promise, key) {
681
+ var _this2 = this;
651
682
  this.promises.set([key, promise]);
683
+
684
+ // Never cache a failed lookup: drop it so the next access retries
685
+ // instead of replaying the same rejection forever (a request issued
686
+ // while the client was offline would otherwise poison the key). The
687
+ // handler also keeps the cached promise from surfacing as an unhandled
688
+ // rejection - callers still receive the rejection from their own await.
689
+ promise["catch"](function () {
690
+ if (_this2.promises.get(key) === promise) {
691
+ _this2.promises["delete"](key);
692
+ }
693
+ });
652
694
  }
653
695
  }, {
654
696
  key: "registerByFunction",
@@ -1689,9 +1731,9 @@ var RoomMessagesHistory = /*#__PURE__*/function () {
1689
1731
  key: "resync",
1690
1732
  value: (function () {
1691
1733
  var _resync = RoomMessagesHistory_asyncToGenerator(/*#__PURE__*/RoomMessagesHistory_regenerator().m(function _callee2(room) {
1692
- var _i, _Array$from, _Array$from$_i, window;
1734
+ var _i, _Array$from, _Array$from$_i, window, _t;
1693
1735
  return RoomMessagesHistory_regenerator().w(function (_context2) {
1694
- while (1) switch (_context2.n) {
1736
+ while (1) switch (_context2.p = _context2.n) {
1695
1737
  case 0:
1696
1738
  this.room = room;
1697
1739
  this.updateTraverseLock(room);
@@ -1701,33 +1743,40 @@ var RoomMessagesHistory = /*#__PURE__*/function () {
1701
1743
  _i = 0, _Array$from = Array.from(this.historyWindows.items);
1702
1744
  case 1:
1703
1745
  if (!(_i < _Array$from.length)) {
1704
- _context2.n = 5;
1746
+ _context2.n = 8;
1705
1747
  break;
1706
1748
  }
1707
1749
  _Array$from$_i = RoomMessagesHistory_slicedToArray(_Array$from[_i], 2), window = _Array$from$_i[1];
1708
- _context2.n = 2;
1750
+ _context2.p = 2;
1751
+ _context2.n = 3;
1709
1752
  return window.setTraverseLock(this.traverseLock);
1710
- case 2:
1753
+ case 3:
1711
1754
  if (!this.traverseLock) {
1712
- _context2.n = 3;
1755
+ _context2.n = 4;
1713
1756
  break;
1714
1757
  }
1715
- return _context2.a(3, 4);
1716
- case 3:
1758
+ return _context2.a(3, 7);
1759
+ case 4:
1717
1760
  if (!(window.state === WindowState.LATEST)) {
1718
- _context2.n = 4;
1761
+ _context2.n = 5;
1719
1762
  break;
1720
1763
  }
1721
- _context2.n = 4;
1764
+ _context2.n = 5;
1722
1765
  return window.resetToLatest(true);
1723
- case 4:
1766
+ case 5:
1767
+ _context2.n = 7;
1768
+ break;
1769
+ case 6:
1770
+ _context2.p = 6;
1771
+ _t = _context2.v;
1772
+ case 7:
1724
1773
  _i++;
1725
1774
  _context2.n = 1;
1726
1775
  break;
1727
- case 5:
1776
+ case 8:
1728
1777
  return _context2.a(2);
1729
1778
  }
1730
- }, _callee2, this);
1779
+ }, _callee2, this, [[2, 6]]);
1731
1780
  }));
1732
1781
  function resync(_x2) {
1733
1782
  return _resync.apply(this, arguments);
@@ -5225,6 +5274,9 @@ var ChatStateTracker = /*#__PURE__*/function () {
5225
5274
  }();
5226
5275
  ;// ./src/WebSocketChatClient.ts
5227
5276
  function WebSocketChatClient_typeof(o) { "@babel/helpers - typeof"; return WebSocketChatClient_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, WebSocketChatClient_typeof(o); }
5277
+ function WebSocketChatClient_createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = WebSocketChatClient_unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
5278
+ function WebSocketChatClient_unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return WebSocketChatClient_arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? WebSocketChatClient_arrayLikeToArray(r, a) : void 0; } }
5279
+ function WebSocketChatClient_arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
5228
5280
  function WebSocketChatClient_regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return WebSocketChatClient_regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (WebSocketChatClient_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, WebSocketChatClient_regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, WebSocketChatClient_regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), WebSocketChatClient_regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", WebSocketChatClient_regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), WebSocketChatClient_regeneratorDefine2(u), WebSocketChatClient_regeneratorDefine2(u, o, "Generator"), WebSocketChatClient_regeneratorDefine2(u, n, function () { return this; }), WebSocketChatClient_regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (WebSocketChatClient_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
5229
5281
  function WebSocketChatClient_regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } WebSocketChatClient_regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { WebSocketChatClient_regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, WebSocketChatClient_regeneratorDefine2(e, r, n, t); }
5230
5282
  function WebSocketChatClient_asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
@@ -5263,7 +5315,13 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
5263
5315
  WebSocketChatClient_defineProperty(_this, "sendQueue", []);
5264
5316
  WebSocketChatClient_defineProperty(_this, "connectingTimeoutId", void 0);
5265
5317
  WebSocketChatClient_defineProperty(_this, "authenticated", void 0);
5266
- WebSocketChatClient_defineProperty(_this, "authenticatedResolvers", void 0);
5318
+ WebSocketChatClient_defineProperty(_this, "authenticatedResolvers", null);
5319
+ /**
5320
+ * Pending promise returned by connect(). Kept until the client is either
5321
+ * authenticated or gives up, so that an automatic reconnect settles the
5322
+ * original caller instead of stranding it on a superseded promise.
5323
+ */
5324
+ WebSocketChatClient_defineProperty(_this, "connectPromise", null);
5267
5325
  WebSocketChatClient_defineProperty(_this, "pingMonitorInterval", void 0);
5268
5326
  WebSocketChatClient_defineProperty(_this, "inFlightPingTimeout", void 0);
5269
5327
  WebSocketChatClient_defineProperty(_this, "lastReceivedMessageAt", void 0);
@@ -5282,10 +5340,11 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
5282
5340
  key: "connect",
5283
5341
  value: function () {
5284
5342
  var _connect = WebSocketChatClient_asyncToGenerator(/*#__PURE__*/WebSocketChatClient_regenerator().m(function _callee() {
5285
- var _this$options$queryPa,
5343
+ var _this$connectPromise2,
5286
5344
  _this2 = this,
5345
+ _this$options$queryPa,
5287
5346
  _this$options$connect;
5288
- var params;
5347
+ var _this$connectPromise, params;
5289
5348
  return WebSocketChatClient_regenerator().w(function (_context) {
5290
5349
  while (1) switch (_context.n) {
5291
5350
  case 0:
@@ -5293,8 +5352,17 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
5293
5352
  _context.n = 1;
5294
5353
  break;
5295
5354
  }
5296
- return _context.a(2);
5355
+ return _context.a(2, (_this$connectPromise = this.connectPromise) !== null && _this$connectPromise !== void 0 ? _this$connectPromise : undefined);
5297
5356
  case 1:
5357
+ // Reuse the promise of an attempt that has not settled yet (an
5358
+ // automatic reconnect), so the caller that started connecting is
5359
+ // resolved by whichever attempt eventually authenticates.
5360
+ (_this$connectPromise2 = this.connectPromise) !== null && _this$connectPromise2 !== void 0 ? _this$connectPromise2 : this.connectPromise = new Promise(function () {
5361
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
5362
+ args[_key] = arguments[_key];
5363
+ }
5364
+ return _this2.authenticatedResolvers = args;
5365
+ });
5298
5366
  params = new URLSearchParams((_this$options$queryPa = this.options.queryParams) !== null && _this$options$queryPa !== void 0 ? _this$options$queryPa : {});
5299
5367
  params.set('token', this.options.token);
5300
5368
  this.ws = new WebSocket("".concat(this.options.url, "?").concat(params));
@@ -5308,12 +5376,7 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
5308
5376
  return _this2.triggerConnectionTimeout();
5309
5377
  }, (_this$options$connect = this.options.connectingTimeoutMs) !== null && _this$options$connect !== void 0 ? _this$options$connect : 10000);
5310
5378
  this.authenticated = false;
5311
- return _context.a(2, new Promise(function () {
5312
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
5313
- args[_key] = arguments[_key];
5314
- }
5315
- return _this2.authenticatedResolvers = args;
5316
- }));
5379
+ return _context.a(2, this.connectPromise);
5317
5380
  }
5318
5381
  }, _callee, this);
5319
5382
  }));
@@ -5326,7 +5389,7 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
5326
5389
  key: "disconnect",
5327
5390
  value: function disconnect() {
5328
5391
  var _this$ws;
5329
- this.sendQueue = [];
5392
+ this.failPendingCommands(new Error('Client disconnected before the command was answered'));
5330
5393
  (_this$ws = this.ws) === null || _this$ws === void 0 || _this$ws.close(1000); // Normal closure
5331
5394
  this.ws = null;
5332
5395
  }
@@ -5387,11 +5450,11 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
5387
5450
  this.authenticated = isAuthenticated;
5388
5451
  if (isAuthenticated) {
5389
5452
  this.startConnectionMonitor();
5390
- this.authenticatedResolvers[0]();
5453
+ this.settleConnect();
5391
5454
  this.emit(this.Event.connect);
5392
5455
  this.sendFromQueue();
5393
5456
  } else {
5394
- this.authenticatedResolvers[1](envelope.data);
5457
+ this.settleConnect(envelope.data);
5395
5458
  }
5396
5459
  }
5397
5460
  }
@@ -5401,11 +5464,59 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
5401
5464
  this.stopConnectionMonitor();
5402
5465
  clearTimeout(this.connectingTimeoutId);
5403
5466
  var reconnect = event.code !== 1000; // Connection was closed because of error
5467
+
5468
+ // The server can no longer answer anything that was queued or in
5469
+ // flight, so settle those promises instead of leaving them pending.
5470
+ this.failPendingCommands(new Error('Connection closed before the command was answered'));
5404
5471
  if (reconnect) {
5472
+ // Keep a pending connect() promise unsettled - the retry below is
5473
+ // expected to authenticate and will resolve it.
5405
5474
  void this.connect();
5475
+ } else {
5476
+ this.settleConnect(new Error('Connection closed before authentication'));
5406
5477
  }
5407
5478
  this.emit(this.Event.disconnect, reconnect);
5408
5479
  }
5480
+
5481
+ /**
5482
+ * Resolve (or reject, when an error is given) a pending connect() promise.
5483
+ * No-op when there is nothing pending.
5484
+ */
5485
+ }, {
5486
+ key: "settleConnect",
5487
+ value: function settleConnect(error) {
5488
+ var resolvers = this.authenticatedResolvers;
5489
+ this.authenticatedResolvers = null;
5490
+ this.connectPromise = null;
5491
+ if (!resolvers) {
5492
+ return;
5493
+ }
5494
+ error ? resolvers[1](error) : resolvers[0]();
5495
+ }
5496
+
5497
+ /**
5498
+ * Reject every command that has not been answered yet - both the ones still
5499
+ * waiting in the send queue and the ones already sent to the server.
5500
+ */
5501
+ }, {
5502
+ key: "failPendingCommands",
5503
+ value: function failPendingCommands(error) {
5504
+ var queued = this.sendQueue;
5505
+ this.sendQueue = [];
5506
+ var _iterator = WebSocketChatClient_createForOfIteratorHelper(queued),
5507
+ _step;
5508
+ try {
5509
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
5510
+ var envelope = _step.value;
5511
+ this.handleEnvelopeSendError(envelope, error);
5512
+ }
5513
+ } catch (err) {
5514
+ _iterator.e(err);
5515
+ } finally {
5516
+ _iterator.f();
5517
+ }
5518
+ this.failAwaitingResponses(error);
5519
+ }
5409
5520
  }, {
5410
5521
  key: "sendFromQueue",
5411
5522
  value: function sendFromQueue() {
@@ -5470,7 +5581,12 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
5470
5581
  _this4.inFlightPingTimeout = undefined;
5471
5582
  _this4.ws.close(3000); // Service Restart (reconnect)
5472
5583
  }, _this4.options.ping.pongBackTimeoutMs);
5473
- _this4.send('Ping', {}).then(function () {
5584
+
5585
+ // A rejection here means the connection dropped while the ping was
5586
+ // in flight; onClose already handles that, so just stop waiting.
5587
+ _this4.send('Ping', {})["catch"](function () {
5588
+ return undefined;
5589
+ }).then(function () {
5474
5590
  clearTimeout(_this4.inFlightPingTimeout);
5475
5591
  _this4.inFlightPingTimeout = undefined;
5476
5592
  });