@@ -3327,6 +3327,7 @@ var ajax_positions_single_new = null;
3327
3327
var ajax_inprogress = false ;
3328
3328
var ajax_inprogress_single = false ;
3329
3329
var ajax_inprogress_single_new = false ;
3330
+ var ajax_positions_first_update_complete = false ;
3330
3331
3331
3332
function refresh ( ) {
3332
3333
if ( ajax_inprogress ) {
@@ -3381,6 +3382,12 @@ function refresh() {
3381
3382
clearTimeout ( periodical ) ;
3382
3383
ajax_inprogress = false ;
3383
3384
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
+
3384
3391
if ( wvar . query ) {
3385
3392
// If we have a query, pan the map to cover the payloads in that query.
3386
3393
var vehicle_query = wvar . query . replace ( / ; / g, ',' ) . split ( ',' ) ;
@@ -3498,6 +3505,7 @@ function liveData() {
3498
3505
// To revert listener-via-websockets change, comment out this line,
3499
3506
// and un-comment the 'Disable periodical listener refresh' lines further below.
3500
3507
client . subscribe ( "amateur-listener/#" ) ;
3508
+ client . subscribe ( "amateur-prediction/#" ) ;
3501
3509
3502
3510
clientConnected = true ;
3503
3511
$ ( "#stText" ) . text ( "websocket |" ) ;
@@ -3562,7 +3570,25 @@ function liveData() {
3562
3570
} else {
3563
3571
updateReceivers ( formatted_frame , single = true ) ;
3564
3572
}
3573
+ } else if ( message . topic . startsWith ( "amateur-prediction" ) ) {
3574
+ var frame = JSON . parse ( message . payloadString . toString ( ) ) ;
3565
3575
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 ) ;
3566
3592
} else {
3567
3593
// Message is payload telemetry
3568
3594
@@ -3699,12 +3725,6 @@ function refreshNewReceivers(initial, serial) {
3699
3725
var ajax_predictions = null ;
3700
3726
3701
3727
function refreshPredictions ( ) {
3702
- if ( ajax_inprogress ) {
3703
- clearTimeout ( periodical_predictions ) ;
3704
- periodical_predictions = setTimeout ( refreshPredictions , 1000 ) ;
3705
- return ;
3706
- }
3707
-
3708
3728
ajax_predictions = $ . ajax ( {
3709
3729
type : "GET" ,
3710
3730
url : predictions_url + encodeURIComponent ( wvar . query ) ,
@@ -3716,15 +3736,11 @@ function refreshPredictions() {
3716
3736
error : function ( ) {
3717
3737
} ,
3718
3738
complete : function ( request , textStatus ) {
3719
- clearTimeout ( periodical_predictions ) ;
3720
- // TODO - Switch this to websockets as well.
3721
- periodical_predictions = setTimeout ( refreshPredictions , 60 * 1000 ) ;
3722
3739
}
3723
3740
} ) ;
3724
3741
}
3725
3742
3726
3743
var periodical , periodical_focus , periodical_focus_new , periodical_receivers , periodical_listeners ;
3727
- var periodical_predictions = null ;
3728
3744
var timer_seconds = 30 ;
3729
3745
3730
3746
function startAjax ( ) {
@@ -3736,7 +3752,6 @@ function startAjax() {
3736
3752
clearTimeout ( periodical_focus ) ;
3737
3753
clearTimeout ( periodical_focus_new ) ;
3738
3754
clearTimeout ( periodical_receivers ) ;
3739
- clearTimeout ( periodical_predictions ) ;
3740
3755
3741
3756
//periodical = setInterval(refresh, timer_seconds * 1000);
3742
3757
refresh ( ) ;
@@ -3761,8 +3776,6 @@ function stopAjax() {
3761
3776
ajax_inprogress_single_new = false ;
3762
3777
if ( ajax_positions_single_new ) ajax_positions_single_new . abort ( ) ;
3763
3778
3764
- clearTimeout ( periodical_predictions ) ;
3765
- periodical_predictions = null ;
3766
3779
if ( ajax_predictions ) ajax_predictions . abort ( ) ;
3767
3780
}
3768
3781
@@ -4200,7 +4213,6 @@ function update(response, none) {
4200
4213
4201
4214
}
4202
4215
4203
- if ( periodical_predictions === null ) refreshPredictions ( ) ;
4204
4216
} ,
4205
4217
4206
4218
} ;
0 commit comments