1
0
Fork 0

lazy node and publish work

master
Matthieu Lalonde 15 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) {
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) {

@ -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) {

@ -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();
});
/*

Loading…
Cancel
Save