Fix streamList updating
This commit is contained in:
parent
ac585ff355
commit
a00221e25e
@ -4,6 +4,7 @@ import { createContext, useEffect, useState } from "react";
|
|||||||
import { MediaContainer } from "./media";
|
import { MediaContainer } from "./media";
|
||||||
import { MinistreamApiClient, StreamInfo } from "./api";
|
import { MinistreamApiClient, StreamInfo } from "./api";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
import { Log } from "./log";
|
||||||
|
|
||||||
interface AppProps {
|
interface AppProps {
|
||||||
api: MinistreamApiClient
|
api: MinistreamApiClient
|
||||||
@ -33,24 +34,10 @@ export function App({ api }: AppProps) {
|
|||||||
setSelectedStream(item)
|
setSelectedStream(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateStreamList = () => {
|
|
||||||
api.listStreams().then((list) => {
|
|
||||||
setStreamList(list)
|
|
||||||
if (list.length != streamList.length) {
|
|
||||||
setStreamList(list)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!list.every((_, idx) => {
|
|
||||||
return list[idx].streamKey === streamList[idx].streamKey
|
|
||||||
})) {
|
|
||||||
setStreamList(list)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const updateTitle = () => {
|
const updateTitle = () => {
|
||||||
api.siteInfo().then((info) => {
|
api.siteInfo().then((info) => {
|
||||||
if (info.siteName != document.title) {
|
if (info.siteName != document.title) {
|
||||||
setTitle(info.siteName)
|
setTitle(info.siteName)
|
||||||
localStorage.setItem(titleKey, info.siteName)
|
localStorage.setItem(titleKey, info.siteName)
|
||||||
@ -59,12 +46,32 @@ export function App({ api }: AppProps) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
setInterval(() => {
|
|
||||||
updateStreamList()
|
|
||||||
}, 10000)
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const updateStreamList = () => {
|
||||||
|
api.listStreams().then((list) => {
|
||||||
|
setStreamList((current) => {
|
||||||
|
if (list.length != current.length) {
|
||||||
|
Log.Debug("Updated streamList!")
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
if (!list.every((_, idx) => {
|
||||||
|
return list[idx].streamKey === current[idx].streamKey
|
||||||
|
})) {
|
||||||
|
Log.Debug("Updated streamList..")
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
return current
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
updateStreamList()
|
updateStreamList()
|
||||||
|
const updateInterval = setInterval(() => {
|
||||||
|
updateStreamList()
|
||||||
|
}, 10000)
|
||||||
|
return () => clearInterval(updateInterval)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
Loading…
Reference in New Issue
Block a user