@firebase/database 0.14.0 → 0.14.1-canary.0bab0b7a7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@ import { stringify, jsonEval, contains, assert, isNodeSdk, stringToByteArray, Sh
4
4
  import { Logger, LogLevel } from '@firebase/logger';
5
5
 
6
6
  const name = "@firebase/database";
7
- const version = "0.14.0";
7
+ const version = "0.14.1-canary.0bab0b7a7";
8
8
 
9
9
  /**
10
10
  * @license
@@ -929,13 +929,14 @@ class RepoInfo {
929
929
  * @param nodeAdmin - Whether this instance uses Admin SDK credentials
930
930
  * @param persistenceKey - Override the default session persistence storage key
931
931
  */
932
- constructor(host, secure, namespace, webSocketOnly, nodeAdmin = false, persistenceKey = '', includeNamespaceInQueryParams = false) {
932
+ constructor(host, secure, namespace, webSocketOnly, nodeAdmin = false, persistenceKey = '', includeNamespaceInQueryParams = false, isUsingEmulator = false) {
933
933
  this.secure = secure;
934
934
  this.namespace = namespace;
935
935
  this.webSocketOnly = webSocketOnly;
936
936
  this.nodeAdmin = nodeAdmin;
937
937
  this.persistenceKey = persistenceKey;
938
938
  this.includeNamespaceInQueryParams = includeNamespaceInQueryParams;
939
+ this.isUsingEmulator = isUsingEmulator;
939
940
  this._host = host.toLowerCase();
940
941
  this._domain = this._host.substr(this._host.indexOf('.') + 1);
941
942
  this.internalHost =
@@ -1580,8 +1581,8 @@ class FirebaseIFrameScriptHolder {
1580
1581
  if (this.myIFrame) {
1581
1582
  //We have to actually remove all of the html inside this iframe before removing it from the
1582
1583
  //window, or IE will continue loading and executing the script tags we've already added, which
1583
- //can lead to some errors being thrown. Setting innerHTML seems to be the easiest way to do this.
1584
- this.myIFrame.doc.body.innerHTML = '';
1584
+ //can lead to some errors being thrown. Setting textContent seems to be the safest way to do this.
1585
+ this.myIFrame.doc.body.textContent = '';
1585
1586
  setTimeout(() => {
1586
1587
  if (this.myIFrame !== null) {
1587
1588
  document.body.removeChild(this.myIFrame);
@@ -2465,7 +2466,12 @@ class Connection {
2465
2466
  if (MESSAGE_DATA in controlData) {
2466
2467
  const payload = controlData[MESSAGE_DATA];
2467
2468
  if (cmd === SERVER_HELLO) {
2468
- this.onHandshake_(payload);
2469
+ const handshakePayload = Object.assign({}, payload);
2470
+ if (this.repoInfo_.isUsingEmulator) {
2471
+ // Upon connecting, the emulator will pass the hostname that it's aware of, but we prefer the user's set hostname via `connectDatabaseEmulator` over what the emulator passes.
2472
+ handshakePayload.h = this.repoInfo_.host;
2473
+ }
2474
+ this.onHandshake_(handshakePayload);
2469
2475
  }
2470
2476
  else if (cmd === END_TRANSMISSION) {
2471
2477
  this.log_('recvd end transmission on primary');
@@ -13453,7 +13459,8 @@ let useRestClient = false;
13453
13459
  */
13454
13460
  function repoManagerApplyEmulatorSettings(repo, host, port, tokenProvider) {
13455
13461
  repo.repoInfo_ = new RepoInfo(`${host}:${port}`,
13456
- /* secure= */ false, repo.repoInfo_.namespace, repo.repoInfo_.webSocketOnly, repo.repoInfo_.nodeAdmin, repo.repoInfo_.persistenceKey, repo.repoInfo_.includeNamespaceInQueryParams);
13462
+ /* secure= */ false, repo.repoInfo_.namespace, repo.repoInfo_.webSocketOnly, repo.repoInfo_.nodeAdmin, repo.repoInfo_.persistenceKey, repo.repoInfo_.includeNamespaceInQueryParams,
13463
+ /*isUsingEmulator=*/ true);
13457
13464
  if (tokenProvider) {
13458
13465
  repo.authTokenProvider_ = tokenProvider;
13459
13466
  }
@@ -13617,9 +13624,11 @@ function getDatabase(app = getApp(), url) {
13617
13624
  const db = _getProvider(app, 'database').getImmediate({
13618
13625
  identifier: url
13619
13626
  });
13620
- const emulator = getDefaultEmulatorHostnameAndPort('database');
13621
- if (emulator) {
13622
- connectDatabaseEmulator(db, ...emulator);
13627
+ if (!db._instanceStarted) {
13628
+ const emulator = getDefaultEmulatorHostnameAndPort('database');
13629
+ if (emulator) {
13630
+ connectDatabaseEmulator(db, ...emulator);
13631
+ }
13623
13632
  }
13624
13633
  return db;
13625
13634
  }