"connection.leaveOnPageUnload" added.

```javascript
// if you want to prevent default
behaviour
connection.leaveOnPageUnload = false;

// display a
notification box
window.addEventListener('beforeunload', function () {

return 'Are you want to leave?';
}, false);

// leave
here
window.addEventListener('unload', function () {

connection.leave();
}, false);
```