Added basic user list, Boing and Kirbeep buzzers as well as some refactoring and ui adjustments

This commit is contained in:
Samuel Kent
2022-12-27 09:30:49 +11:00
parent ced7fa5092
commit 252fa97606
15 changed files with 143 additions and 105 deletions
+29 -5
View File
@@ -1,23 +1,25 @@
// const http = require('http');
const https = require('https');
const http = require('http');
// const https = require('https');
const express = require('express');
const app = express();
const fs = require('fs')
const { Server } = require("socket.io");
var options = {
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem')
// key: fs.readFileSync('key.pem'),
// cert: fs.readFileSync('cert.pem')
};
const server = https.createServer(options, app);
const server = http.createServer(options, app);
const io = new Server(server, {
maxHttpBufferSize: 1e8
});
const userMap = new Map();
let buzzList = [];
let playerList = [];
let chaserList = [];
const teamsList = ["Players","Chasers"]
const teamsScore = [0,0]
@@ -58,6 +60,24 @@ io.on("connection", (socket) => {
//todo ping test
io.emit("clearBuzzers", teamsList[currentTeamNumber]);
});
socket.on("registerUser", (userName, teamName) => {
console.log("reg");
if (teamName == "Players") {
if (!playerList.includes(userName)) {
playerList.push(userName);
}
}
else if (teamName == "Chasers") {
if (!chaserList.includes(userName)) {
chaserList.push(userName);
}
}
io.emit("userListsToClient", playerList, chaserList);
});
// socket.emit("playerRoundScoreToClient");
// socket.emit("chaserRoundScoreToClient");
// socket.emit("currentTeamToClient");
@@ -80,6 +100,10 @@ app.get("/play", (request, response) => {
response.sendFile("pages/play.html", {root: __dirname });
});
app.get("/browserFunctions.js", (request, response) => {
response.sendFile("browserFunctions.js", {root: __dirname });
});
//all files in these folders can be accessed with a GET request of the filename
let assetFolders = ["styles","pages","images","audio"];
assetFolders.forEach((folderName) => {