diff --git a/build.sh b/build.sh index ecabd0e..1c459f2 100755 --- a/build.sh +++ b/build.sh @@ -25,6 +25,7 @@ BUILD_DATE="`date -u +%Y-%m-%dT%H:%M:%SZ`" java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge iscroll.js >> mobile.js java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge chasecar.lib.js | sed "s/{VER}/$VERSION/" >> mobile.js java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge tracker.js >> mobile.js +java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge localtracker.js >> mobile.js java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge app.js | sed "s/{VER}/$VERSION/" | sed "s/{BUILD_DATE}/$BUILD_DATE/" >> mobile.js java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge colour-map.js >> mobile.js java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge xdata.js >> mobile.js diff --git a/css/skeleton.css b/css/skeleton.css index 5db3d38..d38af93 100644 --- a/css/skeleton.css +++ b/css/skeleton.css @@ -21,7 +21,7 @@ /* #Base 960 Grid ================================================== */ - .container { position: relative; width: 960px; margin: 0 auto; padding: 0; } + .container { position: relative; width: 960px; margin: 0 auto; padding: 0; background-color: #ff000088; } .container .column, .container .columns { float: left; display: inline; margin-left: 10px; margin-right: 10px; } .row { margin-bottom: 20px; } diff --git a/js/localtracker.js b/js/localtracker.js new file mode 100644 index 0000000..180248f --- /dev/null +++ b/js/localtracker.js @@ -0,0 +1,125 @@ + +var local_livedata = "ws://sonde.bitnet.be:9001/"; +var local_clientID = "SondeHub-Tracker-" + Math.floor(Math.random() * 10000000000); +var local_client = new Paho.Client(local_livedata, local_clientID); +var local_clientConnected = false; +var local_clientActive = false; +var local_clientTopic; +var local_messageRate = 0; +var local_messageRateAverage = 10; + + +local_live_data_buffer = {positions:{position:[]}} +function local_liveData() { + local_client.onConnectionLost = local_onConnectionLost; + local_client.onMessageArrived = local_onMessageArrived; + + local_client.connect({onSuccess:local_onConnect,onFailure:local_connectionError,reconnect:true}); + + function local_onConnect() { + if (wvar.query && sondePrefix.indexOf(wvar.query) == -1) { + var topic = "sondes/" + wvar.query; + local_client.subscribe(topic); + local_clientTopic = topic; + } else { + local_client.subscribe("batch"); + local_clientTopic = "batch"; + } + // Also subscribe to listener data, for listener and chase-car telemetry. + // To revert listener-via-websockets change, comment out this line, + // and un-comment the 'Disable periodical listener refresh' lines further below. + local_client.subscribe("listener/#"); + + local_clientConnected = true; + $("#stText").text("websocket |"); + }; + + function local_connectionError(error) { + $("#stText").text("conn. error |"); + console.log(error); + local_clientConnected = false; + local_clientActive = false; + if (!document.getElementById("stTimer").classList.contains('friendly-dtime') ) { + document.getElementById("stTimer").classList.add('friendly-dtime'); + $("#updatedText").text(" Updated: "); + } + refresh(); + }; + + function local_onConnectionLost(responseObject) { + if (responseObject.errorCode !== 0) { + local_clientConnected = false; + local_clientActive = false; + if (!document.getElementById("stTimer").classList.contains('friendly-dtime') ) { + document.getElementById("stTimer").classList.add('friendly-dtime'); + $("#updatedText").text(" Updated: "); + } + refresh(); + } + }; + + function local_onMessageArrived(message) { + local_messageRate += 1; + setTimeout(function(){ + local_messageRate -= 1; + }, (1000 * local_messageRateAverage)); + if ( document.getElementById("stTimer").classList.contains('friendly-dtime') ) { + document.getElementById("stTimer").classList.remove('friendly-dtime'); + } + $("#stTimer").text(Math.round(local_messageRate/10) + " msg/s"); + $("#updatedText").text(" "); + var dateNow = new Date().getTime(); + try { + if (local_clientActive) { + if(message.topic.startsWith("listener")){ + // Message is Listener / Chase-Car information + var frame = JSON.parse(message.payloadString.toString()); + // We need to convert this into the right format for feeding into the receiver / chase car update functions. + // Probably a cleaner way of doing this. + // Format needs to be {callsign : {timestamp: frame}} + var formatted_frame = {}; + formatted_frame[frame.uploader_callsign] = {}; + formatted_frame[frame.uploader_callsign][frame.ts] = frame; + + // Send frames with mobile present and true onto the chase-car updater, + // otherwise, send them to the receiver updater. + // Do this on a per-update bases, since listener / chase car updates shouldn't + // be as frequent. + if(frame.hasOwnProperty('mobile')) { + if(frame.mobile == true) { + updateChase(formatted_frame); + } else { + updateReceivers(formatted_frame, single=true); + } + } else { + updateReceivers(formatted_frame, single=true); + } + + } else { + var frame = JSON.parse(message.payloadString.toString()); + + if (wvar.query == "" || sondePrefix.indexOf(wvar.query) > -1 || wvar.query == frame.serial) { + + var test = formatData(frame, true); + if (local_clientActive) { + local_live_data_buffer.positions.position.push.apply(local_live_data_buffer.positions.position,test.positions.position) + $("#stTimer").attr("data-timestamp", dateNow); + $("#stText").text("websocket |"); + } + } + } + } else { + console.log("WebSockets - Discarding Message, not ready yet.") + } + } + catch(err) {} + }; +} + + +// Interval to read in the live data buffer and update the page. +setInterval(function(){ + update(local_live_data_buffer); + local_live_data_buffer.positions.position=[]; +}, 500) + diff --git a/js/tracker.js b/js/tracker.js index a49c01c..b683ca5 100644 --- a/js/tracker.js +++ b/js/tracker.js @@ -1072,6 +1072,7 @@ function load() { startAjax(); liveData(); + local_liveData(); }; L.NumberedDivIcon = L.Icon.extend({