diff --git a/README.md b/README.md deleted file mode 100644 index 887720b..0000000 --- a/README.md +++ /dev/null @@ -1,30 +0,0 @@ -# hello-express - -A server that serves a webpage, its resources, and some data - - -## Your Project - -On the front-end, - -- Edit `views/index.html` to change the content of the webpage -- `public/client.js` is the javacript that runs when you load the webpage -- `public/style.css` is the styles for `views/index.html` -- Drag in `assets`, like images or music, to add them to your project - -On the back-end, - -- your app starts at `server.js` -- add frameworks and packages in `package.json` -- safely store app secrets in `.env` (nobody can see this but you and people you invite) - -Click `Show` in the header to see your app live. Updates to your code will instantly deploy. - - -## Made by [Glitch](https://glitch.com/) - -**Glitch** is the friendly community where you'll build the app of your dreams. Glitch lets you instantly create, remix, edit, and host an app, bot or site, and you can invite collaborators or helpers to simultaneously edit code with you. - -Find out more [about Glitch](https://glitch.com/about). - -( ᵔ ᴥ ᵔ ) \ No newline at end of file diff --git a/package.json b/package.json index b2c5d3d..e7c521e 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,6 @@ { - "//1": "describes your app and its dependencies", - "//2": "https://docs.npmjs.com/files/package.json", - "//3": "updating this file will download and update your packages", - "name": "hello-express", + "name": "buzzers", "version": "0.0.1", - "description": "A simple Node app built on Express, instantly up and running.", "main": "server.js", "scripts": { "start": "node server.js" @@ -18,14 +14,5 @@ }, "engines": { "node": "12.x" - }, - "repository": { - "url": "https://glitch.com/edit/#!/hello-express" - }, - "license": "MIT", - "keywords": [ - "node", - "glitch", - "express" - ] + } } \ No newline at end of file diff --git a/public/script.js b/public/script.js deleted file mode 100644 index e69de29..0000000 diff --git a/room.js b/room.js index 6c501af..25111b8 100644 --- a/room.js +++ b/room.js @@ -2,11 +2,11 @@ const chars = require('./characters.json'); const rooms = {}; function shuffle(a) { - for (let i = a.length - 1; i > 0; i--) { - const j = Math.floor(Math.random() * (i + 1)); - [a[i], a[j]] = [a[j], a[i]]; - } - return a; + for (let i = a.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [a[i], a[j]] = [a[j], a[i]]; + } + return a; } function getOrCreateRoom(roomId) { diff --git a/server.js b/server.js index 5ee5b20..2fc8638 100644 --- a/server.js +++ b/server.js @@ -11,11 +11,7 @@ const app = express(); const server = http.createServer(app); app.use(Fingerprint({ - parameters:[ - Fingerprint.useragent, - Fingerprint.acceptHeaders, - Fingerprint.geoip - ] + parameters: [Fingerprint.useragent, Fingerprint.acceptHeaders, Fingerprint.geoip] })); app.use(bodyParser.json()); @@ -33,7 +29,6 @@ app.get("/", (request, response) => { }); app.get("/:roomId/join", (request, response) => { - let room = rooms.getOrCreateRoom(request.params.roomId); let participant = room.participants.find(p => p.participantId === request.fingerprint.hash); @@ -47,13 +42,12 @@ app.get("/:roomId/join", (request, response) => { character: participant.character, }); } else { - response.render('join', {layout: false, room: request.params.roomId}); + response.render('join', {layout: false, room: request.params.roomId}); } }); app.get("/:roomId/audience", (request, response) => { let room = rooms.getOrCreateRoom(request.params.roomId); - response.render('audience', {layout: false, room: request.params.roomId, participants: room.participants }); }); @@ -63,20 +57,19 @@ app.post("/:roomId/join", (request, response) => { }); server.listen(process.env.PORT, () => { - console.log("Your app is listening on port " + server.address().port); + console.log("Your app is listening on port " + server.address().port); }); - const wss = new WebSocket.Server({ server }); + wss.on('connection', (ws, req) => { - let participant; let roomId = req.url.substring(1); if (roomId.includes("/audience")) { roomId = roomId.replace("/audience", ""); - rooms.addAudienceWS(roomId, ws); } else { + let participant; ws.on('message', (message) => { message = JSON.parse(message); if (message.type === "join") { @@ -89,9 +82,10 @@ wss.on('connection', (ws, req) => { } }); - ws.on('close', () => { - rooms.removeParticipant(roomId, participant.participantId); + if (participant) { + rooms.removeParticipant(roomId, participant.participantId); + } }); } }); \ No newline at end of file diff --git a/views/audience.handlebars b/views/audience.handlebars index db16f1a..b8393d1 100644 --- a/views/audience.handlebars +++ b/views/audience.handlebars @@ -5,10 +5,8 @@ Buzzers - - + -
diff --git a/views/index.handlebars b/views/index.handlebars index 2bd1172..46064f1 100644 --- a/views/index.handlebars +++ b/views/index.handlebars @@ -5,10 +5,8 @@ Buzzers - - + -
diff --git a/views/join.handlebars b/views/join.handlebars index 83bd543..27357b9 100644 --- a/views/join.handlebars +++ b/views/join.handlebars @@ -5,10 +5,8 @@ Buzzers - - + -
diff --git a/views/room.handlebars b/views/room.handlebars index f2c79c5..b150f56 100644 --- a/views/room.handlebars +++ b/views/room.handlebars @@ -5,10 +5,8 @@ Buzzers - - + -