@firebase/database 0.12.8 → 0.13.0-canary.61f7112e0

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.
@@ -989,7 +989,7 @@ var WebSocketConnection = /** @class */ (function () {
989
989
  this.bytesReceived = 0;
990
990
  this.log_ = logWrapper(this.connId);
991
991
  this.stats_ = statsManagerGetCollection(repoInfo);
992
- this.connURL = WebSocketConnection.connectionURL_(repoInfo, transportSessionId, lastSessionId, appCheckToken);
992
+ this.connURL = WebSocketConnection.connectionURL_(repoInfo, transportSessionId, lastSessionId, appCheckToken, applicationId);
993
993
  this.nodeAdmin = repoInfo.nodeAdmin;
994
994
  }
995
995
  /**
@@ -999,7 +999,7 @@ var WebSocketConnection = /** @class */ (function () {
999
999
  * @param lastSessionId - Optional lastSessionId if there was a previous connection
1000
1000
  * @returns connection url
1001
1001
  */
1002
- WebSocketConnection.connectionURL_ = function (repoInfo, transportSessionId, lastSessionId, appCheckToken) {
1002
+ WebSocketConnection.connectionURL_ = function (repoInfo, transportSessionId, lastSessionId, appCheckToken, applicationId) {
1003
1003
  var urlParams = {};
1004
1004
  urlParams[VERSION_PARAM] = PROTOCOL_VERSION;
1005
1005
  if (!util.isNodeSdk() &&
@@ -1017,6 +1017,9 @@ var WebSocketConnection = /** @class */ (function () {
1017
1017
  if (appCheckToken) {
1018
1018
  urlParams[APP_CHECK_TOKEN_PARAM] = appCheckToken;
1019
1019
  }
1020
+ if (applicationId) {
1021
+ urlParams[APPLICATION_ID_PARAM] = applicationId;
1022
+ }
1020
1023
  return repoInfoConnectionURL(repoInfo, WEBSOCKET, urlParams);
1021
1024
  };
1022
1025
  /**
@@ -1032,10 +1035,11 @@ var WebSocketConnection = /** @class */ (function () {
1032
1035
  // Assume failure until proven otherwise.
1033
1036
  PersistentStorage.set('previous_websocket_failure', true);
1034
1037
  try {
1038
+ var options = void 0;
1035
1039
  if (util.isNodeSdk()) {
1036
1040
  var device = this.nodeAdmin ? 'AdminNode' : 'Node';
1037
1041
  // UA Format: Firebase/<wire_protocol>/<sdk_version>/<platform>/<device>
1038
- var options = {
1042
+ var options_1 = {
1039
1043
  headers: {
1040
1044
  'User-Agent': "Firebase/" + PROTOCOL_VERSION + "/" + SDK_VERSION + "/" + process.platform + "/" + device,
1041
1045
  'X-Firebase-GMPID': this.applicationId || ''
@@ -1047,10 +1051,10 @@ var WebSocketConnection = /** @class */ (function () {
1047
1051
  // Note that this header is just used to bypass appcheck, and the token should still be sent
1048
1052
  // through the websocket connection once it is established.
1049
1053
  if (this.authToken) {
1050
- options.headers['Authorization'] = "Bearer " + this.authToken;
1054
+ options_1.headers['Authorization'] = "Bearer " + this.authToken;
1051
1055
  }
1052
1056
  if (this.appCheckToken) {
1053
- options.headers['X-Firebase-AppCheck'] = this.appCheckToken;
1057
+ options_1.headers['X-Firebase-AppCheck'] = this.appCheckToken;
1054
1058
  }
1055
1059
  // Plumb appropriate http_proxy environment variable into faye-websocket if it exists.
1056
1060
  var env = process['env'];
@@ -1058,19 +1062,10 @@ var WebSocketConnection = /** @class */ (function () {
1058
1062
  ? env['HTTPS_PROXY'] || env['https_proxy']
1059
1063
  : env['HTTP_PROXY'] || env['http_proxy'];
1060
1064
  if (proxy) {
1061
- options['proxy'] = { origin: proxy };
1065
+ options_1['proxy'] = { origin: proxy };
1062
1066
  }
1063
- this.mySock = new WebSocketImpl(this.connURL, [], options);
1064
- }
1065
- else {
1066
- var options = {
1067
- headers: {
1068
- 'X-Firebase-GMPID': this.applicationId || '',
1069
- 'X-Firebase-AppCheck': this.appCheckToken || ''
1070
- }
1071
- };
1072
- this.mySock = new WebSocketImpl(this.connURL, [], options);
1073
1067
  }
1068
+ this.mySock = new WebSocketImpl(this.connURL, [], options);
1074
1069
  }
1075
1070
  catch (e) {
1076
1071
  this.log_('Error instantiating WebSocket.');
@@ -1294,7 +1289,7 @@ var WebSocketConnection = /** @class */ (function () {
1294
1289
  }());
1295
1290
 
1296
1291
  var name = "@firebase/database";
1297
- var version = "0.12.8";
1292
+ var version = "0.13.0-canary.61f7112e0";
1298
1293
 
1299
1294
  /**
1300
1295
  * @license
@@ -2226,6 +2221,17 @@ var TransportManager = /** @class */ (function () {
2226
2221
  enumerable: false,
2227
2222
  configurable: true
2228
2223
  });
2224
+ Object.defineProperty(TransportManager, "IS_TRANSPORT_INITIALIZED", {
2225
+ /**
2226
+ * Returns whether transport has been selected to ensure WebSocketConnection or BrowserPollConnection are not called after
2227
+ * TransportManager has already set up transports_
2228
+ */
2229
+ get: function () {
2230
+ return this.globalTransportInitialized_;
2231
+ },
2232
+ enumerable: false,
2233
+ configurable: true
2234
+ });
2229
2235
  TransportManager.prototype.initTransports_ = function (repoInfo) {
2230
2236
  var e_1, _a;
2231
2237
  var isWebSocketsAvailable = WebSocketConnection && WebSocketConnection['isAvailable']();
@@ -2256,6 +2262,7 @@ var TransportManager = /** @class */ (function () {
2256
2262
  }
2257
2263
  finally { if (e_1) throw e_1.error; }
2258
2264
  }
2265
+ TransportManager.globalTransportInitialized_ = true;
2259
2266
  }
2260
2267
  };
2261
2268
  /**
@@ -2280,6 +2287,8 @@ var TransportManager = /** @class */ (function () {
2280
2287
  return null;
2281
2288
  }
2282
2289
  };
2290
+ // Keeps track of whether the TransportManager has already chosen a transport to use
2291
+ TransportManager.globalTransportInitialized_ = false;
2283
2292
  return TransportManager;
2284
2293
  }());
2285
2294
 
@@ -14130,6 +14139,26 @@ var Database = /** @class */ (function () {
14130
14139
  };
14131
14140
  return Database;
14132
14141
  }());
14142
+ function checkTransportInit() {
14143
+ if (TransportManager.IS_TRANSPORT_INITIALIZED) {
14144
+ warn('Transport has already been initialized. Please call this function before calling ref or setting up a listener');
14145
+ }
14146
+ }
14147
+ /**
14148
+ * Force the use of websockets instead of longPolling.
14149
+ */
14150
+ function forceWebSockets() {
14151
+ checkTransportInit();
14152
+ BrowserPollConnection.forceDisallow();
14153
+ }
14154
+ /**
14155
+ * Force the use of longPolling instead of websockets. This will be ignored if websocket protocol is used in databaseURL.
14156
+ */
14157
+ function forceLongPolling() {
14158
+ checkTransportInit();
14159
+ WebSocketConnection.forceDisallow();
14160
+ BrowserPollConnection.forceAllow();
14161
+ }
14133
14162
  /**
14134
14163
  * Returns the instance of the Realtime Database SDK that is associated
14135
14164
  * with the provided {@link @firebase/app#FirebaseApp}. Initializes a new instance with
@@ -14486,6 +14515,8 @@ exports.enableLogging = enableLogging;
14486
14515
  exports.endAt = endAt;
14487
14516
  exports.endBefore = endBefore;
14488
14517
  exports.equalTo = equalTo;
14518
+ exports.forceLongPolling = forceLongPolling;
14519
+ exports.forceWebSockets = forceWebSockets;
14489
14520
  exports.get = get;
14490
14521
  exports.getDatabase = getDatabase;
14491
14522
  exports.goOffline = goOffline;