This commit is contained in:
gs committed 2026-09-25 22:08:37 +08:00
1 parent 01f9f2c514
commit dc23ea53ed
25 files changed
+3116 -176

No files matched your search

+13
View File
@@ -26,6 +26,19 @@ router.get('/stream', (req, res) => {
});
});
// 定时发送心跳保持 SSE 长连接活跃,防止代理与浏览器切断
const sseHeartbeat = setInterval(() => {
clients.forEach(client => {
try {
client.res.write(': ping\n\n');
} catch (e) {}
});
}, 20000);
if (sseHeartbeat.unref) {
sseHeartbeat.unref();
}
function broadcastEvent(eventData) {
const dataString = `data: ${JSON.stringify(eventData)}\n\n`;
clients.forEach(client => {