Skip to content

Commit

Permalink
Updated implementation to full ES6 (modules, classes, etc.).
Browse files Browse the repository at this point in the history
Updated dependency to CometD 8.0.1.

Removed TypeScript testing (apparently too difficult to set it up in Mocha now).

Added "type": "module" in package.json.

Updated README.md.

Signed-off-by: Simone Bordet <[email protected]>
  • Loading branch information
sbordet committed May 21, 2024
1 parent a4dcccc commit ac64477
Show file tree
Hide file tree
Showing 15 changed files with 649 additions and 707 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x, 18.x, 20.x]
node-version: [16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Use NodeJS ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
35 changes: 8 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,26 @@

### CometD NodeJS Client

This project implements adapter code that allows the [CometD JavaScript Client](https://github.com/cometd/cometd-javascript) to run in a NodeJS environment.
This project implements ES6 adapter code that allows the [CometD JavaScript Client](https://github.com/cometd/cometd-javascript) to run in a NodeJS environment.

The adapter code exports an implementation of `XMLHttpRequest` so that the CometD JavaScript Client works in NodeJS as it does within a browser environment.
The adapter code exports an implementation of `XMLHttpRequest` and `WebSocket` so that the CometD JavaScript Client works in NodeJS as it does within a browser environment.

WebSocket is supported via the [`ws`](https://www.npmjs.com/package/ws) package.

### NPM Installation

Firstly, you need to install the CometD NodeJS Client:
Install the CometD NodeJS Client:

```
```js
npm install cometd-nodejs-client
```

The CometD NodeJS Client does not depend on the CometD JavaScript Client; you need the CometD JavaScript Client to develop your applications.

Therefore, you need to install the CometD JavaScript Client, version 3.1.2 or greater:

```
npm install cometd
```

### Usage (CommonJS)

```javascript
// Run the adapter code that implements XMLHttpRequest.
require('cometd-nodejs-client').adapt();

// Your normal CometD client application here.
var lib = require('cometd');
var cometd = new lib.CometD();
...
```
### Usage (ES6)

### Usage (ES Modules)
```js
import { adapt } from "cometd-nodejs-client";
import { CometD } from "cometd";

```javascript
import { CometD } from 'cometd';
import { adapt } from 'cometd-nodejs-client';
// Shim XMLHTTPRequest for Node.js (required by CometD).
adapt();

Expand Down
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Release Instructions (for project committers)

* Run the tests: `npm test`
* Update the `version` field in `package.json` to the version you want to cut.
* Commit: `git commit -s -S -m "Release <version>."`
* Create the git tag: `git tag -a -s -m "Release <version>." <version>`
Expand Down
3 changes: 2 additions & 1 deletion cometd-nodejs-client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export interface HttpProxy {
uri?: string;
includes?: string[];
Expand All @@ -25,7 +26,7 @@ export interface Cookies {
}

export interface Options {
logLevel?: 'debug' | 'info';
logLevel?: "debug" | "info";
httpProxy?: HttpProxy;
cookies?: Cookies;
}
Expand Down
Loading

0 comments on commit ac64477

Please sign in to comment.