Y
Y
Yurka Blokhin2016-06-25 12:48:46
JavaScript
Yurka Blokhin, 2016-06-25 12:48:46

How to display a list of users who are online on the site?

Hello!
I make a chat on nodejs + socket, I use passportjs for authorization. Tell me how to implement the output of a list of unique users who have visited the site and are online. I need to take into account that the user can log in and out from different devices, thereby:

user = {};
socket.on('connect', function() {
    user++
});
socket.on('disconnect', function() {
    user--
});

does not work as desired.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2016-06-26
@Vovchikvoin

Generate a custom token for each user and use it as a key to write to the users object. And as it turns out, remove it from there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question