Fix socket reconnect logic when browser is refreshed after token has expired

This commit is contained in:
Matthew Jones
2015-03-05 11:40:29 -05:00
parent e653e9561a
commit 6034e6108a
2 changed files with 12 additions and 3 deletions

View File

@@ -652,7 +652,9 @@ var tower = angular.module('Tower', [
if($rootScope.dashboardInterval){ if($rootScope.dashboardInterval){
window.clearInterval($rootScope.dashboardInterval); window.clearInterval($rootScope.dashboardInterval);
} }
sock.socket.socket.disconnect(); if (sock) {
sock.socket.socket.disconnect();
}
$location.path('/login'); $location.path('/login');
} }
} else { } else {

View File

@@ -100,8 +100,15 @@ angular.module('SocketIO', ['AuthService', 'Utilities'])
}); });
}); });
self.socket.on('connect_failed', function(reason) { self.socket.on('connect_failed', function(reason) {
var r = reason || 'connection refused by host'; var r = reason || 'connection refused by host',
$log.error('Socket connection failed: ' + r); token_actual = Authorization.getToken();
$log.debug('Socket connection failed: ' + r);
if (token_actual === token) {
self.socket.socket.disconnect();
}
self.scope.$apply(function () { self.scope.$apply(function () {
self.scope.socketStatus = 'error'; self.scope.socketStatus = 'error';
self.scope.socketTip = getSocketTip(self.scope.socketStatus); self.scope.socketTip = getSocketTip(self.scope.socketStatus);