title: How to use socketio for showing Online/Offline User in Real Time Using Sails?
body: <p>My Real Time Chat App is based on  <a href="http://sailsjs.org/" rel="nofollow noreferrer">Sails</a> and <a href="http://socket.io/" rel="nofollow noreferrer">SocketIO</a>.It shows all users along with available online users .When a User logged in,a UserConnected socket is emitted and When a User is disconnected,a UserDisconnected socket is emitted ,
  My Server side socketio code in config/sockets.js is </p>
  
  <pre><code>onConnect: function(session, socket) {
    if (session.passport) {
      if (session.passport.user &amp;&amp; socket.id) {
        sails.io.sockets.emit('UserConnected', {userID : session.passport.user});                       }
      }
    }
    //// By default: do nothing
    //// This is a good place to broadcast a disconnect message, or any other custom socket.io logic
  },
  
  onDisconnect: function(session, socket) {
    if (session.passport) {
      if (session.passport.user &amp;&amp; socket.id) {
       sails.io.sockets.emit('UserDisconnected', {userID : session.passport.user});
      }
    }
    //// By default: do nothing
    //// This is a good place to broadcast a disconnect message, or any other custom socket.io logic
  }
  </code></pre>
  
  <p>The Problem is that when a User refreshes the page ,it shows connected and disconnected to another User and one major problem is that if one User logged in two different browsers and if any one browser is closed is shows User disconnected to other Users  but the User is actually available in another browser.<br> How would I modify/code So that these problems will be fixed?<br>Thanks in Advance</p>