Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
22ba366
added the api-definition, interfaces, realtime connection and backoff…
Samruddhi90 Aug 8, 2025
77bc5ef
Added TODO and comments
Samruddhi90 Aug 8, 2025
c16eadd
Added the visibilityMonitor
Samruddhi90 Aug 9, 2025
c5d7dfb
resolved the comment about the spacing problem
Samruddhi90 Aug 11, 2025
77a6aca
Fix check failures
Samruddhi90 Aug 11, 2025
4002ed9
minor changes
Samruddhi90 Aug 11, 2025
0ff4893
Fix yarn failures
Samruddhi90 Aug 12, 2025
52686fc
Merge branch 'realtime-backoff' into realtime-visibility-api
Samruddhi90 Aug 12, 2025
6105412
resolving the spacing problem
Samruddhi90 Aug 12, 2025
61ba815
Convert backoff time from seconds to minutes
Samruddhi90 Aug 12, 2025
a98f140
Merge branch 'realtime-backoff' into realtime-visibility-api
Samruddhi90 Aug 12, 2025
c4a8b72
fixed the minor errors
Samruddhi90 Aug 13, 2025
5b23deb
Minor refactoring
Samruddhi90 Aug 13, 2025
960b88e
fixing yarn lint errors
Samruddhi90 Aug 13, 2025
2653ebb
Adding synchronous delay
Samruddhi90 Aug 13, 2025
b8b2751
updating the fetch call
Samruddhi90 Aug 14, 2025
024e042
Closing the connection in a proper way
Samruddhi90 Aug 14, 2025
f882ad4
close connection async
Samruddhi90 Aug 14, 2025
a7d271b
Added the comments
Samruddhi90 Aug 14, 2025
ac82ed7
minor fixes
Samruddhi90 Aug 14, 2025
006127b
Modifying the name of the method `beginRealtimeHttpStream` to `prepar…
Samruddhi90 Aug 18, 2025
874299e
Updating the onConfigUpdate method definition.
Samruddhi90 Aug 18, 2025
412b664
Merge branch 'realtime-for-web' into realtime-handle-notifications
Samruddhi90 Aug 18, 2025
649a2ac
Delete realtime_handler.test.ts
Samruddhi90 Aug 18, 2025
11077d8
fixing the comments.
Samruddhi90 Aug 18, 2025
494af7d
Adding a TODO for X-`Firebase-RC-Fetch-Type` header
Samruddhi90 Aug 20, 2025
385d8bd
Update the errorcodes
Samruddhi90 Aug 20, 2025
f583f8e
minor fix
Samruddhi90 Aug 20, 2025
17b9eb5
Resolving the comment
Samruddhi90 Aug 20, 2025
3eee5f8
Adding changeset
Samruddhi90 Aug 21, 2025
5d43520
Realtime RC test cases (#9210)
Samruddhi90 Aug 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added the comments
  • Loading branch information
Samruddhi90 committed Aug 14, 2025
commit a7d271b666c2fcfa255574ee7327970655ee63a8
41 changes: 32 additions & 9 deletions packages/remote-config/src/client/realtime_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ export class RealtimeHandler {
});
}

/**
* Increase the backoff duration with a new end time based on Retry Interval.
*/
private async updateBackoffMetadataWithRetryInterval(
retryIntervalSeconds: number
): Promise<void> {
Expand Down Expand Up @@ -139,8 +142,9 @@ export class RealtimeHandler {
};

/**
* Stops the real-time HTTP connection by aborting the in-progress fetch request
* and canceling the stream reader if they exist.
* Closes the realtime HTTP connection.
* Note: This method is designed to be called only once at a time.
* If a call is already in progress, subsequent calls will be ignored.
*/
private async closeRealtimeHttpConnection(): Promise<void> {
if (this.isClosingConnection) {
Expand Down Expand Up @@ -262,6 +266,11 @@ export class RealtimeHandler {
this.isConnectionActive = connectionRunning;
}

/**
* Combines the check and set operations to prevent multiple asynchronous
* calls from redundantly starting an HTTP connection. This ensures that
* only one attempt is made at a time.
*/
private checkAndSetHttpConnectionFlagIfNotRunning(): boolean {
const canMakeConnection = this.canEstablishStreamConnection();
if (canMakeConnection) {
Expand All @@ -274,9 +283,12 @@ export class RealtimeHandler {
fetchResponse: FetchResponse,
lastKnownVersion: number
): boolean {
// If there is a config, make sure its version is >= the last known version.
if (fetchResponse.config != null && fetchResponse.templateVersion) {
return fetchResponse.templateVersion >= lastKnownVersion;
}
// If there isn't a config, return true if the fetch was successful and backend had no update.
// Else, it returned an out of date config.
return this.storageCache.getLastFetchStatus() === 'success';
}

Expand All @@ -302,6 +314,10 @@ export class RealtimeHandler {
this.observers.forEach(observer => observer.next(configUpdate));
}

/**
* Compares two configuration objects and returns a set of keys that have changed.
* A key is considered changed if it's new, removed, or has a different value.
*/
private getChangedParams(
newConfig: FirebaseRemoteConfigObject,
oldConfig: FirebaseRemoteConfigObject
Expand Down Expand Up @@ -420,6 +436,13 @@ export class RealtimeHandler {
await this.fetchLatestConfig(remainingAttempts, targetVersion);
}

/**
* Processes a stream of real-time messages for configuration updates.
* This method reassembles fragmented messages, validates and parses the JSON,
* and automatically fetches a new config if a newer template version is available.
* It also handles server-specified retry intervals and propagates errors for
* invalid messages or when real-time updates are disabled.
*/
private async handleNotifications(
reader: ReadableStreamDefaultReader
): Promise<void> {
Expand Down Expand Up @@ -527,13 +550,6 @@ export class RealtimeHandler {
'Real-time connection was closed due to an exception.'
);
}
} finally {
// Only need to close the reader, beginRealtimeHttpStream will disconnect
// the connection
if (this.reader) {
void this.reader.cancel();
this.reader = undefined;
}
}
}

Expand Down Expand Up @@ -680,6 +696,13 @@ export class RealtimeHandler {
}
}

/**
* Handles changes to the application's visibility state, managing the real-time connection.
*
* When the application is moved to the background, this method closes the existing
* real-time connection to save resources. When the application returns to the
* foreground, it attempts to re-establish the connection.
*/
private async onVisibilityChange(visible: unknown): Promise<void> {
this.isInBackground = !visible;
if (!visible) {
Expand Down
Loading