Package Exports
- cometd
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cometd) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
##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]);
}