From 4dbcd420c5c4a554ac7493d8e54c066b95cba3cd Mon Sep 17 00:00:00 2001 From: SrGooglo Date: Thu, 20 Feb 2025 02:02:51 +0000 Subject: [PATCH] improve live info sse changes --- .../src/components/Player/LiveInfo/index.jsx | 42 ++++++++++--------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/packages/app/src/components/Player/LiveInfo/index.jsx b/packages/app/src/components/Player/LiveInfo/index.jsx index 90e1b74b..8d1b8d4c 100644 --- a/packages/app/src/components/Player/LiveInfo/index.jsx +++ b/packages/app/src/components/Player/LiveInfo/index.jsx @@ -8,29 +8,31 @@ import "./index.less" const LiveInfo = ({ radioId, initialData }) => { const [data, setData] = React.useState(initialData ?? {}) - const eventManager = React.useMemo( - () => - new SSEEvents( - `${app.cores.api.client().mainOrigin}/music/radio/sse/radio:${radioId}`, - { - update: (data) => { - if (typeof data.now_playing === "string") { - data.now_playing = JSON.parse(data.now_playing) - } - - console.log(`Radio data updated`, data) - setData(data) - }, - }, - ), - [], - ) + const eventManager = React.useRef(null) React.useEffect(() => { - return () => { - eventManager.close() + if (eventManager.current) { + eventManager.current.close() } - }, []) + + eventManager.current = new SSEEvents( + `${app.cores.api.client().mainOrigin}/music/radio/sse/radio:${radioId}`, + { + update: (data) => { + if (typeof data.now_playing === "string") { + data.now_playing = JSON.parse(data.now_playing) + } + + console.log(`Radio data updated`, data) + setData(data) + }, + }, + ) + + return () => { + eventManager.current.close() + } + }, [radioId]) return (