@@ -291,7 +291,9 @@ function PN_API(setup) {
291291 , jsonp_cb = setup [ 'jsonp_cb' ] || function ( ) { return 0 }
292292 , db = setup [ 'db' ] || { 'get' : function ( ) { } , 'set' : function ( ) { } }
293293 , CIPHER_KEY = setup [ 'cipher_key' ]
294- , UUID = setup [ 'uuid' ] || ( db && db [ 'get' ] ( SUBSCRIBE_KEY + 'uuid' ) || '' ) ;
294+ , UUID = setup [ 'uuid' ] || ( db && db [ 'get' ] ( SUBSCRIBE_KEY + 'uuid' ) || '' )
295+ , _poll_timer
296+ , _poll_timer2 ;
295297
296298 var crypto_obj = setup [ 'crypto_obj' ] ||
297299 {
@@ -1351,6 +1353,10 @@ function PN_API(setup) {
13511353 fail : function ( response ) { _invoke_error ( response , err ) ; }
13521354 } ) ;
13531355 } ,
1356+ 'stop_timers' : function ( ) {
1357+ clearTimeout ( _poll_timer ) ;
1358+ clearTimeout ( _poll_timer2 ) ;
1359+ } ,
13541360
13551361 // Expose PUBNUB Functions
13561362 'xdr' : xdr ,
@@ -1372,7 +1378,8 @@ function PN_API(setup) {
13721378 _is_online ( ) || _reset_offline ( 1 , {
13731379 "error" : "Offline. Please check your network settings. "
13741380 } ) ;
1375- timeout ( _poll_online , SECOND ) ;
1381+ _poll_timer && clearTimeout ( _poll_timer ) ;
1382+ _poll_timer = timeout ( _poll_online , SECOND ) ;
13761383 }
13771384
13781385 function _poll_online2 ( ) {
@@ -1382,20 +1389,24 @@ function PN_API(setup) {
13821389 "error" : "Heartbeat failed to connect to Pubnub Servers." +
13831390 "Please check your network settings."
13841391 } ) ;
1385- timeout ( _poll_online2 , KEEPALIVE ) ;
1392+ _poll_timer2 && clearTimeout ( _poll_timer2 ) ;
1393+ _poll_timer2 = timeout ( _poll_online2 , KEEPALIVE ) ;
13861394 } ) ;
13871395 }
13881396
13891397 function _reset_offline ( err , msg ) {
13901398 SUB_RECEIVER && SUB_RECEIVER ( err , msg ) ;
13911399 SUB_RECEIVER = null ;
1400+
1401+ clearTimeout ( _poll_timer ) ;
1402+ clearTimeout ( _poll_timer2 ) ;
13921403 }
13931404
13941405 if ( ! UUID ) UUID = SELF [ 'uuid' ] ( ) ;
13951406 db [ 'set' ] ( SUBSCRIBE_KEY + 'uuid' , UUID ) ;
13961407
1397- timeout ( _poll_online , SECOND ) ;
1398- timeout ( _poll_online2 , KEEPALIVE ) ;
1408+ _poll_timer = timeout ( _poll_online , SECOND ) ;
1409+ _poll_timer2 = timeout ( _poll_online2 , KEEPALIVE ) ;
13991410 PRESENCE_HB_TIMEOUT = timeout ( start_presence_heartbeat , ( PRESENCE_HB_INTERVAL - 3 ) * SECOND ) ;
14001411
14011412 // Detect Age of Message
0 commit comments