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
|
@ -4,29 +4,35 @@ async function getEndpoint(url = '') {
|
||||||
return data;
|
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 () => {
|
window.setInterval(async () => {
|
||||||
data = await getEndpoint('http://127.0.0.1:5000/api/serverstatus');
|
uiUpdateOnce();
|
||||||
document.getElementById("streamTitle").innerHTML = data.streamTitle
|
}, 1000);
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateStreamTitle(value) {
|
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',
|
response = await fetch('http://127.0.0.1:5000/api/update/streamtitle',
|
||||||
{
|
{
|
||||||
method:'POST',
|
method:'POST',
|
||||||
body:JSON.stringify(value)
|
body:JSON.stringify(value)
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
await uiUpdate()
|
await uiUpdateOnce();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function Main() {
|
async function Main() {
|
||||||
await uiUpdate()
|
await uiUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
Main()
|
continuousUiUpdate()
|
||||||
|
|
Loading…
Reference in New Issue