Skip to content

Commit 4ccd09e

Browse files
author
Michael Lehenbauer
authored
Remove nodePatches.ts hackery. (#2144)
This had some very stale code to: 1. Make it possible to use long-polling instead of WebSockets from the Node.JS SDK. This existed purely for testing purposes, wasn't reliable, and hasn't been used in ages. 2. Work around a bad Node.JS bug that was fixed 6 years ago (nodejs/node-v0.x-archive#6506).
1 parent 5037a7f commit 4ccd09e

File tree

5 files changed

+20
-230
lines changed

5 files changed

+20
-230
lines changed

packages/database/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Unreleased
2+
- [changed] Internal cleanup to Node.JS support.
3+
4+
# 6.4.0
25
- [fixed] Fixed an issue that caused `.info/serverTimeOffset` events not to fire (#2043).
36
- [changed] Treat `ns` url query parameter as the default Realtime Database
47
namespace name.

packages/database/index.node.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@ import { enableLogging } from './src/core/util/util';
2525
import { RepoManager } from './src/core/RepoManager';
2626
import * as INTERNAL from './src/api/internal';
2727
import * as TEST_ACCESS from './src/api/test_access';
28-
import './src/nodePatches';
2928
import * as types from '@firebase/database-types';
3029
import { setSDKVersion } from './src/core/version';
3130
import { CONSTANTS, isNodeSdk } from '@firebase/util';
31+
import { setWebSocketImpl } from './src/realtime/WebSocketConnection';
32+
import { Client } from 'faye-websocket';
33+
34+
setWebSocketImpl(Client);
3235

3336
const ServerValue = Database.ServerValue;
3437

packages/database/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"test": "yarn test:emulator",
1717
"test:all": "run-p test:browser test:node",
1818
"test:browser": "karma start --single-run",
19-
"test:node": "TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --file src/nodePatches.ts --opts ../../config/mocha.node.opts",
19+
"test:node": "TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --file index.node.ts --opts ../../config/mocha.node.opts",
2020
"test:emulator": "ts-node --compiler-options='{\"module\":\"commonjs\"}' ../../scripts/emulator-testing/database-test-runner.ts",
2121
"prepare": "yarn build"
2222
},

packages/database/src/nodePatches.ts

Lines changed: 0 additions & 210 deletions
This file was deleted.

packages/database/src/realtime/BrowserPollConnection.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ export class BrowserPollConnection implements Transport {
209209
urlParams[LAST_SESSION_PARAM] = this.lastSessionId;
210210
}
211211
if (
212-
!isNodeSdk() &&
213212
typeof location !== 'undefined' &&
214213
location.href &&
215214
location.href.indexOf(FORGE_DOMAIN) !== -1
@@ -252,17 +251,21 @@ export class BrowserPollConnection implements Transport {
252251

253252
// Static method, use string literal so it can be accessed in a generic way
254253
static isAvailable() {
255-
// NOTE: In React-Native there's normally no 'document', but if you debug a React-Native app in
256-
// the Chrome debugger, 'document' is defined, but document.createElement is null (2015/06/08).
257-
return (
258-
BrowserPollConnection.forceAllow_ ||
259-
(!BrowserPollConnection.forceDisallow_ &&
254+
if (isNodeSdk()) {
255+
return false;
256+
} else if (BrowserPollConnection.forceAllow_) {
257+
return true;
258+
} else {
259+
// NOTE: In React-Native there's normally no 'document', but if you debug a React-Native app in
260+
// the Chrome debugger, 'document' is defined, but document.createElement is null (2015/06/08).
261+
return (
262+
!BrowserPollConnection.forceDisallow_ &&
260263
typeof document !== 'undefined' &&
261264
document.createElement != null &&
262265
!isChromeExtensionContentScript() &&
263-
!isWindowsStoreApp() &&
264-
!isNodeSdk())
265-
);
266+
!isWindowsStoreApp()
267+
);
268+
}
266269
}
267270

268271
/**
@@ -542,15 +545,6 @@ export class FirebaseIFrameScriptHolder {
542545
}, Math.floor(0));
543546
}
544547

545-
if (isNodeSdk() && this.myID) {
546-
const urlParams: { [k: string]: string } = {};
547-
urlParams[FIREBASE_LONGPOLL_DISCONN_FRAME_PARAM] = 't';
548-
urlParams[FIREBASE_LONGPOLL_ID_PARAM] = this.myID;
549-
urlParams[FIREBASE_LONGPOLL_PW_PARAM] = this.myPW;
550-
const theURL = this.urlFn(urlParams);
551-
(FirebaseIFrameScriptHolder as any).nodeRestRequest(theURL);
552-
}
553-
554548
// Protect from being called recursively.
555549
const onDisconnect = this.onDisconnect;
556550
if (onDisconnect) {

0 commit comments

Comments
 (0)