liangzimixin 0.3.37 → 0.3.39
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/index.cjs +22 -1
- package/dist/index.d.cts +4 -0
- package/dist/setup-entry.cjs +22 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -19920,7 +19920,9 @@ var WSClient = class extends import_node_events.EventEmitter {
|
|
|
19920
19920
|
log19.info("ws:connecting", { url: url2 });
|
|
19921
19921
|
return new Promise((resolve3, reject) => {
|
|
19922
19922
|
const ws = new wrapper_default(url2, protocols, { headers });
|
|
19923
|
+
let connected = false;
|
|
19923
19924
|
ws.on("open", () => {
|
|
19925
|
+
connected = true;
|
|
19924
19926
|
log19.info("ws:connected", { url: url2 });
|
|
19925
19927
|
this.emit("open");
|
|
19926
19928
|
resolve3();
|
|
@@ -19938,7 +19940,7 @@ var WSClient = class extends import_node_events.EventEmitter {
|
|
|
19938
19940
|
ws.on("error", (err) => {
|
|
19939
19941
|
log19.error("ws:error", { error: err.message });
|
|
19940
19942
|
this.emit("error", err);
|
|
19941
|
-
if (
|
|
19943
|
+
if (!connected) {
|
|
19942
19944
|
reject(err);
|
|
19943
19945
|
}
|
|
19944
19946
|
});
|
|
@@ -20303,6 +20305,8 @@ var ConnectionManager = class {
|
|
|
20303
20305
|
options;
|
|
20304
20306
|
/** 心跳定时器 */
|
|
20305
20307
|
heartbeatTimer = null;
|
|
20308
|
+
/** pong 超时定时器 — 每次 ping 后独立计时 */
|
|
20309
|
+
pongTimeoutTimer = null;
|
|
20306
20310
|
/** 当前重连尝试次数 */
|
|
20307
20311
|
reconnectAttempts = 0;
|
|
20308
20312
|
/** 是否处于运行状态 */
|
|
@@ -20370,6 +20374,7 @@ var ConnectionManager = class {
|
|
|
20370
20374
|
});
|
|
20371
20375
|
this.client.on("pong", () => {
|
|
20372
20376
|
this.pongReceived = true;
|
|
20377
|
+
this.clearPongTimeout();
|
|
20373
20378
|
log22.info("heartbeat: pong received");
|
|
20374
20379
|
});
|
|
20375
20380
|
}
|
|
@@ -20392,14 +20397,30 @@ var ConnectionManager = class {
|
|
|
20392
20397
|
this.pongReceived = false;
|
|
20393
20398
|
this.client.ping();
|
|
20394
20399
|
log22.info("heartbeat: ping sent");
|
|
20400
|
+
this.clearPongTimeout();
|
|
20401
|
+
this.pongTimeoutTimer = setTimeout(() => {
|
|
20402
|
+
if (!this.pongReceived && this.running) {
|
|
20403
|
+
log22.warn("heartbeat: pong timeout (independent timer), closing connection");
|
|
20404
|
+
this.client.close(4e3, "pong timeout");
|
|
20405
|
+
this.scheduleReconnect();
|
|
20406
|
+
}
|
|
20407
|
+
}, this.options.heartbeatTimeoutMs);
|
|
20395
20408
|
}, this.options.heartbeatIntervalMs);
|
|
20396
20409
|
}
|
|
20410
|
+
/** 清除 pong 超时定时器 */
|
|
20411
|
+
clearPongTimeout() {
|
|
20412
|
+
if (this.pongTimeoutTimer) {
|
|
20413
|
+
clearTimeout(this.pongTimeoutTimer);
|
|
20414
|
+
this.pongTimeoutTimer = null;
|
|
20415
|
+
}
|
|
20416
|
+
}
|
|
20397
20417
|
/** 停止心跳定时器 */
|
|
20398
20418
|
stopHeartbeat() {
|
|
20399
20419
|
if (this.heartbeatTimer) {
|
|
20400
20420
|
clearInterval(this.heartbeatTimer);
|
|
20401
20421
|
this.heartbeatTimer = null;
|
|
20402
20422
|
}
|
|
20423
|
+
this.clearPongTimeout();
|
|
20403
20424
|
}
|
|
20404
20425
|
/** 调度重连 (防止并发重连) */
|
|
20405
20426
|
scheduleReconnect() {
|
package/dist/index.d.cts
CHANGED
|
@@ -855,6 +855,8 @@ declare class ConnectionManager {
|
|
|
855
855
|
private readonly options;
|
|
856
856
|
/** 心跳定时器 */
|
|
857
857
|
private heartbeatTimer;
|
|
858
|
+
/** pong 超时定时器 — 每次 ping 后独立计时 */
|
|
859
|
+
private pongTimeoutTimer;
|
|
858
860
|
/** 当前重连尝试次数 */
|
|
859
861
|
private reconnectAttempts;
|
|
860
862
|
/** 是否处于运行状态 */
|
|
@@ -881,6 +883,8 @@ declare class ConnectionManager {
|
|
|
881
883
|
private registerEvents;
|
|
882
884
|
/** 启动心跳保活 — 定时发送 WebSocket Ping 帧 */
|
|
883
885
|
private startHeartbeat;
|
|
886
|
+
/** 清除 pong 超时定时器 */
|
|
887
|
+
private clearPongTimeout;
|
|
884
888
|
/** 停止心跳定时器 */
|
|
885
889
|
private stopHeartbeat;
|
|
886
890
|
/** 调度重连 (防止并发重连) */
|
package/dist/setup-entry.cjs
CHANGED
|
@@ -18979,7 +18979,9 @@ var WSClient = class extends import_node_events.EventEmitter {
|
|
|
18979
18979
|
log10.info("ws:connecting", { url: url2 });
|
|
18980
18980
|
return new Promise((resolve3, reject) => {
|
|
18981
18981
|
const ws = new wrapper_default(url2, protocols, { headers });
|
|
18982
|
+
let connected = false;
|
|
18982
18983
|
ws.on("open", () => {
|
|
18984
|
+
connected = true;
|
|
18983
18985
|
log10.info("ws:connected", { url: url2 });
|
|
18984
18986
|
this.emit("open");
|
|
18985
18987
|
resolve3();
|
|
@@ -18997,7 +18999,7 @@ var WSClient = class extends import_node_events.EventEmitter {
|
|
|
18997
18999
|
ws.on("error", (err) => {
|
|
18998
19000
|
log10.error("ws:error", { error: err.message });
|
|
18999
19001
|
this.emit("error", err);
|
|
19000
|
-
if (
|
|
19002
|
+
if (!connected) {
|
|
19001
19003
|
reject(err);
|
|
19002
19004
|
}
|
|
19003
19005
|
});
|
|
@@ -19362,6 +19364,8 @@ var ConnectionManager = class {
|
|
|
19362
19364
|
options;
|
|
19363
19365
|
/** 心跳定时器 */
|
|
19364
19366
|
heartbeatTimer = null;
|
|
19367
|
+
/** pong 超时定时器 — 每次 ping 后独立计时 */
|
|
19368
|
+
pongTimeoutTimer = null;
|
|
19365
19369
|
/** 当前重连尝试次数 */
|
|
19366
19370
|
reconnectAttempts = 0;
|
|
19367
19371
|
/** 是否处于运行状态 */
|
|
@@ -19429,6 +19433,7 @@ var ConnectionManager = class {
|
|
|
19429
19433
|
});
|
|
19430
19434
|
this.client.on("pong", () => {
|
|
19431
19435
|
this.pongReceived = true;
|
|
19436
|
+
this.clearPongTimeout();
|
|
19432
19437
|
log13.info("heartbeat: pong received");
|
|
19433
19438
|
});
|
|
19434
19439
|
}
|
|
@@ -19451,14 +19456,30 @@ var ConnectionManager = class {
|
|
|
19451
19456
|
this.pongReceived = false;
|
|
19452
19457
|
this.client.ping();
|
|
19453
19458
|
log13.info("heartbeat: ping sent");
|
|
19459
|
+
this.clearPongTimeout();
|
|
19460
|
+
this.pongTimeoutTimer = setTimeout(() => {
|
|
19461
|
+
if (!this.pongReceived && this.running) {
|
|
19462
|
+
log13.warn("heartbeat: pong timeout (independent timer), closing connection");
|
|
19463
|
+
this.client.close(4e3, "pong timeout");
|
|
19464
|
+
this.scheduleReconnect();
|
|
19465
|
+
}
|
|
19466
|
+
}, this.options.heartbeatTimeoutMs);
|
|
19454
19467
|
}, this.options.heartbeatIntervalMs);
|
|
19455
19468
|
}
|
|
19469
|
+
/** 清除 pong 超时定时器 */
|
|
19470
|
+
clearPongTimeout() {
|
|
19471
|
+
if (this.pongTimeoutTimer) {
|
|
19472
|
+
clearTimeout(this.pongTimeoutTimer);
|
|
19473
|
+
this.pongTimeoutTimer = null;
|
|
19474
|
+
}
|
|
19475
|
+
}
|
|
19456
19476
|
/** 停止心跳定时器 */
|
|
19457
19477
|
stopHeartbeat() {
|
|
19458
19478
|
if (this.heartbeatTimer) {
|
|
19459
19479
|
clearInterval(this.heartbeatTimer);
|
|
19460
19480
|
this.heartbeatTimer = null;
|
|
19461
19481
|
}
|
|
19482
|
+
this.clearPongTimeout();
|
|
19462
19483
|
}
|
|
19463
19484
|
/** 调度重连 (防止并发重连) */
|
|
19464
19485
|
scheduleReconnect() {
|