diff --git a/lib/xmpp-client/basic-client.js b/lib/xmpp-client/basic-client.js index 392d632..4e34e75 100644 --- a/lib/xmpp-client/basic-client.js +++ b/lib/xmpp-client/basic-client.js @@ -100,6 +100,18 @@ BasicClient.prototype.iq = function(to, query, callback, error) { return n; }; +/* +Answer an iq query +*/ +BasicClient.prototype.resultIq = function(iqGet, result) { + this.xmpp.send(new xmpp.Element('iq', { + type: 'result', + from: iqGet.attrs.to, + to: iqGet.attrs.from, + id: iqGet.attrs.id + }).cnode(result).tree()); +}; + BasicClient.prototype.registerIqHandler = function(xmlns, action) { this._iqHandler[xmlns] = action; }; diff --git a/lib/xmpp-client/client.js b/lib/xmpp-client/client.js index 279c437..a8e8d39 100644 --- a/lib/xmpp-client/client.js +++ b/lib/xmpp-client/client.js @@ -13,6 +13,37 @@ var Client = function(params, callback) { callback.apply(this); }); }); + this.registerIqHandler('http://jabber.org/protocol/disco#info', function(stanza) { + sys.debug((stanza.attrs.from + " wont to disco!")[jabber.color]); + jabber.resultIq(stanza, new xmpp.Element('query', {xmlns: 'http://jabber.org/protocol/disco#info'}) + .c('feature', {'var': 'http://jabber.org/protocol/disco#info'}).up() + .c('feature', {'var': 'http://jabber.org/protocol/disco#items'}).up() + .c('feature', {'var': 'http://jabber.org/protocol/muc'}).up() + .c('identity', { + category: 'conference', + type: 'text', + name: 'Play-Specific Chatrooms' + }).up() + .tree() + ); + }); + this.registerIqHandler('jabber:iq:last', function(stanza) { + sys.debug((stanza.attrs.from + ' wonts last')[jabber.color]); + //[FIXME] giving a good last time + jabber.resultIq(stanza, new xmpp.Element('query', { + xmlns: 'jabber:iq:last', seconds:'1'}) + .tree() + ); + }); + this.registerIqHandler('jabber:iq:version', function(stanza) { + jabber.resultIq(stanza, new xmpp.Element('query', {xmlns:'jabber:iq:version'}) + .c('name').t('node-xmpp-client').up() + .c('version').t('0.0.1').up() + .c('os').t(process.platform).up() + .tree() + ); + }); + }; sys.inherits(Client, BasicClient); @@ -30,3 +61,15 @@ Client.prototype.askForRoster = function(callback) { callback.call(jabber, jabber.roster); }); }; + +Client.prototype.disconnect = function() { + this.xmpp.send(new xmpp.Element('presence', {type: 'unavailable'}) + .c('status').t('Logged out') + .tree()); + var jabber = this; +/* Object.keys(this.rooms).forEach(function(room) { + jabber.rooms[room].leave(); + });*/ + this.xmpp.end(); + sys.debug("disconnect from XMPP"); +};