Show waiting players during practice

This commit is contained in:
2026-05-08 13:29:49 -04:00
parent 4631f9b7c5
commit 48b619e92b
3 changed files with 76 additions and 7 deletions

View File

@@ -76,6 +76,15 @@ const server = http.createServer((request, response) => {
return;
}
if (requestUrl.pathname === "/lobby") {
response.writeHead(200, {
"Cache-Control": "no-store",
"Content-Type": "application/json; charset=utf-8",
});
response.end(request.method === "HEAD" ? undefined : JSON.stringify(lobbyStatus()));
return;
}
const staticName = staticFiles.get(requestUrl.pathname);
if (!staticName) {
response.writeHead(404);
@@ -257,6 +266,13 @@ function pairClients(xClient, oClient) {
send(oClient, { type: "paired", player: "O", roomId });
}
function lobbyStatus() {
return {
activeGames: rooms.size,
waitingPlayers: waitingClientId && clients.has(waitingClientId) ? 1 : 0,
};
}
function handleSocketData(client, buffer) {
if (!clients.has(client.id)) {
return;