@@ -3526,7 +3526,7 @@ function refresh() {
35263526 $ ( "#stText" ) . text ( "" ) ;
35273527 } ,
35283528 error : function ( ) {
3529- $ ( "#stText" ) . text ( "error |" ) ;
3529+ $ ( "#stText" ) . text ( "poll error |" ) ;
35303530 document . getElementById ( "timeperiod" ) . disabled = false ;
35313531 ajax_inprogress = false ;
35323532 } ,
@@ -3535,6 +3535,7 @@ function refresh() {
35353535 document . getElementById ( "timeperiod" ) . disabled = false ;
35363536 }
35373537 clientActive = true ;
3538+ //console.log("WebSockets - Resuming Websockets updates after poll.")
35383539 clearTimeout ( periodical ) ;
35393540 ajax_inprogress = false ;
35403541 }
@@ -3628,37 +3629,61 @@ function liveData() {
36283629
36293630 } else {
36303631 var frame = JSON . parse ( message . payloadString . toString ( ) ) ;
3632+
36313633 if ( wvar . query == "" || sondePrefix . indexOf ( wvar . query ) > - 1 || wvar . query == frame . serial ) {
3632- if ( frame . length == null ) {
3633- var tempDate = new Date ( frame . time_received ) . getTime ( ) ;
3634- } else {
3635- var tempDate = new Date ( frame [ frame . length - 1 ] . time_received ) . getTime ( )
3636- }
3637- if ( ( dateNow - tempDate ) < 45000 ) {
3638- var test = formatData ( frame , true ) ;
3639- if ( clientActive ) {
3640- live_data_buffer . positions . position . push . apply ( live_data_buffer . positions . position , test . positions . position )
3641- }
3634+
3635+ var test = formatData ( frame , true ) ;
3636+ if ( clientActive ) {
3637+ live_data_buffer . positions . position . push . apply ( live_data_buffer . positions . position , test . positions . position )
36423638 $ ( "#stTimer" ) . attr ( "data-timestamp" , dateNow ) ;
36433639 $ ( "#stText" ) . text ( "websocket |" ) ;
3644- } else if ( ( dateNow - new Date ( frame . time_received ) . getTime ( ) ) > 150000 ) {
3645- $ ( "#stText" ) . text ( "data error |" ) ;
3646- refresh ( ) ;
3647- } else {
3648- $ ( "#stText" ) . text ( "data error |" ) ;
36493640 }
3641+
3642+ // if (frame.length == null) {
3643+ // var tempDate = new Date(frame.datetime).getTime();
3644+ // } else {
3645+ // var tempDate = new Date(frame[frame.length - 1].datetime).getTime()
3646+ // }
3647+ // if ((dateNow - tempDate) < 100000) {
3648+ // // Data is recent enough.
3649+ // var test = formatData(frame, true);
3650+ // if (clientActive) {
3651+ // live_data_buffer.positions.position.push.apply(live_data_buffer.positions.position,test.positions.position)
3652+ // }
3653+ // $("#stTimer").attr("data-timestamp", dateNow);
3654+ // $("#stText").text("websocket ("+ ((dateNow - tempDate)/1000).toFixed(1) +" s) |");
3655+ // } else if ((dateNow - new Date(frame.datetime).getTime()) > 150000) {
3656+ // // Data is very old, which may indicate that our tab has probably been suspended.
3657+ // // We now poll for data.
3658+ // $("#stText").text("data error ("+ ((dateNow - tempDate)/1000).toFixed(1) +" s) |");
3659+ // console.log("WebSockets - Data Age was " + ((dateNow - tempDate)/1000).toFixed(1) + " s, frame length: " + frame.length + ". Discarding and polling for data.");
3660+ // // Discard all further messages until we have finished the next poll.
3661+ // console.log("WebSockets - Tab possibly suspended, polling for updates.")
3662+ // clientActive = false;
3663+ // refresh();
3664+ // } else {
3665+ // $("#stText").text("data error ("+ ((dateNow - tempDate)/1000).toFixed(1) +" s) |");
3666+ // console.log("WebSockets - Data Age was " + ((dateNow - tempDate)/1000).toFixed(1) + " s, frame length: " + frame.length + ". Discarding frame.");
3667+ // }
36503668 }
36513669 }
3670+ } else {
3671+ console . log ( "WebSockets - Discarding Message, not ready yet." )
36523672 }
36533673 }
36543674 catch ( err ) { }
36553675 } ;
36563676}
36573677
3678+
3679+ // Interval to read in the live data buffer and update the page.
36583680setInterval ( function ( ) {
36593681 update ( live_data_buffer ) ;
36603682 live_data_buffer . positions . position = [ ] ;
3661- } , 200 )
3683+ } , 500 )
3684+
3685+ // Event listener to update on page resume from suspend.
3686+ document . addEventListener ( 'resume' , refresh ) ;
36623687
36633688function refreshSingle ( serial ) {
36643689 if ( ajax_inprogress_single ) {
@@ -4066,7 +4091,7 @@ function updateChase(r) {
40664091 response . positions . position = dataTemp ;
40674092 response . fetch_timestamp = Date . now ( ) ;
40684093 if ( response . positions . position . length > 0 ) {
4069- update ( response ) ;
4094+ live_data_buffer . positions . position . push . apply ( live_data_buffer . positions . position , response . positions . position )
40704095 }
40714096}
40724097
@@ -4115,7 +4140,7 @@ function updateReceivers(r, single) {
41154140 receiver . alt = alt ;
41164141 receiver . age = age . toISOString ( ) ;
41174142 receiver . description = "<font style='font-size: 13px'>" + receiver . name + "</font><br/><font size='-2'><BR><B>Radio: </B>" + last . software_name + "-" + last . software_version
4118- + "<BR><B>Antenna: </B>" + last . uploader_antenna + "<BR><B>Last Contact: </B>" + age . toISOString ( ) + "<BR></font>" ;
4143+ + "<BR><B>Antenna: </B>" + last . uploader_antenna + "<BR><B>Last Contact: </B>" + last . ts + "Z <BR></font>" ;
41194144 receiver . fresh = true ;
41204145
41214146 updateReceiverMarker ( receiver ) ;
@@ -4473,93 +4498,85 @@ function update(response, none) {
44734498 lastPPointer : lastPositions . positions . position ,
44744499 idx : 0 ,
44754500 max : response . positions . position . length ,
4476- step : function ( ctx ) {
4477- var draw_idx = - 1 ;
4501+ run : function ( ctx ) {
4502+ while ( ctx . idx < ctx . max ) {
4503+ var draw_idx = - 1 ;
44784504
4479- var i = ctx . idx ;
4480- var max = i + 5000 ;
4481- max = ( max >= ctx . max ) ? ctx . max : max ;
4505+ var i = ctx . idx ;
4506+ var max = i + 5000 ;
4507+ max = ( max >= ctx . max ) ? ctx . max : max ;
44824508
4483- for ( ; i < max ; i ++ ) {
4484- var row = ctx . positions [ i ] ;
4509+ for ( ; i < max ; i ++ ) {
4510+ var row = ctx . positions [ i ] ;
44854511
4486- // set the position based on the last record (oldest) returned from the server. Only provide minute accuracy to allow better hit rate with cloudfront
4487- this_position_id = new Date ( row . gps_time ) ;
4512+ // set the position based on the last record (oldest) returned from the server. Only provide minute accuracy to allow better hit rate with cloudfront
4513+ this_position_id = new Date ( row . gps_time ) ;
44884514
4489- if ( new Date ( position_id ) < this_position_id || position_id == 0 ) {
4490- if ( new Date ( ) > this_position_id ) {
4491- this_position_id . setSeconds ( 0 )
4492- this_position_id . setMilliseconds ( 0 )
4493- position_id = this_position_id . toISOString ( )
4515+ if ( new Date ( position_id ) < this_position_id || position_id == 0 ) {
4516+ if ( new Date ( ) > this_position_id ) {
4517+ this_position_id . setSeconds ( 0 )
4518+ this_position_id . setMilliseconds ( 0 )
4519+ position_id = this_position_id . toISOString ( )
4520+ }
44944521 }
4495- }
44964522
4497- if ( ! row . picture ) {
4498- addPosition ( row ) ;
4499- got_positions = true ;
4523+ if ( ! row . picture ) {
4524+ addPosition ( row ) ;
4525+ got_positions = true ;
4526+ }
45004527 }
4501- }
45024528
4503- ctx . idx = max ;
4529+ ctx . idx = max ;
45044530
4505- if ( ctx . idx < ctx . max ) {
4506- setTimeout ( function ( ) { ctx . step ( ctx ) ; } , 4 ) ;
4507- } else {
4508- ctx . list = Object . keys ( vehicles ) ;
4509- setTimeout ( function ( ) { ctx . draw ( ctx ) ; } , 16 ) ;
4510- }
4511- } ,
4512- draw : function ( ctx ) {
4513- if ( ctx . list . length < 1 ) {
4514- setTimeout ( function ( ) { ctx . end ( ctx ) ; } , 16 ) ;
4515- return ;
45164531 }
45174532
4518- // pop a callsign from the top
4519- var vcallsign = ctx . list . shift ( ) ;
4520- var vehicle = vehicles [ vcallsign ] ;
4533+ ctx . list = Object . keys ( vehicles ) ;
45214534
4522- if ( vehicle === undefined ) return ;
4535+ // draw loop
4536+ while ( ctx . list . length >= 1 ) {
4537+ // pop a callsign from the top
4538+ var vcallsign = ctx . list . shift ( ) ;
4539+ var vehicle = vehicles [ vcallsign ] ;
45234540
4524- if ( vehicle . updated ) {
4525- updatePolyline ( vcallsign ) ;
4526-
4527- updateVehicleInfo ( vcallsign , vehicle . curr_position ) ;
4541+ if ( vehicle === undefined ) return ;
45284542
4529- // remember last position for each vehicle
4530- ctx . lastPPointer . push ( vehicle . curr_position ) ;
4543+ if ( vehicle . updated ) {
4544+ updatePolyline ( vcallsign ) ;
4545+
4546+ updateVehicleInfo ( vcallsign , vehicle . curr_position ) ;
4547+
4548+ // remember last position for each vehicle
4549+ ctx . lastPPointer . push ( vehicle . curr_position ) ;
45314550
4532- if ( listScroll ) listScroll . refresh ( ) ;
4533- if ( zoomed_in && follow_vehicle == vcallsign && ! manual_pan ) panTo ( follow_vehicle ) ;
4534- if ( follow_vehicle == vcallsign ) {
4535- update_lookangles ( follow_vehicle ) ;
4536- drawLOSPaths ( vcallsign ) ;
4551+ if ( listScroll ) listScroll . refresh ( ) ;
4552+ if ( zoomed_in && follow_vehicle == vcallsign && ! manual_pan ) panTo ( follow_vehicle ) ;
4553+ if ( follow_vehicle == vcallsign ) {
4554+ update_lookangles ( follow_vehicle ) ;
4555+ drawLOSPaths ( vcallsign ) ;
4556+ }
45374557 }
45384558 }
4559+ // ctx.end
45394560
4540- // step to the next callsign
4541- setTimeout ( function ( ) { ctx . draw ( ctx ) ; } , 16 ) ;
4542- } ,
4543- end : function ( ctx ) {
4544-
4545- // update graph is current vehicles is followed
4546- if ( follow_vehicle !== null &&
4547- vehicles . hasOwnProperty ( follow_vehicle ) &&
4548- vehicles [ follow_vehicle ] . graph_data_updated ) updateGraph ( follow_vehicle , false ) ;
4561+ // update graph is current vehicles is followed
4562+ if ( follow_vehicle !== null &&
4563+ vehicles . hasOwnProperty ( follow_vehicle ) &&
4564+ vehicles [ follow_vehicle ] . graph_data_updated ) updateGraph ( follow_vehicle , false ) ;
45494565
4550- if ( got_positions && ! zoomed_in && Object . keys ( vehicles ) . length ) {
4566+ if ( got_positions && ! zoomed_in && Object . keys ( vehicles ) . length ) {
45514567 if ( vehicles . hasOwnProperty ( wvar . query ) && wvar . query !== "" ) {
45524568 zoom_on_payload ( ) ;
45534569 }
45544570 // TODO: Zoom to geolocation position
45554571
4556- }
4572+ }
4573+
4574+ if ( periodical_predictions === null ) refreshPredictions ( ) ;
4575+ } ,
45574576
4558- if ( periodical_predictions === null ) refreshPredictions ( ) ;
4559- }
45604577 } ;
45614578
4562- ctx_init . step ( ctx_init ) ;
4579+ ctx_init . run ( ctx_init ) ;
45634580}
45644581
45654582function zoom_on_payload ( ) {
0 commit comments