From 9274b90b9b54bce6cba326277c2aaac80bbdda0c Mon Sep 17 00:00:00 2001 From: jaredevantabor Date: Tue, 11 Oct 2016 14:22:42 -0700 Subject: [PATCH] switching websocket to secure websocket (wss://) dpending on protocol --- .../client/src/shared/socket/socket.service.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/awx/ui/client/src/shared/socket/socket.service.js b/awx/ui/client/src/shared/socket/socket.service.js index 6a992d4e5f..056bd09bbf 100644 --- a/awx/ui/client/src/shared/socket/socket.service.js +++ b/awx/ui/client/src/shared/socket/socket.service.js @@ -13,7 +13,17 @@ export default init: function() { var self = this, host = window.location.host, - url = "ws://" + host + "/websocket/"; + protocol, + url; + + if($location.protocol() === 'http'){ + protocol = 'ws'; + } + if($location.protocol() === 'https'){ + protocol = 'wss'; + } + url = `${protocol}://${host}/websocket/`; + if (!$rootScope.sessionTimer || ($rootScope.sessionTimer && !$rootScope.sessionTimer.isExpired())) { // We have a valid session token, so attempt socket connection $log.debug('Socket connecting to: ' + url); @@ -83,7 +93,7 @@ export default // The naming scheme is "ws" then a // dash (-) and the group_name, then the job ID // ex: 'ws-jobs-' - str = `ws-${data.group_name}-${data.job}` + str = `ws-${data.group_name}-${data.job}`; } else if(data.group_name==="ad_hoc_command_events"){ // The naming scheme is "ws" then a @@ -194,7 +204,7 @@ export default // This function is used for add a state resolve to all states, // socket-enabled AND socket-disabled, and whether the $state // requires a subscribe or an unsubscribe - self = this; + var self = this; socketPromise.promise.then(function(){ if(!state.socket){ state.socket = {groups: {}};