buzzers/room.js
Glitch (hello-express) 1abee4f9d7 🤖🍲 Checkpoint
./room.js:530995/86
./server.js:530995/1413
./package.json:530995/1484
./views/room.handlebars:530995/1594
2020-04-09 11:04:28 +00:00

29 lines
478 B
JavaScript

const rooms = {};
function getOrCreateRoom(roomId) {
let room = rooms[roomId];
if (!room) {
room = {
roomId: roomId,
participants: []
};
rooms[roomId] = room;
}
return room;
}
function addParticipant(roomId, participantId, participantName) {
let room = getOrCreateRoom(roomId);
room.participants.push({
participantId,
participantName,
});
rooms[roomId] = room;
}
module.exports = {getOrCreateRoom, addParticipant}