react-firebase-chat icon indicating copy to clipboard operation
react-firebase-chat copied to clipboard

Show # of users connected

Open vybezi opened this issue 4 years ago • 8 comments

It would be nice to know the number of users currently connected in the chat.

vybezi avatar Sep 23 '20 18:09 vybezi

As far as I am sure, it is currently really hard to determine the number of online users. I suppose there could be a way of checking the number of active authentication tokens from Google(?), however, I do not think Google would allow that.

chmus avatar Sep 24 '20 19:09 chmus

You could make something like an xhttp request to an endpoint that never ends (It stops when the browser gets closed). This way, you can see how many people are currently connected to the chat. I don't think there is an easy solution for this.

Paultje52 avatar Sep 24 '20 19:09 Paultje52

@Paultje52, but wouldn't that overload the server?

chmus avatar Sep 24 '20 20:09 chmus

Don't think so. The server only needs to send and revive ping packets and keep track when a client gets disconnected. It should be possible, but I never tested something like this with hundreds of people all connected at the same time.

It would be very tricky xD

Paultje52 avatar Sep 24 '20 21:09 Paultje52

Maybe with the help of socket's but then there will be need to set up backend.

PrasadBroo avatar Oct 05 '20 13:10 PrasadBroo

should use socket. Check Travser video on youtube

wetech16 avatar Dec 14 '20 22:12 wetech16

We can create a collection of number of people signin/out in firestore. When sign in&sign out function called, update that collection. Then use useCollectionData() like the message to fetch data from that collection whenever there is a change.

wetech16 avatar Dec 24 '20 17:12 wetech16

Or, one just can add lastSeen property, and each of the online clients should send a clientOnline request every 5 seconds. And as for the total number, the server should count all clients with lastSeen no older than 5-10 seconds (some might have an unstable network).

Note: I did not think about this idea too much. Therefore there might be some points which I missed, indeed.

PrimeofTech avatar Dec 24 '20 21:12 PrimeofTech