mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 18:44:16 +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 LiveInfo = ({ radioId, initialData }) => {
|
||||||
const [data, setData] = React.useState(initialData ?? {})
|
const [data, setData] = React.useState(initialData ?? {})
|
||||||
|
|
||||||
const eventManager = React.useMemo(
|
const eventManager = React.useRef(null)
|
||||||
() =>
|
|
||||||
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)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
[],
|
|
||||||
)
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
return () => {
|
if (eventManager.current) {
|
||||||
eventManager.close()
|
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 (
|
return (
|
||||||
<div className="live-info">
|
<div className="live-info">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user