From 431c1a54e72a7b214d0bc0e19e458aa1f14c27e5 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Wed, 17 Jun 2020 16:35:47 -0700 Subject: [PATCH] Split out status polling into own file --- webroot/index.html | 3 ++- webroot/js/app.js | 32 -------------------------------- webroot/js/status.js | 31 +++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 33 deletions(-) create mode 100644 webroot/js/status.js diff --git a/webroot/index.html b/webroot/index.html index a8ce1fea5..ca37ab3d6 100644 --- a/webroot/index.html +++ b/webroot/index.html @@ -155,12 +155,13 @@ GW TODO: - + + \ No newline at end of file diff --git a/webroot/js/app.js b/webroot/js/app.js index d485d653c..3cdcd38c1 100644 --- a/webroot/js/app.js +++ b/webroot/js/app.js @@ -29,38 +29,6 @@ async function setupApp() { app.title = config.title; } -async function getStatus() { - const url = "/status"; - - try { - const response = await fetch(url); - const status = await response.json(); - - if (!app.isOnline && status.online) { - // The stream was offline, but now it's online. Force start of playback after an arbitrary - // delay to make sure the stream has actual data ready to go. - setTimeout(function () { - restartPlayer(); - }, 3000) - - } - - app.streamStatus = status.online - ? "Stream is online." - : "Stream is offline." - - app.viewerCount = status.viewerCount; - app.sessionMaxViewerCount = status.sessionMaxViewerCount; - app.overallMaxViewerCount = status.overallMaxViewerCount; - app.isOnline = status.online; - - } catch (e) { - app.streamStatus = "Stream server is offline." - app.viewerCount = 0 - } - -} - var websocketReconnectTimer; function setupWebsocket() { clearTimeout(websocketReconnectTimer) diff --git a/webroot/js/status.js b/webroot/js/status.js new file mode 100644 index 000000000..347eba18c --- /dev/null +++ b/webroot/js/status.js @@ -0,0 +1,31 @@ +async function getStatus() { + const url = "/status"; + + try { + const response = await fetch(url); + const status = await response.json(); + + if (!app.isOnline && status.online) { + // The stream was offline, but now it's online. Force start of playback after an arbitrary + // delay to make sure the stream has actual data ready to go. + setTimeout(function () { + restartPlayer(); + }, 3000) + + } + + app.streamStatus = status.online + ? "Stream is online." + : "Stream is offline." + + app.viewerCount = status.viewerCount; + app.sessionMaxViewerCount = status.sessionMaxViewerCount; + app.overallMaxViewerCount = status.overallMaxViewerCount; + app.isOnline = status.online; + + } catch (e) { + app.streamStatus = "Stream server is offline." + app.viewerCount = 0 + } + +} \ No newline at end of file