dshost-plugin 0.1.13 → 0.1.14

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.
Files changed (2) hide show
  1. package/lib/core.js +15 -0
  2. package/package.json +1 -1
package/lib/core.js CHANGED
@@ -458,7 +458,19 @@ export function startAgent(opts) {
458
458
  log.log?.(`[agent] Connecting to ${relayUrl} ...`);
459
459
  const ws = new WebSocket(relayUrl);
460
460
 
461
+ // 握手超时看门狗:如果 WS open 事件在 20s 内未到达(TCP 连上但 upgrade
462
+ // 响应丢失——WiFi 恢复期/代理链路抖动时常见),主动 terminate 触发 close
463
+ // → 重连,避免永久挂死在 CONNECTING 状态(旧逻辑的致命缺陷:startHeartbeat
464
+ // 只在 registered 后启动,握手挂死时无任何看门狗看管新连接)。
465
+ const handshakeTimer = setTimeout(() => {
466
+ if (ws.readyState === WebSocket.CONNECTING) {
467
+ log.log?.('[agent] handshake timeout (20s, no WS open), forcing reconnect');
468
+ try { ws.terminate(); } catch (eT) {}
469
+ }
470
+ }, 20000);
471
+
461
472
  ws.on('open', () => {
473
+ clearTimeout(handshakeTimer);
462
474
  log.log?.('[agent] Connected to relay');
463
475
  send(ws, { type: 'register', token, version });
464
476
  });
@@ -545,6 +557,8 @@ export function startAgent(opts) {
545
557
  });
546
558
 
547
559
  ws.on('close', (code, reason) => {
560
+ clearTimeout(handshakeTimer);
561
+ if (heartbeatInterval) { clearInterval(heartbeatInterval); heartbeatInterval = null; }
548
562
  log.log?.(`[agent] Disconnected (${code}): ${reason}`);
549
563
  registered = false;
550
564
  for (const [, stream] of streams) {
@@ -560,6 +574,7 @@ export function startAgent(opts) {
560
574
  });
561
575
 
562
576
  ws.on('error', (err) => {
577
+ clearTimeout(handshakeTimer);
563
578
  log.error?.(`[agent] WS Error: ${err.message}`);
564
579
  ws.close();
565
580
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dshost-plugin",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "description": "Official remote cloud relay plugin for DSHost (dshost.me): securely access your dsh Web UI from anywhere",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",