Skip to content

Commit 7a4e65c

Browse files
authored
Fix websocketonly flag (#6126)
* Fixed issue where webSocketOnly was incorrectly set to nodeAdmin Co-authored-by: Maneesh Tewani <[email protected]>
1 parent d756f4e commit 7a4e65c

File tree

5 files changed

+55
-2
lines changed

5 files changed

+55
-2
lines changed

.changeset/twenty-shoes-cheer.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@firebase/database": patch
3+
---
4+
5+
Fix issue where if a websocket protocol was used in the databaseURL, `webSocketOnly` field was incorrectly set to undefined. (When using `wss` or `ws` protocols in the databaseURL, webSocketOnly will be true and longPolling will be disabled)

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Before you start working on a larger contribution, you should get in touch with
7777

7878
* Create your patch, **including appropriate test cases**. Patches with tests are more likely to be merged.
7979
* Avoid checking in files that shouldn't be tracked (e.g `node_modules`, `gulp-cache`, `.tmp`, `.idea`). If your development setup automatically creates some of these files, please add them to the `.gitignore` at the root of the package (click [here][gitignore] to read more on how to add entries to the `.gitignore`).
80-
* Commit your changes using a commit message that follows our [commit message guidelines](#commit-message-guidelines).
80+
* Commit your changes
8181

8282
```shell
8383
git commit -a

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,20 @@ implementation. The SDK is built via a combination of all of these packages
168168
which are published under the [`firebase`
169169
scope](https://www.npmjs.com/search?q=scope%3Afirebase) on NPM.
170170

171+
### Testing the SDK Locally
172+
173+
Please be sure to build your repo before proceeding any further.
174+
In order to manually test your SDK changes locally, you must use [yarn link](https://classic.yarnpkg.com/en/docs/cli/link):
175+
176+
```shell
177+
$ cd packages/firebase
178+
$ yarn link # initialize the linking to the other folder
179+
$ cd ../<my-test-app-dir> # cd into your personal project directory
180+
$ yarn link firebase # tell yarn to use the locally built firebase SDK instead
181+
```
182+
183+
This will create a symlink and point your `<my-test-app-dir>` to the locally built version of the firebase SDK.
184+
171185
### Helper Scripts
172186

173187
Each package in the `packages` directory exposes a `dev` script. This script

packages/database/src/core/util/libs/parser.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ export const parseRepoInfo = function (
9292
parsedUrl.host,
9393
parsedUrl.secure,
9494
namespace,
95-
nodeAdmin,
9695
webSocketOnly,
96+
nodeAdmin,
9797
/*persistenceKey=*/ '',
9898
/*includeNamespaceInQueryParams=*/ namespace !== parsedUrl.subdomain
9999
),

packages/database/test/parser.test.ts

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @license
3+
* Copyright 2022 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { expect } from 'chai';
19+
20+
import { parseRepoInfo } from '../src/core/util/libs/parser';
21+
22+
describe('parser', () => {
23+
it('should set websocketUrl correctly based on the protocol', () => {
24+
const httpsRepoInfo = parseRepoInfo(
25+
'https://test-ns.firebaseio.com',
26+
false
27+
);
28+
expect(httpsRepoInfo.repoInfo.webSocketOnly).to.equal(false);
29+
const wssRepoInfo = parseRepoInfo('wss://test-ns.firebaseio.com', false);
30+
expect(wssRepoInfo.repoInfo.webSocketOnly).to.equal(true);
31+
const wsRepoInfo = parseRepoInfo('ws://test-ns.firebaseio.com', false);
32+
expect(wsRepoInfo.repoInfo.webSocketOnly).to.equal(true);
33+
});
34+
});

0 commit comments

Comments
 (0)