@@ -27,6 +27,7 @@ import { Provider } from '@firebase/component';
2727import {
2828 getModularInstance ,
2929 createMockUserToken ,
30+ // deepEqual,
3031 EmulatorMockTokenOptions ,
3132 getDefaultEmulatorHostnameAndPort
3233} from '@firebase/util' ;
@@ -38,7 +39,7 @@ import {
3839 FirebaseAuthTokenProvider
3940} from '../core/AuthTokenProvider' ;
4041import { Repo , repoInterrupt , repoResume , repoStart } from '../core/Repo' ;
41- import { RepoInfo } from '../core/RepoInfo' ;
42+ import { RepoInfo , RepoInfoEmulatorOptions } from '../core/RepoInfo' ;
4243import { parseRepoInfo } from '../core/util/libs/parser' ;
4344import { newEmptyPath , pathIsEmpty } from '../core/util/Path' ;
4445import {
@@ -84,19 +85,20 @@ let useRestClient = false;
8485 */
8586function repoManagerApplyEmulatorSettings (
8687 repo : Repo ,
87- host : string ,
88- port : number ,
89- tokenProvider ?: AuthTokenProvider
88+ hostAndPort : string ,
89+ emulatorOptions : RepoInfoEmulatorOptions ,
90+ tokenProvider ?: AuthTokenProvider ,
9091) : void {
9192 repo . repoInfo_ = new RepoInfo (
92- ` ${ host } : ${ port } ` ,
93+ hostAndPort ,
9394 /* secure= */ false ,
9495 repo . repoInfo_ . namespace ,
9596 repo . repoInfo_ . webSocketOnly ,
9697 repo . repoInfo_ . nodeAdmin ,
9798 repo . repoInfo_ . persistenceKey ,
9899 repo . repoInfo_ . includeNamespaceInQueryParams ,
99- /*isUsingEmulator=*/ true
100+ /*isUsingEmulator=*/ true ,
101+ emulatorOptions
100102 ) ;
101103
102104 if ( tokenProvider ) {
@@ -350,13 +352,23 @@ export function connectDatabaseEmulator(
350352) : void {
351353 db = getModularInstance ( db ) ;
352354 db . _checkNotDeleted ( 'useEmulator' ) ;
355+ const hostAndPort = `${ host } :${ port } ` ;
356+ const repo = db . _repoInternal ;
353357 if ( db . _instanceStarted ) {
358+ // If the instance has already been started, then silenty fail if this function is called again
359+ // with the same parameters. If the parameters differ then assert.
360+ if (
361+ true
362+ // hostAndPort === db._repoInternal.repoInfo_.host //&&
363+ //deepEqual(options, repo.repoInfo_.emulatorOptions)
364+ ) {
365+ return ;
366+ }
354367 fatal (
355- 'Cannot call useEmulator () after instance has already been initialized .'
368+ 'connectDatabaseEmulator () cannot alter the emulator configuration after the database instance has started .'
356369 ) ;
357370 }
358371
359- const repo = db . _repoInternal ;
360372 let tokenProvider : EmulatorTokenProvider | undefined = undefined ;
361373 if ( repo . repoInfo_ . nodeAdmin ) {
362374 if ( options . mockUserToken ) {
@@ -374,7 +386,7 @@ export function connectDatabaseEmulator(
374386 }
375387
376388 // Modify the repo to apply emulator settings
377- repoManagerApplyEmulatorSettings ( repo , host , port , tokenProvider ) ;
389+ repoManagerApplyEmulatorSettings ( repo , hostAndPort , options , tokenProvider ) ;
378390}
379391
380392/**
0 commit comments