From cba060d6538d57f86dcc7a5b88820462248eead4 Mon Sep 17 00:00:00 2001 From: jmal Date: Tue, 18 Jun 2024 22:59:05 +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 | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/src/sse/SSEClient.js b/src/sse/SSEClient.js index 4deacce..e527dee 100644 --- a/src/sse/SSEClient.js +++ b/src/sse/SSEClient.js @@ -5,7 +5,6 @@ import { generateUUID } from "ant-design-vue/lib/vc-select/util"; let eventSource = null; let timer = null; -let lastHeartbeat = new Date().getTime(); const uuid = generateUUID(); const throttledConnectSSE = _.throttle((username) => { @@ -32,16 +31,11 @@ function connectToSSE(username) { eventSource.addEventListener('message', handleMessage); eventSource.addEventListener('error', handleError.bind(null, username)); - startHeartbeatCheck(username); } function handleMessage(event) { - if (event.data === 'h') { - lastHeartbeat = new Date().getTime(); - } else { - const msg = JSON.parse(event.data); - onMessage(msg); - } + const msg = JSON.parse(event.data); + onMessage(msg); } function handleError(username) { @@ -55,18 +49,6 @@ function clearExistingTimer() { } } -function startHeartbeatCheck(username) { - clearExistingTimer(); - timer = setInterval(() => { - if (eventSource.readyState === 1 && new Date().getTime() - lastHeartbeat > 5000) { - eventSource.close(); - } - if (eventSource.readyState === 2) { - throttledConnectSSE(username); - } - }, 3000); -} - function onMessage(msg) { const { url, body } = msg; const eventMapping = {