diff --git a/awx/ui/static/js/app.js b/awx/ui/static/js/app.js index 71aae69986..712cdb72be 100644 --- a/awx/ui/static/js/app.js +++ b/awx/ui/static/js/app.js @@ -575,8 +575,9 @@ angular.module('Tower', [ setInterval(function() { if (sock.checkStatus() === 'error' || checkCount > 3) { // there's an error or we're stuck in a 'connecting' state. attempt to reconnect - sock = null; + $log.debug('socket status: ' + sock.checkStatus()); $log.debug('attempting new socket connection'); + sock = null; openSocket(); checkCount = 0; } diff --git a/awx/ui/static/js/helpers/LoadConfig.js b/awx/ui/static/js/helpers/LoadConfig.js index bb30181aff..dce2b7bd75 100644 --- a/awx/ui/static/js/helpers/LoadConfig.js +++ b/awx/ui/static/js/helpers/LoadConfig.js @@ -14,7 +14,7 @@ angular.module('LoadConfigHelper', ['Utilities']) -.factory('LoadConfig', ['$log', '$rootScope', '$http', 'ProcessErrors', function($log, $rootScope, $http, ProcessErrors) { +.factory('LoadConfig', ['$log', '$rootScope', '$http', 'ProcessErrors', 'Store', function($log, $rootScope, $http, ProcessErrors, Store) { return function() { if ($rootScope.removeLoadConfig) { @@ -27,6 +27,7 @@ angular.module('LoadConfigHelper', ['Utilities']) .success(function(data) { $log.info('loaded config.js'); $AnsibleConfig = eval(data); + Store('AnsibleConfig', $AnsibleConfig); $rootScope.$emit('ConfigReady'); }) .error(function(data, status) { @@ -41,6 +42,7 @@ angular.module('LoadConfigHelper', ['Utilities']) .success(function(data) { $log.info('loaded local_config.js'); $AnsibleConfig = eval(data); + Store('AnsibleConfig', $AnsibleConfig); $rootScope.$emit('ConfigReady'); }) .error(function() { diff --git a/awx/ui/static/lib/ansible/Socket.js b/awx/ui/static/lib/ansible/Socket.js index cb550f38fd..963b5b80ae 100644 --- a/awx/ui/static/lib/ansible/Socket.js +++ b/awx/ui/static/lib/ansible/Socket.js @@ -12,13 +12,26 @@ angular.module('SocketIO', ['AuthService', 'Utilities']) - .factory('Socket', ['$rootScope', '$location', '$log', 'Authorization', function ($rootScope, $location, $log, Authorization) { + .factory('Socket', ['$rootScope', '$location', '$log', 'Authorization', 'Store', function ($rootScope, $location, $log, Authorization, Store) { return function(params) { var scope = params.scope, host = $location.host(), endpoint = params.endpoint, protocol = $location.protocol(), - url = protocol + '://' + host + ':' + $AnsibleConfig.websocket_port + '/socket.io/' + endpoint; + config, socketPort, 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. + if ($AnsibleConfig) { + socketPort = $AnsibleConfig.websocket_port; + } + else { + $log.debug('getting web socket port from local storage'); + config = Store('AnsibleConfig'); + socketPort = config.websocket_port; + } + url = protocol + '://' + host + ':' + socketPort + '/socket.io/' + endpoint; + $log.debug('opening socket connection to: ' + url); function getSocketTip(status) { var result = ''; @@ -43,7 +56,7 @@ angular.module('SocketIO', ['AuthService', 'Utilities']) init: function() { var self = this, token = Authorization.getToken(); - if (!$rootScope.sessionTimer.isExpired()) { + if (!$rootScope.sessionTimer || ($rootScope.sessionTimer && !$rootScope.sessionTimer.isExpired())) { // We have a valid session token, so attmempt socket connection $log.debug('Socket connecting to: ' + url); self.scope.socket_url = url; diff --git a/awx/ui/static/lib/ansible/Timer.js b/awx/ui/static/lib/ansible/Timer.js index 36912da5fc..28253f9523 100644 --- a/awx/ui/static/lib/ansible/Timer.js +++ b/awx/ui/static/lib/ansible/Timer.js @@ -41,7 +41,9 @@ angular.module('TimerService', ['ngCookies', 'Utilities']) }, moveForward: function () { - var t = new Date().getTime() + ($AnsibleConfig.session_timeout * 1000); + var tm, t; + tm = ($AnsibleConfig) ? $AnsibleConfig.session_timeout : 1800; + t = new Date().getTime() + (tm * 1000); this.sessionTime = t; $cookieStore.put('sessionTime', t); $rootScope.sessionExpired = false; diff --git a/awx/ui/static/lib/ansible/Utilities.js b/awx/ui/static/lib/ansible/Utilities.js index 6c96ea6e11..f21198850d 100644 --- a/awx/ui/static/lib/ansible/Utilities.js +++ b/awx/ui/static/lib/ansible/Utilities.js @@ -138,13 +138,11 @@ angular.module('Utilities', ['RestServices', 'Utilities']) return function (scope, data, status, form, defaultMsg) { var field, fieldErrors, msg, keys; Wait('stop'); - if ($AnsibleConfig.debug_mode) { - $log.debug('Debug status: ' + status); - $log.debug('Debug data: '); - $log.debug(data); - if (defaultMsg.msg) { - $log.debug('Debug: ' + defaultMsg.msg); - } + $log.debug('Debug status: ' + status); + $log.debug('Debug data: '); + $log.debug(data); + if (defaultMsg.msg) { + $log.debug('Debug: ' + defaultMsg.msg); } if (status === 403) { msg = 'The API responded with a 403 Access Denied error. '; @@ -158,7 +156,9 @@ angular.module('Utilities', ['RestServices', 'Utilities']) Alert('Deleted Object', 'The requested object was previously deleted and can no longer be accessed.'); } else if ((status === 'Token is expired') || (status === 401 && data.detail && data.detail === 'Token is expired') || (status === 401 && data.detail && data.detail === 'Invalid token')) { - $rootScope.sessionTimer.expireSession(); + if ($rootScope.sessionTimer) { + $rootScope.sessionTimer.expireSession(); + } $location.url('/login'); } else if (data.non_field_errors) { Alert('Error!', data.non_field_errors);