polfan-server-js-client 0.2.66 → 0.2.67
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/.idea/workspace.xml +18 -22
- package/build/index.cjs.js +62 -2
- package/build/index.cjs.js.map +1 -1
- package/build/index.umd.js +1 -1
- package/build/index.umd.js.map +1 -1
- package/build/types/AbstractChatClient.d.ts +3 -1
- package/build/types/WebSocketChatClient.d.ts +20 -0
- package/build/types/types/src/index.d.ts +3 -1
- package/build/types/types/src/schemes/commands/Ping.d.ts +2 -0
- package/build/types/types/src/schemes/events/Pong.d.ts +2 -0
- package/package.json +1 -1
- package/src/AbstractChatClient.ts +3 -1
- package/src/WebSocketChatClient.ts +66 -3
- package/src/types/src/index.ts +4 -0
- package/src/types/src/schemes/commands/Ping.ts +3 -0
- package/src/types/src/schemes/events/Pong.ts +3 -0
package/.idea/workspace.xml
CHANGED
|
@@ -4,17 +4,13 @@
|
|
|
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="
|
|
8
|
-
<change
|
|
9
|
-
<change
|
|
10
|
-
<change beforePath="$PROJECT_DIR$/
|
|
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="Connection handling optimizations">
|
|
8
|
+
<change afterPath="$PROJECT_DIR$/src/types/src/schemes/commands/Ping.ts" afterDir="false" />
|
|
9
|
+
<change afterPath="$PROJECT_DIR$/src/types/src/schemes/events/Pong.ts" afterDir="false" />
|
|
10
|
+
<change beforePath="$PROJECT_DIR$/src/AbstractChatClient.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/AbstractChatClient.ts" afterDir="false" />
|
|
15
11
|
<change beforePath="$PROJECT_DIR$/src/WebSocketChatClient.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/WebSocketChatClient.ts" afterDir="false" />
|
|
16
|
-
<change beforePath="$PROJECT_DIR$/src/
|
|
17
|
-
<change beforePath="$PROJECT_DIR$/src/
|
|
12
|
+
<change beforePath="$PROJECT_DIR$/src/types" beforeDir="false" afterPath="$PROJECT_DIR$/src/types" afterDir="false" />
|
|
13
|
+
<change beforePath="$PROJECT_DIR$/src/types/src/index.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/types/src/index.ts" afterDir="false" />
|
|
18
14
|
</list>
|
|
19
15
|
<option name="SHOW_DIALOG" value="false" />
|
|
20
16
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
@@ -166,15 +162,7 @@
|
|
|
166
162
|
<workItem from="1764758258935" duration="1127000" />
|
|
167
163
|
<workItem from="1764792690210" duration="1002000" />
|
|
168
164
|
<workItem from="1764794428269" duration="595000" />
|
|
169
|
-
<workItem from="1764847260499" duration="
|
|
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>
|
|
165
|
+
<workItem from="1764847260499" duration="25756000" />
|
|
178
166
|
</task>
|
|
179
167
|
<task id="LOCAL-00018" summary="Fix authentication">
|
|
180
168
|
<option name="closed" value="true" />
|
|
@@ -560,7 +548,15 @@
|
|
|
560
548
|
<option name="project" value="LOCAL" />
|
|
561
549
|
<updated>1764689897014</updated>
|
|
562
550
|
</task>
|
|
563
|
-
<
|
|
551
|
+
<task id="LOCAL-00066" summary="Connection handling optimizations">
|
|
552
|
+
<option name="closed" value="true" />
|
|
553
|
+
<created>1764955397384</created>
|
|
554
|
+
<option name="number" value="00066" />
|
|
555
|
+
<option name="presentableId" value="LOCAL-00066" />
|
|
556
|
+
<option name="project" value="LOCAL" />
|
|
557
|
+
<updated>1764955397384</updated>
|
|
558
|
+
</task>
|
|
559
|
+
<option name="localTasksCounter" value="67" />
|
|
564
560
|
<servers />
|
|
565
561
|
</component>
|
|
566
562
|
<component name="TypeScriptGeneratedFilesManager">
|
|
@@ -578,7 +574,6 @@
|
|
|
578
574
|
</option>
|
|
579
575
|
</component>
|
|
580
576
|
<component name="VcsManagerConfiguration">
|
|
581
|
-
<MESSAGE value="Fix package.json exports" />
|
|
582
577
|
<MESSAGE value="Fix package.json type exports" />
|
|
583
578
|
<MESSAGE value="New message type" />
|
|
584
579
|
<MESSAGE value="Dedicated event for user status change" />
|
|
@@ -603,7 +598,8 @@
|
|
|
603
598
|
<MESSAGE value="Update deps and improve library building" />
|
|
604
599
|
<MESSAGE value="Improvements and fixes to collection mirroring" />
|
|
605
600
|
<MESSAGE value="Align to custom colors and nicks protocol changes" />
|
|
606
|
-
<
|
|
601
|
+
<MESSAGE value="Connection handling optimizations" />
|
|
602
|
+
<option name="LAST_COMMIT_MESSAGE" value="Connection handling optimizations" />
|
|
607
603
|
</component>
|
|
608
604
|
<component name="github-copilot-workspace">
|
|
609
605
|
<instructionFileLocations>
|
package/build/index.cjs.js
CHANGED
|
@@ -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,56 @@ 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.disconnect();
|
|
4489
|
+
void _this4.connect();
|
|
4490
|
+
}, _this4.options.ping.pongBackTimeoutMs);
|
|
4491
|
+
_this4.pingInFlight = true;
|
|
4492
|
+
_this4.send('Ping', {}).then(function () {
|
|
4493
|
+
_this4.pingInFlight = false;
|
|
4494
|
+
clearTimeout(timeout);
|
|
4495
|
+
});
|
|
4496
|
+
case 3:
|
|
4497
|
+
return _context3.a(2);
|
|
4498
|
+
}
|
|
4499
|
+
}, _callee3);
|
|
4500
|
+
})), 1000);
|
|
4501
|
+
}
|
|
4502
|
+
}, {
|
|
4503
|
+
key: "stopConnectionMonitor",
|
|
4504
|
+
value: function stopConnectionMonitor() {
|
|
4505
|
+
if (this.pingIntervalId) {
|
|
4506
|
+
clearInterval(this.pingIntervalId);
|
|
4507
|
+
this.pingIntervalId = undefined;
|
|
4508
|
+
}
|
|
4509
|
+
this.pingInFlight = false;
|
|
4510
|
+
}
|
|
4451
4511
|
}]);
|
|
4452
4512
|
}(AbstractChatClient);
|
|
4453
4513
|
;// ./src/WebApiChatClient.ts
|