From db2f1fdd932b0338e897d6e90d95cd6ccd5a0090 Mon Sep 17 00:00:00 2001 From: jmal Date: Wed, 12 Jun 2024 09:27:18 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96sse=E8=BF=9E=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sse/SSEClient.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/sse/SSEClient.js b/src/sse/SSEClient.js index 4e21cb1..92ad32b 100644 --- a/src/sse/SSEClient.js +++ b/src/sse/SSEClient.js @@ -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);