duplicate user fix
This commit is contained in:
		
							parent
							
								
									08c66deaf0
								
							
						
					
					
						commit
						773e175288
					
				
							
								
								
									
										10
									
								
								src/index.ts
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/index.ts
									
									
									
									
									
								
							@ -37,6 +37,16 @@ io.on("connection", (socket: Socket) => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  // Handle user-online event
 | 
					  // Handle user-online event
 | 
				
			||||||
  socket.on("user-online", (user: any) => {
 | 
					  socket.on("user-online", (user: any) => {
 | 
				
			||||||
 | 
					    // console.log("User online:", user);
 | 
				
			||||||
 | 
					    // Check if the same user exists in the map
 | 
				
			||||||
 | 
					    for (const [key, value] of onlineUsers.entries()) {
 | 
				
			||||||
 | 
					      console.log("value", value);
 | 
				
			||||||
 | 
					      if (value.userId === user.userId) {
 | 
				
			||||||
 | 
					        // Assuming user object has an 'id' property
 | 
				
			||||||
 | 
					        onlineUsers.delete(key);
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    // Now we store the socket ID along with the user details
 | 
					    // Now we store the socket ID along with the user details
 | 
				
			||||||
    onlineUsers.set(socket.id, { ...user, socketId: socket.id });
 | 
					    onlineUsers.set(socket.id, { ...user, socketId: socket.id });
 | 
				
			||||||
    io.emit("online-users", Array.from(onlineUsers.values()));
 | 
					    io.emit("online-users", Array.from(onlineUsers.values()));
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user