diff --git a/public_html/script.js b/public_html/script.js index a1769fb..0acc1ea 100644 --- a/public_html/script.js +++ b/public_html/script.js @@ -29,8 +29,22 @@ var TrackedHistorySize = 0; var SitePosition = null; var ReceiverClock = null; + +var LastReceiverTimestamp = null; +var StaleReceiverCount = 0; +var FetchPending = null; + function fetchData() { - $.getJSON('data/aircraft.json', function(data) { + if (FetchPending !== null && FetchPending.state() == 'pending') { + // don't double up on fetches, let the last one resolve + return; + } + + FetchPending = $.ajax({ url: 'data/aircraft.json', + timeout: 5000, + cache: false, + dataType: 'json' }); + FetchPending.done(function(data) { // Loop through all the planes in the data packet var now = data.now; var acs = data.aircraft; @@ -71,7 +85,25 @@ function fetchData() { var rcv = new Date(now * 1000); ReceiverClock.render(rcv.getUTCHours(),rcv.getUTCMinutes(),rcv.getUTCSeconds()); } + + // Check for stale receiver data + if (LastReceiverTimestamp === now) { + StaleReceiverCount++; + if (StaleReceiverCount > 5) { + $("#update_error_detail").text("The data from dump1090 hasn't been updated in a while. Maybe dump1090 is no longer running?"); + $("#update_error").css('display','block'); + } + } else { + StaleReceiverCount = 0; + LastReceiverTimestamp = now; + $("#update_error").css('display','none'); + } }); + + FetchPending.fail(function(jqxhr, status, error) { + $("#update_error_detail").text("AJAX call failed (" + status + (error ? (": " + error) : "") + "). Maybe dump1090 is no longer running?"); + $("#update_error").css('display','block'); + }); } function initialize() { diff --git a/public_html/style.css b/public_html/style.css index 602a97a..d25688b 100644 --- a/public_html/style.css +++ b/public_html/style.css @@ -11,8 +11,9 @@ div#SpecialSquawkWarning { position: absolute; bottom: 25px; right: 430px; borde background-color: #FFFFA3; opacity: 0.75; filter:alpha(opacity=75); padding: 5px; text-align: center; } -table#optionsTabs { width: 100%; font-size: small; font-family: monospace; background-color: #ddd; - border: 1px; border-color: #000000;} +div#update_error { position: absolute; bottom: 25px; left: 25px; border: 2px solid red; + background-color: #FFFFA3; opacity: 0.75; filter:alpha(opacity=75); padding: 5px; + text-align: center; } #tableinfo, #sudo_buttons { font-size: x-small; font-family: monospace; }