@@ -99,7 +99,7 @@ export class RealtimeHandler {
99
99
const numFailedStreams =
100
100
( ( await this . storage . getRealtimeBackoffMetadata ( ) ) ?. numFailedStreams ||
101
101
0 ) + 1 ;
102
- const backoffMillis = calculateBackoffMillis ( numFailedStreams ) * 60 ;
102
+ const backoffMillis = calculateBackoffMillis ( numFailedStreams , 60000 , 2 ) ;
103
103
await this . storage . setRealtimeBackoffMetadata ( {
104
104
backoffEndTimeMillis : new Date (
105
105
lastFailedStreamTime . getTime ( ) + backoffMillis
@@ -142,6 +142,7 @@ export class RealtimeHandler {
142
142
* and canceling the stream reader if they exist.
143
143
*/
144
144
private closeRealtimeHttpConnection ( ) : void {
145
+ // Aborting only when the controller is not null and tab is in foreground.
145
146
if ( this . controller && ! this . isInBackground ) {
146
147
this . controller . abort ( ) ;
147
148
this . controller = undefined ;
@@ -269,7 +270,7 @@ export class RealtimeHandler {
269
270
if ( fetchResponse . config != null && fetchResponse . templateVersion ) {
270
271
return fetchResponse . templateVersion >= lastKnownVersion ;
271
272
}
272
- return false ;
273
+ return this . storageCache . getLastFetchStatus ( ) === 'success' ;
273
274
}
274
275
275
276
private parseAndValidateConfigUpdateMessage ( message : string ) : string {
@@ -336,10 +337,11 @@ export class RealtimeHandler {
336
337
`Fetching config with custom signals: ${ JSON . stringify ( customSignals ) } `
337
338
) ;
338
339
}
340
+ const abortSignal = new RemoteConfigAbortSignal ( ) ;
339
341
try {
340
342
const fetchRequest : FetchRequest = {
341
343
cacheMaxAgeMillis : 0 ,
342
- signal : new RemoteConfigAbortSignal ( ) ,
344
+ signal : abortSignal ,
343
345
customSignals : customSignals ,
344
346
fetchType : 'REALTIME' ,
345
347
fetchAttempt : currentAttempt
@@ -409,10 +411,11 @@ export class RealtimeHandler {
409
411
return ;
410
412
}
411
413
412
- const timeTillFetch = this . getRandomInt ( 4 ) ;
414
+ const timeTillFetchSeconds = this . getRandomInt ( 4 ) ;
415
+ const timeTillFetchInMiliseconds = timeTillFetchSeconds * 1000 ;
413
416
setTimeout ( async ( ) => {
414
417
await this . fetchLatestConfig ( remainingAttempts , targetVersion ) ;
415
- } , timeTillFetch ) ;
418
+ } , timeTillFetchInMiliseconds ) ;
416
419
}
417
420
418
421
private async handleNotifications (
0 commit comments