mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
improve live info sse changes
This commit is contained in:
parent
8d4e752662
commit
4dbcd420c5
@ -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 (
|
||||
<div className="live-info">
|
||||
|
Loading…
x
Reference in New Issue
Block a user