Skip to content

Commit

Permalink
Fix websocketonly flag (#6126)
Browse files Browse the repository at this point in the history
* Fixed issue where webSocketOnly was incorrectly set to nodeAdmin

Co-authored-by: Maneesh Tewani <mtewani@google.com>
  • Loading branch information
maneesht and maneesht authored Apr 8, 2022
1 parent d756f4e commit 7a4e65c
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
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 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)
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 2022 Google LLC
*
* 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);
});
});

0 comments on commit 7a4e65c

Please sign in to comment.