Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- added a continuous check for offline
  • Loading branch information
temi committed Aug 28, 2023
1 parent 664b067 commit 493f4bf
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions grails-app/assets/javascripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,24 @@ function isOffline() {
})

return deferred.promise();
}

function checkOfflineForIntervalAndTriggerEvents (interval) {
interval = interval || 10000;
var isCurrentlyOffline = false;
return setInterval(function () {
isOffline().then(function () {
if (!isCurrentlyOffline) {
var event = new Event('offline');
document.dispatchEvent(event);
isCurrentlyOffline = true;
}
}, function () {
if (isCurrentlyOffline) {
var event = new Event('online');
document.dispatchEvent(event);
isCurrentlyOffline = false;
}
});
}, interval);
}

0 comments on commit 493f4bf

Please sign in to comment.