Answer the question
In order to leave comments, you need to log in
Does socket.io have a client layer?
Each tab in the browser on the server is represented by a unique socket object. I would like not to work with such a connection, but to work with a set of sockets as with 1 client of the subject area.
While solved it by means of rooms (room). All sockets of one client get to 1 room and the message for this client goes to this room. But for some reason it seems that this is a crutch option and it can be done easier.
Answer the question
In order to leave comments, you need to log in
Do it with an array. Let's say you get a user id when connecting to socket.io.
Write it to an object.
var clients = {}; // global variable node
... соединение {
('u' + user_id in clients ? client['u' + user_id] : clients['u' + user_id] = []).push(socket.id);
... }
{
'u1': [socket_id_hash_one, socket_id_hash_two]
}
var clients = {}; // global variable node
... соединение {
('u' + user_id in clients ? client['u' + user_id] : clients['u' + user_id] = []).push(socket.id);
... }
...
setInterval(function () {
// io.eio.clientsCount — количество подключенных клиентов
// io.eio.clients — список socket_id подключенных клиентов
// на основании пишем цикл, который изменяет объект clients в зависимости от io.eio.clients
// на этом основании можно сделать user online list
}, 500);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question