diff --git a/lib/xmpp-client/client.js b/lib/xmpp-client/client.js index db894e2..cd91b53 100644 --- a/lib/xmpp-client/client.js +++ b/lib/xmpp-client/client.js @@ -65,7 +65,7 @@ Client.prototype.getRoster = function(callback) { /* http://xmpp.org/extensions/xep-0092.html */ -Client.prototype.getVersion = function(jid, callback, error) { +Client.prototype.getVersion = function(jid, success, error) { var jabber = this; this.iq(jid, new xmpp.Element('query', {xmlns: 'jabber:iq:version'}), function(iq) { var v = iq.getChild('query', 'jabber:iq:version'); @@ -74,10 +74,24 @@ Client.prototype.getVersion = function(jid, callback, error) { version: v.getChildText('version'), os: v.getChildText('os') }; - callback.call(jabber, version); + success.call(jabber, version); }, error); }; +/* +http://xmpp.org/extensions/xep-0012.html +*/ + +Client.prototype.getLast = function(jid, success, error) { + var jabber = this; + this.iq(jid, new xmpp.Element('query', {xmlns: 'jabber:iq:last'}), + function(iq) { + success.call(jabber, parseInt(iq.getChild('query', 'jabber:iq:last').attrs.seconds, 10)); + }, + error + ); +}; + Client.prototype.disconnect = function() { this.xmpp.send(new xmpp.Element('presence', {type: 'unavailable'}) .c('status').t('Logged out') diff --git a/test/test-iq.js b/test/test-iq.js index bcd3610..65f5d8a 100644 --- a/test/test-iq.js +++ b/test/test-iq.js @@ -4,7 +4,7 @@ var sys = require('sys'), Client = require('../lib/xmpp-client').Client, conf = require('./conf').conf; -exports.testIq = function(test) { +exports.testVersion = function(test) { test.expect(1); var a = new Client(conf.a, function() { //sys.debug(this.jid.toString().blue); @@ -21,4 +21,18 @@ exports.testIq = function(test) { }); }); }); +}; + +exports.testLast = function(test) { + test.expect(1); + var a = new Client(conf.a, function() { + //sys.debug(this.jid.toString().blue); + var b = new Client(conf.b, function() { + a.getLast(a.jid, function(version) { + sys.debug(version); + test.ok(version > 0, 'last'); + test.done(); + }); + }); + }); }; \ No newline at end of file