I am using socket.io to make a chat application where I need to show the current user list. Till now it is working fine with the current user list being displayed
I am using this code for maintaining the user list
usernames[socket.id] = name;//where name is the name of the user
Then on disconnect I am again deleting that user from the list
delete usernames[socket.id];
But, my problem with this method is that suppose there are three users a,b and c
now the userlist will be populated on the connection event,something like this
io.sockets.on('connection', function(socket) {
...
socket.on('register', function(name) {
usernames[socket.id] = name;
And the user list will be something like "a,b and c"
But, what I want is that for user "a" the list should show "b and c" and for "b" it should be "a and c" and for "c" it should be "a and b".
I also thought about removing it on the client side based on some variable which stores the name of the user who is viewing it but for this chat multiple users can have the same name. So if suppose all the three have name "a" then it will remove all three instead of removing only one name from the list.
....I guess I am out of ideas on this one. Plz help me to implement it in socket.io