diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..fe04cea --- /dev/null +++ b/.travis.yml @@ -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" diff --git a/README.markdown b/README.markdown index 46f27ab..5161726 100644 --- a/README.markdown +++ b/README.markdown @@ -1,3 +1,5 @@ + + Superfeedr-node =============== diff --git a/lib/superfeedr.js b/lib/superfeedr.js index f8dbb66..6e87117 100644 --- a/lib/superfeedr.js +++ b/lib/superfeedr.js @@ -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); @@ -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(); @@ -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) { @@ -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(); @@ -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(); diff --git a/package.json b/package.json index 890ed18..435aaab 100644 --- a/package.json +++ b/package.json @@ -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 " diff --git a/test/test.js b/test/test.js index 39ffa7e..c5beb1a 100644 --- a/test/test.js +++ b/test/test.js @@ -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 () { @@ -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(); } }); @@ -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(); } });