File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -149,6 +149,7 @@ export default class LiveQueryClient extends events.EventEmitter {
149149 throw new Error ( 'You need to set a proper Parse LiveQuery server url before using LiveQueryClient' ) ;
150150 }
151151
152+ this . reconnectHandle = null ;
152153 this . attempts = 1 ; ;
153154 this . id = 0 ;
154155 this . requestId = 1 ;
@@ -427,13 +428,25 @@ export default class LiveQueryClient extends events.EventEmitter {
427428
428429 _handleReconnect ( ) {
429430 // if closed or currently reconnecting we stop attempting to reconnect
430- if ( this . state === CLIENT_STATE . DISCONNECTED || this . state === CLIENT_STATE . RECONNECTING ) {
431+ if ( this . state === CLIENT_STATE . DISCONNECTED ) {
431432 return ;
432433 }
434+
433435 this . state = CLIENT_STATE . RECONNECTING ;
434436 let time = generateInterval ( this . attempts ) ;
435- console . info ( 'attempting to reconnect after ' + time + 'ms' ) ;
436- setTimeout ( ( ( ) => {
437+
438+ // handle case when both close/error occur at frequent rates we ensure we do not reconnect unnecessarily.
439+ // we're unable to distinguish different between close/error when we're unable to reconnect therefore
440+ // we try to reonnect in both cases
441+ // server side ws and browser WebSocket behave differently in when close/error get triggered
442+
443+ if ( this . reconnectHandle ) {
444+ clearTimeout ( this . reconnectHandle ) ;
445+ } else {
446+ console . info ( 'attempting to reconnect' ) ;
447+ }
448+
449+ this . reconnectHandle = setTimeout ( ( ( ) => {
437450 this . attempts ++ ;
438451 this . connectPromise = new ParsePromise ( ) ;
439452 this . open ( ) ;
You can’t perform that action at this time.
0 commit comments