Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cometd

Package Overview
Dependencies
Maintainers
1
Versions
87
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cometd

A lightweight cometD Library with lightweight dependencies. No jQuery needed!

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12K
increased by2.93%
Maintainers
1
Weekly downloads
 
Created
Source

##A Simple HowTo:

Include the library

    var cometD = require('cometd').cometD();

Subscribe to a topic

    cometD.topic = '/topic/exampleTopic';

Add a eventListener

    cometD.addEventListener('/topic/exampleTopic', function (topic, message) {});

Start the execution

    cometD.init(
        {
            token: "A optional Bearer token",
            url: 'http://urltoyourservice.com/cometd/26.0',
            debug: true
        }
    );

###Multi Subscription

You have two options for subscribe more than one topic. You can use a wildcard in your topic like this:

    cometD.topic = '/topic/*';

If you use this, you can add a eventListener to each channel.

    cometD.addEventListener('/topic/topic1', function (topic, message) {});
    cometD.addEventListener('/topic/topic2', function (topic, message) {});

Or you can use only one handler function. You can also access the topicName:

    function myHandler(theTopicName, message){
      console.log(theTopicName);
    }

    cometD.addEventListener('/topic/topic1', myHandler);
    cometD.addEventListener('/topic/topic2', myHandler);

Sometime wildcards are not available. But this isn't a problem. The cometD object isn't a singleton. Each Instance has his own cookie.

    var topics = ['topic1', 'topic2'];

    function myCometDFunction(topic){
       var cometD = require('./cometD.js').cometD();

       cometD.topic = '/topic/' + topic;
       cometD.init(
           {
             token: "Bearer Token",
             url: 'http://aserviceurl.com/cometd/26.0',
             debug: true
           }
       );

       cometD.addEventListener('/topic/' + topic, function(topicName, message){});
     }


    for (var i = 0; i < topics.length; i++) {
      myCometDFunction(topics[i]);
    }

Keywords

FAQs

Package last updated on 12 May 2016

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