From 60882d9a5cb7eeec7a49afec15bfea96b74d75df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 2 Mar 2015 22:20:27 +0100 Subject: [PATCH] Don't consider it a disconnect until after some failed direct tries to reconnect Should solve issues where the "Disconnected" dialog briefly appears when the connection gets interrupted only briefly, e.g. when starting a timelapse download in Firefox. --- src/octoprint/static/js/app/dataupdater.js | 43 ++++++++++++---------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/src/octoprint/static/js/app/dataupdater.js b/src/octoprint/static/js/app/dataupdater.js index d25a731b..6be7c754 100644 --- a/src/octoprint/static/js/app/dataupdater.js +++ b/src/octoprint/static/js/app/dataupdater.js @@ -6,7 +6,8 @@ function DataUpdater(allViewModels) { self._socket = undefined; self._autoReconnecting = false; self._autoReconnectTrial = 0; - self._autoReconnectTimeouts = [1, 1, 2, 3, 5, 8, 13, 20, 40, 100]; + self._autoReconnectTimeouts = [0, 1, 1, 2, 3, 5, 8, 13, 20, 40, 100]; + self._autoReconnectDialogIndex = 1; self.connect = function() { var options = {}; @@ -31,29 +32,33 @@ function DataUpdater(allViewModels) { }; self._onclose = function() { - var handled = false; - _.each(self.allViewModels, function(viewModel) { - if (handled == true) { + if (self._autoReconnectTrial >= self._autoReconnectDialogIndex) { + // Only consider it a real disconnect if the trial number has exceeded our threshold. + + var handled = false; + _.each(self.allViewModels, function(viewModel) { + if (handled == true) { + return; + } + + if (viewModel.hasOwnProperty("onServerDisconnect")) { + if (!viewModel.onServerDisconnect()) { + handled = true; + } + } + }); + + if (handled) { return; } - if (viewModel.hasOwnProperty("onServerDisconnect")) { - if (!viewModel.onServerDisconnect()) { - handled = true; - } - } - }); - - if (handled) { - return; + showOfflineOverlay( + gettext("Server is offline"), + gettext("The server appears to be offline, at least I'm not getting any response from it. I'll try to reconnect automatically over the next couple of minutes, however you are welcome to try a manual reconnect anytime using the button below."), + self.reconnect + ); } - showOfflineOverlay( - gettext("Server is offline"), - gettext("The server appears to be offline, at least I'm not getting any response from it. I'll try to reconnect automatically over the next couple of minutes, however you are welcome to try a manual reconnect anytime using the button below."), - self.reconnect - ); - if (self._autoReconnectTrial < self._autoReconnectTimeouts.length) { var timeout = self._autoReconnectTimeouts[self._autoReconnectTrial]; log.info("Reconnect trial #" + self._autoReconnectTrial + ", waiting " + timeout + "s");