New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cometd-node-promise-client

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cometd-node-promise-client

CometD client for Node.js that adds support for promises

  • 1.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

CometD client for Node.js that adds support for promises

Installation

Add the client to your project by running:
npm install cometd-node-promise-client

Usage

  1. Instantiate the CometD client

1.a) with the default console logger:

const cometd = new CometdClient();

OR

1.b) with the Winston logger:

Winston.loggers.add('COMETD', {
  console: { level: 'info', colorize: true, label: 'COMETD' }
});
const cometd = new CometdClient(Winston.loggers.get('COMETD'));
  1. Configure the CometD client
cometd.configure({
    url: cometdServerUrl,
    requestHeaders: { Authorization: 'Bearer ' + this.session.access_token }, // Optional parameter if you wan to pass additional headers
    appendMessageTypeToURL: false
});
  1. Handshake with the CometD server and subscribe to a topicName topic:
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):

const cometdPromises = [
    cometd.subscribe(topic1, onMessage1Received),
    cometd.subscribe(topic2, onMessage2Received)
];
cometd.batch(cometdPromises).then(() => {
    // This promise resolves when the batch is processed
});
  1. If you wish to unsubscribe from a topic:
cometd.unsubscribe(subscription).then(() => {
    // This promise resolves when the client has succesfully unsubscribed
});
  1. When you no longer need your CometD client, disconnect from the server:
cometd.disconnect().then(() => {
    // This promise resolves when the client has succesfully disconnected
});

disconnect() unsubscribes from all active subscriptions.

Keywords

FAQs

Package last updated on 14 Aug 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc