Skip to content

Commit

Permalink
Fix db.useEmulator (#4828)
Browse files Browse the repository at this point in the history
* Fix db.useEmulator

* Create sweet-monkeys-warn.md
  • Loading branch information
schmidt-sebastian committed Apr 27, 2021
1 parent d47fb41 commit d422436
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/sweet-monkeys-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@firebase/database": patch
---

Fixes a regression introduced with 8.4.1 that broke `useEmulator()`.
13 changes: 6 additions & 7 deletions packages/database/src/core/PersistentConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,6 @@ export class PersistentConnection extends ServerActions {
const onReady = this.onReady_.bind(this);
const onDisconnect = this.onRealtimeDisconnect_.bind(this);
const connId = this.id + ':' + PersistentConnection.nextConnectionId_++;
const self = this;
const lastSessionId = this.lastSessionId;
let canceled = false;
let connection: Connection | null = null;
Expand Down Expand Up @@ -807,17 +806,17 @@ export class PersistentConnection extends ServerActions {
.then(result => {
if (!canceled) {
log('getToken() completed. Creating connection.');
self.authToken_ = result && result.accessToken;
this.authToken_ = result && result.accessToken;
connection = new Connection(
connId,
self.repoInfo_,
self.applicationId_,
this.repoInfo_,
this.applicationId_,
onDataMessage,
onReady,
onDisconnect,
/* onKill= */ reason => {
warn(reason + ' (' + self.repoInfo_.toString() + ')');
self.interrupt(SERVER_KILL_INTERRUPT_REASON);
warn(reason + ' (' + this.repoInfo_.toString() + ')');
this.interrupt(SERVER_KILL_INTERRUPT_REASON);
},
lastSessionId
);
Expand All @@ -826,7 +825,7 @@ export class PersistentConnection extends ServerActions {
}
})
.then(null, error => {
self.log_('Failed to get token: ' + error);
this.log_('Failed to get token: ' + error);
if (!canceled) {
if (this.repoInfo_.nodeAdmin) {
// This may be a critical error for the Admin Node.js SDK, so log a warning.
Expand Down
4 changes: 2 additions & 2 deletions packages/database/src/exp/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export class FirebaseDatabase implements _FirebaseService {

/** @hideconstructor */
constructor(
private _repoInternal: Repo,
public _repoInternal: Repo,
/** The FirebaseApp associated with this Realtime Database instance. */
readonly app: FirebaseApp
) {}
Expand Down Expand Up @@ -300,7 +300,7 @@ export function useDatabaseEmulator(
);
}
// Modify the repo to apply emulator settings
repoManagerApplyEmulatorSettings(db._repo, host, port);
repoManagerApplyEmulatorSettings(db._repoInternal, host, port);
}

/**
Expand Down

0 comments on commit d422436

Please sign in to comment.