修改推送数据格式

This commit is contained in:
2025-07-02 21:05:33 +08:00
parent 318c6b5cc1
commit f347e1bd9c
9 changed files with 137 additions and 22 deletions

View File

@ -8,6 +8,7 @@
// 引入客户端管理模块,用于维护连接的客户端
const clients = require('./clients');
const timestamp = require('../utils/timeFormatter');
/**
* 设置 SSEServer-Sent Events响应头确保客户端能够正确接收事件流
@ -27,7 +28,7 @@ function setupSSEHeaders(res) {
function sendHeartbeat() {
const data = {
event: 'heartbeat', // 事件类型为 heartbeat
time: new Date().toISOString() // 当前时间的 ISO 字符串格式
time: timestamp.formatTime() // 当前时间的 ISO 字符串格式
};
return clients.broadcast(data); // 广播给所有连接的客户端
}