From 19c152355c844b0c6be8933ba3c98118d8728152 Mon Sep 17 00:00:00 2001 From: minbo Date: Fri, 29 Nov 2024 19:11:00 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20sse=20=EB=A1=9C=EC=A7=81=20=EC=A3=BC?= =?UTF-8?q?=EC=84=9D=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/Header/User/Login/Login.tsx | 104 +++++++++--------- 1 file changed, 51 insertions(+), 53 deletions(-) diff --git a/src/components/common/Header/User/Login/Login.tsx b/src/components/common/Header/User/Login/Login.tsx index 73770aa..a2f7795 100644 --- a/src/components/common/Header/User/Login/Login.tsx +++ b/src/components/common/Header/User/Login/Login.tsx @@ -50,59 +50,57 @@ export default function Login({ name }: LoginProps) { router.push(ROUTE.CHAT); }; - useEffect(() => { - if (!userInfo) return; - - let eventSource: EventSource; - - const connectSSE = () => { - if (retryCount >= 3) { - setError("연결 시도 횟수를 초과했습니다."); - return; - } - - eventSource = new EventSource(`${process.env.NEXT_PUBLIC_BASE_URL}api/sse/connect`, { - withCredentials: true, - }); - - eventSource.addEventListener("notification", (event) => { - const newNotification = event.data; - let parsedData; - - try { - parsedData = JSON.parse(newNotification); - } catch (error) { - return; - } - - setNotifications(parsedData); - }); - - eventSource.onerror = (error) => { - console.error("SSE error:", error); - setError("연결에 실패했습니다. 재연결 중..."); - setIsConnected(false); - eventSource.close(); - setRetryCount((prevCount) => prevCount + 1); - setTimeout(connectSSE, 5000); - }; - - eventSource.onopen = () => { - setError(null); - setIsConnected(true); - setRetryCount(0); - console.log("SSE 연결 성공"); - }; - }; - - connectSSE(); - - return () => { - if (eventSource) { - eventSource.close(); - } - }; - }, [userInfo, retryCount]); + // useEffect(() => { + // let eventSource: EventSource; + + // const connectSSE = () => { + // if (retryCount >= 3) { + // setError("연결 시도 횟수를 초과했습니다."); + // return; + // } + + // eventSource = new EventSource(`${process.env.NEXT_PUBLIC_BASE_URL}api/sse/connect`, { + // withCredentials: true, + // }); + + // eventSource.addEventListener("notification", (event) => { + // const newNotification = event.data; + // let parsedData; + + // try { + // parsedData = JSON.parse(newNotification); + // } catch (error) { + // return; + // } + + // setNotifications(parsedData); + // }); + + // eventSource.onerror = (error) => { + // console.error("SSE error:", error); + // setError("연결에 실패했습니다. 재연결 중..."); + // setIsConnected(false); + // eventSource.close(); + // setRetryCount((prevCount) => prevCount + 1); + // setTimeout(connectSSE, 5000); + // }; + + // eventSource.onopen = () => { + // setError(null); + // setIsConnected(true); + // setRetryCount(0); + // console.log("SSE 연결 성공"); + // }; + // }; + + // connectSSE(); + + // return () => { + // if (eventSource) { + // eventSource.close(); + // } + // }; + // }, [userInfo, retryCount]); return (