Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to support Node 0.12.4+, 4.x, 5.x #23

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
language: node_js
sudo: false
env:
- CXX=g++-4.8
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8

node_js:
- "0.12.4"
- "0.12.7"
- "4.0.0"
- "4.1.0"
- "4.1.1"
- "4.2.1"
- "4.2.2"
- "4.2.3"
- "5.0.0"
- "5.1.1"
- "5.2.0"
- "5.3.0"
2 changes: 2 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<a href="https://travis-ci.org/davepenfold/superfeedr-node"><img src="https://travis-ci.org/davepenfold/superfeedr-node.svg?branch=master" /></a>

Superfeedr-node
===============

Expand Down
40 changes: 32 additions & 8 deletions lib/superfeedr.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,48 @@
var xmpp = require('node-xmpp');
var Client = require('node-xmpp-client');
var Core = require('node-xmpp-core');
var ltx = require('ltx');
var util = require('util');
var EventEmitter = require('events').EventEmitter;

SUPERFEEDR_ENDPOINT = "firehoser.superfeedr.com";

function Superfeedr(login, password, resource) {

var self = this;

this.jid = login + "@superfeedr.com";

if(resource !== undefined) {
this.jid += '/'+resource
}

this.callbacks = {};
this.client = new xmpp.Client({ jid: this.jid, password: password });
var self = this;
this.client = new Client({ jid: this.jid, password: password });

this.client.connection.socket.setTimeout(0);
this.client.connection.socket.setKeepAlive(true, 10000);

this.client.on('online', function() {
self.client.send(new xmpp.Element('presence', { }).c('show').t('chat').up().c('status').t(''));
self.client.send(new ltx.Element('presence', { }).c('show').t('chat').up().c('status').t(''));
self.emit('connected');
});

this.client.on('error', function(err) {
self.emit('error', err);
});

this.client.on('offline', function() {
self.emit('offline');
});

this.client.on('reconnect', function() {
self.emit('reconnected');
});

this.client.on('disconnect', function() {
self.emit('disconnected');
});

this.client.on('stanza', function(stanza) {
if(self.callbacks[stanza.attrs.id]) {
self.callbacks[stanza.attrs.id](stanza, self);
Expand Down Expand Up @@ -187,7 +211,7 @@ util.inherits(Superfeedr, EventEmitter);

Superfeedr.prototype.subscribe = function(url, clb) {
var id = Math.floor(Math.random()*100000).toString();
var subscribeStanza = new xmpp.Iq({to: SUPERFEEDR_ENDPOINT, id:id, type:'set', from: this.client.jid})
var subscribeStanza = new Core.Stanza.Iq({to: SUPERFEEDR_ENDPOINT, id:id, type:'set', from: this.client.jid})
.c("pubsub", {xmlns: "http://jabber.org/protocol/pubsub"})
.c("subscribe", {node: url, jid: this.jid}).root();

Expand Down Expand Up @@ -221,7 +245,7 @@ Superfeedr.prototype.subscribe = function(url, clb) {

Superfeedr.prototype.unsubscribe = function(url, clb) {
var id = Math.floor(Math.random()*100000).toString();
var unsubscribeStanza = new xmpp.Iq({to: SUPERFEEDR_ENDPOINT, id:id, type:'set', from: this.client.jid})
var unsubscribeStanza = new Core.Stanza.Iq({to: SUPERFEEDR_ENDPOINT, id:id, type:'set', from: this.client.jid})
.c("pubsub", {xmlns: "http://jabber.org/protocol/pubsub"})
.c("unsubscribe", {node: url, jid: this.jid}).root();
this.callbacks[id] = function(response, superfeedr) {
Expand Down Expand Up @@ -260,7 +284,7 @@ Superfeedr.prototype.list = function(page, clb) {
page = 1;
}

var listStanza = new xmpp.Iq({type:'get', from: this.client.jid, to: SUPERFEEDR_ENDPOINT, id:id})
var listStanza = new Core.Stanza.Iq({type:'get', from: this.client.jid, to: SUPERFEEDR_ENDPOINT, id:id})
.c("pubsub", {xmlns: "http://jabber.org/protocol/pubsub", "xmlns:superfeedr":"http://superfeedr.com/xmpp-pubsub-ext"})
.c("subscriptions", {jid: this.jid, "superfeedr:page": page}).root();

Expand Down Expand Up @@ -300,7 +324,7 @@ Superfeedr.prototype.list = function(page, clb) {
Superfeedr.prototype.retrieve = function retrieve(url, clb) {
var self = this;
var id = Math.floor(Math.random()*100000).toString();
var retrieveStanza = new xmpp.Iq({to: SUPERFEEDR_ENDPOINT, id:id, type:'get', from: self.client.jid})
var retrieveStanza = new Core.Stanza.Iq({to: SUPERFEEDR_ENDPOINT, id:id, type:'get', from: self.client.jid})
.c("pubsub", {xmlns: "http://jabber.org/protocol/pubsub"})
.c("items", {node: url}).root();

Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
"node": ">=0.6.0"
},
"dependencies": {
"node-xmpp": ">=0.3.1"
"ltx": "^0.9.0",
"node-xmpp-client": "^2.1.0",
"node-xmpp-core": "^4.2.0"
},
"devDependencies": {
"mocha": "0.1.0",
"request": "*",
"underscore": "*"
"mocha": "^2.2.5",
"request": "*",
"underscore": "*"
},
"scripts": {
"test": "export NODE_ENV=test; mocha "
Expand Down
9 changes: 6 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ describe('superfeedr', function () {
var client = null;

before(function (done) {
client = new Superfeedr("nodesample", "nodesample");
client = new Superfeedr("nodesuperfeedrTest", "nodesuperfeedrTest123");
client.on('connected', done);
client.on('error', function(err) {
done(new Error(err));
});
});

describe('List', function () {
Expand Down Expand Up @@ -45,7 +48,7 @@ describe('superfeedr', function () {
describe('retrieve', function() {
before(function(done) {
client.subscribe("http://blog.superfeedr.com/atom.xml", function(err, feed) {
if(!err && feed.url === "http://blog.superfeedr.com/atom.xml" && feed.title === 'Superfeedr Blog : Real-time cloudy thoughts from a super-hero') {
if(!err && feed.url === "http://blog.superfeedr.com/atom.xml" && feed.title === 'Superfeedr Blog') {
done();
}
});
Expand Down Expand Up @@ -89,7 +92,7 @@ describe('superfeedr', function () {

it('should call the subscription callback', function (done) {
client.subscribe("http://blog.superfeedr.com/atom.xml", function (err, feed) {
if (!err && feed.url === "http://blog.superfeedr.com/atom.xml" && feed.title === 'Superfeedr Blog : Real-time cloudy thoughts from a super-hero') {
if (!err && feed.url === "http://blog.superfeedr.com/atom.xml" && feed.title === 'Superfeedr Blog') {
done();
}
});
Expand Down