aboutsummaryrefslogtreecommitdiff
path: root/priv/static/room/displayState.js
diff options
context:
space:
mode:
authorArjun Satarkar <me@arjunsatarkar.net>2024-07-26 14:20:14 +0000
committerArjun Satarkar <me@arjunsatarkar.net>2024-07-26 14:23:53 +0000
commitcd794243a5bba358d995e26ba024268e7d5d3f85 (patch)
tree2df6974cc40f736441f7b985ca95a7f897f4510e /priv/static/room/displayState.js
parent37ab5213a368926506206cb21a438cb7fea3d530 (diff)
downloadmediasync-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.js25
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);
+})();