javascriptjqueryruby-on-railsruby-on-rails-3faye

See and talk to your currently online users on your site in a Ruby on Rails 3 application


I have a Ruby on Rails 3 application, and I want to be able to see a list of who is currently online. For example user1, IP address, and country. I then want to be able to open a chat / push messages to this user until they leave my site.

How can I accurately monitor who is currently on the site and instantly remove the user from the list when they leave?

I then can talk to them via faye pub/sub.


Solution

  • How can I accurately monitor who is currently on the site and instantly remove from list when they leave?

    Well using HTTP you can not do this "instantly" in a browser. Almost all solutions I see use a heartbeat technique. Every X seconds, a request is sent from the browser (using Ajax), that tells if the user is online. If you haven't heard from the user in x heartbeats, you regard the user as disconnected - even Facebook uses this, it seems. I will recommend you to drop your requirement for instant, unless it's really important.

    Another approach is to implement Flash or Silverlight, to make a socket connection to the server. But the demand on the server is high, and if many people is on your site, you will run into trouble with ports and so on.