title: Detect Websocket close connection when the users close browser?
body: <p>I am using HTML5 websocket and nodejs in my project to create a simple chat.</p>
  
  <p>Everything works as it should so far.</p>
  
  <p>However, I need to figure out how to detect if the the users that are connected, lost connection somehow and in particular, if they close their browser etc.</p>
  
  <p>I tried the following code.</p>
  
  <p><strong>I can successfully connect like this:</strong></p>
  
  <pre><code>wss.on('connection', function(ws, req) {
  
  //do my stuff here/////
  console.log('connection started');
  
  });
  </code></pre>
  
  <p>However, i cannot see anything in the console when i disconnect by closing the browser. </p>
  
  <p><strong>I use this code to detect connection close:</strong></p>
  
  <pre><code>wss.on('closed', function(ws) {
          console.log('connection closed');
  });
  </code></pre>
  
  <p>Could someone please let me know if I am missing something and or doing something wrong?</p>
  
  <p>Thanks in advance. </p>
  
  <p><strong>edit:</strong></p>
  
  <p>This seems to work:</p>
  
  <pre><code>  ws.on("close", function() {
      console.log("closed");
    });
  </code></pre>