From 5da9c8e9fe980d114787c7557cffb02323535793 Mon Sep 17 00:00:00 2001 From: Matthieu Lalonde Date: Thu, 12 Aug 2010 13:18:00 +0200 Subject: [PATCH] lazy node and publish work --- lib/xmpp-client/client.js | 10 ++++++---- lib/xmpp-client/pubsub.js | 14 ++++++++++---- test/test.js | 10 ++++++---- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/lib/xmpp-client/client.js b/lib/xmpp-client/client.js index b0b60ab..ade5f94 100644 --- a/lib/xmpp-client/client.js +++ b/lib/xmpp-client/client.js @@ -40,16 +40,17 @@ BasicClient.prototype.presence = function(type) { }; BasicClient.prototype.iq = function(to, query, callback) { - var n = this._iq++; + var n = 'node' + this._iq++; this._iqCallback[n] = callback; var attrs = { - type:"get", + type: 'get', id: n }; if(to != null) { attrs.to = to; }; this.xmpp.send(new xmpp.Element('iq', attrs).cnode(query).tree()); + return n; }; @@ -226,18 +227,19 @@ Client.prototype.askForRoster = function(callback) { }; Client.prototype.iqSet = function(to, query, callback) { - var n = this._iq++; + var n = 'node' + this._iq++; if(callback != null) { this._iqCallback[n] = callback; } var attrs = { - type:"set", + type: "set", id: n }; if(to != null) { attrs.to = to; } this.xmpp.send(new xmpp.Element('iq', attrs).cnode(query).tree()); + return n; }; Client.prototype.resultIq = function(iqGet, result) { diff --git a/lib/xmpp-client/pubsub.js b/lib/xmpp-client/pubsub.js index 89cec74..2a662f8 100644 --- a/lib/xmpp-client/pubsub.js +++ b/lib/xmpp-client/pubsub.js @@ -69,11 +69,17 @@ Pubsub.prototype.createNode = function(node, callback) { ); }; -Pubsub.prototype.publish = function(node, publish) { +Pubsub.prototype.publish = function(node, content) { this.client.iqSet(this.to, new xmpp.Element('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'}) - .cnode(publish) - .tree() - ); + .c('publish', {node: node}) + .c('item') + .cnode(content) + .tree(), + function(iq) { + sys.debug('PUBLISH : ' + iq); + sys.debug('just published'.yellow); + } + ); }; Pubsub.prototype.suscribe = function(node, callback) { diff --git a/test/test.js b/test/test.js index 5d6122a..c54f553 100644 --- a/test/test.js +++ b/test/test.js @@ -1,5 +1,6 @@ var sys = require('sys'), colors = require('colors'), + xmpp = require('node-xmpp'), Client = require('../lib/xmpp-client').Client, JID = require('node-xmpp').JID, conf = require('./conf').conf; @@ -86,15 +87,16 @@ exports.testPubSub = function(test) { var b = new Client(conf.b, function() { sys.debug('b is connected'.red); this.addListener('iq:error', function(id, stanza) { - sys.debug(stanza.toString().yellow); + sys.error(stanza.toString().red); test.done(); }); var p = b.pubsub(); p.node(POEMS, function() { sys.debug('got my node'.yellow); - p.suscribe(POEMS, function(item) { - sys.debug(item.toString().yellow); - }); + p.publish(POEMS, new xmpp.Element('entry', {xmlns: 'http://www.w3.org/2005/Atom'}).c('title').t('blab blah').tree()); + /*p.suscribe(POEMS, function(item) { + sys.debug('SUSCRIBE : ' + item.toString().yellow); + });*/ //test.done(); }); /*