diff --git a/templates/update.js b/templates/update.js index 754d490a35174d92d3c31589fc4a19bad51c2e0b..af49b6a98f8e4b02a7c7e67f283198cd1ee5893b 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"); };