panrouter 5.3.3 → 5.3.4
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/package.json +1 -1
- package/pool-worker.mjs +19 -0
package/package.json
CHANGED
package/pool-worker.mjs
CHANGED
|
@@ -53,6 +53,7 @@ const WS_RECONNECT_MAX = 30000; // 上限 30 秒
|
|
|
53
53
|
|
|
54
54
|
let ws = null;
|
|
55
55
|
let reconnectTimer = null;
|
|
56
|
+
let heartbeatTimer = null;
|
|
56
57
|
let reconnectDelay = WS_RECONNECT_BASE;
|
|
57
58
|
let isShuttingDown = false;
|
|
58
59
|
|
|
@@ -96,6 +97,7 @@ function connectToHub() {
|
|
|
96
97
|
switch (msg.type) {
|
|
97
98
|
case "registered":
|
|
98
99
|
log("主控已确认节点注册", "OK");
|
|
100
|
+
startHeartbeat();
|
|
99
101
|
break;
|
|
100
102
|
|
|
101
103
|
case "request":
|
|
@@ -113,6 +115,7 @@ function connectToHub() {
|
|
|
113
115
|
|
|
114
116
|
ws.on("close", (code, reason) => {
|
|
115
117
|
log(`WebSocket 断开 (code: ${code})${reason ? " " + reason : ""}`, "ERR");
|
|
118
|
+
stopHeartbeat();
|
|
116
119
|
ws = null;
|
|
117
120
|
if (!isShuttingDown) scheduleReconnect();
|
|
118
121
|
});
|
|
@@ -208,6 +211,21 @@ function safeSend(data) {
|
|
|
208
211
|
}
|
|
209
212
|
}
|
|
210
213
|
|
|
214
|
+
// ─── 心跳保活(每 25 秒发送 ping,避免 Cloudflare 闲置超时) ─────────────────
|
|
215
|
+
function startHeartbeat() {
|
|
216
|
+
stopHeartbeat();
|
|
217
|
+
heartbeatTimer = setInterval(() => {
|
|
218
|
+
safeSend({ type: "ping" });
|
|
219
|
+
}, 25000);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function stopHeartbeat() {
|
|
223
|
+
if (heartbeatTimer) {
|
|
224
|
+
clearInterval(heartbeatTimer);
|
|
225
|
+
heartbeatTimer = null;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
211
229
|
// ─── 检查端口 ────────────────────────────────────────────────────────────────
|
|
212
230
|
|
|
213
231
|
function isPortOpen(port) {
|
|
@@ -271,6 +289,7 @@ function gracefulShutdown() {
|
|
|
271
289
|
log("收到关机指令,正在安全退出...", "OFF");
|
|
272
290
|
|
|
273
291
|
// 清理定时器
|
|
292
|
+
stopHeartbeat();
|
|
274
293
|
if (reconnectTimer) {
|
|
275
294
|
clearTimeout(reconnectTimer);
|
|
276
295
|
reconnectTimer = null;
|