1
0
Fork 0

pubsub message

master
Matthieu Lalonde 14 years ago committed by Mathieu Lecarme
parent b3f974ec94
commit 44fe080270

@ -115,7 +115,9 @@ var Client = function(params, callback) {
} else {
jabber._debug('MESSAGE: ' + stanza);
var event_ = stanza.getChild('event', 'http://jabber.org/protocol/pubsub#event');
sys.debug(event_.toString().green);
if(event_ != null) {
sys.debug('beuha'.green);
jabber.emit('pubsub:event', from, event_.getChild('items').attrs.node, event_, stanza);
} else {
jabber.emit('message', from, stanza.getChild('body').getText(), stanza);

@ -9,6 +9,17 @@ function Pubsub(client, to) {
to = 'pubsub.' + this.client.jid.domain;
}
this.to = to;
this._eventCallback = {};
var pubsub = this;
this.client.addListener('pubsub:event', function(from, node, event_, stanza) {
if(from == pubsub.to) {
sys.debug('a pubsub event'.yellow);
var cb = pubsub._eventCallback[node];
if(cb != null) {
cb.call(pubsub, event_, stanza);
}
}
});
};
sys.inherits(Pubsub, events.EventEmitter);
@ -153,7 +164,7 @@ Pubsub.prototype.suscribe = function(node, onMessage, onSuscribed) {
.tree(),
function(iq) {
sys.debug(('Suscribe to ' + node).yellow);
jabber._pubSubCallback[pubsub.to + '#' + node] = onMessage;
pubsub._eventCallback[node] = onMessage;
var s = iq.getChild('pubsub', 'http://jabber.org/protocol/pubsub').attrs;
onSuscribed.call(jabber, s.subscription, s.subid);
}

@ -96,13 +96,17 @@ exports.testPubSub = function(test) {
});*/
p.node(POEMS, function() {
sys.debug('got my node'.yellow);
p.suscribe(POEMS, function(item) {
sys.debug('SUSCRIBE : ' + item.toString().yellow);
test.done();
},
function(subsription, id) {
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('MESSAGE PUBSUB : ' + item.toString().yellow);
test.done();
},
function(subsription, id) {
p.publish(POEMS, new xmpp.Element('entry', {xmlns: 'http://www.w3.org/2005/Atom'})
.c('title').t('blab blah')
.tree());
}
);
//test.done();
});
/*

Loading…
Cancel
Save