2020-04-09 10:42:19 +00:00
|
|
|
|
|
|
|
const rooms = {};
|
|
|
|
|
2020-04-09 10:53:21 +00:00
|
|
|
function getOrCreateRoom(roomId) {
|
2020-04-09 10:42:19 +00:00
|
|
|
let room = rooms[roomId];
|
|
|
|
|
|
|
|
if (!room) {
|
|
|
|
room = {
|
|
|
|
roomId: roomId,
|
|
|
|
participants: []
|
|
|
|
};
|
|
|
|
rooms[roomId] = room;
|
|
|
|
}
|
|
|
|
|
|
|
|
return room;
|
|
|
|
}
|
|
|
|
|
2020-04-09 10:53:21 +00:00
|
|
|
function addParticipant(roomId, participantId, participantName) {
|
|
|
|
let room = getOrCreateRoom(roomId);
|
|
|
|
|
|
|
|
room.participants.push({
|
|
|
|
participantId,
|
|
|
|
participantName,
|
|
|
|
});
|
2020-04-09 10:42:19 +00:00
|
|
|
|
2020-04-09 10:53:21 +00:00
|
|
|
rooms[roomId] = room;
|
|
|
|
}
|
|
|
|
|
2020-04-09 11:04:28 +00:00
|
|
|
module.exports = {getOrCreateRoom, addParticipant}
|