# HG changeset patch # User Sonny Piers # Date 1328114856 -3600 # Node ID bbcc6bbdac738840036b182eced9a125c13f1007 # Parent bcb5b7c2c3d31769e65018d37bf453cf200a4952 Make it works :-) diff --git a/lightstring.js b/lightstring.js --- a/lightstring.js +++ b/lightstring.js @@ -113,6 +113,7 @@ Lightstring.Connection = function(aServi if (aService) this.service = aService; this.handlers = {}; + this.callbacks = {}; this.on('stream:features', function(stanza) { var nodes = stanza.DOM.querySelectorAll('mechanism'); //SASL/Auth features @@ -146,27 +147,33 @@ Lightstring.Connection = function(aServi //XMPP features else { this.emit('features', stanza); + var that = this; //Bind http://xmpp.org/rfcs/rfc3920.html#bind var bind = - "" + + "" + "" + (this.jid.resource? "" + this.jid.resource + "": "") + "" + ""; - this.send( bind, + //Success function(stanza) { //Session http://xmpp.org/rfcs/rfc3921.html#session + alert('iq callback!!!'); this.jid = new Lightstring.JID(stanza.DOM.textContent); - this.send( - "" + + that.send( + "" + "" + "", function() { - this.emit('connected'); + that.emit('connected'); } ); + }, + //Error + function(stanza) { + //TODO: Error? } ); } @@ -317,12 +324,12 @@ Lightstring.Connection.prototype = { return; var type = stanza.DOM.getAttributeNS(null, 'type'); - if (type !== 'result' || type !== 'error') + if (type !== 'result' && type !== 'error') return; //TODO: emit an warning, perhaps. var callback = that.callbacks[id]; - if (type === 'result' && callback.result) - callback.result(stanza); + if (type === 'result' && callback.success) + callback.success(stanza); else if (type === 'error' && callback.error) callback.error(stanza); @@ -341,7 +348,7 @@ Lightstring.Connection.prototype = { * @param {String|Object} aStanza The message to send. * @param {Function} [aCallback] Executed on answer. (stanza must be iq) */ - send: function(aStanza, aResult, aError) { + send: function(aStanza, aSuccess, aError) { if (!(aStanza instanceof Lightstring.Stanza)) var stanza = new Lightstring.Stanza(aStanza); else @@ -355,15 +362,15 @@ Lightstring.Connection.prototype = { if (type !== 'get' || type !== 'set') ; //TODO: emit an error. - var callback = {result: aResult, error: aError}; + var callback = {success: aSuccess, error: aError}; var id = stanza.DOM.getAttributeNS(null, 'id'); if (!id) ; //TODO: emit an warning. else - this.callback[id] = callback; + this.callbacks[id] = callback; - } else if (aResult || aError) + } else if (aSuccess || aError) ; //TODO: callback can’t be called with non-iq stanza.