Fix streamList updating

This commit is contained in:
Torjus Håkestad 2023-12-06 02:52:56 +01:00
parent ac585ff355
commit a00221e25e

View File

@ -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,21 +34,7 @@ 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) => {
@ -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(() => {