更新
This commit is contained in:
1 parent
01f9f2c514
commit
dc23ea53ed
25 files changed
+3116
-176
No files matched your search
@@ -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 => {
|
||||
|
||||
Reference in new issue
Block a user