Showing posts with label active users. Show all posts
Showing posts with label active users. Show all posts

Saturday, March 12, 2011

Facebook type getting a list of all logged in active users in realtime

Hi,

If you have used social networks such as facebook. They have a feature of showing all your friends who are online. I have made a custom code to achieve the same. But in my case instead of seeing online friends, I am checking for all online users. But of course you can change that logic to serve your purpose. You will find the code at the bottom of this page, but first let me explain what is happening.

By default i have created the following users:


To demonstrate this, I need to open atleast 2 different browsers. I am using Chrome for hasan/hasan login to see what happens:
In this the user sees 3 inactive users. Now I will login using user/user credentials in Safari. Following is what happened without page refresh in the above screen:
Now if the second user instead of logout, just closes the window, or tab then again in few seconds the first user will get the following: