Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup RTDB connection before auth token is fetched #2349

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
28 changes: 16 additions & 12 deletions packages/database/src/core/PersistentConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,22 @@ export class PersistentConnection extends ServerActions {

const forceRefresh = this.forceTokenRefresh_;
this.forceTokenRefresh_ = false;

// Establish connection with RTDB ASAP (whilst we're getting our auth token)
// so any queries made after auth token is fetched are not delayed (as much)
// by the WebSocket setup (which can take 500ms or more)
connection = new Connection(
connId,
self.repoInfo_,
onDataMessage,
onReady,
onDisconnect,
/* onKill= */ function(reason) {
warn(reason + ' (' + self.repoInfo_.toString() + ')');
self.interrupt(SERVER_KILL_INTERRUPT_REASON);
},
lastSessionId
);

// First fetch auth token, and establish connection after fetching the token was successful
this.authTokenProvider_
Expand All @@ -747,18 +763,6 @@ export class PersistentConnection extends ServerActions {
if (!canceled) {
log('getToken() completed. Creating connection.');
self.authToken_ = result && result.accessToken;
connection = new Connection(
connId,
self.repoInfo_,
onDataMessage,
onReady,
onDisconnect,
/* onKill= */ function(reason) {
warn(reason + ' (' + self.repoInfo_.toString() + ')');
self.interrupt(SERVER_KILL_INTERRUPT_REASON);
},
lastSessionId
);
} else {
log('getToken() completed but was canceled');
}
Expand Down