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:
Ariana Giroux 2022-08-04 17:36:01 -06:00
parent 2306bbc2e7
commit 08287a9758
1 changed files with 16 additions and 10 deletions

View File

@ -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()