Skip to content

Commit

Permalink
Update custom-event-handlers.js
Browse files Browse the repository at this point in the history
  • Loading branch information
sunil-singularityx authored Feb 11, 2024
1 parent 86a65b6 commit a6ea647
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions server/custom-event-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ exports.handleConnection = (socket) => {

exports.handleJoinRoom = (socket, data) => {
const { userName, roomID } = data;


const isAlreadyInRoom = onlineUsers[socket.id]?.room === roomID;

Expand Down Expand Up @@ -83,6 +84,7 @@ const leaveCurrentRoom = (socket) => {
return;
}


announceUserAction(socket, roomID, 'left');
removeParticipantFromLists(socket, roomID);

Expand All @@ -92,11 +94,13 @@ const leaveCurrentRoom = (socket) => {
const removeParticipantFromLists = (socket, roomID) => {
delete onlineUsers[socket.id].room;
delete rooms[roomID].participants[socket.id];

}

const announceUserAction = (socket, roomID, action) => {
const userName = rooms[roomID].participants[socket.id].userName;
const text = `${ userName } has ${ action } the chat`;


this.handleSendMessage(socket, { text, roomID });
}

0 comments on commit a6ea647

Please sign in to comment.