diff --git a/awx/ui/static/lib/ansible/Socket.js b/awx/ui/static/lib/ansible/Socket.js index 0a01415b84..c32e5ec851 100644 --- a/awx/ui/static/lib/ansible/Socket.js +++ b/awx/ui/static/lib/ansible/Socket.js @@ -27,7 +27,8 @@ angular.module('SocketIO', ['AuthService', 'Utilities']) host = $location.host(), endpoint = params.endpoint, protocol = $location.protocol(), - config, socketPort, url; + config, socketPort, + handshakeData, url; // Since some pages are opened in a new tab, we might get here before AnsibleConfig is available. // In that case, load from local storage. @@ -61,23 +62,34 @@ angular.module('SocketIO', ['AuthService', 'Utilities']) scope: scope, url: url, socket: null, + init: function() { var self = this, token = Authorization.getToken(); if (!$rootScope.sessionTimer || ($rootScope.sessionTimer && !$rootScope.sessionTimer.isExpired())) { - // We have a valid session token, so attmempt socket connection + // We have a valid session token, so attempt socket connection $log.debug('Socket connecting to: ' + url); self.scope.socket_url = url; - self.socket = io.connect(url, { headers: - { + handshakeData = { + headers: { 'Authorization': 'Token ' + token, 'X-Auth-Token': 'Token ' + token - }, + } + } + + self.socket = io.connect(url, { + // headers: + // { + // 'Authorization': 'Token ' + token, + // 'X-Auth-Token': 'Token ' + token + // }, 'connect timeout': 3000, 'try multiple transports': false, 'max reconneciton attemps': 3, 'reconnection limit': 3000, + 'force new connection': true, }); + self.socket.on('connection', function() { $log.debug('Socket connecting...'); self.scope.$apply(function () { @@ -168,6 +180,19 @@ angular.module('SocketIO', ['AuthService', 'Utilities']) }); }); }, + disconnect: function(){ + var self = this; + $rootScope.disconnect_timer = setInterval(function(){disconnectSocket()}, 1000); + + function disconnectSocket() { + self.socket.socket.disconnect(); + window.clearInterval($rootScope.disconnect_timer); + } + // self.scope.$apply(function () { + + // }); + + }, emit: function (eventName, data, callback) { var self = this; self.socket.emit(eventName, data, function () {