I have created a realtime chat application similar to facebook using PHP/MySQL and node.js (socket.io) but i am now facing the following problem.
Scenario
The logged in user has a list of friends similar to facebook and when any of his friends becomes away, offline, online etc. i would like his friends list to be updated with this in realtime without reloading the entire friends list with for example ajax polling every x seconds.
Every action the logged in user makes on the website like for example the change of page, new chat window, search or whatever i have a column named last_active
that updates with the current unix_timestamp.
This is done to keep track of the user being online or away. If the timestamp is bigger than 300 seconds the user i away.
Every thirty seconds the database updates the column last_online
with unix_timestamp for the logged in user.
This is done to keep track of the user being online. If the timestamp is bigger than 35 seconds we can assume he has closed the window and will be seen as offline and not away.
The user can also set his online status manually to busy, invisible etc. and this is set to the column custom_status
for the logged in user.
Everything above is working as it should provided that the user always reload the page to see what online status his friends have but i would like this to be updated in realtime and not when reloading the entire page or using ajax polling to reload the entire friends list.
I was thinking about comparing the current online status on the client side and when a change occurs emit this to socket.io. I then loop through all connected clients and emit the users new online status to all connected friends.
But i guess there will be performance issues with this when say for example 1000 users are connected?
How would you handle this?
Aucun commentaire:
Enregistrer un commentaire