Listen to onunload and onbeforeunload for channel saving

- Fix bug where $scope.connected will be reset to false when the user joins a channel