@firebase/database 0.12.8 → 0.13.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Unreleased
2
2
 
3
+ ## 0.13.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`9c6808fea`](https://github.com/firebase/firebase-js-sdk/commit/9c6808fea231d1ab6de6f6ab548c67b751a12a78) [#6171](https://github.com/firebase/firebase-js-sdk/pull/6171) - Add `forceWebSockets()` and `forceLongPolling()`
8
+
9
+ ### Patch Changes
10
+
11
+ - [`874cdbbcc`](https://github.com/firebase/firebase-js-sdk/commit/874cdbbccbc2bf8f4ee18abe220e87dc52e6a8db) [#6232](https://github.com/firebase/firebase-js-sdk/pull/6232) - Added GMPID to websocket connection.
12
+
13
+ - Updated dependencies [[`9c5c9c36d`](https://github.com/firebase/firebase-js-sdk/commit/9c5c9c36da80b98b73cfd60ef2e2965087e9f801)]:
14
+ - @firebase/util@1.6.0
15
+ - @firebase/component@0.5.14
16
+
3
17
  ## 0.12.8
4
18
 
5
19
  ### Patch Changes
@@ -1,10 +1,10 @@
1
1
  import { getApp, _getProvider, SDK_VERSION as SDK_VERSION$1, _registerComponent, registerVersion } from '@firebase/app';
2
2
  import { Component } from '@firebase/component';
3
- import { stringify, jsonEval, contains, assert, base64, stringToByteArray, Sha1, isNodeSdk, deepCopy, base64Encode, isMobileCordova, stringLength, Deferred, safeGet, isAdmin, isValidFormat, isEmpty, isReactNative, assertionError, map, querystring, errorPrefix, getModularInstance, createMockUserToken } from '@firebase/util';
3
+ import { stringify, jsonEval, contains, assert, isNodeSdk, base64, stringToByteArray, Sha1, deepCopy, base64Encode, isMobileCordova, stringLength, Deferred, safeGet, isAdmin, isValidFormat, isEmpty, isReactNative, assertionError, map, querystring, errorPrefix, getModularInstance, createMockUserToken } from '@firebase/util';
4
4
  import { Logger, LogLevel } from '@firebase/logger';
5
5
 
6
6
  const name = "@firebase/database";
7
- const version = "0.12.8";
7
+ const version = "0.13.0";
8
8
 
9
9
  /**
10
10
  * @license
@@ -1803,7 +1803,7 @@ class WebSocketConnection {
1803
1803
  this.bytesReceived = 0;
1804
1804
  this.log_ = logWrapper(this.connId);
1805
1805
  this.stats_ = statsManagerGetCollection(repoInfo);
1806
- this.connURL = WebSocketConnection.connectionURL_(repoInfo, transportSessionId, lastSessionId, appCheckToken);
1806
+ this.connURL = WebSocketConnection.connectionURL_(repoInfo, transportSessionId, lastSessionId, appCheckToken, applicationId);
1807
1807
  this.nodeAdmin = repoInfo.nodeAdmin;
1808
1808
  }
1809
1809
  /**
@@ -1813,7 +1813,7 @@ class WebSocketConnection {
1813
1813
  * @param lastSessionId - Optional lastSessionId if there was a previous connection
1814
1814
  * @returns connection url
1815
1815
  */
1816
- static connectionURL_(repoInfo, transportSessionId, lastSessionId, appCheckToken) {
1816
+ static connectionURL_(repoInfo, transportSessionId, lastSessionId, appCheckToken, applicationId) {
1817
1817
  const urlParams = {};
1818
1818
  urlParams[VERSION_PARAM] = PROTOCOL_VERSION;
1819
1819
  if (!isNodeSdk() &&
@@ -1831,6 +1831,9 @@ class WebSocketConnection {
1831
1831
  if (appCheckToken) {
1832
1832
  urlParams[APP_CHECK_TOKEN_PARAM] = appCheckToken;
1833
1833
  }
1834
+ if (applicationId) {
1835
+ urlParams[APPLICATION_ID_PARAM] = applicationId;
1836
+ }
1834
1837
  return repoInfoConnectionURL(repoInfo, WEBSOCKET, urlParams);
1835
1838
  }
1836
1839
  /**
@@ -1845,6 +1848,7 @@ class WebSocketConnection {
1845
1848
  // Assume failure until proven otherwise.
1846
1849
  PersistentStorage.set('previous_websocket_failure', true);
1847
1850
  try {
1851
+ let options;
1848
1852
  if (isNodeSdk()) {
1849
1853
  const device = this.nodeAdmin ? 'AdminNode' : 'Node';
1850
1854
  // UA Format: Firebase/<wire_protocol>/<sdk_version>/<platform>/<device>
@@ -1873,17 +1877,8 @@ class WebSocketConnection {
1873
1877
  if (proxy) {
1874
1878
  options['proxy'] = { origin: proxy };
1875
1879
  }
1876
- this.mySock = new WebSocketImpl(this.connURL, [], options);
1877
- }
1878
- else {
1879
- const options = {
1880
- headers: {
1881
- 'X-Firebase-GMPID': this.applicationId || '',
1882
- 'X-Firebase-AppCheck': this.appCheckToken || ''
1883
- }
1884
- };
1885
- this.mySock = new WebSocketImpl(this.connURL, [], options);
1886
1880
  }
1881
+ this.mySock = new WebSocketImpl(this.connURL, [], options);
1887
1882
  }
1888
1883
  catch (e) {
1889
1884
  this.log_('Error instantiating WebSocket.');
@@ -2137,6 +2132,13 @@ class TransportManager {
2137
2132
  static get ALL_TRANSPORTS() {
2138
2133
  return [BrowserPollConnection, WebSocketConnection];
2139
2134
  }
2135
+ /**
2136
+ * Returns whether transport has been selected to ensure WebSocketConnection or BrowserPollConnection are not called after
2137
+ * TransportManager has already set up transports_
2138
+ */
2139
+ static get IS_TRANSPORT_INITIALIZED() {
2140
+ return this.globalTransportInitialized_;
2141
+ }
2140
2142
  initTransports_(repoInfo) {
2141
2143
  const isWebSocketsAvailable = WebSocketConnection && WebSocketConnection['isAvailable']();
2142
2144
  let isSkipPollConnection = isWebSocketsAvailable && !WebSocketConnection.previouslyFailed();
@@ -2156,6 +2158,7 @@ class TransportManager {
2156
2158
  transports.push(transport);
2157
2159
  }
2158
2160
  }
2161
+ TransportManager.globalTransportInitialized_ = true;
2159
2162
  }
2160
2163
  }
2161
2164
  /**
@@ -2180,7 +2183,9 @@ class TransportManager {
2180
2183
  return null;
2181
2184
  }
2182
2185
  }
2183
- }
2186
+ }
2187
+ // Keeps track of whether the TransportManager has already chosen a transport to use
2188
+ TransportManager.globalTransportInitialized_ = false;
2184
2189
 
2185
2190
  /**
2186
2191
  * @license
@@ -13640,6 +13645,26 @@ class Database {
13640
13645
  }
13641
13646
  }
13642
13647
  }
13648
+ function checkTransportInit() {
13649
+ if (TransportManager.IS_TRANSPORT_INITIALIZED) {
13650
+ warn('Transport has already been initialized. Please call this function before calling ref or setting up a listener');
13651
+ }
13652
+ }
13653
+ /**
13654
+ * Force the use of websockets instead of longPolling.
13655
+ */
13656
+ function forceWebSockets() {
13657
+ checkTransportInit();
13658
+ BrowserPollConnection.forceDisallow();
13659
+ }
13660
+ /**
13661
+ * Force the use of longPolling instead of websockets. This will be ignored if websocket protocol is used in databaseURL.
13662
+ */
13663
+ function forceLongPolling() {
13664
+ checkTransportInit();
13665
+ WebSocketConnection.forceDisallow();
13666
+ BrowserPollConnection.forceAllow();
13667
+ }
13643
13668
  /**
13644
13669
  * Returns the instance of the Realtime Database SDK that is associated
13645
13670
  * with the provided {@link @firebase/app#FirebaseApp}. Initializes a new instance with
@@ -13964,5 +13989,5 @@ const forceRestClient = function (forceRestClient) {
13964
13989
  */
13965
13990
  registerDatabase();
13966
13991
 
13967
- export { DataSnapshot, Database, OnDisconnect, QueryConstraint, TransactionResult, QueryImpl as _QueryImpl, QueryParams as _QueryParams, ReferenceImpl as _ReferenceImpl, forceRestClient as _TEST_ACCESS_forceRestClient, hijackHash as _TEST_ACCESS_hijackHash, repoManagerDatabaseFromApp as _repoManagerDatabaseFromApp, setSDKVersion as _setSDKVersion, validatePathString as _validatePathString, validateWritablePath as _validateWritablePath, child, connectDatabaseEmulator, enableLogging, endAt, endBefore, equalTo, get, getDatabase, goOffline, goOnline, increment, limitToFirst, limitToLast, off, onChildAdded, onChildChanged, onChildMoved, onChildRemoved, onDisconnect, onValue, orderByChild, orderByKey, orderByPriority, orderByValue, push, query, ref, refFromURL, remove, runTransaction, serverTimestamp, set, setPriority, setWithPriority, startAfter, startAt, update };
13992
+ export { DataSnapshot, Database, OnDisconnect, QueryConstraint, TransactionResult, QueryImpl as _QueryImpl, QueryParams as _QueryParams, ReferenceImpl as _ReferenceImpl, forceRestClient as _TEST_ACCESS_forceRestClient, hijackHash as _TEST_ACCESS_hijackHash, repoManagerDatabaseFromApp as _repoManagerDatabaseFromApp, setSDKVersion as _setSDKVersion, validatePathString as _validatePathString, validateWritablePath as _validateWritablePath, child, connectDatabaseEmulator, enableLogging, endAt, endBefore, equalTo, forceLongPolling, forceWebSockets, get, getDatabase, goOffline, goOnline, increment, limitToFirst, limitToLast, off, onChildAdded, onChildChanged, onChildMoved, onChildRemoved, onDisconnect, onValue, orderByChild, orderByKey, orderByPriority, orderByValue, push, query, ref, refFromURL, remove, runTransaction, serverTimestamp, set, setPriority, setWithPriority, startAfter, startAt, update };
13968
13993
  //# sourceMappingURL=index.esm2017.js.map