Skip to content

Commit

Permalink
Prepare for new release 1.2.11
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbrand committed Dec 13, 2016
1 parent 2fd3b20 commit c16f9d4
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 39 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Strophe.js Change Log

## Version 1.2.11 - Unreleased
## Version 1.2.11 - 2016-12-13
* 189 Strophe never reaches DISCONNECTED status after .connect(..) and
.disconnect(..) calls while offline.
* Add `sendPresence` method, similar to `sendIQ`, i.e. for cases where you expect a
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "strophe.js",
"description": "Strophe.js is an XMPP library for JavaScript",
"version": "1.2.10",
"version": "1.2.11",
"license": "MIT",
"main": "strophe.js",
"authors": [
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "strophe.js",
"description": "Strophe.js is an XMPP library for JavaScript",
"version": "1.2.10",
"version": "1.2.11",
"homepage": "http://strophe.im/strophejs",
"repository": {
"type": "git",
Expand Down Expand Up @@ -67,7 +67,7 @@
"grunt-natural-docs": "~1.0.1",
"grunt-shell": "~2.1.0",
"http-server": "^0.9.0",
"phantomjs": "^2.1.7",
"phantomjs": "~1.9.7-1",
"qunit-phantomjs-runner": "^2.1.0",
"requirejs": "~2.3.2"
}
Expand Down
127 changes: 95 additions & 32 deletions strophe.js
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ Strophe = {
* The version of the Strophe library. Unreleased builds will have
* a version of head-HASH where HASH is a partial revision.
*/
VERSION: "1.2.10",
VERSION: "1.2.11",

/** Constants: XMPP Namespace Constants
* Common namespace constants from the XMPP RFCs and XEPs.
Expand Down Expand Up @@ -2830,6 +2830,67 @@ Strophe.Connection.prototype = {
this._onIdle();
},

/** Function: sendPresence
* Helper function to send presence stanzas. The main benefit is for
* sending presence stanzas for which you expect a responding presence
* stanza with the same id (for example when leaving a chat room).
*
* Parameters:
* (XMLElement) elem - The stanza to send.
* (Function) callback - The callback function for a successful request.
* (Function) errback - The callback function for a failed or timed
* out request. On timeout, the stanza will be null.
* (Integer) timeout - The time specified in milliseconds for a
* timeout to occur.
*
* Returns:
* The id used to send the presence.
*/
sendPresence: function(elem, callback, errback, timeout) {
var timeoutHandler = null;
var that = this;
if (typeof(elem.tree) === "function") {
elem = elem.tree();
}
var id = elem.getAttribute('id');
if (!id) { // inject id if not found
id = this.getUniqueId("sendPresence");
elem.setAttribute("id", id);
}

if (typeof callback === "function" || typeof errback === "function") {
var handler = this.addHandler(function (stanza) {
// remove timeout handler if there is one
if (timeoutHandler) {
that.deleteTimedHandler(timeoutHandler);
}
var type = stanza.getAttribute('type');
if (type == 'error') {
if (errback) {
errback(stanza);
}
} else if (callback) {
callback(stanza);
}
}, null, 'presence', null, id);

// if timeout specified, set up a 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);
return id;
},

/** Function: sendIQ
* Helper function to send IQ stanzas.
*
Expand All @@ -2847,7 +2908,6 @@ Strophe.Connection.prototype = {
sendIQ: function(elem, callback, errback, timeout) {
var timeoutHandler = null;
var that = this;

if (typeof(elem.tree) === "function") {
elem = elem.tree();
}
Expand All @@ -2857,39 +2917,41 @@ Strophe.Connection.prototype = {
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);
if (typeof callback === "function" || typeof errback === "function") {
var handler = this.addHandler(function (stanza) {
// remove timeout handler if there is one
if (timeoutHandler) {
that.deleteTimedHandler(timeoutHandler);
}
} else if (iqtype == 'error') {
if (errback) {
errback(stanza);
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
};
}
} else {
throw {
name: "StropheError",
message: "Got bad IQ type of " + iqtype
};
}, null, 'iq', ['error', 'result'], id);

// if timeout specified, set up a 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;
});
}
}, null, 'iq', ['error', 'result'], id);

// if timeout specified, set up a 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);
return id;
Expand Down Expand Up @@ -3129,6 +3191,7 @@ Strophe.Connection.prototype = {
} else {
Strophe.info("Disconnect was called before Strophe connected to the server");
this._proto._abortAllRequests();
this._doDisconnect();
}
},

Expand Down
6 changes: 3 additions & 3 deletions strophe.min.js

Large diffs are not rendered by default.

0 comments on commit c16f9d4

Please sign in to comment.