Simplified javascript function for updating UI
- breaks uiUpdate() into two functions - uiUpdateOnce(), which contains the bulk of the UI updating code - continuousUiUpdate(), which runs the aforementioned function once every second. - updates updateStreamTitle() to conform to this new change - removes call to Main(), replacing it with a call to the new continuousUiUpdate()
This commit is contained in:
parent
2306bbc2e7
commit
08287a9758
1 changed files with 16 additions and 10 deletions
|
@ -4,29 +4,35 @@ async function getEndpoint(url = '') {
|
|||
return data;
|
||||
}
|
||||
|
||||
async function uiUpdate() {
|
||||
async function uiUpdateOnce() {
|
||||
var data = await getEndpoint('http://127.0.0.1:5000/api/serverstatus');
|
||||
document.getElementById("streamTitle").innerHTML = data.streamTitle;
|
||||
document.getElementById("currentViewers").innerHTML = data.viewerCount;
|
||||
document.getElementById("sessionMaxViewerCount").innerHTML = data.sessionMaxViewerCount;
|
||||
document.getElementById("overallMaxViewerCount").innerHTML = data.overallMaxViewerCount;
|
||||
document.getElementById("tags").innerHTML = data.tags;
|
||||
}
|
||||
|
||||
async function continuousUiUpdate() {
|
||||
window.setInterval(async () => {
|
||||
data = await getEndpoint('http://127.0.0.1:5000/api/serverstatus');
|
||||
document.getElementById("streamTitle").innerHTML = data.streamTitle
|
||||
document.getElementById("currentViewers").innerHTML = data.viewerCount
|
||||
document.getElementById("sessionMaxViewerCount").innerHTML = data.sessionMaxViewerCount
|
||||
document.getElementById("overallMaxViewerCount").innerHTML = data.overallMaxViewerCount
|
||||
document.getElementById("tags").innerHTML = data.tags
|
||||
}, 1000)
|
||||
uiUpdateOnce();
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
async function updateStreamTitle(value) {
|
||||
// this function simply passes data along to the python script, and allows
|
||||
// python to handle data processing
|
||||
response = await fetch('http://127.0.0.1:5000/api/update/streamtitle',
|
||||
{
|
||||
method:'POST',
|
||||
body:JSON.stringify(value)
|
||||
}
|
||||
);
|
||||
await uiUpdate()
|
||||
await uiUpdateOnce();
|
||||
}
|
||||
|
||||
async function Main() {
|
||||
await uiUpdate()
|
||||
}
|
||||
|
||||
Main()
|
||||
continuousUiUpdate()
|
||||
|
|
Loading…
Reference in a new issue