From 281c3ef4d65e4c333346f3470c6dd6f836831101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Mon, 4 Dec 2023 02:01:36 +0100 Subject: [PATCH] Refresh stream list periodically --- src/js/app.tsx | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/js/app.tsx b/src/js/app.tsx index 7497d50..926bfcc 100644 --- a/src/js/app.tsx +++ b/src/js/app.tsx @@ -28,9 +28,38 @@ export class App extends React.Component { } async componentDidMount(): Promise { + await this.updateStreamList() + setInterval(() => { + this.updateStreamList() + }, 10000) + } + + async updateStreamList() { const streams = await this.apiClient.listStreams() + const sortedStreams = streams.sort((a, b) => { + if (a > b) { + return -1 + } else if (a < b) { + return 1 + } + return 0 + }) + + if (sortedStreams.length != this.state.streamList.length) { + this.setStreamList(streams) + } + + if (!sortedStreams.every((_, idx) => { + return sortedStreams[idx] === this.state.streamList[idx] + })) { + this.setStreamList(streams) + } + } + + setStreamList(streamList: string[]) { + console.log("stream list updated") this.setState((state) => { - return { selectedStream: state.selectedStream, streamList: streams } + return { selectedStream: state.selectedStream, streamList: streamList } }) }