💽👫 Checkpoint
./server.js:530995/100 ./room.js:530995/323 ./views/room.handlebars:530995/140
This commit is contained in:
parent
645e0f11e5
commit
5bf6096180
14
room.js
14
room.js
@ -41,4 +41,16 @@ function addParticipantWS(roomId, participantId, ws) {
|
||||
room.participants.find(p => p.participantId === participantId).ws = ws;
|
||||
}
|
||||
|
||||
module.exports = {getOrCreateRoom, addParticipant, addParticipantWS}
|
||||
function buzz(roomId, participant) {
|
||||
let room = getOrCreateRoom(roomId);
|
||||
room.participants.forEach(p => {
|
||||
if (p.ws) {
|
||||
p.ws.send(JSON.stringify({
|
||||
type: "buzz",
|
||||
participant: participant.participantName
|
||||
}));
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {getOrCreateRoom, addParticipant, addParticipantWS, buzz}
|
@ -80,8 +80,8 @@ wss.on('connection', (ws, req) => {
|
||||
ws.send('Joined as ' + participant.participantName);
|
||||
}
|
||||
if (message.type === "buzz") {
|
||||
// TODO: Handle Buzzer
|
||||
console.log(`${participant.participantName} buzzed!`)
|
||||
rooms.buzz(roomId, participant);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -36,8 +36,11 @@
|
||||
}));
|
||||
};
|
||||
|
||||
socket.onmessage = function(event) {
|
||||
console.log(event);
|
||||
socket.onmessage = function(msg) {
|
||||
msg = JSON.parse(msg);
|
||||
if (msg.type === "buzz") {
|
||||
alert(`${msg.participant} buzzed`);
|
||||
}
|
||||
};
|
||||
|
||||
socket.onerror = function(error) {
|
||||
|
Loading…
Reference in New Issue
Block a user