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 @@ + + +
+ +