diff --git a/html/demo.js b/html/demo.js index 3c36c55..e4c7e89 100644 --- a/html/demo.js +++ b/html/demo.js @@ -86,6 +86,33 @@ function joinBucket(i) { } } +function server_api_path() { + return new URL(serverPath.value, document.location).href; +} + +function updateCurrentUsers() { + var xhr = new XMLHttpRequest(); + xhr.open('POST', server_api_path() + "?action=status", true); + xhr.onreadystatechange = function () { + if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { + const x_audio_metadata = JSON.parse(this.getResponseHeader( + "X-Audio-Metadata")); + let roomText = "The room is currently empty."; + if (x_audio_metadata.n_connected_users) { + if (x_audio_metadata.n_connected_users == 1) { + roomText = "There is currently 1 person in the room."; + } else { + roomText = "There are currently " + x_audio_metadata.n_connected_users + + " people in the room."; + } + } + window.currentUsers.innerText = roomText; + } + }; + xhr.send(); +} +updateCurrentUsers(); + const user_bucket_index = {}; // userid -> bucket index (-1 means unbucketed) const bucket_divs = []; // bucket index -> bucket div @@ -1337,7 +1364,7 @@ function connect_twilio() { } async function start_singing() { - var final_url = new URL(serverPath.value, document.location).href; + var final_url = server_api_path(); singer_client = new bb.SingerClient({ context: bucket_ctx, diff --git a/html/index.html b/html/index.html index f92715e..c4f2d02 100644 --- a/html/index.html +++ b/html/index.html @@ -648,7 +648,7 @@

Settings that affect everyone

Welcome! This is a program for singing with people over the - Internet. + Internet.


diff --git a/server.py b/server.py index cbe6e5c..ad59fbd 100755 --- a/server.py +++ b/server.py @@ -36,6 +36,12 @@ SUPPORT_SERVER_CONTROL = False +# The maximum number of users to allow to join. This is enforced on a +# best-effort basis by the client. If many people are calibrating at +# the same time this will be exceeded, because we only check before +# calibration. +MAX_USERS = 22 # XXX needs tuning + try: # Grab these on startup, when they are very very likely to be the actual # running version. @@ -881,6 +887,13 @@ def handle_post(in_data, query_string, print_status, client_address=None) -> Tup raw_params = urllib.parse.parse_qs(query_string, strict_parsing=True) query_params = clean_query_params(raw_params) + action = query_params.get("action", None) + if action == "status": + return np.zeros(0, np.uint8), json.dumps({ + "n_connected_users": len(active_users()), + "max_users": MAX_USERS, + }) + userid = query_params.get("userid", None) if userid is not None: if int(userid) < 0 or int(userid) > 0xffff_ffff_ffff_ffff: