📺🌘 Checkpoint

./views/room.handlebars:530995/1530
./server.js:530995/548
./public/style.css:530995/195
This commit is contained in:
Glitch (hello-express) 2020-04-09 11:28:30 +00:00
parent cd9cb268ef
commit 385214f520
3 changed files with 40 additions and 23 deletions

View File

@ -54,3 +54,11 @@ footer {
padding-top: 1.5em; padding-top: 1.5em;
border-top: 1px solid lightgrey; border-top: 1px solid lightgrey;
} }
#buzzer {
width: 90vw;
height: 90vh;
margin: 0 auto;
border-radius: 100%;
background: red;
}

View File

@ -58,11 +58,16 @@ server.listen(process.env.PORT, () => {
const wss = new WebSocket.Server({ server }); const wss = new WebSocket.Server({ server });
wss.on('connection', (ws, req) => { wss.on('connection', (ws, req) => {
let participant;
ws.on('message', (message) => { ws.on('message', (message) => {
message = JSON.stringify(message); message = JSON.parse(message);
console.log(message) if (message.type === "join") {
console.log(message.type) participant = message.data;
console.log(message.data) ws.send('Joined as ' + participant.participantName);
}
if (message.type === "buzz") {
// TODO: Handle Buzzer
}
}); });
ws.send('Connected'); ws.send('Connected');

View File

@ -27,22 +27,26 @@
let socket = new WebSocket(`wss://${window.location.hostname}`); let socket = new WebSocket(`wss://${window.location.hostname}`);
socket.onopen = function(e) { socket.onopen = function(e) {
socket.send({ socket.send(JSON.stringify({
type: "join", type: "join",
data: { data: {
participantId: '{{participantId}}', participantId: '{{participantId}}',
participantName: '{{participantName}}', participantName: '{{participantName}}',
} }
}); }));
}; };
socket.onmessage = function(event) { socket.onmessage = function(event) {
console.log(event.message);
}; };
socket.onerror = function(error) { socket.onerror = function(error) {
alert(`[error] ${error.message}`); alert(`[error] ${error.message}`);
}; };
document.getElementById('buzzer').addEventListener('mousedown', function() {
socket.send(JSON.stringify({ type: "buzz" }));
});
</script> </script>
</body> </body>
</html> </html>