mirror of
https://github.com/ansible/awx.git
synced 2026-05-14 04:47:44 -02:30
Adding unsubscribe method for non-socket-enabled routes
with the idea that we only want to unsubscribe directly following a subscribe (no need to unsubscribe if we're already unsubscribed).
This commit is contained in:
@@ -100,8 +100,34 @@ export default
|
|||||||
}, 2000);
|
}, 2000);
|
||||||
},
|
},
|
||||||
subscribe: function(state){
|
subscribe: function(state){
|
||||||
console.log(state.name);
|
console.log("Next state: " + state.name);
|
||||||
this.emit(JSON.stringify(state.socket));
|
this.emit(JSON.stringify(state.socket));
|
||||||
|
this.setLast(state);
|
||||||
|
},
|
||||||
|
unsubscribe: function(state){
|
||||||
|
if(this.requiresNewSubscribe(state)){
|
||||||
|
this.emit(JSON.stringify(state.socket));
|
||||||
|
}
|
||||||
|
this.setLast(state);
|
||||||
|
},
|
||||||
|
setLast: function(state){
|
||||||
|
this.last = state;
|
||||||
|
},
|
||||||
|
getLast: function(){
|
||||||
|
return this.last;
|
||||||
|
},
|
||||||
|
requiresNewSubscribe(state){
|
||||||
|
if (this.getLast() !== undefined){
|
||||||
|
if( _.isEmpty(state.socket.groups) && _.isEmpty(this.getLast().socket.groups)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
checkStatus: function() {
|
checkStatus: function() {
|
||||||
|
|
||||||
@@ -140,7 +166,7 @@ export default
|
|||||||
},
|
},
|
||||||
emit: function(data, callback) {
|
emit: function(data, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
$log.debug('Sent to Server: ' + data);
|
$log.debug('Sent to Websocket Server: ' + data);
|
||||||
$rootScope.socketPromise.promise.then(function(){
|
$rootScope.socketPromise.promise.then(function(){
|
||||||
self.socket.send(data, function () {
|
self.socket.send(data, function () {
|
||||||
var args = arguments;
|
var args = arguments;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ export default function($stateProvider) {
|
|||||||
$rootScope.socketPromise.promise.then(function(){
|
$rootScope.socketPromise.promise.then(function(){
|
||||||
if(!state.socket){
|
if(!state.socket){
|
||||||
state.socket = {groups: {}};
|
state.socket = {groups: {}};
|
||||||
|
SocketService.unsubscribe(state);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if(state.socket.groups.hasOwnProperty( "job_events")){
|
if(state.socket.groups.hasOwnProperty( "job_events")){
|
||||||
@@ -19,9 +20,8 @@ export default function($stateProvider) {
|
|||||||
if(state.socket.groups.hasOwnProperty( "ad_hoc_command_events")){
|
if(state.socket.groups.hasOwnProperty( "ad_hoc_command_events")){
|
||||||
state.socket.groups.job_events = [$stateParams.id];
|
state.socket.groups.job_events = [$stateParams.id];
|
||||||
}
|
}
|
||||||
|
SocketService.subscribe(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
SocketService.subscribe(state);
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}];
|
}];
|
||||||
|
|||||||
Reference in New Issue
Block a user