title: Node.js - socket disconnect event doesn't work properly
body: <p>In my Node app, I am using <code>socket.io</code> for websocket functionality.</p>
  
  <p>In order to let the client know when the server becomes unavailable, I'm using the following code:</p>
  
  <pre><code>socket.on('disconnect', function(){
          //show error to client
      });
  </code></pre>
  
  <p>This works fine, but there's a nasty side-effect. Every time I click a link to navigate away from the page (or just reload the page) the message pops up - because the <em>client</em> disconnects. I certainly do not wish to display a message saying 'the server is unavailable' every time the visitor clicks a link.</p>
  
  <p>I could put a timeout on the error message, giving the browser time to simply navigate away before the error shows. But you'll admit this is a shabby solution. Also, there would be two problems:</p>
  
  <p>1) the error message would be delayed by the timeout amount in cases when it needs to actually be displayed, leaving the user with a non-functioning app and no notification during that interval</p>
  
  <p>2) it wouldn't work for page reloads (I think)</p>
  
  <p>Anyway, there's gotta be a better way. Right?</p>
  
  <p>Note: this is a problem in Firefox, but not Chrome. Haven't tested other browsers yet. Firefox also displays an error message in the console stating that the websocket connection was interrupted, and I'm inclined to believe these two problems have a common cause. I have read quite a few questions and answers regarding this console error, but none seem to apply to my situation.</p>