@@ -10,6 +10,7 @@ var livedata = "wss://ws-reader.v2.sondehub.org/";
1010var clientID = "SondeHub-Tracker-" + Math . floor ( Math . random ( ) * 10000 ) ;
1111var client = new Paho . Client ( livedata , clientID ) ;
1212var clientConnected = false ;
13+ var clientActive = false ;
1314
1415var host_url = "" ;
1516var markers_url = "img/markers/" ;
@@ -341,9 +342,8 @@ function clean_refresh(text, force, history_step) {
341342 if ( text == wvar . mode && ! force ) return false ;
342343 stopAjax ( ) ;
343344
344- if ( clientConnected ) {
345- client . disconnect ( ) ;
346- clientConnected = false ;
345+ if ( clientActive ) {
346+ clientActive = false ;
347347 }
348348
349349 // reset mode if, invalid mode is specified
@@ -2910,6 +2910,8 @@ function refresh() {
29102910 if ( wvar . query == "" || sondePrefix . indexOf ( wvar . query ) > - 1 ) {
29112911 if ( ! clientConnected ) {
29122912 liveData ( ) ;
2913+ } else if ( clientConnected ) {
2914+ clientActive = true ;
29132915 }
29142916 }
29152917 clearTimeout ( periodical ) ;
@@ -2927,35 +2929,40 @@ function liveData() {
29272929 function onConnect ( ) {
29282930 client . subscribe ( "#" ) ;
29292931 clientConnected = true ;
2932+ clientActive = true ;
29302933 } ;
29312934
29322935 function connectionError ( error ) {
29332936 $ ( "#stText" ) . text ( "error |" ) ;
29342937 clientConnected = false ;
2938+ clientActive = false ;
29352939 refresh ( ) ;
29362940 } ;
29372941
29382942 function onConnectionLost ( responseObject ) {
29392943 if ( responseObject . errorCode !== 0 ) {
29402944 clientConnected = false ;
2945+ clientActive = false ;
29412946 refresh ( ) ;
29422947 }
29432948 } ;
29442949
29452950 function onMessageArrived ( message ) {
2946- var frame = JSON . parse ( message . payloadString . toString ( ) ) ;
2947- if ( ( new Date ( ) . getTime ( ) - new Date ( frame . time_received ) . getTime ( ) ) < 30000 ) {
2948- var test = formatData ( frame , true ) ;
2949- if ( clientConnected ) {
2950- update ( test ) ;
2951+ if ( clientActive ) {
2952+ var frame = JSON . parse ( message . payloadString . toString ( ) ) ;
2953+ if ( ( new Date ( ) . getTime ( ) - new Date ( frame . time_received ) . getTime ( ) ) < 30000 ) {
2954+ var test = formatData ( frame , true ) ;
2955+ if ( clientActive ) {
2956+ update ( test ) ;
2957+ }
2958+ $ ( "#stTimer" ) . attr ( "data-timestamp" , new Date ( ) . getTime ( ) ) ;
2959+ $ ( "#stText" ) . text ( "websocket |" ) ;
2960+ } else if ( ( new Date ( ) . getTime ( ) - new Date ( frame . time_received ) . getTime ( ) ) > 150000 ) {
2961+ $ ( "#stText" ) . text ( "error |" ) ;
2962+ refresh ( ) ;
2963+ } else {
2964+ $ ( "#stText" ) . text ( "error |" ) ;
29512965 }
2952- $ ( "#stTimer" ) . attr ( "data-timestamp" , new Date ( ) . getTime ( ) ) ;
2953- $ ( "#stText" ) . text ( "websocket |" ) ;
2954- } else if ( ( new Date ( ) . getTime ( ) - new Date ( frame . time_received ) . getTime ( ) ) > 150000 ) {
2955- $ ( "#stText" ) . text ( "error |" ) ;
2956- refresh ( ) ;
2957- } else {
2958- $ ( "#stText" ) . text ( "error |" ) ;
29592966 }
29602967 } ;
29612968}
0 commit comments