perf: 优化sse连接

This commit is contained in:
jmal 2024-06-12 09:27:18 +08:00
parent 029685448f
commit db2f1fdd93

View File

@ -17,6 +17,13 @@ const throttledConnectSSE = _.throttle((username) => {
}, 3000);
function connectToSSE(username) {
if (eventSource) {
// 移除之前的事件监听器
eventSource.removeEventListener('message', handleMessage);
eventSource.removeEventListener('error', handleError.bind(null, username));
}
const url = `/api/events?username=${username}&uuid=${uuid}`;
eventSource = new EventSource(url);