react-firebase-chat
react-firebase-chat copied to clipboard
Show # of users connected
It would be nice to know the number of users currently connected in the chat.
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.
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, but wouldn't that overload the server?
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
Maybe with the help of socket's but then there will be need to set up backend.
should use socket. Check Travser video on youtube
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.
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.