polfan-server-js-client 0.2.66 → 0.2.68

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,17 +4,8 @@
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="Align to custom colors and nicks protocol changes">
8
- <change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
9
- <change beforePath="$PROJECT_DIR$/build/index.cjs.js" beforeDir="false" afterPath="$PROJECT_DIR$/build/index.cjs.js" afterDir="false" />
10
- <change beforePath="$PROJECT_DIR$/build/index.cjs.js.map" beforeDir="false" afterPath="$PROJECT_DIR$/build/index.cjs.js.map" afterDir="false" />
11
- <change beforePath="$PROJECT_DIR$/build/index.umd.js" beforeDir="false" afterPath="$PROJECT_DIR$/build/index.umd.js" afterDir="false" />
12
- <change beforePath="$PROJECT_DIR$/build/index.umd.js.map" beforeDir="false" afterPath="$PROJECT_DIR$/build/index.umd.js.map" afterDir="false" />
13
- <change beforePath="$PROJECT_DIR$/build/types/WebSocketChatClient.d.ts" beforeDir="false" afterPath="$PROJECT_DIR$/build/types/WebSocketChatClient.d.ts" afterDir="false" />
14
- <change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
7
+ <list default="true" id="831dae43-0da1-47fd-a5f7-33dd5eec2992" name="Changes" comment="Ping-pong connection monitoring">
15
8
  <change beforePath="$PROJECT_DIR$/src/WebSocketChatClient.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/WebSocketChatClient.ts" afterDir="false" />
16
- <change beforePath="$PROJECT_DIR$/src/state-tracker/MessagesManager.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/state-tracker/MessagesManager.ts" afterDir="false" />
17
- <change beforePath="$PROJECT_DIR$/src/state-tracker/TopicHistoryWindow.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/state-tracker/TopicHistoryWindow.ts" afterDir="false" />
18
9
  </list>
19
10
  <option name="SHOW_DIALOG" value="false" />
20
11
  <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -166,23 +157,7 @@
166
157
  <workItem from="1764758258935" duration="1127000" />
167
158
  <workItem from="1764792690210" duration="1002000" />
168
159
  <workItem from="1764794428269" duration="595000" />
169
- <workItem from="1764847260499" duration="12786000" />
170
- </task>
171
- <task id="LOCAL-00017" summary="New scheme of Bye event">
172
- <option name="closed" value="true" />
173
- <created>1740250355576</created>
174
- <option name="number" value="00017" />
175
- <option name="presentableId" value="LOCAL-00017" />
176
- <option name="project" value="LOCAL" />
177
- <updated>1740250355576</updated>
178
- </task>
179
- <task id="LOCAL-00018" summary="Fix authentication">
180
- <option name="closed" value="true" />
181
- <created>1740253483444</created>
182
- <option name="number" value="00018" />
183
- <option name="presentableId" value="LOCAL-00018" />
184
- <option name="project" value="LOCAL" />
185
- <updated>1740253483444</updated>
160
+ <workItem from="1764847260499" duration="26458000" />
186
161
  </task>
187
162
  <task id="LOCAL-00019" summary="Add notify option to Kick command">
188
163
  <option name="closed" value="true" />
@@ -560,7 +535,23 @@
560
535
  <option name="project" value="LOCAL" />
561
536
  <updated>1764689897014</updated>
562
537
  </task>
563
- <option name="localTasksCounter" value="66" />
538
+ <task id="LOCAL-00066" summary="Connection handling optimizations">
539
+ <option name="closed" value="true" />
540
+ <created>1764955397384</created>
541
+ <option name="number" value="00066" />
542
+ <option name="presentableId" value="LOCAL-00066" />
543
+ <option name="project" value="LOCAL" />
544
+ <updated>1764955397384</updated>
545
+ </task>
546
+ <task id="LOCAL-00067" summary="Ping-pong connection monitoring">
547
+ <option name="closed" value="true" />
548
+ <created>1765145134871</created>
549
+ <option name="number" value="00067" />
550
+ <option name="presentableId" value="LOCAL-00067" />
551
+ <option name="project" value="LOCAL" />
552
+ <updated>1765145134871</updated>
553
+ </task>
554
+ <option name="localTasksCounter" value="68" />
564
555
  <servers />
565
556
  </component>
566
557
  <component name="TypeScriptGeneratedFilesManager">
@@ -578,8 +569,6 @@
578
569
  </option>
579
570
  </component>
580
571
  <component name="VcsManagerConfiguration">
581
- <MESSAGE value="Fix package.json exports" />
582
- <MESSAGE value="Fix package.json type exports" />
583
572
  <MESSAGE value="New message type" />
584
573
  <MESSAGE value="Dedicated event for user status change" />
585
574
  <MESSAGE value="Fix update the latest message in a room default topic" />
@@ -603,7 +592,9 @@
603
592
  <MESSAGE value="Update deps and improve library building" />
604
593
  <MESSAGE value="Improvements and fixes to collection mirroring" />
605
594
  <MESSAGE value="Align to custom colors and nicks protocol changes" />
606
- <option name="LAST_COMMIT_MESSAGE" value="Align to custom colors and nicks protocol changes" />
595
+ <MESSAGE value="Connection handling optimizations" />
596
+ <MESSAGE value="Ping-pong connection monitoring" />
597
+ <option name="LAST_COMMIT_MESSAGE" value="Ping-pong connection monitoring" />
607
598
  </component>
608
599
  <component name="github-copilot-workspace">
609
600
  <instructionFileLocations>
@@ -4269,7 +4269,7 @@ var WebSocketChatClientEvent = /*#__PURE__*/function (WebSocketChatClientEvent)
4269
4269
  }(WebSocketChatClientEvent || {});
4270
4270
  var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
4271
4271
  function WebSocketChatClient(options) {
4272
- var _this$options$stateTr;
4272
+ var _this$options$stateTr, _options$ping, _options$ping2, _options$ping2$enable, _options$ping3, _options$ping3$noActi, _options$ping4, _options$ping4$pongBa;
4273
4273
  var _this;
4274
4274
  WebSocketChatClient_classCallCheck(this, WebSocketChatClient);
4275
4275
  _this = WebSocketChatClient_callSuper(this, WebSocketChatClient);
@@ -4280,10 +4280,17 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
4280
4280
  WebSocketChatClient_defineProperty(_this, "connectingTimeoutId", void 0);
4281
4281
  WebSocketChatClient_defineProperty(_this, "authenticated", void 0);
4282
4282
  WebSocketChatClient_defineProperty(_this, "authenticatedResolvers", void 0);
4283
+ WebSocketChatClient_defineProperty(_this, "pingIntervalId", void 0);
4284
+ WebSocketChatClient_defineProperty(_this, "lastReceivedMessageAt", void 0);
4285
+ WebSocketChatClient_defineProperty(_this, "pingInFlight", void 0);
4283
4286
  _this.options = options;
4284
4287
  if ((_this$options$stateTr = _this.options.stateTracking) !== null && _this$options$stateTr !== void 0 ? _this$options$stateTr : true) {
4285
4288
  _this.state = new ChatStateTracker(_this);
4286
4289
  }
4290
+ (_options$ping = options.ping) !== null && _options$ping !== void 0 ? _options$ping : options.ping = {};
4291
+ (_options$ping2$enable = (_options$ping2 = options.ping).enabled) !== null && _options$ping2$enable !== void 0 ? _options$ping2$enable : _options$ping2.enabled = true;
4292
+ (_options$ping3$noActi = (_options$ping3 = options.ping).noActivityTimeoutMs) !== null && _options$ping3$noActi !== void 0 ? _options$ping3$noActi : _options$ping3.noActivityTimeoutMs = 15000;
4293
+ (_options$ping4$pongBa = (_options$ping4 = options.ping).pongBackTimeoutMs) !== null && _options$ping4$pongBa !== void 0 ? _options$ping4$pongBa : _options$ping4.pongBackTimeoutMs = 5000;
4287
4294
  return _this;
4288
4295
  }
4289
4296
  WebSocketChatClient_inherits(WebSocketChatClient, _AbstractChatClient);
@@ -4336,7 +4343,7 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
4336
4343
  value: function disconnect() {
4337
4344
  var _this$ws;
4338
4345
  this.sendQueue = [];
4339
- (_this$ws = this.ws) === null || _this$ws === void 0 || _this$ws.close();
4346
+ (_this$ws = this.ws) === null || _this$ws === void 0 || _this$ws.close(1000); // Normal closure
4340
4347
  this.ws = null;
4341
4348
  }
4342
4349
  }, {
@@ -4384,6 +4391,7 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
4384
4391
  }, {
4385
4392
  key: "onMessage",
4386
4393
  value: function onMessage(event) {
4394
+ this.lastReceivedMessageAt = Date.now();
4387
4395
  var envelope = JSON.parse(event.data);
4388
4396
  this.handleIncomingEnvelope(envelope);
4389
4397
  this.emit(envelope.type, envelope.data);
@@ -4394,6 +4402,7 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
4394
4402
  var isAuthenticated = envelope.type !== 'Bye';
4395
4403
  this.authenticated = isAuthenticated;
4396
4404
  if (isAuthenticated) {
4405
+ this.startConnectionMonitor();
4397
4406
  this.authenticatedResolvers[0]();
4398
4407
  this.emit(this.Event.connect);
4399
4408
  this.sendFromQueue();
@@ -4405,6 +4414,7 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
4405
4414
  }, {
4406
4415
  key: "onClose",
4407
4416
  value: function onClose(event) {
4417
+ this.stopConnectionMonitor();
4408
4418
  clearTimeout(this.connectingTimeoutId);
4409
4419
  var reconnect = event.code !== 1000; // Connection was closed because of error
4410
4420
  if (reconnect) {
@@ -4448,6 +4458,55 @@ var WebSocketChatClient = /*#__PURE__*/function (_AbstractChatClient) {
4448
4458
  value: function isOpenWsState() {
4449
4459
  return this.ws && this.ws.readyState === this.ws.OPEN;
4450
4460
  }
4461
+ }, {
4462
+ key: "startConnectionMonitor",
4463
+ value: function startConnectionMonitor() {
4464
+ var _this4 = this;
4465
+ if (!this.options.ping.enabled) {
4466
+ return;
4467
+ }
4468
+ this.lastReceivedMessageAt = Date.now();
4469
+ this.pingIntervalId = setInterval(/*#__PURE__*/WebSocketChatClient_asyncToGenerator(/*#__PURE__*/WebSocketChatClient_regenerator().m(function _callee3() {
4470
+ var timeout;
4471
+ return WebSocketChatClient_regenerator().w(function (_context3) {
4472
+ while (1) switch (_context3.n) {
4473
+ case 0:
4474
+ if (!(!_this4.isReady || _this4.pingInFlight)) {
4475
+ _context3.n = 1;
4476
+ break;
4477
+ }
4478
+ return _context3.a(2);
4479
+ case 1:
4480
+ if (!(Date.now() - _this4.lastReceivedMessageAt < _this4.options.ping.noActivityTimeoutMs)) {
4481
+ _context3.n = 2;
4482
+ break;
4483
+ }
4484
+ return _context3.a(2);
4485
+ case 2:
4486
+ timeout = setTimeout(function () {
4487
+ _this4.pingInFlight = false;
4488
+ _this4.ws.close(1012); // Service Restart (reconnect)
4489
+ }, _this4.options.ping.pongBackTimeoutMs);
4490
+ _this4.pingInFlight = true;
4491
+ _this4.send('Ping', {}).then(function () {
4492
+ _this4.pingInFlight = false;
4493
+ clearTimeout(timeout);
4494
+ });
4495
+ case 3:
4496
+ return _context3.a(2);
4497
+ }
4498
+ }, _callee3);
4499
+ })), 1000);
4500
+ }
4501
+ }, {
4502
+ key: "stopConnectionMonitor",
4503
+ value: function stopConnectionMonitor() {
4504
+ if (this.pingIntervalId) {
4505
+ clearInterval(this.pingIntervalId);
4506
+ this.pingIntervalId = undefined;
4507
+ }
4508
+ this.pingInFlight = false;
4509
+ }
4451
4510
  }]);
4452
4511
  }(AbstractChatClient);
4453
4512
  ;// ./src/WebApiChatClient.ts