@@ -4,6 +4,7 @@ dotenv.config();
44export let loggedInUsers = [ ] //{email: [array of socket ids]}
55let io
66
7+ console . log ( loggedInUsers ) ;
78
89const addLoggedInUser = ( email , socketId ) => {
910 const user = loggedInUsers . find ( user => user . email === email )
@@ -43,10 +44,15 @@ export const socketConnection = (server) => {
4344
4445 socket . on ( "successfulLogin" , ( { email } ) => {
4546 addLoggedInUser ( email , socket . id ) ;
47+ console . log ( loggedInUsers ) ;
48+
4649 } ) ;
47- socket . on ( "succesfulLogout" , ( { email } ) => {
50+
51+ socket . on ( "successfulLogout" , ( { email } ) => {
4852 removeLoggedInUser ( email , socket . id ) ;
53+ console . log ( loggedInUsers ) ;
4954 } ) ;
55+
5056 socket . on ( "disconnect" , ( ) => {
5157 loggedInUsers = loggedInUsers
5258 . map ( ( user ) => {
@@ -55,5 +61,28 @@ export const socketConnection = (server) => {
5561 } )
5662 . filter ( ( user ) => user . socketId . length > 0 ) ;
5763 } ) ;
64+
65+ // // Handle message seen event
66+ // socket.on("messageSeen", ({ chatID, messageID, email }) => {
67+ // // Notify other users in the chat that the message has been seen
68+ // const user = loggedInUsers.find(user => user.email === email);
69+ // if (user) {
70+ // user.socketId.forEach((receiverSocket) => {
71+ // io.to(receiverSocket).emit("messageSeen", { chatID, messageID });
72+ // });
73+ // }
74+ // });
75+
76+ // // Handle typing status event
77+ // socket.on("typingStatus", ({ chatID, email, isTyping }) => {
78+ // // Broadcast typing status to other users in the chat
79+ // const user = loggedInUsers.find(user => user.email === email);
80+ // if (user) {
81+ // user.socketId.forEach((receiverSocket) => {
82+ // io.to(receiverSocket).emit("typingStatus", { chatID, email, isTyping });
83+ // });
84+ // }
85+ // });
86+
5887 } ) ;
5988} ;
0 commit comments