# cometd-node-promise-client

> CometD client for Node.js that adds support for promises

Latest version **1.1.2** (published 2018-08-14) · Apache-2.0 license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install cometd-node-promise-client
pnpm add cometd-node-promise-client
yarn add cometd-node-promise-client
bun add cometd-node-promise-client
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2018-08-14 |
| First published | 2018-08-14 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 16.5 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Philippe Ozil |
| Maintainers | pozil |
| Keywords | cometd, streaming, promise |

## Links

- npm: https://www.npmjs.com/package/cometd-node-promise-client
- Repository: https://github.com/pozil/cometd-node-client
- Issues: https://github.com/pozil/cometd-node-client/issues
- npm.io page: https://npm.io/package/cometd-node-promise-client

## Dependencies (3)

- [ws](https://npm.io/package/ws.md) ^4.1.0
- [cometd](https://npm.io/package/cometd.md) ^3.1.4
- [cometd-nodejs-client](https://npm.io/package/cometd-nodejs-client.md) ^1.0.2

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 1.1.2 (latest) — 2018-08-14
- 1.1.1 — 2018-08-14
- 1.1.0 — 2018-08-14

## README

# CometD client for Node.js that adds support for promises

## Installation
Add the client to your project by running:<br/>
`npm install cometd-node-promise-client`

## Usage

1) Instantiate the CometD client

1.a) with the default console logger:
```js
const cometd = new CometdClient();
```

OR

1.b) with the Winston logger:
```js
Winston.loggers.add('COMETD', {
  console: { level: 'info', colorize: true, label: 'COMETD' }
});
const cometd = new CometdClient(Winston.loggers.get('COMETD'));
```

2) Configure the CometD client
```js
cometd.configure({
    url: cometdServerUrl,
    requestHeaders: { Authorization: 'Bearer ' + this.session.access_token }, // Optional parameter if you wan to pass additional headers
    appendMessageTypeToURL: false
});
```

3) Handshake with the CometD server and subscribe to a `topicName` topic:
```js
cometd.connect().then(() => {
    // Connection succeeded
    cometd.subscribe(topicName, onMessageReceived).then(subscription => {
        // This promise resolves when the client has succesfully subscribed
    });
});
```

The `onMessageReceived` callback function is executed each time a `topicName` message is received.

Alternatively, you can batch subscriptions (network optimization):
```js
const cometdPromises = [
    cometd.subscribe(topic1, onMessage1Received),
    cometd.subscribe(topic2, onMessage2Received)
];
cometd.batch(cometdPromises).then(() => {
    // This promise resolves when the batch is processed
});
```

4) If you wish to unsubscribe from a topic:
```js
cometd.unsubscribe(subscription).then(() => {
    // This promise resolves when the client has succesfully unsubscribed
});
```

5) When you no longer need your CometD client, disconnect from the server:
```js
cometd.disconnect().then(() => {
    // This promise resolves when the client has succesfully disconnected
});
```

`disconnect()` unsubscribes from all active subscriptions.

---
_Source: https://npm.io/package/cometd-node-promise-client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
