diff options
author | Arjun Satarkar <me@arjunsatarkar.net> | 2024-07-26 14:20:14 +0000 |
---|---|---|
committer | Arjun Satarkar <me@arjunsatarkar.net> | 2024-07-26 14:23:53 +0000 |
commit | cd794243a5bba358d995e26ba024268e7d5d3f85 (patch) | |
tree | 2df6974cc40f736441f7b985ca95a7f897f4510e /priv/static/room/displayState.js | |
parent | 37ab5213a368926506206cb21a438cb7fea3d530 (diff) | |
download | mediasync-cd794243a5bba358d995e26ba024268e7d5d3f85.tar mediasync-cd794243a5bba358d995e26ba024268e7d5d3f85.tar.gz mediasync-cd794243a5bba358d995e26ba024268e7d5d3f85.zip |
Add Discord Activity functionality (mostly) + general improvements
Diffstat (limited to 'priv/static/room/displayState.js')
-rw-r--r-- | priv/static/room/displayState.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/priv/static/room/displayState.js b/priv/static/room/displayState.js new file mode 100644 index 0000000..3a5e923 --- /dev/null +++ b/priv/static/room/displayState.js @@ -0,0 +1,25 @@ +"use strict"; + +(() => { + const INTERVAL_MILLISECONDS = 3000; + + setInterval(() => { + const stateElement = document.getElementsByClassName("state-element").item(0); + if (stateElement !== null) { + fetch(STATE_URL) + .then((response) => { + if (!response.ok) { + throw new Error(`Error: fetching state returned ${response.status}`); + } + return response.json(); + }) + .then((json) => { + const viewersConnected = json.viewersConnected; + stateElement.dataset.text = `total viewers: ${viewersConnected}`; + }) + .catch((_) => { + stateElement.dataset.text = STATE_ELEMENT_INITIAL_TEXT; + }); + } + }, INTERVAL_MILLISECONDS); +})(); |