From 9b373d60b233c84f4f13d105298973a44410a3e6 Mon Sep 17 00:00:00 2001 From: extempl Date: Thu, 26 Jan 2012 13:39:18 +0200 Subject: [PATCH 1/2] We don't need more and more handlers for stanzas which will never appear. E.g. PONG reuqest. --- src/core.js | 73 +++++++++++++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/src/core.js b/src/core.js index 8cce1493..fedc69c0 100644 --- a/src/core.js +++ b/src/core.js @@ -2018,42 +2018,43 @@ Strophe.Connection.prototype = { id = this.getUniqueId("sendIQ"); elem.setAttribute("id", id); } - - var handler = this.addHandler(function (stanza) { - // remove timeout handler if there is one - if (timeoutHandler) { - that.deleteTimedHandler(timeoutHandler); - } - - var iqtype = stanza.getAttribute('type'); - if (iqtype == 'result') { - if (callback) { - callback(stanza); - } - } else if (iqtype == 'error') { - if (errback) { - errback(stanza); - } - } else { - throw { - name: "StropheError", - message: "Got bad IQ type of " + iqtype - }; - } - }, null, 'iq', null, id); - - // if timeout specified, setup timeout handler. - if (timeout) { - timeoutHandler = this.addTimedHandler(timeout, function () { - // get rid of normal handler - that.deleteHandler(handler); - - // call errback on timeout with null stanza - if (errback) { - errback(null); - } - return false; - }); + if(sentType != 'error' && sentType != 'result') { + var handler = this.addHandler(function (stanza) { + // remove timeout handler if there is one + if (timeoutHandler) { + that.deleteTimedHandler(timeoutHandler); + } + + var iqtype = stanza.getAttribute('type'); + if (iqtype == 'result') { + if (callback) { + callback(stanza); + } + } else if (iqtype == 'error') { + if (errback) { + errback(stanza); + } + } else { + throw { + name: "StropheError", + message: "Got bad IQ type of " + iqtype + }; + } + }, null, 'iq', null, id); + + // if timeout specified, setup timeout handler. + if (timeout) { + timeoutHandler = this.addTimedHandler(timeout, function () { + // get rid of normal handler + that.deleteHandler(handler); + + // call errback on timeout with null stanza + if (errback) { + errback(null); + } + return false; + }); + } } this.send(elem); From 3b078091cf0f1c03299f9f603ed220ae73e6f76e Mon Sep 17 00:00:00 2001 From: extempl Date: Thu, 26 Jan 2012 13:43:21 +0200 Subject: [PATCH 2/2] Update src/core.js --- src/core.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core.js b/src/core.js index fedc69c0..868c6322 100644 --- a/src/core.js +++ b/src/core.js @@ -2018,6 +2018,7 @@ Strophe.Connection.prototype = { id = this.getUniqueId("sendIQ"); elem.setAttribute("id", id); } + var sentType = elem.getAttribute('type'); if(sentType != 'error' && sentType != 'result') { var handler = this.addHandler(function (stanza) { // remove timeout handler if there is one