diff --git a/bower.json b/bower.json index b75bbb814..128acd1d2 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "converse.js", "description": "Web-based XMPP/Jabber chat client written in javascript", - "version": "0.10.1", + "version": "1.0.0", "license": "MPL-2.0", "devDependencies": { "jasmine": "https://github.com/jcbrand/jasmine.git#1_3_x", diff --git a/dist/converse-mobile.js b/dist/converse-mobile.js index 1da0eab85..d245a75ad 100644 --- a/dist/converse-mobile.js +++ b/dist/converse-mobile.js @@ -1,11 +1,9 @@ /** - * @license almond 0.3.1 Copyright (c) 2011-2014, The Dojo Foundation All Rights Reserved. - * Available via the MIT or new BSD license. - * see: http://github.com/jrburke/almond for details + * @license almond 0.3.2 Copyright jQuery Foundation and other contributors. + * Released under MIT license, http://github.com/requirejs/almond/LICENSE */ //Going sloppy to avoid 'use strict' string cost, but strict practices should //be followed. -/*jslint sloppy: true */ /*global setTimeout: false */ var requirejs, require, define; @@ -33,60 +31,58 @@ var requirejs, require, define; */ function normalize(name, baseName) { var nameParts, nameSegment, mapValue, foundMap, lastIndex, - foundI, foundStarMap, starI, i, j, part, + foundI, foundStarMap, starI, i, j, part, normalizedBaseParts, baseParts = baseName && baseName.split("/"), map = config.map, starMap = (map && map['*']) || {}; //Adjust any relative paths. - if (name && name.charAt(0) === ".") { - //If have a base name, try to normalize against it, - //otherwise, assume it is a top-level require that will - //be relative to baseUrl in the end. - if (baseName) { - name = name.split('/'); - lastIndex = name.length - 1; + if (name) { + name = name.split('/'); + lastIndex = name.length - 1; - // Node .js allowance: - if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) { - name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, ''); - } + // If wanting node ID compatibility, strip .js from end + // of IDs. Have to do this here, and not in nameToUrl + // because node allows either .js or non .js to map + // to same file. + if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) { + name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, ''); + } - //Lop off the last part of baseParts, so that . matches the - //"directory" and not name of the baseName's module. For instance, - //baseName of "one/two/three", maps to "one/two/three.js", but we - //want the directory, "one/two" for this normalization. - name = baseParts.slice(0, baseParts.length - 1).concat(name); + // Starts with a '.' so need the baseName + if (name[0].charAt(0) === '.' && baseParts) { + //Convert baseName to array, and lop off the last part, + //so that . matches that 'directory' and not name of the baseName's + //module. For instance, baseName of 'one/two/three', maps to + //'one/two/three.js', but we want the directory, 'one/two' for + //this normalization. + normalizedBaseParts = baseParts.slice(0, baseParts.length - 1); + name = normalizedBaseParts.concat(name); + } - //start trimDots - for (i = 0; i < name.length; i += 1) { - part = name[i]; - if (part === ".") { - name.splice(i, 1); - i -= 1; - } else if (part === "..") { - if (i === 1 && (name[2] === '..' || name[0] === '..')) { - //End of the line. Keep at least one non-dot - //path segment at the front so it can be mapped - //correctly to disk. Otherwise, there is likely - //no path mapping for a path starting with '..'. - //This can still fail, but catches the most reasonable - //uses of .. - break; - } else if (i > 0) { - name.splice(i - 1, 2); - i -= 2; - } + //start trimDots + for (i = 0; i < name.length; i++) { + part = name[i]; + if (part === '.') { + name.splice(i, 1); + i -= 1; + } else if (part === '..') { + // If at the start, or previous value is still .., + // keep them so that when converted to a path it may + // still work when converted to a path, even though + // as an ID it is less than ideal. In larger point + // releases, may be better to just kick out an error. + if (i === 0 || (i === 1 && name[2] === '..') || name[i - 1] === '..') { + continue; + } else if (i > 0) { + name.splice(i - 1, 2); + i -= 2; } } - //end trimDots - - name = name.join("/"); - } else if (name.indexOf('./') === 0) { - // No baseName, so this is ID is resolved relative - // to baseUrl, pull off the leading dot. - name = name.substring(2); } + //end trimDots + + name = name.join('/'); } //Apply map config if available. @@ -432,7 +428,7 @@ var requirejs, require, define; define("components/almond/almond.js", function(){}); /*! - * jQuery JavaScript Library v1.12.2 + * jQuery JavaScript Library v1.12.3 * http://jquery.com/ * * Includes Sizzle.js @@ -442,7 +438,7 @@ define("components/almond/almond.js", function(){}); * Released under the MIT license * http://jquery.org/license * - * Date: 2016-03-17T17:44Z + * Date: 2016-04-05T19:16Z */ (function( global, factory ) { @@ -498,7 +494,7 @@ var support = {}; var - version = "1.12.2", + version = "1.12.3", // Define a local copy of jQuery jQuery = function( selector, context ) { @@ -10798,13 +10794,6 @@ function createActiveXHR() { -// Prevent auto-execution of scripts when no explicit dataType was provided (See gh-2432) -jQuery.ajaxPrefilter( function( s ) { - if ( s.crossDomain ) { - s.contents.script = false; - } -} ); - // Install script dataType jQuery.ajaxSetup( { accepts: { @@ -11085,7 +11074,7 @@ jQuery.fn.load = function( url, params, callback ) { // If it fails, this function gets "jqXHR", "status", "error" } ).always( callback && function( jqXHR, status ) { self.each( function() { - callback.apply( self, response || [ jqXHR.responseText, status, jqXHR ] ); + callback.apply( this, response || [ jqXHR.responseText, status, jqXHR ] ); } ); } ); } @@ -18810,8 +18799,7 @@ return { * The bound function. */ if (!Function.prototype.bind) { - Function.prototype.bind = function (obj /*, arg1, arg2, ... */) - { + Function.prototype.bind = function (obj /*, arg1, arg2, ... */) { var func = this; var _slice = Array.prototype.slice; var _concat = Array.prototype.concat; @@ -18870,6 +18858,7 @@ if (!Array.prototype.indexOf) }; } })); + /* This program is distributed under the terms of the MIT license. Please see the LICENSE file for details. @@ -19092,6 +19081,7 @@ Strophe = { * Status.DISCONNECTED - The connection has been terminated * Status.DISCONNECTING - The connection is currently being terminated * Status.ATTACHED - The connection has been attached + * Status.CONNTIMEOUT - The connection has timed out */ Status: { ERROR: 0, @@ -19103,7 +19093,8 @@ Strophe = { DISCONNECTED: 6, DISCONNECTING: 7, ATTACHED: 8, - REDIRECT: 9 + REDIRECT: 9, + CONNTIMEOUT: 10 }, /** Constants: Log Level Constants @@ -19166,8 +19157,7 @@ Strophe = { * referenced under Strophe.NS * (String) value - The actual namespace. */ - addNamespace: function (name, value) - { + addNamespace: function (name, value) { Strophe.NS[name] = value; }, @@ -19185,8 +19175,7 @@ Strophe = { * (Function) func - The function to apply to each child. This * function should take a single argument, a DOM element. */ - forEachChild: function (elem, elemName, func) - { + forEachChild: function (elem, elemName, func) { var i, childNode; for (i = 0; i < elem.childNodes.length; i++) { @@ -19211,8 +19200,7 @@ Strophe = { * true if the element's tag name matches _el_, and false * otherwise. */ - isTagEqual: function (el, name) - { + isTagEqual: function (el, name) { return el.tagName == name; }, @@ -19310,8 +19298,7 @@ Strophe = { * Returns: * A new XML DOM element. */ - xmlElement: function (name) - { + xmlElement: function (name) { if (!name) { return null; } var node = Strophe.xmlGenerator().createElement(name); @@ -19400,8 +19387,7 @@ Strophe = { * Returns: * A new XML DOM text node. */ - xmlTextNode: function (text) - { + xmlTextNode: function (text) { return Strophe.xmlGenerator().createTextNode(text); }, @@ -19414,8 +19400,7 @@ Strophe = { * Returns: * A new XML DOM text node. */ - xmlHtmlNode: function (html) - { + xmlHtmlNode: function (html) { var node; //ensure text is escaped if (window.DOMParser) { @@ -19438,8 +19423,7 @@ Strophe = { * Returns: * A String with the concatenated text of all text element children. */ - getText: function (elem) - { + getText: function (elem) { if (!elem) { return null; } var str = ""; @@ -19469,8 +19453,7 @@ Strophe = { * Returns: * A new, copied DOM element tree. */ - copyElement: function (elem) - { + copyElement: function (elem) { var i, el; if (elem.nodeType == Strophe.ElementType.NORMAL) { el = Strophe.xmlElement(elem.tagName); @@ -19503,8 +19486,7 @@ Strophe = { * Returns: * A new, copied DOM element tree. */ - createHtml: function (elem) - { + createHtml: function (elem) { var i, el, j, tag, attribute, value, css, cssAttrs, attr, cssName, cssValue; if (elem.nodeType == Strophe.ElementType.NORMAL) { tag = elem.nodeName.toLowerCase(); // XHTML tags must be lower case. @@ -19576,8 +19558,7 @@ Strophe = { * Returns: * An escaped node (or local part). */ - escapeNode: function (node) - { + escapeNode: function (node) { if (typeof node !== "string") { return node; } return node.replace(/^\s+|\s+$/g, '') .replace(/\\/g, "\\5c") @@ -19601,8 +19582,7 @@ Strophe = { * Returns: * An unescaped node (or local part). */ - unescapeNode: function (node) - { + unescapeNode: function (node) { if (typeof node !== "string") { return node; } return node.replace(/\\20/g, " ") .replace(/\\22/g, '"') @@ -19625,8 +19605,7 @@ Strophe = { * Returns: * A String containing the node. */ - getNodeFromJid: function (jid) - { + getNodeFromJid: function (jid) { if (jid.indexOf("@") < 0) { return null; } return jid.split("@")[0]; }, @@ -19640,8 +19619,7 @@ Strophe = { * Returns: * A String containing the domain. */ - getDomainFromJid: function (jid) - { + getDomainFromJid: function (jid) { var bare = Strophe.getBareJidFromJid(jid); if (bare.indexOf("@") < 0) { return bare; @@ -19661,8 +19639,7 @@ Strophe = { * Returns: * A String containing the resource. */ - getResourceFromJid: function (jid) - { + getResourceFromJid: function (jid) { var s = jid.split("/"); if (s.length < 2) { return null; } s.splice(0, 1); @@ -19678,8 +19655,7 @@ Strophe = { * Returns: * A String containing the bare JID. */ - getBareJidFromJid: function (jid) - { + getBareJidFromJid: function (jid) { return jid ? jid.split("/")[0] : null; }, @@ -19713,8 +19689,7 @@ Strophe = { * (String) msg - The log message. */ /* jshint ignore:start */ - log: function (level, msg) - { + log: function (level, msg) { return; }, /* jshint ignore:end */ @@ -19736,8 +19711,7 @@ Strophe = { * Parameters: * (String) msg - The log message. */ - info: function (msg) - { + info: function (msg) { this.log(this.LogLevel.INFO, msg); }, @@ -19747,8 +19721,7 @@ Strophe = { * Parameters: * (String) msg - The log message. */ - warn: function (msg) - { + warn: function (msg) { this.log(this.LogLevel.WARN, msg); }, @@ -19758,8 +19731,7 @@ Strophe = { * Parameters: * (String) msg - The log message. */ - error: function (msg) - { + error: function (msg) { this.log(this.LogLevel.ERROR, msg); }, @@ -19769,8 +19741,7 @@ Strophe = { * Parameters: * (String) msg - The log message. */ - fatal: function (msg) - { + fatal: function (msg) { this.log(this.LogLevel.FATAL, msg); }, @@ -19783,8 +19754,7 @@ Strophe = { * Returns: * The serialized element tree as a String. */ - serialize: function (elem) - { + serialize: function (elem) { var result; if (!elem) { return null; } @@ -19857,8 +19827,7 @@ Strophe = { * (String) name - The name of the extension. * (Object) ptype - The plugin's prototype. */ - addConnectionPlugin: function (name, ptype) - { + addConnectionPlugin: function (name, ptype) { Strophe._connectionPlugins[name] = ptype; } }; @@ -19904,8 +19873,7 @@ Strophe = { * Returns: * A new Strophe.Builder. */ -Strophe.Builder = function (name, attrs) -{ +Strophe.Builder = function (name, attrs) { // Set correct namespace for jabber:client elements if (name == "presence" || name == "message" || name == "iq") { if (attrs && !attrs.xmlns) { @@ -19932,8 +19900,7 @@ Strophe.Builder.prototype = { * Returns: * The DOM tree as a element object. */ - tree: function () - { + tree: function () { return this.nodeTree; }, @@ -19947,8 +19914,7 @@ Strophe.Builder.prototype = { * Returns: * The serialized DOM tree in a String. */ - toString: function () - { + toString: function () { return Strophe.serialize(this.nodeTree); }, @@ -19962,8 +19928,7 @@ Strophe.Builder.prototype = { * Returns: * The Stophe.Builder object. */ - up: function () - { + up: function () { this.node = this.node.parentNode; return this; }, @@ -19980,8 +19945,7 @@ Strophe.Builder.prototype = { * Returns: * The Strophe.Builder object. */ - attrs: function (moreattrs) - { + attrs: function (moreattrs) { for (var k in moreattrs) { if (moreattrs.hasOwnProperty(k)) { if (moreattrs[k] === undefined) { @@ -20010,8 +19974,7 @@ Strophe.Builder.prototype = { * Returns: * The Strophe.Builder object. */ - c: function (name, attrs, text) - { + c: function (name, attrs, text) { var child = Strophe.xmlElement(name, attrs, text); this.node.appendChild(child); if (typeof text !== "string") { @@ -20034,8 +19997,7 @@ Strophe.Builder.prototype = { * Returns: * The Strophe.Builder object. */ - cnode: function (elem) - { + cnode: function (elem) { var impNode; var xmlGen = Strophe.xmlGenerator(); try { @@ -20064,8 +20026,7 @@ Strophe.Builder.prototype = { * Returns: * The Strophe.Builder object. */ - t: function (text) - { + t: function (text) { var child = Strophe.xmlTextNode(text); this.node.appendChild(child); return this; @@ -20082,8 +20043,7 @@ Strophe.Builder.prototype = { * Returns: * The Strophe.Builder object. */ - h: function (html) - { + h: function (html) { var fragment = document.createElement('body'); // force the browser to try and fix any invalid HTML tags @@ -20128,8 +20088,7 @@ Strophe.Builder.prototype = { * Returns: * A new Strophe.Handler object. */ -Strophe.Handler = function (handler, ns, name, type, id, from, options) -{ +Strophe.Handler = function (handler, ns, name, type, id, from, options) { this.handler = handler; this.ns = ns; this.name = name; @@ -20162,8 +20121,7 @@ Strophe.Handler.prototype = { * Returns: * true if the stanza matches and false otherwise. */ - isMatch: function (elem) - { + isMatch: function (elem) { var nsMatch; var from = null; @@ -20209,24 +20167,25 @@ Strophe.Handler.prototype = { * Returns: * A boolean indicating if the handler should remain active. */ - run: function (elem) - { + run: function (elem) { var result = null; try { result = this.handler(elem); } catch (e) { if (e.sourceURL) { - Strophe.fatal("error: " + this.handler + - " " + e.sourceURL + ":" + - e.line + " - " + e.name + ": " + e.message); + Strophe.fatal( + "error: " + this.handler + + " " + e.sourceURL + ":" + e.line + + " - " + e.name + ": " + e.message + "\n" + e.stack); } else if (e.fileName) { if (typeof(console) != "undefined") { console.trace(); - console.error(this.handler, " - error - ", e, e.message); + console.error(this.handler, " - error - ", e, + e.message + "\n" + e.stack); } Strophe.fatal("error: " + this.handler + " " + e.fileName + ":" + e.lineNumber + " - " + - e.name + ": " + e.message); + e.name + ": " + e.message + "\n" + e.stack); } else { Strophe.fatal("error: " + e.message + "\n" + e.stack); } @@ -20243,8 +20202,7 @@ Strophe.Handler.prototype = { * Returns: * A String. */ - toString: function () - { + toString: function () { return "{Handler: " + this.handler + "(" + this.name + "," + this.id + "," + this.ns + ")}"; } @@ -20275,8 +20233,7 @@ Strophe.Handler.prototype = { * Returns: * A new Strophe.TimedHandler object. */ -Strophe.TimedHandler = function (period, handler) -{ +Strophe.TimedHandler = function (period, handler) { this.period = period; this.handler = handler; @@ -20292,8 +20249,7 @@ Strophe.TimedHandler.prototype = { * true if the Strophe.TimedHandler should be called again, and false * otherwise. */ - run: function () - { + run: function () { this.lastCalled = new Date().getTime(); return this.handler(); }, @@ -20301,8 +20257,7 @@ Strophe.TimedHandler.prototype = { /** PrivateFunction: reset * Reset the last called time for the Strophe.TimedHandler. */ - reset: function () - { + reset: function () { this.lastCalled = new Date().getTime(); }, @@ -20312,8 +20267,7 @@ Strophe.TimedHandler.prototype = { * Returns: * The string representation. */ - toString: function () - { + toString: function () { return "{TimedHandler: " + this.handler + "(" + this.period +")}"; } }; @@ -20360,13 +20314,8 @@ Strophe.TimedHandler.prototype = { * document. These cookies will then be included in the BOSH XMLHttpRequest * or in the websocket connection. * - * The passed in value must be a map of cookie names and string values or - * cookie attributes. + * The passed in value must be a map of cookie names and string values: * - * For example: - * { "myCookie": "1234" } - * - * or: * { "myCookie": { * "value": "1234", * "domain": ".example.org", @@ -20426,7 +20375,7 @@ Strophe.TimedHandler.prototype = { * and for some reason need to send cookies to it. * In order for this to work cross-domain, the server must also enable * credentials by setting the Access-Control-Allow-Credentials response header - * to “true”. For most usecases however this setting should be false (which + * to "true". For most usecases however this setting should be false (which * is the default). * Additionally, when using Access-Control-Allow-Credentials, the * Access-Control-Allow-Origin header can't be set to the wildcard "*", but @@ -20439,8 +20388,7 @@ Strophe.TimedHandler.prototype = { * Returns: * A new Strophe.Connection object. */ -Strophe.Connection = function (service, options) -{ +Strophe.Connection = function (service, options) { // The service URL this.service = service; // Configuration options @@ -20497,7 +20445,10 @@ Strophe.Connection = function (service, options) this.maxRetries = 5; // Call onIdle callback every 1/10th of a second - this._idleTimeout = setTimeout(this._onIdle.bind(this), 100); + // XXX: setTimeout should be called only with function expressions (23974bc1) + this._idleTimeout = setTimeout(function() { + this._onIdle(); + }.bind(this), 100); utils.addCookies(this.options.cookies); @@ -20521,8 +20472,7 @@ Strophe.Connection.prototype = { * This function should be called after a connection is disconnected * before that connection is reused. */ - reset: function () - { + reset: function () { this._proto._reset(); // SASL @@ -20557,8 +20507,7 @@ Strophe.Connection.prototype = { * This causes Strophe to send the data in a single request, saving * many request trips. */ - pause: function () - { + pause: function () { this.paused = true; }, @@ -20567,8 +20516,7 @@ Strophe.Connection.prototype = { * * This resumes after pause() has been called. */ - resume: function () - { + resume: function () { this.paused = false; }, @@ -20638,8 +20586,7 @@ Strophe.Connection.prototype = { * (String) authcid - The optional alternative authentication identity * (username) if intending to impersonate another user. */ - connect: function (jid, pass, callback, wait, hold, route, authcid) - { + connect: function (jid, pass, callback, wait, hold, route, authcid) { this.jid = jid; /** Variable: authzid * Authorization identity. @@ -20695,8 +20642,7 @@ Strophe.Connection.prototype = { * (Integer) wind - The optional HTTBIND window value. This is the * allowed range of request ids that are valid. The default is 5. */ - attach: function (jid, sid, rid, callback, wait, hold, wind) - { + attach: function (jid, sid, rid, callback, wait, hold, wind) { if (this._proto instanceof Strophe.Bosh) { this._proto._attach(jid, sid, rid, callback, wait, hold, wind); } else { @@ -20734,8 +20680,7 @@ Strophe.Connection.prototype = { * (Integer) wind - The optional HTTBIND window value. This is the * allowed range of request ids that are valid. The default is 5. */ - restore: function (jid, callback, wait, hold, wind) - { + restore: function (jid, callback, wait, hold, wind) { if (this._sessionCachingSupported()) { this._proto._restore(jid, callback, wait, hold, wind); } else { @@ -20750,8 +20695,7 @@ Strophe.Connection.prototype = { * Checks whether sessionStorage and JSON are supported and whether we're * using BOSH. */ - _sessionCachingSupported: function () - { + _sessionCachingSupported: function () { if (this._proto instanceof Strophe.Bosh) { if (!JSON) { return false; } try { @@ -20784,8 +20728,7 @@ Strophe.Connection.prototype = { * (XMLElement) elem - The XML data received by the connection. */ /* jshint unused:false */ - xmlInput: function (elem) - { + xmlInput: function (elem) { return; }, /* jshint unused:true */ @@ -20809,8 +20752,7 @@ Strophe.Connection.prototype = { * (XMLElement) elem - The XMLdata sent by the connection. */ /* jshint unused:false */ - xmlOutput: function (elem) - { + xmlOutput: function (elem) { return; }, /* jshint unused:true */ @@ -20828,8 +20770,7 @@ Strophe.Connection.prototype = { * (String) data - The data received by the connection. */ /* jshint unused:false */ - rawInput: function (data) - { + rawInput: function (data) { return; }, /* jshint unused:true */ @@ -20847,8 +20788,7 @@ Strophe.Connection.prototype = { * (String) data - The data sent by the connection. */ /* jshint unused:false */ - rawOutput: function (data) - { + rawOutput: function (data) { return; }, /* jshint unused:true */ @@ -20865,8 +20805,7 @@ Strophe.Connection.prototype = { * (Number) rid - The next valid rid */ /* jshint unused:false */ - nextValidRid: function (rid) - { + nextValidRid: function (rid) { return; }, /* jshint unused:true */ @@ -20883,8 +20822,7 @@ Strophe.Connection.prototype = { * [XMLElement] | * Strophe.Builder) elem - The stanza to send. */ - send: function (elem) - { + send: function (elem) { if (elem === null) { return ; } if (typeof(elem.sort) === "function") { for (var i = 0; i < elem.length; i++) { @@ -20907,8 +20845,7 @@ Strophe.Connection.prototype = { * several send()s are called in succession. flush() can be used to * immediately send all pending data. */ - flush: function () - { + flush: function () { // cancel the pending idle period and run the idle function // immediately clearTimeout(this._idleTimeout); @@ -21024,13 +20961,15 @@ Strophe.Connection.prototype = { /** PrivateFunction: _sendRestart * Send an xmpp:restart stanza. */ - _sendRestart: function () - { + _sendRestart: function () { this._data.push("restart"); this._proto._sendRestart(); - this._idleTimeout = setTimeout(this._onIdle.bind(this), 100); + // XXX: setTimeout should be called only with function expressions (23974bc1) + this._idleTimeout = setTimeout(function() { + this._onIdle(); + }.bind(this), 100); }, /** Function: addTimedHandler @@ -21055,8 +20994,7 @@ Strophe.Connection.prototype = { * Returns: * A reference to the handler that can be used to remove it. */ - addTimedHandler: function (period, handler) - { + addTimedHandler: function (period, handler) { var thand = new Strophe.TimedHandler(period, handler); this.addTimeds.push(thand); return thand; @@ -21072,8 +21010,7 @@ Strophe.Connection.prototype = { * Parameters: * (Strophe.TimedHandler) handRef - The handler reference. */ - deleteTimedHandler: function (handRef) - { + deleteTimedHandler: function (handRef) { // this must be done in the Idle loop so that we don't change // the handlers during iteration this.removeTimeds.push(handRef); @@ -21117,8 +21054,7 @@ Strophe.Connection.prototype = { * Returns: * A reference to the handler that can be used to remove it. */ - addHandler: function (handler, ns, name, type, id, from, options) - { + addHandler: function (handler, ns, name, type, id, from, options) { var hand = new Strophe.Handler(handler, ns, name, type, id, from, options); this.addHandlers.push(hand); return hand; @@ -21134,8 +21070,7 @@ Strophe.Connection.prototype = { * Parameters: * (Strophe.Handler) handRef - The handler reference. */ - deleteHandler: function (handRef) - { + deleteHandler: function (handRef) { // this must be done in the Idle loop so that we don't change // the handlers during iteration this.removeHandlers.push(handRef); @@ -21163,8 +21098,7 @@ Strophe.Connection.prototype = { * Parameters: * (String) reason - The reason the disconnect is occuring. */ - disconnect: function (reason) - { + disconnect: function (reason) { this._changeConnectStatus(Strophe.Status.DISCONNECTING, reason); Strophe.info("Disconnect was called because: " + reason); @@ -21196,8 +21130,7 @@ Strophe.Connection.prototype = { * in Strophe.Status * (String) condition - the error condition or null */ - _changeConnectStatus: function (status, condition) - { + _changeConnectStatus: function (status, condition) { // notify all plugins listening for status changes for (var k in Strophe._connectionPlugins) { if (Strophe._connectionPlugins.hasOwnProperty(k)) { @@ -21207,7 +21140,7 @@ Strophe.Connection.prototype = { plugin.statusChanged(status, condition); } catch (err) { Strophe.error("" + k + " plugin caused an exception " + - "changing status: " + err); + "changing status: " + err.stack); } } } @@ -21219,7 +21152,7 @@ Strophe.Connection.prototype = { this.connect_callback(status, condition); } catch (e) { Strophe.error("User connection callback caused an " + - "exception: " + e); + "exception: " + e.stack); } } }, @@ -21230,8 +21163,7 @@ Strophe.Connection.prototype = { * This is the last piece of the disconnection logic. This resets the * connection and alerts the user's connection callback. */ - _doDisconnect: function (condition) - { + _doDisconnect: function (condition) { if (typeof this._idleTimeout == "number") { clearTimeout(this._idleTimeout); } @@ -21274,8 +21206,7 @@ Strophe.Connection.prototype = { * (Strophe.Request) req - The request that has data ready. * (string) req - The stanza a raw string (optiona). */ - _dataRecv: function (req, raw) - { + _dataRecv: function (req, raw) { Strophe.info("_dataRecv called"); var elem = this._proto._reqToData(req); if (elem === null) { return; } @@ -21389,8 +21320,7 @@ Strophe.Connection.prototype = { * Useful for plugins with their own xmpp connect callback (when their) * want to do something special). */ - _connect_cb: function (req, _callback, raw) - { + _connect_cb: function (req, _callback, raw) { Strophe.info("_connect_cb was called"); this.connected = true; @@ -21474,8 +21404,7 @@ Strophe.Connection.prototype = { * the code will fall back to legacy authentication. * */ - authenticate: function (matched) - { + authenticate: function (matched) { var i; // Sorting matched mechanisms according to priority. for (i = 0; i < matched.length - 1; ++i) { @@ -21581,8 +21510,7 @@ Strophe.Connection.prototype = { * false to remove the handler. */ /* jshint unused:false */ - _auth1_cb: function (elem) - { + _auth1_cb: function (elem) { // build plaintext auth iq var iq = $iq({type: "set", id: "_auth_2"}) .c('query', {xmlns: Strophe.NS.AUTH}) @@ -21616,8 +21544,7 @@ Strophe.Connection.prototype = { * Returns: * false to remove the handler. */ - _sasl_success_cb: function (elem) - { + _sasl_success_cb: function (elem) { if (this._sasl_data["server-signature"]) { var serverSignature; var success = Base64.decode(Strophe.getText(elem)); @@ -21684,8 +21611,7 @@ Strophe.Connection.prototype = { * Returns: * false to remove the handler. */ - _sasl_auth1_cb: function (elem) - { + _sasl_auth1_cb: function (elem) { // save stream:features for future usage this.features = elem; @@ -21720,7 +21646,6 @@ Strophe.Connection.prototype = { .tree()); } } - return false; }, @@ -21733,8 +21658,7 @@ Strophe.Connection.prototype = { * Returns: * false to remove the handler. */ - _sasl_bind_cb: function (elem) - { + _sasl_bind_cb: function (elem) { if (elem.getAttribute("type") == "error") { Strophe.info("SASL binding failed."); var conflict = elem.getElementsByTagName("conflict"), condition; @@ -21785,8 +21709,7 @@ Strophe.Connection.prototype = { * Returns: * false to remove the handler. */ - _sasl_session_cb: function (elem) - { + _sasl_session_cb: function (elem) { if (elem.getAttribute("type") == "result") { this.authenticated = true; this._changeConnectStatus(Strophe.Status.CONNECTED, null); @@ -21795,7 +21718,6 @@ Strophe.Connection.prototype = { this._changeConnectStatus(Strophe.Status.AUTHFAIL, null); return false; } - return false; }, @@ -21809,8 +21731,7 @@ Strophe.Connection.prototype = { * false to remove the handler. */ /* jshint unused:false */ - _sasl_failure_cb: function (elem) - { + _sasl_failure_cb: function (elem) { // delete unneeded handlers if (this._sasl_success_handler) { this.deleteHandler(this._sasl_success_handler); @@ -21840,8 +21761,7 @@ Strophe.Connection.prototype = { * Returns: * false to remove the handler. */ - _auth2_cb: function (elem) - { + _auth2_cb: function (elem) { if (elem.getAttribute("type") == "result") { this.authenticated = true; this._changeConnectStatus(Strophe.Status.CONNECTED, null); @@ -21849,7 +21769,6 @@ Strophe.Connection.prototype = { this._changeConnectStatus(Strophe.Status.AUTHFAIL, null); this.disconnect('authentication failed'); } - return false; }, @@ -21864,8 +21783,7 @@ Strophe.Connection.prototype = { * (Integer) period - The period of the handler. * (Function) handler - The callback function. */ - _addSysTimedHandler: function (period, handler) - { + _addSysTimedHandler: function (period, handler) { var thand = new Strophe.TimedHandler(period, handler); thand.user = false; this.addTimeds.push(thand); @@ -21907,6 +21825,8 @@ Strophe.Connection.prototype = { { Strophe.info("_onDisconnectTimeout was called"); + this._changeConnectStatus(Strophe.Status.CONNTIMEOUT, null); + this._proto._onDisconnectTimeout(); // actually disconnect @@ -21965,7 +21885,10 @@ Strophe.Connection.prototype = { // reactivate the timer only if connected if (this.connected) { - this._idleTimeout = setTimeout(this._onIdle.bind(this), 100); + // XXX: setTimeout should be called only with function expressions (23974bc1) + this._idleTimeout = setTimeout(function() { + this._onIdle(); + }.bind(this), 100); } } }; @@ -22057,8 +21980,7 @@ Strophe.SASLMechanism.prototype = { * Parameters: * (Strophe.Connection) connection - Target Connection. */ - onStart: function(connection) - { + onStart: function(connection) { this._connection = connection; }, @@ -22370,8 +22292,7 @@ return { * (Integer) sends - The number of times this same request has been * sent. */ -Strophe.Request = function (elem, func, rid, sends) -{ +Strophe.Request = function (elem, func, rid, sends) { this.id = ++Strophe._requestId; this.xmlData = elem; this.data = Strophe.serialize(elem); @@ -22412,8 +22333,7 @@ Strophe.Request.prototype = { * Returns: * The DOM element tree of the response. */ - getResponse: function () - { + getResponse: function () { var node = null; if (this.xhr.responseXML && this.xhr.responseXML.documentElement) { node = this.xhr.responseXML.documentElement; @@ -22441,8 +22361,7 @@ Strophe.Request.prototype = { * Returns: * A new XMLHttpRequest. */ - _newXHR: function () - { + _newXHR: function () { var xhr = null; if (window.XMLHttpRequest) { xhr = new XMLHttpRequest(); @@ -22518,8 +22437,7 @@ Strophe.Bosh.prototype = { * Returns: * A Strophe.Builder with a element. */ - _buildBody: function () - { + _buildBody: function () { var bodyWrap = $build('body', { rid: this.rid++, xmlns: Strophe.NS.HTTPBIND @@ -22527,7 +22445,7 @@ Strophe.Bosh.prototype = { if (this.sid !== null) { bodyWrap.attrs({sid: this.sid}); } - if (this._conn.options.keepalive) { + if (this._conn.options.keepalive && this._conn._sessionCachingSupported()) { this._cacheSession(); } return bodyWrap; @@ -22538,12 +22456,13 @@ Strophe.Bosh.prototype = { * * This function is called by the reset function of the Strophe Connection */ - _reset: function () - { + _reset: function () { this.rid = Math.floor(Math.random() * 4294967295); this.sid = null; this.errors = 0; - window.sessionStorage.removeItem('strophe-bosh-session'); + if (this._conn._sessionCachingSupported()) { + window.sessionStorage.removeItem('strophe-bosh-session'); + } this._conn.nextValidRid(this.rid); }, @@ -22553,8 +22472,7 @@ Strophe.Bosh.prototype = { * * Creates and sends the Request that initializes the BOSH connection. */ - _connect: function (wait, hold, route) - { + _connect: function (wait, hold, route) { this.wait = wait || this.wait; this.hold = hold || this.hold; this.errors = 0; @@ -22611,8 +22529,7 @@ Strophe.Bosh.prototype = { * (Integer) wind - The optional HTTBIND window value. This is the * allowed range of request ids that are valid. The default is 5. */ - _attach: function (jid, sid, rid, callback, wait, hold, wind) - { + _attach: function (jid, sid, rid, callback, wait, hold, wind) { this._conn.jid = jid; this.sid = sid; this.rid = rid; @@ -22650,15 +22567,14 @@ Strophe.Bosh.prototype = { * (Integer) wind - The optional HTTBIND window value. This is the * allowed range of request ids that are valid. The default is 5. */ - _restore: function (jid, callback, wait, hold, wind) - { + _restore: function (jid, callback, wait, hold, wind) { var session = JSON.parse(window.sessionStorage.getItem('strophe-bosh-session')); if (typeof session !== "undefined" && session !== null && session.rid && session.sid && session.jid && - (typeof jid === "undefined" || jid === "null" || Strophe.getBareJidFromJid(session.jid) == Strophe.getBareJidFromJid(jid))) + (typeof jid === "undefined" || jid === null || Strophe.getBareJidFromJid(session.jid) == Strophe.getBareJidFromJid(jid))) { this._conn.restored = true; this._attach(session.jid, session.sid, session.rid, callback, wait, hold, wind); @@ -22674,8 +22590,7 @@ Strophe.Bosh.prototype = { * Parameters: * (Strophe.Request) bodyWrap - The received stanza. */ - _cacheSession: function () - { + _cacheSession: function () { if (this._conn.authenticated) { if (this._conn.jid && this.rid && this.sid) { window.sessionStorage.setItem('strophe-bosh-session', JSON.stringify({ @@ -22696,8 +22611,7 @@ Strophe.Bosh.prototype = { * Parameters: * (Strophe.Request) bodyWrap - The received stanza. */ - _connect_cb: function (bodyWrap) - { + _connect_cb: function (bodyWrap) { var typ = bodyWrap.getAttribute("type"); var cond, conflict; if (typ !== null && typ == "terminate") { @@ -22736,8 +22650,7 @@ Strophe.Bosh.prototype = { * Parameters: * (Request) pres - This stanza will be sent before disconnecting. */ - _disconnect: function (pres) - { + _disconnect: function (pres) { this._sendTerminate(pres); }, @@ -22746,11 +22659,12 @@ Strophe.Bosh.prototype = { * * Resets the SID and RID. */ - _doDisconnect: function () - { + _doDisconnect: function () { this.sid = null; this.rid = Math.floor(Math.random() * 4294967295); - window.sessionStorage.removeItem('strophe-bosh-session'); + if (this._conn._sessionCachingSupported()) { + window.sessionStorage.removeItem('strophe-bosh-session'); + } this._conn.nextValidRid(this.rid); }, @@ -22761,8 +22675,7 @@ Strophe.Bosh.prototype = { * Returns: * True, if there are no Requests queued, False otherwise. */ - _emptyQueue: function () - { + _emptyQueue: function () { return this._requests.length === 0; }, @@ -22776,8 +22689,7 @@ Strophe.Bosh.prototype = { * Parameters: * (Integer) reqStatus - The request status. */ - _hitError: function (reqStatus) - { + _hitError: function (reqStatus) { this.errors++; Strophe.warn("request errored, status: " + reqStatus + ", number of errors: " + this.errors); @@ -22791,8 +22703,7 @@ Strophe.Bosh.prototype = { * Called on stream start/restart when no stream:features * has been received and sends a blank poll request. */ - _no_auth_received: function (_callback) - { + _no_auth_received: function (_callback) { if (_callback) { _callback = _callback.bind(this._conn); } else { @@ -22908,8 +22819,7 @@ Strophe.Bosh.prototype = { * (Function) func - The handler for the request. * (Strophe.Request) req - The request that is changing readyState. */ - _onRequestStateChange: function (func, req) - { + _onRequestStateChange: function (func, req) { Strophe.debug("request id " + req.id + "." + req.sends + " state changed to " + req.xhr.readyState); @@ -23004,8 +22914,7 @@ Strophe.Bosh.prototype = { * Parameters: * (Integer) i - The index of the request in the queue. */ - _processRequest: function (i) - { + _processRequest: function (i) { var self = this; var req = this._requests[i]; var reqStatus = -1; @@ -23097,7 +23006,11 @@ Strophe.Bosh.prototype = { // expanding retry window var backoff = Math.min(Math.floor(Strophe.TIMEOUT * this.wait), Math.pow(req.sends, 3)) * 1000; - setTimeout(sendFunc, backoff); + + // XXX: setTimeout should be called only with function expressions (23974bc1) + setTimeout(function() { + sendFunc(); + }, backoff); } else { sendFunc(); } @@ -23128,8 +23041,7 @@ Strophe.Bosh.prototype = { * Parameters: * (Strophe.Request) req - The request to remove. */ - _removeRequest: function (req) - { + _removeRequest: function (req) { Strophe.debug("removing request"); var i; @@ -23151,8 +23063,7 @@ Strophe.Bosh.prototype = { * Parameters: * (Integer) i - The index of the request in the queue. */ - _restartRequest: function (i) - { + _restartRequest: function (i) { var req = this._requests[i]; if (req.dead === null) { req.dead = new Date(); @@ -23173,8 +23084,7 @@ Strophe.Bosh.prototype = { * Returns: * The stanza that was passed. */ - _reqToData: function (req) - { + _reqToData: function (req) { try { return req.getResponse(); } catch (e) { @@ -23190,8 +23100,7 @@ Strophe.Bosh.prototype = { * the BOSH server a terminate body and includes an unavailable * presence if authentication has completed. */ - _sendTerminate: function (pres) - { + _sendTerminate: function (pres) { Strophe.info("_sendTerminate was called"); var body = this._buildBody().attrs({type: "terminate"}); @@ -23216,15 +23125,18 @@ Strophe.Bosh.prototype = { _send: function () { clearTimeout(this._conn._idleTimeout); this._throttledRequestHandler(); - this._conn._idleTimeout = setTimeout(this._conn._onIdle.bind(this._conn), 100); + + // XXX: setTimeout should be called only with function expressions (23974bc1) + this._conn._idleTimeout = setTimeout(function() { + this._onIdle(); + }.bind(this._conn), 100); }, /** PrivateFunction: _sendRestart * * Send an xmpp:restart stanza. */ - _sendRestart: function () - { + _sendRestart: function () { this._throttledRequestHandler(); clearTimeout(this._conn._idleTimeout); }, @@ -23236,8 +23148,7 @@ Strophe.Bosh.prototype = { * request ids overflow the connection window in the case that one * request died. */ - _throttledRequestHandler: function () - { + _throttledRequestHandler: function () { if (!this._requests) { Strophe.debug("_throttledRequestHandler called with " + "undefined requests"); @@ -23352,8 +23263,7 @@ Strophe.Websocket.prototype = { * Returns: * A Strophe.Builder with a element. */ - _buildStream: function () - { + _buildStream: function () { return $build("open", { "xmlns": Strophe.NS.FRAMING, "to": this._conn.domain, @@ -23423,8 +23333,7 @@ Strophe.Websocket.prototype = { * This function is called by the reset function of the Strophe Connection. * Is not needed by WebSockets. */ - _reset: function () - { + _reset: function () { return; }, @@ -23546,8 +23455,7 @@ Strophe.Websocket.prototype = { * Parameters: * (Request) pres - This stanza will be sent before disconnecting. */ - _disconnect: function (pres) - { + _disconnect: function (pres) { if (this.socket && this.socket.readyState !== WebSocket.CLOSED) { if (pres) { this._conn.send(pres); @@ -23570,8 +23478,7 @@ Strophe.Websocket.prototype = { * * Just closes the Socket for WebSockets */ - _doDisconnect: function () - { + _doDisconnect: function () { Strophe.info("WebSockets _doDisconnect was called"); this._closeSocket(); }, @@ -23580,8 +23487,7 @@ Strophe.Websocket.prototype = { * _Private_ helper function to wrap a stanza in a tag. * This is used so Strophe can process stanzas from WebSockets like BOSH */ - _streamWrap: function (stanza) - { + _streamWrap: function (stanza) { return "" + stanza + ''; }, @@ -23591,8 +23497,7 @@ Strophe.Websocket.prototype = { * * Closes the socket if it is still open and deletes it */ - _closeSocket: function () - { + _closeSocket: function () { if (this.socket) { try { this.socket.close(); } catch (e) {} } @@ -23605,8 +23510,7 @@ Strophe.Websocket.prototype = { * Returns: * True, because WebSocket messages are send immediately after queueing. */ - _emptyQueue: function () - { + _emptyQueue: function () { return true; }, @@ -23629,8 +23533,7 @@ Strophe.Websocket.prototype = { * Called on stream start/restart when no stream:features * has been received. */ - _no_auth_received: function (_callback) - { + _no_auth_received: function (_callback) { Strophe.error("Server did not send any auth methods"); this._conn._changeConnectStatus(Strophe.Status.CONNFAIL, "Server did not send any auth methods"); if (_callback) { @@ -23693,11 +23596,22 @@ Strophe.Websocket.prototype = { /** PrivateFunction: _onMessage * _Private_ function to handle websockets messages. * - * This function parses each of the messages as if they are full documents. [TODO : We may actually want to use a SAX Push parser]. + * This function parses each of the messages as if they are full documents. + * [TODO : We may actually want to use a SAX Push parser]. * - * Since all XMPP traffic starts with "" - * The first stanza will always fail to be parsed... - * Addtionnaly, the seconds stanza will always be a with the stream NS defined in the previous stanza... so we need to 'force' the inclusion of the NS in this stanza! + * Since all XMPP traffic starts with + * + * + * The first stanza will always fail to be parsed. + * + * Additionally, the seconds stanza will always be with + * the stream NS defined in the previous stanza, so we need to 'force' + * the inclusion of the NS in this stanza. * * Parameters: * (string) message - The websocket message. @@ -23716,7 +23630,6 @@ Strophe.Websocket.prototype = { } else if (message.data.search("\n \n