1
0
Fork 0

lazy node and publish work

master
Matthieu Lalonde 14 years ago committed by Mathieu Lecarme
parent 70edad92e1
commit 5da9c8e9fe

@ -40,16 +40,17 @@ BasicClient.prototype.presence = function(type) {
}; };
BasicClient.prototype.iq = function(to, query, callback) { BasicClient.prototype.iq = function(to, query, callback) {
var n = this._iq++; var n = 'node' + this._iq++;
this._iqCallback[n] = callback; this._iqCallback[n] = callback;
var attrs = { var attrs = {
type:"get", type: 'get',
id: n id: n
}; };
if(to != null) { if(to != null) {
attrs.to = to; attrs.to = to;
}; };
this.xmpp.send(new xmpp.Element('iq', attrs).cnode(query).tree()); 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) { Client.prototype.iqSet = function(to, query, callback) {
var n = this._iq++; var n = 'node' + this._iq++;
if(callback != null) { if(callback != null) {
this._iqCallback[n] = callback; this._iqCallback[n] = callback;
} }
var attrs = { var attrs = {
type:"set", type: "set",
id: n id: n
}; };
if(to != null) { if(to != null) {
attrs.to = to; attrs.to = to;
} }
this.xmpp.send(new xmpp.Element('iq', attrs).cnode(query).tree()); this.xmpp.send(new xmpp.Element('iq', attrs).cnode(query).tree());
return n;
}; };
Client.prototype.resultIq = function(iqGet, result) { Client.prototype.resultIq = function(iqGet, result) {

@ -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'}) this.client.iqSet(this.to, new xmpp.Element('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'})
.cnode(publish) .c('publish', {node: node})
.tree() .c('item')
); .cnode(content)
.tree(),
function(iq) {
sys.debug('PUBLISH : ' + iq);
sys.debug('just published'.yellow);
}
);
}; };
Pubsub.prototype.suscribe = function(node, callback) { Pubsub.prototype.suscribe = function(node, callback) {

@ -1,5 +1,6 @@
var sys = require('sys'), var sys = require('sys'),
colors = require('colors'), colors = require('colors'),
xmpp = require('node-xmpp'),
Client = require('../lib/xmpp-client').Client, Client = require('../lib/xmpp-client').Client,
JID = require('node-xmpp').JID, JID = require('node-xmpp').JID,
conf = require('./conf').conf; conf = require('./conf').conf;
@ -86,15 +87,16 @@ exports.testPubSub = function(test) {
var b = new Client(conf.b, function() { var b = new Client(conf.b, function() {
sys.debug('b is connected'.red); sys.debug('b is connected'.red);
this.addListener('iq:error', function(id, stanza) { this.addListener('iq:error', function(id, stanza) {
sys.debug(stanza.toString().yellow); sys.error(stanza.toString().red);
test.done(); test.done();
}); });
var p = b.pubsub(); var p = b.pubsub();
p.node(POEMS, function() { p.node(POEMS, function() {
sys.debug('got my node'.yellow); sys.debug('got my node'.yellow);
p.suscribe(POEMS, function(item) { p.publish(POEMS, new xmpp.Element('entry', {xmlns: 'http://www.w3.org/2005/Atom'}).c('title').t('blab blah').tree());
sys.debug(item.toString().yellow); /*p.suscribe(POEMS, function(item) {
}); sys.debug('SUSCRIBE : ' + item.toString().yellow);
});*/
//test.done(); //test.done();
}); });
/* /*

Loading…
Cancel
Save