From f3151bd2032f8e62c9e9bb44cb9247033b95f975 Mon Sep 17 00:00:00 2001 From: Robin Sonnabend <robin@fsmpi.rwth-aachen.de> Date: Sun, 8 Nov 2015 22:29:53 +0100 Subject: [PATCH] Retrying for update.js --- templates/update.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/templates/update.js b/templates/update.js index 754d490..af49b6a 100644 --- a/templates/update.js +++ b/templates/update.js @@ -1,13 +1,30 @@ var {{ prefix }}returned = true; var {{ prefix }}last_content = ""; +var {{ prefix }}no_return_counter = 0; +var {{ prefix }}notification_div = null; function {{ prefix }}request() { - if (!{{ prefix }}returned) - return; + if (!{{ prefix }}returned) { + {{ prefix }}no_return_counter += 1; + console.log("Connection lost"); + if ({{ prefix }}no_return_counter > 5) { + if ({{ prefix }}notification_div != null) { + {{ prefix }}notification_div.innerHTML = "Connection lost, retrying"; + console.log("Retrying"); + } + } else { + return; + } + } else { + if ({{ prefix }}notification_div.innerHTML == "Connection lost, retrying") { + {{ prefix }}notification_div.innerHTML = ""; + } + } {{ prefix }}returned = false; var {{ prefix }}xmlhttp = new XMLHttpRequest(); {{ prefix }}xmlhttp.onreadystatechange=function() { if ({{ prefix }}xmlhttp.readyState == 4 && {{ prefix }}xmlhttp.status == 200) { {{ prefix }}returned = true; + {{ prefix }}no_return_counter = 0; {{ prefix }}update({{ prefix }}xmlhttp.responseText); } }; @@ -27,5 +44,6 @@ var {{ prefix }}f = window.onload; window.onload=function() { {{ prefix }}f(); window.setInterval({{ prefix }}request, 1000 * {{ update_interval }}); + {{ prefix }}notification_div = document.getElementById("rede-layout-notification"); }; -- GitLab