From 0c282eaf59afd1d060c85d0ebb3c99fe9dbad581 Mon Sep 17 00:00:00 2001 From: "Glitch (hello-express)" Date: Thu, 9 Apr 2020 12:16:21 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8D=A2=F0=9F=91=97=20Checkpoint=20./room.?= =?UTF-8?q?js:530995/263=20./server.js:530995/2484=20./views/room.handleba?= =?UTF-8?q?rs:530995/81=20./public/style.css:530995/227=20./views/audience?= =?UTF-8?q?.handlebars:530995/2587?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/style.css | 16 ++++++++++++++++ room.js | 11 ++++++++++- server.js | 7 +++++++ views/audience.handlebars | 29 +++++++++++++++++++++++++++++ views/room.handlebars | 2 +- 5 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 views/audience.handlebars diff --git a/public/style.css b/public/style.css index 61623ab..f7ae227 100644 --- a/public/style.css +++ b/public/style.css @@ -66,4 +66,20 @@ footer { font-size: 4em; color: white; text-shadow: 2px 2px 2px black; +} + +h2 img { + max-height: 40px; +} + +figure.participant { + display: inline-block; +} + +figure.participant img { + max-height: 150px; +} +figure.participant figcaption { + font-weight: bold; + font-size: 1.3em; } \ No newline at end of file diff --git a/room.js b/room.js index 7d012a0..a34878a 100644 --- a/room.js +++ b/room.js @@ -1,6 +1,14 @@ 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; +} + function getOrCreateRoom(roomId) { let room = rooms[roomId]; @@ -8,7 +16,7 @@ function getOrCreateRoom(roomId) { room = { roomId: roomId, participants: [], - characters: + characters: shuffle(chars) }; rooms[roomId] = room; } @@ -22,6 +30,7 @@ function addParticipant(roomId, participantId, participantName) { room.participants.push({ participantId, participantName, + character: room.characters[room.participants.length] }); rooms[roomId] = room; diff --git a/server.js b/server.js index cef15fb..db6129d 100644 --- a/server.js +++ b/server.js @@ -44,12 +44,19 @@ app.get("/:roomId/join", (request, response) => { name: participant.participantName, participantName: participant.participantName, participantId: participant.participantId, + character: participant.character, }); } else { 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 }); +}); + app.post("/:roomId/join", (request, response) => { rooms.addParticipant(request.params.roomId, request.fingerprint.hash, request.body.name); response.redirect(`/${request.params.roomId}/join`); diff --git a/views/audience.handlebars b/views/audience.handlebars new file mode 100644 index 0000000..436d1bc --- /dev/null +++ b/views/audience.handlebars @@ -0,0 +1,29 @@ + + + + + Buzzer + + + + + + + + +
+

{{room}}

+
+ +
+

Participants

+ + {{#each participants}} +
+ +
{{this.participantName}}
+
+ {{/each}} +
+ + diff --git a/views/room.handlebars b/views/room.handlebars index 1d43f64..1bc1fbc 100644 --- a/views/room.handlebars +++ b/views/room.handlebars @@ -16,7 +16,7 @@
-

Oh hi, {{name}}

+

Oh hi, {{name}}