@@ -165,7 +165,6 @@ export class PersistentConnection extends ServerActions {
165
165
'Auth override specified in options, but not supported on non Node.js platforms'
166
166
) ;
167
167
}
168
- this . scheduleConnect_ ( 0 ) ;
169
168
170
169
VisibilityMonitor . getInstance ( ) . on ( 'visible' , this . onVisible_ , this ) ;
171
170
@@ -194,6 +193,8 @@ export class PersistentConnection extends ServerActions {
194
193
}
195
194
196
195
get ( query : QueryContext ) : Promise < string > {
196
+ this . initConnection_ ( ) ;
197
+
197
198
const deferred = new Deferred < string > ( ) ;
198
199
const request = {
199
200
p : query . _path . toString ( ) ,
@@ -249,6 +250,8 @@ export class PersistentConnection extends ServerActions {
249
250
tag : number | null ,
250
251
onComplete : ( a : string , b : unknown ) => void
251
252
) {
253
+ this . initConnection_ ( ) ;
254
+
252
255
const queryId = query . _queryIdentifier ;
253
256
const pathString = query . _path . toString ( ) ;
254
257
this . log_ ( 'Listen called for ' + pathString + ' ' + queryId ) ;
@@ -490,6 +493,8 @@ export class PersistentConnection extends ServerActions {
490
493
data : unknown ,
491
494
onComplete ?: ( a : string , b : string ) => void
492
495
) {
496
+ this . initConnection_ ( ) ;
497
+
493
498
if ( this . connected_ ) {
494
499
this . sendOnDisconnect_ ( 'o' , pathString , data , onComplete ) ;
495
500
} else {
@@ -506,6 +511,8 @@ export class PersistentConnection extends ServerActions {
506
511
data : unknown ,
507
512
onComplete ?: ( a : string , b : string ) => void
508
513
) {
514
+ this . initConnection_ ( ) ;
515
+
509
516
if ( this . connected_ ) {
510
517
this . sendOnDisconnect_ ( 'om' , pathString , data , onComplete ) ;
511
518
} else {
@@ -521,6 +528,8 @@ export class PersistentConnection extends ServerActions {
521
528
pathString : string ,
522
529
onComplete ?: ( a : string , b : string ) => void
523
530
) {
531
+ this . initConnection_ ( ) ;
532
+
524
533
if ( this . connected_ ) {
525
534
this . sendOnDisconnect_ ( 'oc' , pathString , null , onComplete ) ;
526
535
} else {
@@ -576,6 +585,8 @@ export class PersistentConnection extends ServerActions {
576
585
onComplete : ( a : string , b : string | null ) => void ,
577
586
hash ?: string
578
587
) {
588
+ this . initConnection_ ( ) ;
589
+
579
590
const request : { [ k : string ] : unknown } = {
580
591
/*path*/ p : pathString ,
581
592
/*data*/ d : data
@@ -737,6 +748,12 @@ export class PersistentConnection extends ServerActions {
737
748
} , Math . floor ( timeout ) ) as any ;
738
749
}
739
750
751
+ private initConnection_ ( ) {
752
+ if ( ! this . realtime_ && this . firstConnection_ ) {
753
+ this . scheduleConnect_ ( 0 ) ;
754
+ }
755
+ }
756
+
740
757
private onVisible_ ( visible : boolean ) {
741
758
// NOTE: Tabbing away and back to a window will defeat our reconnect backoff, but I think that's fine.
742
759
if (
0 commit comments