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

Fixes issue with sockets and XHR requests for backgrounded tabs

adjusts toggling based on API setting and doesn't toggle for job stdout page
This commit is contained in:
Jared Tabor 2018-03-22 16:10:07 -07:00
parent f6e507ad12
commit 8643972064
2 changed files with 30 additions and 2 deletions

View File

@ -8,7 +8,8 @@ export default
['$rootScope', '$location', '$log','$state', '$q', 'i18n',
function ($rootScope, $location, $log, $state, $q, i18n) {
var needsResubscribing = false,
socketPromise = $q.defer();
socketPromise = $q.defer(),
needsRefreshAfterBlur;
return {
init: function() {
var self = this,
@ -24,6 +25,26 @@ export default
}
url = `${protocol}://${host}/websocket/`;
// only toggle background tabbed sockets if the
// UI_LIVE_UPDATES_ENABLED flag is true in the settings file
if(window.liveUpdates){
document.addEventListener('visibilitychange', function() {
$log.debug(document.visibilityState);
if(document.visibilityState === 'hidden'){
window.liveUpdates = false;
}
else if(document.visibilityState === 'visible'){
window.liveUpdates = true;
if(needsRefreshAfterBlur){
$state.go('.', null, {reload: true});
needsRefreshAfterBlur = false;
}
}
});
}
if (!$rootScope.sessionTimer || ($rootScope.sessionTimer && !$rootScope.sessionTimer.isExpired())) {
$log.debug('Socket connecting to: ' + url);
@ -75,6 +96,13 @@ export default
$log.debug('Received From Server: ' + e.data);
var data = JSON.parse(e.data), str = "";
if(!window.liveUpdates && data.group_name !== "control" && $state.current.name !== "jobResult"){
$log.debug('Message from server dropped: ' + e.data);
needsRefreshAfterBlur = true;
return;
}
if(data.group_name==="jobs" && !('status' in data)){
// we know that this must have been a
// summary complete message b/c status is missing.

View File

@ -12,7 +12,7 @@
<link rel="shortcut icon" href="{{ STATIC_URL }}assets/favicon.ico?v={{version}}" />
<script>
var $basePath = "{{ STATIC_URL }}";
var $liveUpdates = "{{ UI_LIVE_UPDATES_ENABLED }}";
window.liveUpdates = "{{ UI_LIVE_UPDATES_ENABLED }}" === "False" ? false : true;
</script>
<script src="{{ STATIC_URL }}app.vendor.js?v={{version}}"></script>
<script src="{{ STATIC_URL }}app.js?v={{version}}"></script>