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 {
149
149
throw new Error ( 'You need to set a proper Parse LiveQuery server url before using LiveQueryClient' ) ;
150
150
}
151
151
152
+ this . reconnectHandle = null ;
152
153
this . attempts = 1 ; ;
153
154
this . id = 0 ;
154
155
this . requestId = 1 ;
@@ -427,13 +428,25 @@ export default class LiveQueryClient extends events.EventEmitter {
427
428
428
429
_handleReconnect ( ) {
429
430
// 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 ) {
431
432
return ;
432
433
}
434
+
433
435
this . state = CLIENT_STATE . RECONNECTING ;
434
436
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 ( ( ( ) => {
437
450
this . attempts ++ ;
438
451
this . connectPromise = new ParsePromise ( ) ;
439
452
this . open ( ) ;
You can’t perform that action at this time.
0 commit comments