claude-opencode-viewer 2.6.24 → 2.6.25
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/server.js +14 -0
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -708,6 +708,8 @@ function createServerAndWss() {
|
|
|
708
708
|
function setupWss(wssInst) {
|
|
709
709
|
wssInst.on('connection', (ws, req) => {
|
|
710
710
|
LOG('[WS] 客户端连接 from', req.socket.remoteAddress);
|
|
711
|
+
ws.isAlive = true;
|
|
712
|
+
ws.on('pong', () => { ws.isAlive = true; });
|
|
711
713
|
|
|
712
714
|
ws.send(JSON.stringify({
|
|
713
715
|
type: 'state',
|
|
@@ -937,6 +939,18 @@ wssInst.on('connection', (ws, req) => {
|
|
|
937
939
|
}
|
|
938
940
|
});
|
|
939
941
|
});
|
|
942
|
+
|
|
943
|
+
// WebSocket 心跳保活,防止中间网络设备断开空闲连接
|
|
944
|
+
const HEARTBEAT_INTERVAL = 15000;
|
|
945
|
+
const heartbeat = setInterval(() => {
|
|
946
|
+
wssInst.clients.forEach((ws) => {
|
|
947
|
+
if (ws.isAlive === false) return ws.terminate();
|
|
948
|
+
ws.isAlive = false;
|
|
949
|
+
ws.ping();
|
|
950
|
+
});
|
|
951
|
+
}, HEARTBEAT_INTERVAL);
|
|
952
|
+
|
|
953
|
+
wssInst.on('close', () => clearInterval(heartbeat));
|
|
940
954
|
} // end setupWss
|
|
941
955
|
|
|
942
956
|
createServerAndWss();
|