|
|
@ -31,7 +31,67 @@ Pubsub.prototype.createTree = function() {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Pubsub.prototype.discoverNodes = function(callback) {
|
|
|
|
Pubsub.prototype.disco = function(callback) {
|
|
|
|
|
|
|
|
var jabber = this.client;
|
|
|
|
|
|
|
|
this.client.iq(this.to,
|
|
|
|
|
|
|
|
new xmpp.Element('query', {xmlns: 'http://jabber.org/protocol/disco#info'}),
|
|
|
|
|
|
|
|
function(iq) {
|
|
|
|
|
|
|
|
callback.call(jabber, iq.getChild('query', 'http://jabber.org/protocol/disco#info'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Pubsub.prototype.discoNode = function(node, callback) {
|
|
|
|
|
|
|
|
var jabber = this.client;
|
|
|
|
|
|
|
|
this.client.iq(this.to,
|
|
|
|
|
|
|
|
new xmpp.Element('query', {xmlns: 'http://jabber.org/protocol/disco#info', node: node}),
|
|
|
|
|
|
|
|
function(iq) {
|
|
|
|
|
|
|
|
callback.call(jabber, iq.getChild('query', 'http://jabber.org/protocol/disco#info'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Pubsub.prototype.subscriptions = function(callback) {
|
|
|
|
|
|
|
|
var jabber = this.client;
|
|
|
|
|
|
|
|
this.client.iq(this.to,
|
|
|
|
|
|
|
|
new xmpp.Element('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'}).c('subscriptions'),
|
|
|
|
|
|
|
|
function(iq) {
|
|
|
|
|
|
|
|
callback.call(jabber, iq
|
|
|
|
|
|
|
|
.getChild('pubsub', 'http://jabber.org/protocol/pubsub')
|
|
|
|
|
|
|
|
.getChild('subscriptions')
|
|
|
|
|
|
|
|
.getChildren('subscription')
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Pubsub.prototype.nodeSubscriptions = function(node, callback) {
|
|
|
|
|
|
|
|
var jabber = this.client;
|
|
|
|
|
|
|
|
this.client.iq(this.to,
|
|
|
|
|
|
|
|
new xmpp.Element('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'}).c('subscriptions', {node: node}),
|
|
|
|
|
|
|
|
function(iq) {
|
|
|
|
|
|
|
|
callback.call(jabber, iq
|
|
|
|
|
|
|
|
.getChild('pubsub', 'http://jabber.org/protocol/pubsub')
|
|
|
|
|
|
|
|
.getChild('subscriptions')
|
|
|
|
|
|
|
|
.getChildren('subscription')
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Pubsub.prototype.discoNodeItems = function(node, callback) {
|
|
|
|
|
|
|
|
var jabber = this.client;
|
|
|
|
|
|
|
|
this.client.iq(this.to,
|
|
|
|
|
|
|
|
new xmpp.Element('query', {xmlns: 'http://jabber.org/protocol/disco#items', node: node}),
|
|
|
|
|
|
|
|
function(iq) {
|
|
|
|
|
|
|
|
callback.call(jabber, iq.getChild('query', 'http://jabber.org/protocol/disco#items').getChildren('item'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Pubsub.prototype.discoNodes = function(callback) {
|
|
|
|
var jabber = this.client;
|
|
|
|
var jabber = this.client;
|
|
|
|
this.client.iq(this.to,
|
|
|
|
this.client.iq(this.to,
|
|
|
|
new xmpp.Element('query', {xmlns: 'http://jabber.org/protocol/disco#items'}),
|
|
|
|
new xmpp.Element('query', {xmlns: 'http://jabber.org/protocol/disco#items'}),
|
|
|
@ -44,7 +104,7 @@ Pubsub.prototype.discoverNodes = function(callback) {
|
|
|
|
Pubsub.prototype.node = function(node, callback) {
|
|
|
|
Pubsub.prototype.node = function(node, callback) {
|
|
|
|
var exist = false;
|
|
|
|
var exist = false;
|
|
|
|
var pubsub = this;
|
|
|
|
var pubsub = this;
|
|
|
|
this.discoverNodes(function(items) {
|
|
|
|
this.discoNodes(function(items) {
|
|
|
|
items.forEach(function(item) {
|
|
|
|
items.forEach(function(item) {
|
|
|
|
if(item.attrs.node == node) { exist = true; }
|
|
|
|
if(item.attrs.node == node) { exist = true; }
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -82,17 +142,20 @@ Pubsub.prototype.publish = function(node, content) {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Pubsub.prototype.suscribe = function(node, callback) {
|
|
|
|
Pubsub.prototype.suscribe = function(node, onMessage, onSuscribed) {
|
|
|
|
var jabber = this.client;
|
|
|
|
var jabber = this.client;
|
|
|
|
|
|
|
|
var pubsub = this;
|
|
|
|
jabber.iqSet(this.to, new xmpp.Element('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'})
|
|
|
|
jabber.iqSet(this.to, new xmpp.Element('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'})
|
|
|
|
.c('subscription', {
|
|
|
|
.c('subscribe', {
|
|
|
|
node: node,
|
|
|
|
node: node,
|
|
|
|
jid: jabber.jid.user + '@' + jabber.jid.domain
|
|
|
|
jid: jabber.jid.user + '@' + jabber.jid.domain
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.tree(),
|
|
|
|
.tree(),
|
|
|
|
function(stanza) {
|
|
|
|
function(iq) {
|
|
|
|
sys.debug(stanza.toString().yellow);
|
|
|
|
sys.debug(('Suscribe to ' + node).yellow);
|
|
|
|
jabber._pubSubCallback[to + '#' + node] = callback;
|
|
|
|
jabber._pubSubCallback[pubsub.to + '#' + node] = onMessage;
|
|
|
|
|
|
|
|
var s = iq.getChild('pubsub', 'http://jabber.org/protocol/pubsub').attrs;
|
|
|
|
|
|
|
|
onSuscribed.call(jabber, s.subscription, s.subid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
);
|
|
|
|
};
|
|
|
|
};
|
|
|
|