Skip to content

Fix websocketonly flag #6126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Apr 8, 2022
5 changes: 5 additions & 0 deletions .changeset/twenty-shoes-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@firebase/database": patch
---

Fix `webSocketOnly` field to be set to true in `RepoInfo` when using the websocket protocol in the databaseURL in firebase configuration (when using `wss` or `ws` in the RTDB URL, webSocketOnly will be true and longPolling will be disabled)
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Before you start working on a larger contribution, you should get in touch with

* Create your patch, **including appropriate test cases**. Patches with tests are more likely to be merged.
* 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`).
* Commit your changes using a commit message that follows our [commit message guidelines](#commit-message-guidelines).
* Commit your changes

```shell
git commit -a
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,20 @@ implementation. The SDK is built via a combination of all of these packages
which are published under the [`firebase`
scope](https://www.npmjs.com/search?q=scope%3Afirebase) on NPM.

### Testing the SDK Locally

Please be sure to build your repo before proceeding any further.
In order to manually test your SDK changes locally, you must use [yarn link](https://classic.yarnpkg.com/en/docs/cli/link):

```shell
$ cd packages/firebase
$ yarn link # initialize the linking to the other folder
$ cd ../<my-test-app-dir> # cd into your personal project directory
$ yarn link firebase # tell yarn to use the locally built firebase SDK instead
```

This will create a symlink and point your `<my-test-app-dir>` to the locally built version of the firebase SDK.

### Helper Scripts

Each package in the `packages` directory exposes a `dev` script. This script
Expand Down
2 changes: 1 addition & 1 deletion packages/database/src/core/util/libs/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ export const parseRepoInfo = function (
parsedUrl.host,
parsedUrl.secure,
namespace,
nodeAdmin,
webSocketOnly,
nodeAdmin,
/*persistenceKey=*/ '',
/*includeNamespaceInQueryParams=*/ namespace !== parsedUrl.subdomain
),
Expand Down
34 changes: 34 additions & 0 deletions packages/database/test/parser.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* @license
* Copyright 2017 Google LLC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2022

*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { expect } from 'chai';

import { parseRepoInfo } from '../src/core/util/libs/parser';

describe('parser', () => {
it('should set websocketUrl correctly based on the protocol', () => {
const httpsRepoInfo = parseRepoInfo(
'https://test-ns.firebaseio.com',
false
);
expect(httpsRepoInfo.repoInfo.webSocketOnly).to.equal(false);
const wssRepoInfo = parseRepoInfo('wss://test-ns.firebaseio.com', false);
expect(wssRepoInfo.repoInfo.webSocketOnly).to.equal(true);
const wsRepoInfo = parseRepoInfo('ws://test-ns.firebaseio.com', false);
expect(wsRepoInfo.repoInfo.webSocketOnly).to.equal(true);
});
});