1

I m using nodejs (0.8.15) and socket.io (0.9) I m creating chat with rooms and namespaces. So, the problems are:

1) Every time when users enter some room, they need to view list of online users in this room. On wiki https://github.com/LearnBoost/socket.io/wiki/Rooms i read that i can get list of client's socket id io.sockets.clients('room'), but users have nick names, and i store them like this:

var io = io.listen(server);
var chat = io.of('/chat').on('connection', function (socket) {
{
  socket.on('user-entered-to-chat', function(nickname) {
    // how i store nickname
    socket.nickname = nickname;
    ...
    // i need do something here or above to make array of nicknames
    socket.emit('get-users-list`, array);
  }
});

Q: How to access to every persons socket to get their information like nickname?

Of course, i can save nicknames with their socket.id in database, but i don't want go this way.

2) Also, i can declace var nicknames=[]; somewhere on the top of code, but what if i have 500+ users in one room online - Is it a good way? will it work with 500+?

I thought chat variable for all users and i tried to write in var chat.nicknames=[] all nicknames, but it did't work. It didn't work also for io.sockets.nicknames = []. Every user has his own chat.

3) Where stores all information/data about sockets? For example, list of clients in room. On my nodejs server/computer?

thank you

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.