File tree Expand file tree Collapse file tree 1 file changed +27
-23
lines changed
Expand file tree Collapse file tree 1 file changed +27
-23
lines changed Original file line number Diff line number Diff line change 703703 if ( cmd === "onConnect" ) {
704704 $ . extend ( opt , msg ) ;
705705 if ( opt . heartbeatUrl ) {
706- if ( opt . heartbeat ) {
707- window . clearInterval ( opt . heartbeat ) ;
708- }
709- opt . heartbeat = window . setInterval ( function ( ) {
710- if ( $ . ss . eventSource . readyState === 2 ) //CLOSED
711- {
712- window . clearInterval ( opt . heartbeat ) ;
713- var stopFn = $ . ss . handlers [ "onStop" ] ;
714- if ( stopFn != null )
715- stopFn . apply ( $ . ss . eventSource ) ;
716- $ . ss . reconnectServerEvents ( { errorArgs : { error :'CLOSED' } } ) ;
717- return ;
718- }
719- $ . ajax ( {
720- type : "POST" ,
721- url : opt . heartbeatUrl ,
722- data : null ,
723- dataType : "text" ,
724- success : function ( r ) { } ,
725- error : function ( ) {
726- $ . ss . reconnectServerEvents ( { errorArgs : arguments } ) ;
706+ $ . ss . CONNECT_ID = $ . ss . CONNECT_ID ? $ . ss . CONNECT_ID + 1 : 1 ;
707+ ( function ( connectId ) {
708+ function sendHeartbeat ( ) {
709+ if ( connectId !== $ . ss . CONNECT_ID ) // Only allow latest connections heartbeat callback through
710+ return ;
711+ if ( $ . ss . eventSource . readyState === 2 ) //CLOSED
712+ {
713+ var stopFn = $ . ss . handlers [ "onStop" ] ;
714+ if ( stopFn != null )
715+ stopFn . apply ( $ . ss . eventSource ) ;
716+ $ . ss . reconnectServerEvents ( { errorArgs : { error :'CLOSED' } } ) ;
717+ return ;
727718 }
728- } ) ;
729- } , parseInt ( opt . heartbeatIntervalMs ) || 10000 ) ;
719+ $ . ajax ( {
720+ type : "POST" ,
721+ url : opt . heartbeatUrl ,
722+ data : null ,
723+ dataType : "text" ,
724+ success : function ( r ) {
725+ setTimeout ( sendHeartbeat , parseInt ( opt . heartbeatIntervalMs ) || 10000 )
726+ } ,
727+ error : function ( ) {
728+ $ . ss . reconnectServerEvents ( { errorArgs : arguments } ) ;
729+ }
730+ } ) ;
731+ }
732+ setTimeout ( sendHeartbeat , parseInt ( opt . heartbeatIntervalMs ) || 10000 ) ;
733+ } ) ( $ . ss . CONNECT_ID ) ;
730734 }
731735 if ( opt . unRegisterUrl ) {
732736 $ ( window ) . on ( "unload" , function ( ) {
You can’t perform that action at this time.
0 commit comments