Skip to content

Commit

Permalink
Possible fix for museumsvictoria#259
Browse files Browse the repository at this point in the history
Proactively disconnect and reconnect websockets when visibility and/or connectivity changes
  • Loading branch information
mcartmel committed Nov 20, 2023
1 parent e6f7624 commit 5216dbf
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions nodel-webui-js/src/nodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2543,6 +2543,18 @@ var updateLogs = function(){
offline();
$('body').data('update', setTimeout(function() { updateLogs(); }, 1000));
}
// proactively disconnect websocket when the page is not being viewed
$(document).off("visibilitychange.socket").on("visibilitychange.socket", function() {
if(document.hidden) socket.close();
else updateLogs();
});
// proactively disconnect when network is disconnected
$(window).off("offline.socket").on("offline.socket", function() {
socket.close();
});
$(window).off("online.socket").on("online.socket", function() {
if(!document.hidden) updateLogs();
});
} catch(exception){
console.log('Error: '+exception);
offline();
Expand Down

0 comments on commit 5216dbf

Please sign in to comment.