1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-02 01:21:21 +03:00

Merge pull request #447 from jaredevantabor/socket-fix

Final Socket Fix!
This commit is contained in:
Michael Abashian 2017-09-25 10:09:08 -04:00 committed by GitHub
commit c9ce751bf0
2 changed files with 7 additions and 21 deletions

View File

@ -146,8 +146,7 @@ var awApp = angular.module('awApp', [
.constant('AngularScheduler.showUTCField', true) .constant('AngularScheduler.showUTCField', true)
.constant('$timezones.definitions.location', urlPrefix + 'lib/angular-tz-extensions/tz/data') .constant('$timezones.definitions.location', urlPrefix + 'lib/angular-tz-extensions/tz/data')
.config(['$logProvider', function($logProvider) { .config(['$logProvider', function($logProvider) {
// $logProvider.debugEnabled($ENV['ng-debug'] || false); $logProvider.debugEnabled($ENV['ng-debug'] || false);
$logProvider.debugEnabled(true);
}]) }])
.config(['ngToastProvider', function(ngToastProvider) { .config(['ngToastProvider', function(ngToastProvider) {
ngToastProvider.configure({ ngToastProvider.configure({

View File

@ -16,7 +16,6 @@ export default
protocol, protocol,
url; url;
console.log("UPDATED");
if($location.protocol() === 'http'){ if($location.protocol() === 'http'){
protocol = 'ws'; protocol = 'ws';
} }
@ -28,15 +27,13 @@ export default
if (!$rootScope.sessionTimer || ($rootScope.sessionTimer && !$rootScope.sessionTimer.isExpired())) { if (!$rootScope.sessionTimer || ($rootScope.sessionTimer && !$rootScope.sessionTimer.isExpired())) {
$log.debug('Socket connecting to: ' + url); $log.debug('Socket connecting to: ' + url);
console.log("prior to new ReconnectingWebSocket..., self.socket is: " + self.socket);
self.socket = new ReconnectingWebSocket(url, null, { self.socket = new ReconnectingWebSocket(url, null, {
timeoutInterval: 3000, timeoutInterval: 3000,
maxReconnectAttempts: 10 }); maxReconnectAttempts: 10 });
self.socket.onopen = function () { self.socket.onopen = function () {
$log.debug("Websocket connection opened." + self.socket.readyState); $log.debug("Websocket connection opened. Socket readyState: " + self.socket.readyState);
// socketPromise.resolve(); socketPromise.resolve();
// console.log('promise resolved, and readyState: '+ self.socket.readyState);
self.checkStatus(); self.checkStatus();
if(needsResubscribing){ if(needsResubscribing){
self.subscribe(self.getLast()); self.subscribe(self.getLast());
@ -78,11 +75,6 @@ export default
$log.debug('Received From Server: ' + e.data); $log.debug('Received From Server: ' + e.data);
var data = JSON.parse(e.data), str = ""; var data = JSON.parse(e.data), str = "";
if(_.has(data, "accept") && data.accept === true){
console.log('handshake message received from server. readyState: '+ this.readyState, data);
socketPromise.resolve();
return;
}
if(data.group_name==="jobs" && !('status' in data)){ if(data.group_name==="jobs" && !('status' in data)){
// we know that this must have been a // we know that this must have been a
// summary complete message b/c status is missing. // summary complete message b/c status is missing.
@ -124,7 +116,6 @@ export default
if(this.socket){ if(this.socket){
this.socket.close(); this.socket.close();
delete this.socket; delete this.socket;
console.log("Socket deleted: "+this.socket);
} }
}, },
subscribe: function(state){ subscribe: function(state){
@ -132,11 +123,8 @@ export default
// listen for specific messages. A subscription object could // listen for specific messages. A subscription object could
// look like {"groups":{"jobs": ["status_changed", "summary"]}. // look like {"groups":{"jobs": ["status_changed", "summary"]}.
// This is used by all socket-enabled $states // This is used by all socket-enabled $states
let self = this; this.emit(JSON.stringify(state.data.socket));
socketPromise.promise.then(function(){ this.setLast(state);
self.emit(JSON.stringify(state.data.socket));
self.setLast(state);
});
}, },
unsubscribe: function(state){ unsubscribe: function(state){
// Unsubscribing tells the API that the user is no longer on // Unsubscribing tells the API that the user is no longer on
@ -196,12 +184,10 @@ export default
// Function used for sending objects to the API over the // Function used for sending objects to the API over the
// websocket. // websocket.
var self = this; var self = this;
$log.debug('Sent to Websocket Server: ' + data);
socketPromise.promise.then(function(){ socketPromise.promise.then(function(){
console.log("socket readyState at emit: " + self.socket.readyState);
if(self.socket.readyState === 0){ if(self.socket.readyState === 0){
$log.debug('Unable to send message, waiting 500ms to resend. Socket readyState: ' + self.socket.readyState);
setTimeout(function(){ setTimeout(function(){
console.log('inside timeout: ' + self.socket.readyState);
self.subscribe(self.getLast()); self.subscribe(self.getLast());
}, 500); }, 500);
} }
@ -214,6 +200,7 @@ export default
} }
}); });
}); });
$log.debug('Sent to Websocket Server: ' + data);
} }
}); });
}, },