@@ -3327,6 +3327,7 @@ var ajax_positions_single_new = null;
33273327var ajax_inprogress = false ;
33283328var ajax_inprogress_single = false ;
33293329var ajax_inprogress_single_new = false ;
3330+ var ajax_positions_first_update_complete = false ;
33303331
33313332function refresh ( ) {
33323333 if ( ajax_inprogress ) {
@@ -3381,6 +3382,12 @@ function refresh() {
33813382 clearTimeout ( periodical ) ;
33823383 ajax_inprogress = false ;
33833384
3385+ // refresh predictions has to run after positions otherwise the data won't update correctly - but we only want to run it once because websockets
3386+ if ( ajax_positions_first_update_complete == false ) {
3387+ refreshPredictions ( ) ;
3388+ ajax_positions_first_update_complete = true ;
3389+ }
3390+
33843391 if ( wvar . query ) {
33853392 // If we have a query, pan the map to cover the payloads in that query.
33863393 var vehicle_query = wvar . query . replace ( / ; / g, ',' ) . split ( ',' ) ;
@@ -3498,6 +3505,7 @@ function liveData() {
34983505 // To revert listener-via-websockets change, comment out this line,
34993506 // and un-comment the 'Disable periodical listener refresh' lines further below.
35003507 client . subscribe ( "amateur-listener/#" ) ;
3508+ client . subscribe ( "amateur-prediction/#" ) ;
35013509
35023510 clientConnected = true ;
35033511 $ ( "#stText" ) . text ( "websocket |" ) ;
@@ -3562,7 +3570,25 @@ function liveData() {
35623570 } else {
35633571 updateReceivers ( formatted_frame , single = true ) ;
35643572 }
3573+ } else if ( message . topic . startsWith ( "amateur-prediction" ) ) {
3574+ var frame = JSON . parse ( message . payloadString . toString ( ) ) ;
35653575
3576+ var pred_data = [
3577+ {
3578+ "vehicle" : frame . payload_callsign ,
3579+ "time" : frame . datetime ,
3580+ "latitude" : frame . position [ 1 ] ,
3581+ "longitude" : frame . position [ 0 ] ,
3582+ "altitude" : frame . altitude ,
3583+ "ascent_rate" : frame . ascent_rate ,
3584+ "descent_rate" : frame . descent_rate ,
3585+ "burst_altitude" : frame . burst_altitude ,
3586+ "descending" : frame . descending ? 1 : 0 ,
3587+ "landed" : frame . landed ? 1 : 0 ,
3588+ "data" : JSON . stringify ( frame . data )
3589+ }
3590+ ]
3591+ updatePredictions ( pred_data ) ;
35663592 } else {
35673593 // Message is payload telemetry
35683594
@@ -3699,12 +3725,6 @@ function refreshNewReceivers(initial, serial) {
36993725var ajax_predictions = null ;
37003726
37013727function refreshPredictions ( ) {
3702- if ( ajax_inprogress ) {
3703- clearTimeout ( periodical_predictions ) ;
3704- periodical_predictions = setTimeout ( refreshPredictions , 1000 ) ;
3705- return ;
3706- }
3707-
37083728 ajax_predictions = $ . ajax ( {
37093729 type : "GET" ,
37103730 url : predictions_url + encodeURIComponent ( wvar . query ) ,
@@ -3716,15 +3736,11 @@ function refreshPredictions() {
37163736 error : function ( ) {
37173737 } ,
37183738 complete : function ( request , textStatus ) {
3719- clearTimeout ( periodical_predictions ) ;
3720- // TODO - Switch this to websockets as well.
3721- periodical_predictions = setTimeout ( refreshPredictions , 60 * 1000 ) ;
37223739 }
37233740 } ) ;
37243741}
37253742
37263743var periodical , periodical_focus , periodical_focus_new , periodical_receivers , periodical_listeners ;
3727- var periodical_predictions = null ;
37283744var timer_seconds = 30 ;
37293745
37303746function startAjax ( ) {
@@ -3736,7 +3752,6 @@ function startAjax() {
37363752 clearTimeout ( periodical_focus ) ;
37373753 clearTimeout ( periodical_focus_new ) ;
37383754 clearTimeout ( periodical_receivers ) ;
3739- clearTimeout ( periodical_predictions ) ;
37403755
37413756 //periodical = setInterval(refresh, timer_seconds * 1000);
37423757 refresh ( ) ;
@@ -3761,8 +3776,6 @@ function stopAjax() {
37613776 ajax_inprogress_single_new = false ;
37623777 if ( ajax_positions_single_new ) ajax_positions_single_new . abort ( ) ;
37633778
3764- clearTimeout ( periodical_predictions ) ;
3765- periodical_predictions = null ;
37663779 if ( ajax_predictions ) ajax_predictions . abort ( ) ;
37673780}
37683781
@@ -4200,7 +4213,6 @@ function update(response, none) {
42004213
42014214 }
42024215
4203- if ( periodical_predictions === null ) refreshPredictions ( ) ;
42044216 } ,
42054217
42064218 } ;
0 commit comments