From 3368d45b5ce8d167e4c869893a039566be17ae19 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Thu, 15 Jun 2017 12:15:42 +0200 Subject: [PATCH] New release: v1.2.14 --- CHANGELOG.md | 2 +- Makefile | 13 +++++---- RELEASE_CHECKLIST.md | 24 ++++++++-------- package.json | 2 +- src/core.js | 2 +- src/websocket.js | 33 ++++++++++++++++------ strophe.js | 67 +++++++++++++++++++++++++++++++++----------- strophe.min.js | 4 +-- 8 files changed, 98 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4cbe3f9..e925f40c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Strophe.js Change Log -## Version 1.2.14 - Unreleased +## Version 1.2.14 - 2017-06-15 * #231 SASL OAuth Bearer authentication should not require a JID node, when a user identifer can be retreived from the bearer token. * #250 Show XHR error message diff --git a/Makefile b/Makefile index a7bf5e9a..4292802e 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ SRC_DIR = src DOC_DIR = doc DOC_TEMP = doc-temp NDPROJ_DIR = ndproj +SED ?= sed STROPHE = strophe.js STROPHE_MIN = strophe.min.js @@ -19,7 +20,7 @@ all: doc $(STROPHE) $(STROPHE_MIN) help: @echo "Please use \`make ' where is one of the following:" @echo "" - @echo " release Prepare a new release of strophe.js. E.g. `make release VERSION=1.2.13`" + @echo " release Prepare a new release of strophe.js. E.g. `make release VERSION=1.2.14`" @echo " serve Serve this directory via a webserver on port 8000." @echo " stamp-npm Install NPM dependencies and create the guard file stamp-npm which will prevent those dependencies from being installed again." @@ -42,8 +43,8 @@ doc: .PHONY: release release: - sed -i 's/\"version\":\ \"[0-9]\+\.[0-9]\+\.[0-9]\+\"/\"version\":\ \"$(VERSION)\"/' package.json - sed -i "s/Unreleased/`date +%Y-%m-%d`/" CHANGELOG.md + $(SED) -i 's/\"version\":\ \"[0-9]\+\.[0-9]\+\.[0-9]\+\"/\"version\":\ \"$(VERSION)\"/' package.json + $(SED) -i "s/Unreleased/`date +%Y-%m-%d`/" CHANGELOG.md make dist make doc @@ -52,15 +53,15 @@ dist: $(STROPHE) $(STROPHE_MIN) $(STROPHE_LIGHT) $(STROPHE_MIN): src node_modules Makefile $(RJS) -o build.js insertRequire=strophe-polyfill include=strophe-polyfill out=$(STROPHE_MIN) - sed -i s/@VERSION@/$(VERSION)/ $(STROPHE_MIN) + $(SED) -i s/@VERSION@/$(VERSION)/ $(STROPHE_MIN) $(STROPHE): src node_modules Makefile $(RJS) -o build.js optimize=none insertRequire=strophe-polyfill include=strophe-polyfill out=$(STROPHE) - sed -i s/@VERSION@/$(VERSION)/ $(STROPHE) + $(SED) -i s/@VERSION@/$(VERSION)/ $(STROPHE) $(STROPHE_LIGHT): src node_modules Makefile $(RJS) -o build.js optimize=none out=$(STROPHE_LIGHT) - sed -i s/@VERSION@/$(VERSION)/ $(STROPHE_LIGHT) + $(SED) -i s/@VERSION@/$(VERSION)/ $(STROPHE_LIGHT) .PHONY: jshint jshint: stamp-npm diff --git a/RELEASE_CHECKLIST.md b/RELEASE_CHECKLIST.md index 6cf1c34f..80292d0b 100644 --- a/RELEASE_CHECKLIST.md +++ b/RELEASE_CHECKLIST.md @@ -1,15 +1,13 @@ # Release Checklist -- Make sure all tests pass (run 'make check') -- Decide on version number -- Update CHANGELOG.md -- Check for correct version number in package.json and bower,json -- Run "make release" -- Commit the newly generated files (mention it's a new release) -- Tag code with version (git tag -s vVERSION ) -- Push repo and tags (git push && git push --tags) -- Publish on NPM: "npm publish" -- Add documentation to strophe.im repo -- Update links in index.markdown in Strophe.im -- Update link to documentation in README -- Tell the world +1. Make sure all tests pass (run 'make check') +2. Update CHANGELOG.md +3. Run "make release VERSION=1.2.14" (on Mac, prefix with "SED=gsed" so that + GNU-sed is used). +4. Commit the newly generated files (mention it's a new release) +5. Tag code with version (git tag -s vVERSION ) +6. Push repo and tags (git push && git push --tags) +7. Publish on NPM: "npm publish" +8. Add documentation to strophe.im repo +9. Update links in index.markdown in Strophe.im +10. Update link to documentation in README diff --git a/package.json b/package.json index d1cdac0a..7a1604bd 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "strophe.js", "description": "Strophe.js is an XMPP library for JavaScript", - "version": "1.2.13", + "version": "1.2.14", "homepage": "http://strophe.im/strophejs", "repository": { "type": "git", diff --git a/src/core.js b/src/core.js index 1e8e6f2e..3d7ad132 100644 --- a/src/core.js +++ b/src/core.js @@ -1747,7 +1747,7 @@ Strophe.Connection.prototype = { * Patches that handle websocket errors would be very welcome. * * Parameters: - * (String) protocol - 'HTTP' or 'websocket' + * (String) protocol - 'HTTP' or 'websocket' * (Integer) status_code - Error status code (e.g 500, 400 or 404) * (Function) callback - Function that will fire on Http error * diff --git a/src/websocket.js b/src/websocket.js index e33285c8..2803a259 100644 --- a/src/websocket.js +++ b/src/websocket.js @@ -249,17 +249,23 @@ Strophe.Websocket.prototype = { //_connect_cb will check for stream:error and disconnect on error this._connect_cb(streamStart); } - } else if (message.data.indexOf(" 0 && reqStatus < 500) || req.sends > 5) { + var valid_request = reqStatus > 0 && reqStatus < 500; + var too_many_retries = req.sends > this._conn.maxRetries; + if (valid_request || too_many_retries) { // remove from internal queue this._removeRequest(req); Strophe.debug("request id "+req.id+" should now be removed"); @@ -5497,8 +5504,11 @@ Strophe.Bosh.prototype = { } else { Strophe.error("request id "+req.id+"."+req.sends+" error "+reqStatus+" happened"); } - if (!(reqStatus > 0 && reqStatus < 500) || req.sends > 5) { + + if (!valid_request && !too_many_retries) { this._throttledRequestHandler(); + } else if (too_many_retries && !this._conn.connected) { + this._conn._changeConnectStatus(Strophe.Status.CONNFAIL, "giving-up"); } }, @@ -5560,7 +5570,7 @@ Strophe.Bosh.prototype = { req.xhr.withCredentials = true; } } catch (e2) { - Strophe.error("XHR open failed."); + Strophe.error("XHR open failed: " + e2.toString()); if (!this._conn.connected) { this._conn._changeConnectStatus( Strophe.Status.CONNFAIL, "bad-service"); @@ -6006,17 +6016,23 @@ Strophe.Websocket.prototype = { //_connect_cb will check for stream:error and disconnect on error this._connect_cb(streamStart); } - } else if (message.data.indexOf("0&&(t.splice(u-1,2),u-=2)}t=t.join("/")}if((f||m)&&p){for(n=t.split("/"),u=n.length;u>0;u-=1){if(i=n.slice(0,u).join("/"),f)for(l=f.length;l>0;l-=1)if(s=p[f.slice(0,l).join("/")],s&&(s=s[i])){r=s,a=u;break}if(r)break;!h&&m&&m[i]&&(h=m[i],c=u)}!r&&h&&(r=h,a=c),r&&(n.splice(0,a,r),t=n.join("/"))}return t}function o(t,e){return function(){var n=T.call(arguments,0);return"string"!=typeof n[0]&&1===n.length&&n.push(null),f.apply(i,n.concat([t,e]))}}function a(t){return function(e){return r(e,t)}}function h(t){return function(e){g[t]=e}}function c(t){if(s(S,t)){var e=S[t];delete S[t],y[t]=!0,_.apply(i,e)}if(!s(g,t)&&!s(y,t))throw new Error("No "+t);return g[t]}function u(t){var e,n=t?t.indexOf("!"):-1;return n>-1&&(e=t.substring(0,n),t=t.substring(n+1,t.length)),[e,t]}function l(t){return t?u(t):[]}function d(t){return function(){return b&&b.config&&b.config[t]||{}}}var _,f,p,m,g={},S={},b={},y={},v=Object.prototype.hasOwnProperty,T=[].slice,x=/\.js$/;p=function(t,e){var n,i=u(t),s=i[0],o=e[1];return t=i[1],s&&(s=r(s,o),n=c(s)),s?t=n&&n.normalize?n.normalize(t,a(o)):r(t,o):(t=r(t,o),i=u(t),s=i[0],t=i[1],s&&(n=c(s))),{f:s?s+"!"+t:t,n:t,pr:s,p:n}},m={require:function(t){return o(t)},exports:function(t){var e=g[t];return"undefined"!=typeof e?e:g[t]={}},module:function(t){return{id:t,uri:"",exports:g[t],config:d(t)}}},_=function(t,e,n,r){var a,u,d,_,f,b,v,T=[],x=typeof n;if(r=r||t,b=l(r),"undefined"===x||"function"===x){for(e=!e.length&&n.length?["require","exports","module"]:e,f=0;f>>0;if("function"!=typeof t)throw new TypeError(t+" is not a function");for(arguments.length>1&&(n=e),i=0;i>2,o=(3&n)<<4|i>>4,a=(15&i)<<2|s>>6,h=63&s,isNaN(i)?(o=(3&n)<<4,a=h=64):isNaN(s)&&(h=64),c=c+e.charAt(r)+e.charAt(o)+e.charAt(a)+e.charAt(h);while(u>4,i=(15&o)<<4|a>>2,s=(3&a)<<6|h,c+=String.fromCharCode(n),64!==a&&(c+=String.fromCharCode(i)),64!==h&&(c+=String.fromCharCode(s));while(u>5]|=128<<24-i%32,t[(i+64>>9<<4)+15]=i;var o,a,h,c,u,l,d,_,f=new Array(80),p=1732584193,m=-271733879,g=-1732584194,S=271733878,b=-1009589776;for(o=0;o16&&(i=t(i,8*e.length));for(var s=new Array(16),r=new Array(16),a=0;a<16;a++)s[a]=909522486^i[a],r[a]=1549556828^i[a];var h=t(s.concat(o(n)),512+8*n.length);return t(r.concat(h),672)}function s(t,e){var n=(65535&t)+(65535&e),i=(t>>16)+(e>>16)+(n>>16);return i<<16|65535&n}function r(t,e){return t<>>32-e}function o(t){for(var e=[],n=255,i=0;i<8*t.length;i+=8)e[i>>5]|=(t.charCodeAt(i/8)&n)<<24-i%32;return e}function a(t){for(var e="",n=255,i=0;i<32*t.length;i+=8)e+=String.fromCharCode(t[i>>5]>>>24-i%32&n);return e}function h(t){for(var e,n,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s="",r=0;r<4*t.length;r+=3)for(e=(t[r>>2]>>8*(3-r%4)&255)<<16|(t[r+1>>2]>>8*(3-(r+1)%4)&255)<<8|t[r+2>>2]>>8*(3-(r+2)%4)&255,n=0;n<4;n++)s+=8*r+6*n>32*t.length?"=":i.charAt(e>>6*(3-n)&63);return s}return{b64_hmac_sha1:function(t,e){return h(i(t,e))},b64_sha1:function(e){return h(t(o(e),8*e.length))},binb2str:a,core_hmac_sha1:i,str_hmac_sha1:function(t,e){return a(i(t,e))},str_sha1:function(e){return a(t(o(e),8*e.length))}}}),function(t,e){"function"==typeof n&&n.amd?n("strophe-md5",[],function(){return e()}):t.MD5=e()}(this,function(){var t=function(t,e){var n=(65535&t)+(65535&e),i=(t>>16)+(e>>16)+(n>>16);return i<<16|65535&n},e=function(t,e){return t<>>32-e},n=function(t){for(var e=[],n=0;n<8*t.length;n+=8)e[n>>5]|=(255&t.charCodeAt(n/8))<>5]>>>n%32&255);return e},s=function(t){for(var e="0123456789abcdef",n="",i=0;i<4*t.length;i++)n+=e.charAt(t[i>>2]>>i%4*8+4&15)+e.charAt(t[i>>2]>>i%4*8&15);return n},r=function(n,i,s,r,o,a){return t(e(t(t(i,n),t(r,a)),o),s)},o=function(t,e,n,i,s,o,a){return r(e&n|~e&i,t,e,s,o,a)},a=function(t,e,n,i,s,o,a){return r(e&i|n&~i,t,e,s,o,a)},h=function(t,e,n,i,s,o,a){return r(e^n^i,t,e,s,o,a)},c=function(t,e,n,i,s,o,a){return r(n^(e|~i),t,e,s,o,a)},u=function(e,n){e[n>>5]|=128<>>9<<4)+14]=n;for(var i,s,r,u,l=1732584193,d=-271733879,_=-1732584194,f=271733878,p=0;p=0&&n<=127?i+=t.charAt(e):n>2047?(i+=String.fromCharCode(224|n>>12&15),i+=String.fromCharCode(128|n>>6&63),i+=String.fromCharCode(128|n>>0&63)):(i+=String.fromCharCode(192|n>>6&31),i+=String.fromCharCode(128|n>>0&63));return i},addCookies:function(t){var e,n,i,s,r,o,a;for(e in t||{})r="",o="",a="",n=t[e],i="object"==typeof n,s=escape(unescape(i?n.value:n)),i&&(r=n.expires?";expires="+n.expires:"",o=n.domain?";domain="+n.domain:"",a=n.path?";path="+n.path:""),document.cookie=e+"="+s+r+o+a}};return t}),function(t,e){if("function"==typeof n&&n.amd)n("strophe-core",["strophe-sha1","strophe-md5","strophe-utils"],function(){return e.apply(this,arguments)});else{var i=e(t.SHA1,t.MD5,t.stropheUtils);t.Strophe=i.Strophe,t.$build=i.$build,t.$iq=i.$iq,t.$msg=i.$msg,t.$pres=i.$pres,t.SHA1=i.SHA1,t.MD5=i.MD5,t.b64_hmac_sha1=i.SHA1.b64_hmac_sha1,t.b64_sha1=i.SHA1.b64_sha1,t.str_hmac_sha1=i.SHA1.str_hmac_sha1,t.str_sha1=i.SHA1.str_sha1}}(this,function(t,e,n){function i(t,e){return new a.Builder(t,e)}function s(t){return new a.Builder("message",t)}function r(t){return new a.Builder("iq",t)}function o(t){return new a.Builder("presence",t)}var a;return a={VERSION:"1.2.13",NS:{HTTPBIND:"http://jabber.org/protocol/httpbind",BOSH:"urn:xmpp:xbosh",CLIENT:"jabber:client",AUTH:"jabber:iq:auth",ROSTER:"jabber:iq:roster",PROFILE:"jabber:iq:profile",DISCO_INFO:"http://jabber.org/protocol/disco#info",DISCO_ITEMS:"http://jabber.org/protocol/disco#items",MUC:"http://jabber.org/protocol/muc",SASL:"urn:ietf:params:xml:ns:xmpp-sasl",STREAM:"http://etherx.jabber.org/streams",FRAMING:"urn:ietf:params:xml:ns:xmpp-framing",BIND:"urn:ietf:params:xml:ns:xmpp-bind",SESSION:"urn:ietf:params:xml:ns:xmpp-session",VERSION:"jabber:iq:version",STANZAS:"urn:ietf:params:xml:ns:xmpp-stanzas",XHTML_IM:"http://jabber.org/protocol/xhtml-im",XHTML:"http://www.w3.org/1999/xhtml"},XHTML:{tags:["a","blockquote","br","cite","em","img","li","ol","p","span","strong","ul","body"],attributes:{a:["href"],blockquote:["style"],br:[],cite:["style"],em:[],img:["src","alt","style","height","width"],li:["style"],ol:["style"],p:["style"],span:["style"],strong:[],ul:["style"],body:[]},css:["background-color","color","font-family","font-size","font-style","font-weight","margin-left","margin-right","text-align","text-decoration"],validTag:function(t){for(var e=0;e0)for(var n=0;n/g,">"),t=t.replace(/'/g,"'"),t=t.replace(/"/g,""")},xmlunescape:function(t){return t=t.replace(/\&/g,"&"),t=t.replace(/</g,"<"),t=t.replace(/>/g,">"),t=t.replace(/'/g,"'"),t=t.replace(/"/g,'"')},xmlTextNode:function(t){return a.xmlGenerator().createTextNode(t)},xmlHtmlNode:function(t){var e;if(DOMParser){var n=new DOMParser;e=n.parseFromString(t,"text/xml")}else e=new ActiveXObject("Microsoft.XMLDOM"),e.async="false",e.loadXML(t);return e},getText:function(t){if(!t)return null;var e="";0===t.childNodes.length&&t.nodeType===a.ElementType.TEXT&&(e+=t.nodeValue);for(var n=0;n0&&(o=h.join("; "),n.setAttribute(r,o))}else n.setAttribute(r,o);for(e=0;e/g,"\\3e").replace(/@/g,"\\40")},unescapeNode:function(t){return"string"!=typeof t?t:t.replace(/\\20/g," ").replace(/\\22/g,'"').replace(/\\26/g,"&").replace(/\\27/g,"'").replace(/\\2f/g,"/").replace(/\\3a/g,":").replace(/\\3c/g,"<").replace(/\\3e/g,">").replace(/\\40/g,"@").replace(/\\5c/g,"\\")},getNodeFromJid:function(t){return t.indexOf("@")<0?null:t.split("@")[0]},getDomainFromJid:function(t){var e=a.getBareJidFromJid(t);if(e.indexOf("@")<0)return e;var n=e.split("@");return n.splice(0,1),n.join("@")},getResourceFromJid:function(t){var e=t.split("/");return e.length<2?null:(e.splice(0,1),e.join("/"))},getBareJidFromJid:function(t){return t?t.split("/")[0]:null},_handleError:function(t){"undefined"!=typeof t.stack&&a.fatal(t.stack),t.sourceURL?a.fatal("error: "+this.handler+" "+t.sourceURL+":"+t.line+" - "+t.name+": "+t.message):t.fileName?a.fatal("error: "+this.handler+" "+t.fileName+":"+t.lineNumber+" - "+t.name+": "+t.message):a.fatal("error: "+t.message)},log:function(t,e){},debug:function(t){this.log(this.LogLevel.DEBUG,t)},info:function(t){this.log(this.LogLevel.INFO,t)},warn:function(t){this.log(this.LogLevel.WARN,t)},error:function(t){this.log(this.LogLevel.ERROR,t)},fatal:function(t){this.log(this.LogLevel.FATAL,t)},serialize:function(t){var e;if(!t)return null;"function"==typeof t.tree&&(t=t.tree());var n,i,s=t.nodeName;for(t.getAttribute("_realname")&&(s=t.getAttribute("_realname")),e="<"+s,n=0;n0){for(e+=">",n=0;n"}e+=""}else e+="/>";return e},_requestId:0,_connectionPlugins:{},addConnectionPlugin:function(t,e){a._connectionPlugins[t]=e}},a.Builder=function(t,e){"presence"!==t&&"message"!==t&&"iq"!==t||(e&&!e.xmlns?e.xmlns=a.NS.CLIENT:e||(e={xmlns:a.NS.CLIENT})),this.nodeTree=a.xmlElement(t,e),this.node=this.nodeTree},a.Builder.prototype={tree:function(){return this.nodeTree},toString:function(){return a.serialize(this.nodeTree)},up:function(){return this.node=this.node.parentNode,this},root:function(){return this.node=this.nodeTree,this},attrs:function(t){for(var e in t)t.hasOwnProperty(e)&&(void 0===t[e]?this.node.removeAttribute(e):this.node.setAttribute(e,t[e]));return this},c:function(t,e,n){var i=a.xmlElement(t,e,n);return this.node.appendChild(i),"string"!=typeof n&&"number"!=typeof n&&(this.node=i),this},cnode:function(t){var e,n=a.xmlGenerator();try{e=void 0!==n.importNode}catch(t){e=!1}var i=e?n.importNode(t,!0):a.copyElement(t);return this.node.appendChild(i),this.node=i,this},t:function(t){var e=a.xmlTextNode(t);return this.node.appendChild(e),this},h:function(t){var e=document.createElement("body");e.innerHTML=t;for(var n=a.createHtml(e);n.childNodes.length>0;)this.node.appendChild(n.childNodes[0]);return this}},a.Handler=function(t,e,n,i,s,r,o){this.handler=t,this.ns=e,this.name=n,this.type=i,this.id=s,this.options=o||{matchBareFromJid:!1,ignoreNamespaceFragment:!1},this.options.matchBare&&(a.warn('The "matchBare" option is deprecated, use "matchBareFromJid" instead.'),this.options.matchBareFromJid=this.options.matchBare,delete this.options.matchBare),this.options.matchBareFromJid?this.from=r?a.getBareJidFromJid(r):null:this.from=r,this.user=!0},a.Handler.prototype={getNamespace:function(t){var e=t.getAttribute("xmlns");return e&&this.options.ignoreNamespaceFragment&&(e=e.split("#")[0]),e},namespaceMatch:function(t){var e=!1;if(!this.ns)return!0;var n=this;return a.forEachChild(t,null,function(t){n.getNamespace(t)===n.ns&&(e=!0)}),e=e||this.getNamespace(t)===this.ns},isMatch:function(t){var e=t.getAttribute("from");this.options.matchBareFromJid&&(e=a.getBareJidFromJid(e));var n=t.getAttribute("type");return!(!this.namespaceMatch(t)||this.name&&!a.isTagEqual(t,this.name)||this.type&&(Array.isArray(this.type)?this.type.indexOf(n)===-1:n!==this.type)||this.id&&t.getAttribute("id")!==this.id||this.from&&e!==this.from)},run:function(t){var e=null;try{e=this.handler(t)}catch(t){throw a._handleError(t),t}return e},toString:function(){return"{Handler: "+this.handler+"("+this.name+","+this.id+","+this.ns+")}"}},a.TimedHandler=function(t,e){this.period=t,this.handler=e,this.lastCalled=(new Date).getTime(),this.user=!0},a.TimedHandler.prototype={run:function(){return this.lastCalled=(new Date).getTime(),this.handler()},reset:function(){this.lastCalled=(new Date).getTime()},toString:function(){return"{TimedHandler: "+this.handler+"("+this.period+")}"}},a.Connection=function(t,e){this.service=t,this.options=e||{};var i=this.options.protocol||"";0===t.indexOf("ws:")||0===t.indexOf("wss:")||0===i.indexOf("ws")?this._proto=new a.Websocket(this):this._proto=new a.Bosh(this),this.jid="",this.domain=null,this.features=null,this._sasl_data={},this.do_session=!1,this.do_bind=!1,this.timedHandlers=[],this.handlers=[],this.removeTimeds=[],this.removeHandlers=[],this.addTimeds=[],this.addHandlers=[],this.protocolErrorHandlers={HTTP:{},websocket:{}},this._idleTimeout=null,this._disconnectTimeout=null,this.authenticated=!1,this.connected=!1,this.disconnecting=!1,this.do_authentication=!0,this.paused=!1,this.restored=!1,this._data=[],this._uniqueId=0,this._sasl_success_handler=null,this._sasl_failure_handler=null,this._sasl_challenge_handler=null,this.maxRetries=5,this._idleTimeout=setTimeout(function(){this._onIdle()}.bind(this),100),n.addCookies(this.options.cookies),this.registerSASLMechanisms(this.options.mechanisms);for(var s in a._connectionPlugins)if(a._connectionPlugins.hasOwnProperty(s)){var r=a._connectionPlugins[s],o=function(){};o.prototype=r,this[s]=new o,this[s].init(this)}},a.Connection.prototype={reset:function(){this._proto._reset(),this.do_session=!1,this.do_bind=!1,this.timedHandlers=[],this.handlers=[],this.removeTimeds=[],this.removeHandlers=[],this.addTimeds=[],this.addHandlers=[],this.authenticated=!1,this.connected=!1,this.disconnecting=!1,this.restored=!1,this._data=[],this._requests=[],this._uniqueId=0},pause:function(){this.paused=!0},resume:function(){this.paused=!1},getUniqueId:function(t){var e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=16*Math.random()|0,n="x"===t?e:3&e|8;return n.toString(16)});return"string"==typeof t||"number"==typeof t?e+":"+t:e+""},addProtocolErrorHandler:function(t,e,n){this.protocolErrorHandlers[t][e]=n},connect:function(t,e,n,i,s,r,o){this.jid=t,this.authzid=a.getBareJidFromJid(this.jid),this.authcid=o||a.getNodeFromJid(this.jid),this.pass=e,this.servtype="xmpp",this.connect_callback=n,this.disconnecting=!1,this.connected=!1,this.authenticated=!1,this.restored=!1,this.domain=a.getDomainFromJid(this.jid),this._changeConnectStatus(a.Status.CONNECTING,null),this._proto._connect(i,s,r)},attach:function(t,e,n,i,s,r,o){if(!(this._proto instanceof a.Bosh))throw{name:"StropheSessionError",message:'The "attach" method can only be used with a BOSH connection.'};this._proto._attach(t,e,n,i,s,r,o)},restore:function(t,e,n,i,s){if(!this._sessionCachingSupported())throw{name:"StropheSessionError",message:'The "restore" method can only be used with a BOSH connection.'};this._proto._restore(t,e,n,i,s)},_sessionCachingSupported:function(){if(this._proto instanceof a.Bosh){if(!JSON)return!1;try{sessionStorage.setItem("_strophe_","_strophe_"),sessionStorage.removeItem("_strophe_")}catch(t){return!1}return!0}return!1},xmlInput:function(t){},xmlOutput:function(t){},rawInput:function(t){},rawOutput:function(t){},nextValidRid:function(t){},send:function(t){if(null!==t){if("function"==typeof t.sort)for(var e=0;e=0&&this.addHandlers.splice(e,1)},registerSASLMechanisms:function(t){this.mechanisms={},t=t||[a.SASLAnonymous,a.SASLExternal,a.SASLMD5,a.SASLOAuthBearer,a.SASLPlain,a.SASLSHA1],t.forEach(this.registerSASLMechanism.bind(this))},registerSASLMechanism:function(t){this.mechanisms[t.prototype.name]=t},disconnect:function(t){if(this._changeConnectStatus(a.Status.DISCONNECTING,t),a.info("Disconnect was called because: "+t),this.connected){var e=!1;this.disconnecting=!0,this.authenticated&&(e=o({xmlns:a.NS.CLIENT,type:"unavailable"})),this._disconnectTimeout=this._addSysTimedHandler(3e3,this._onDisconnectTimeout.bind(this)),this._proto._disconnect(e)}else a.info("Disconnect was called before Strophe connected to the server"),this._proto._abortAllRequests(),this._doDisconnect()},_changeConnectStatus:function(t,e){for(var n in a._connectionPlugins)if(a._connectionPlugins.hasOwnProperty(n)){var i=this[n];if(i.statusChanged)try{i.statusChanged(t,e)}catch(t){a.error(""+n+" plugin caused an exception changing status: "+t)}}if(this.connect_callback)try{this.connect_callback(t,e)}catch(t){a._handleError(t),a.error("User connection callback caused an exception: "+t)}},_doDisconnect:function(t){"number"==typeof this._idleTimeout&&clearTimeout(this._idleTimeout),null!==this._disconnectTimeout&&(this.deleteTimedHandler(this._disconnectTimeout),this._disconnectTimeout=null),a.info("_doDisconnect was called"),this._proto._doDisconnect(),this.authenticated=!1,this.disconnecting=!1,this.restored=!1,this.handlers=[],this.timedHandlers=[],this.removeTimeds=[],this.removeHandlers=[],this.addTimeds=[],this.addHandlers=[],this._changeConnectStatus(a.Status.DISCONNECTED,t),this.connected=!1},_dataRecv:function(t,e){a.info("_dataRecv called");var n=this._proto._reqToData(t);if(null!==n){this.xmlInput!==a.Connection.prototype.xmlInput&&(n.nodeName===this._proto.strip&&n.childNodes.length?this.xmlInput(n.childNodes[0]):this.xmlInput(n)),this.rawInput!==a.Connection.prototype.rawInput&&(e?this.rawInput(e):this.rawInput(a.serialize(n)));for(var i,s;this.removeHandlers.length>0;)s=this.removeHandlers.pop(),i=this.handlers.indexOf(s),i>=0&&this.handlers.splice(i,1);for(;this.addHandlers.length>0;)this.handlers.push(this.addHandlers.pop());if(this.disconnecting&&this._proto._emptyQueue())return void this._doDisconnect();var r,o,h=n.getAttribute("type");if(null!==h&&"terminate"===h){if(this.disconnecting)return;return r=n.getAttribute("condition"),o=n.getElementsByTagName("conflict"),null!==r?("remote-stream-error"===r&&o.length>0&&(r="conflict"),this._changeConnectStatus(a.Status.CONNFAIL,r)):this._changeConnectStatus(a.Status.CONNFAIL,"unknown"),void this._doDisconnect(r)}var c=this;a.forEachChild(n,null,function(t){var e,n;for(n=c.handlers,c.handlers=[],e=0;e0:i.getElementsByTagName("stream:features").length>0||i.getElementsByTagName("features").length>0,!r)return void this._proto._no_auth_received(e);var o,h,c=[],u=i.getElementsByTagName("mechanism");if(u.length>0)for(o=0;ot[i].prototype.priority&&(i=n);i!==e&&(s=t[e],t[e]=t[i],t[i]=s)}return t},_attemptSASLAuth:function(t){t=this.sortMechanismsByPriority(t||[]);var e=0,n=!1;for(e=0;e0&&(e="conflict"),this._changeConnectStatus(a.Status.AUTHFAIL,e),!1}var i,s=t.getElementsByTagName("bind");return s.length>0?(i=s[0].getElementsByTagName("jid"),void(i.length>0&&(this.jid=a.getText(i[0]),this.do_session?(this._addSysHandler(this._sasl_session_cb.bind(this),null,null,null,"_session_auth_2"),this.send(r({type:"set",id:"_session_auth_2"}).c("session",{xmlns:a.NS.SESSION}).tree())):(this.authenticated=!0,this._changeConnectStatus(a.Status.CONNECTED,null))))):(a.info("SASL binding failed."),this._changeConnectStatus(a.Status.AUTHFAIL,null),!1)},_sasl_session_cb:function(t){if("result"===t.getAttribute("type"))this.authenticated=!0,this._changeConnectStatus(a.Status.CONNECTED,null);else if("error"===t.getAttribute("type"))return a.info("Session creation failed."),this._changeConnectStatus(a.Status.AUTHFAIL,null),!1;return!1},_sasl_failure_cb:function(t){return this._sasl_success_handler&&(this.deleteHandler(this._sasl_success_handler),this._sasl_success_handler=null),this._sasl_challenge_handler&&(this.deleteHandler(this._sasl_challenge_handler),this._sasl_challenge_handler=null),this._sasl_mechanism&&this._sasl_mechanism.onFailure(),this._changeConnectStatus(a.Status.AUTHFAIL,null),!1},_auth2_cb:function(t){return"result"===t.getAttribute("type")?(this.authenticated=!0,this._changeConnectStatus(a.Status.CONNECTED,null)):"error"===t.getAttribute("type")&&(this._changeConnectStatus(a.Status.AUTHFAIL,null),this.disconnect("authentication failed")),!1},_addSysTimedHandler:function(t,e){var n=new a.TimedHandler(t,e);return n.user=!1,this.addTimeds.push(n),n},_addSysHandler:function(t,e,n,i,s){var r=new a.Handler(t,e,n,i,s);return r.user=!1,this.addHandlers.push(r),r},_onDisconnectTimeout:function(){return a.info("_onDisconnectTimeout was called"),this._changeConnectStatus(a.Status.CONNTIMEOUT,null),this._proto._onDisconnectTimeout(),this._doDisconnect(),!1},_onIdle:function(){for(var t,e,n,i;this.addTimeds.length>0;)this.timedHandlers.push(this.addTimeds.pop());for(;this.removeTimeds.length>0;)e=this.removeTimeds.pop(),t=this.timedHandlers.indexOf(e),t>=0&&this.timedHandlers.splice(t,1);var s=(new Date).getTime();for(i=[],t=0;t0&&(n="conflict"),this._conn._changeConnectStatus(t.Status.CONNFAIL,n)):this._conn._changeConnectStatus(t.Status.CONNFAIL,"unknown"),this._conn._doDisconnect(n),t.Status.CONNFAIL;this.sid||(this.sid=e.getAttribute("sid"));var r=e.getAttribute("requests");r&&(this.window=parseInt(r,10));var o=e.getAttribute("hold");o&&(this.hold=parseInt(o,10));var a=e.getAttribute("wait");a&&(this.wait=parseInt(a,10));var h=e.getAttribute("inactivity");h&&(this.inactivity=parseInt(h,10))},_disconnect:function(t){this._sendTerminate(t)},_doDisconnect:function(){this.sid=null,this.rid=Math.floor(4294967295*Math.random()),this._conn._sessionCachingSupported()&&window.sessionStorage.removeItem("strophe-bosh-session"),this._conn.nextValidRid(this.rid)},_emptyQueue:function(){return 0===this._requests.length},_callProtocolErrorHandlers:function(t){var e,n=this._getRequestStatus(t);e=this._conn.protocolErrorHandlers.HTTP[n],e&&e.call(this,n)},_hitError:function(e){this.errors++,t.warn("request errored, status: "+e+", number of errors: "+this.errors),this.errors>4&&this._conn._onDisconnectTimeout()},_no_auth_received:function(e){e=e?e.bind(this._conn):this._conn._connect_cb.bind(this._conn);var n=this._buildBody();this._requests.push(new t.Request(n.tree(),this._onRequestStateChange.bind(this,e.bind(this._conn)),n.tree().getAttribute("rid"))),this._throttledRequestHandler()},_onDisconnectTimeout:function(){this._abortAllRequests()},_abortAllRequests:function(){for(var t;this._requests.length>0;)t=this._requests.pop(),t.abort=!0,t.xhr.abort(),t.xhr.onreadystatechange=function(){}},_onIdle:function(){var e=this._conn._data;if(this._conn.authenticated&&0===this._requests.length&&0===e.length&&!this._conn.disconnecting&&(t.info("no requests during idle cycle, sending blank request"),e.push(null)),!this._conn.paused){if(this._requests.length<2&&e.length>0){for(var n=this._buildBody(),i=0;i0){var s=this._requests[0].age();null!==this._requests[0].dead&&this._requests[0].timeDead()>Math.floor(t.SECONDARY_TIMEOUT*this.wait)&&this._throttledRequestHandler(),s>Math.floor(t.TIMEOUT*this.wait)&&(t.warn("Request "+this._requests[0].id+" timed out, over "+Math.floor(t.TIMEOUT*this.wait)+" seconds since last activity"),this._throttledRequestHandler())}}},_getRequestStatus:function(e,n){var i;if(4===e.xhr.readyState)try{i=e.xhr.status}catch(e){t.error("Caught an error while retrieving a request's status, reqStatus: "+i)}return"undefined"==typeof i&&(i="number"==typeof n?n:0),i},_onRequestStateChange:function(e,n){if(t.debug("request id "+n.id+"."+n.sends+" state changed to "+n.xhr.readyState),n.abort)return void(n.abort=!1);if(4===n.xhr.readyState){var i=this._getRequestStatus(n);if(this.disconnecting&&i>=400)return this._hitError(i),void this._callProtocolErrorHandlers(n);if((i>0&&i<500||n.sends>5)&&(this._removeRequest(n),t.debug("request id "+n.id+" should now be removed")),200===i){var s=this._requests[0]===n,r=this._requests[1]===n;(r||s&&this._requests.length>0&&this._requests[0].age()>Math.floor(t.SECONDARY_TIMEOUT*this.wait))&&this._restartRequest(0),this._conn.nextValidRid(Number(n.rid)+1),t.debug("request id "+n.id+"."+n.sends+" got 200"),e(n),this.errors=0}else 0===i||i>=400&&i<600||i>=12e3?(t.error("request id "+n.id+"."+n.sends+" error "+i+" happened"),this._hitError(i),this._callProtocolErrorHandlers(n),i>=400&&i<500&&(this._conn._changeConnectStatus(t.Status.DISCONNECTING,null),this._conn._doDisconnect())):t.error("request id "+n.id+"."+n.sends+" error "+i+" happened");i>0&&i<500&&!(n.sends>5)||this._throttledRequestHandler()}},_processRequest:function(e){var n=this,i=this._requests[e],s=this._getRequestStatus(i,-1);if(i.sends>this._conn.maxRetries)return void this._conn._onDisconnectTimeout();var r=i.age(),o=!isNaN(r)&&r>Math.floor(t.TIMEOUT*this.wait),a=null!==i.dead&&i.timeDead()>Math.floor(t.SECONDARY_TIMEOUT*this.wait),h=4===i.xhr.readyState&&(s<1||s>=500);if((o||a||h)&&(a&&t.error("Request "+this._requests[e].id+" timed out (secondary), restarting"),i.abort=!0,i.xhr.abort(),i.xhr.onreadystatechange=function(){},this._requests[e]=new t.Request(i.xmlData,i.origFunc,i.rid,i.sends),i=this._requests[e]),0===i.xhr.readyState){t.debug("request id "+i.id+"."+i.sends+" posting");try{var c=this._conn.options.contentType||"text/xml; charset=utf-8";i.xhr.open("POST",this._conn.service,!this._conn.options.sync),"undefined"!=typeof i.xhr.setRequestHeader&&i.xhr.setRequestHeader("Content-Type",c),this._conn.options.withCredentials&&(i.xhr.withCredentials=!0)}catch(e){return t.error("XHR open failed."),this._conn.connected||this._conn._changeConnectStatus(t.Status.CONNFAIL,"bad-service"),void this._conn.disconnect()}var u=function(){if(i.date=new Date,n._conn.options.customHeaders){var t=n._conn.options.customHeaders;for(var e in t)t.hasOwnProperty(e)&&i.xhr.setRequestHeader(e,t[e])}i.xhr.send(i.data)};if(i.sends>1){var l=1e3*Math.min(Math.floor(t.TIMEOUT*this.wait),Math.pow(i.sends,3));setTimeout(function(){u()},l)}else u();i.sends++,this._conn.xmlOutput!==t.Connection.prototype.xmlOutput&&(i.xmlData.nodeName===this.strip&&i.xmlData.childNodes.length?this._conn.xmlOutput(i.xmlData.childNodes[0]):this._conn.xmlOutput(i.xmlData)),this._conn.rawOutput!==t.Connection.prototype.rawOutput&&this._conn.rawOutput(i.data)}else t.debug("_processRequest: "+(0===e?"first":"second")+" request has readyState of "+i.xhr.readyState)},_removeRequest:function(e){t.debug("removing request");var n;for(n=this._requests.length-1;n>=0;n--)e===this._requests[n]&&this._requests.splice(n,1);e.xhr.onreadystatechange=function(){},this._throttledRequestHandler()},_restartRequest:function(t){var e=this._requests[t];null===e.dead&&(e.dead=new Date),this._processRequest(t)},_reqToData:function(t){try{return t.getResponse()}catch(t){if("parsererror"!==t)throw t;this._conn.disconnect("strophe-parsererror")}},_sendTerminate:function(e){t.info("_sendTerminate was called");var n=this._buildBody().attrs({type:"terminate"});e&&n.cnode(e.tree());var i=new t.Request(n.tree(),this._onRequestStateChange.bind(this,this._conn._dataRecv.bind(this._conn)),n.tree().getAttribute("rid"));this._requests.push(i),this._throttledRequestHandler()},_send:function(){clearTimeout(this._conn._idleTimeout),this._throttledRequestHandler(),this._conn._idleTimeout=setTimeout(function(){this._onIdle()}.bind(this._conn),100)},_sendRestart:function(){this._throttledRequestHandler(),clearTimeout(this._conn._idleTimeout)},_throttledRequestHandler:function(){this._requests?t.debug("_throttledRequestHandler called with "+this._requests.length+" requests"):t.debug("_throttledRequestHandler called with undefined requests"),this._requests&&0!==this._requests.length&&(this._requests.length>0&&this._processRequest(0),this._requests.length>1&&Math.abs(this._requests[0].rid-this._requests[1].rid): "+i);var s=e.getAttribute("version");return"string"!=typeof s?n="Missing version in ":"1.0"!==s&&(n="Wrong version in : "+s),!n||(this._conn._changeConnectStatus(t.Status.CONNFAIL,n),this._conn._doDisconnect(),!1)},_connect_cb_wrapper:function(e){if(0===e.data.indexOf("\s*)*/,"");if(""===n)return;var i=(new DOMParser).parseFromString(n,"text/xml").documentElement;this._conn.xmlInput(i),this._conn.rawInput(e.data),this._handleStreamStart(i)&&this._connect_cb(i)}else if(0===e.data.indexOf(" tag.")}}this._conn._doDisconnect()},_doDisconnect:function(){t.info("WebSockets _doDisconnect was called"),this._closeSocket()},_streamWrap:function(t){return""+t+""},_closeSocket:function(){if(this.socket)try{this.socket.close()}catch(t){}this.socket=null},_emptyQueue:function(){return!0},_onClose:function(){this._conn.connected&&!this._conn.disconnecting?(t.error("Websocket closed unexpectedly"),this._conn._doDisconnect()):t.info("Websocket closed")},_no_auth_received:function(e){t.error("Server did not send any auth methods"),this._conn._changeConnectStatus(t.Status.CONNFAIL,"Server did not send any auth methods"),e&&(e=e.bind(this._conn))(),this._conn._doDisconnect()},_onDisconnectTimeout:function(){},_abortAllRequests:function(){},_onError:function(e){t.error("Websocket error "+e),this._conn._changeConnectStatus(t.Status.CONNFAIL,"The WebSocket connection could not be established or was disconnected."),this._disconnect()},_onIdle:function(){var e=this._conn._data;if(e.length>0&&!this._conn.paused){for(var n=0;n0&&(t.splice(u-1,2),u-=2)}t=t.join("/")}if((f||m)&&p){for(n=t.split("/"),u=n.length;u>0;u-=1){if(i=n.slice(0,u).join("/"),f)for(l=f.length;l>0;l-=1)if(s=p[f.slice(0,l).join("/")],s&&(s=s[i])){r=s,a=u;break}if(r)break;!h&&m&&m[i]&&(h=m[i],c=u)}!r&&h&&(r=h,a=c),r&&(n.splice(0,a,r),t=n.join("/"))}return t}function o(t,e){return function(){var n=T.call(arguments,0);return"string"!=typeof n[0]&&1===n.length&&n.push(null),f.apply(i,n.concat([t,e]))}}function a(t){return function(e){return r(e,t)}}function h(t){return function(e){g[t]=e}}function c(t){if(s(S,t)){var e=S[t];delete S[t],y[t]=!0,_.apply(i,e)}if(!s(g,t)&&!s(y,t))throw new Error("No "+t);return g[t]}function u(t){var e,n=t?t.indexOf("!"):-1;return n>-1&&(e=t.substring(0,n),t=t.substring(n+1,t.length)),[e,t]}function l(t){return t?u(t):[]}function d(t){return function(){return b&&b.config&&b.config[t]||{}}}var _,f,p,m,g={},S={},b={},y={},v=Object.prototype.hasOwnProperty,T=[].slice,x=/\.js$/;p=function(t,e){var n,i=u(t),s=i[0],o=e[1];return t=i[1],s&&(s=r(s,o),n=c(s)),s?t=n&&n.normalize?n.normalize(t,a(o)):r(t,o):(t=r(t,o),i=u(t),s=i[0],t=i[1],s&&(n=c(s))),{f:s?s+"!"+t:t,n:t,pr:s,p:n}},m={require:function(t){return o(t)},exports:function(t){var e=g[t];return"undefined"!=typeof e?e:g[t]={}},module:function(t){return{id:t,uri:"",exports:g[t],config:d(t)}}},_=function(t,e,n,r){var a,u,d,_,f,b,v,T=[],x=typeof n;if(r=r||t,b=l(r),"undefined"===x||"function"===x){for(e=!e.length&&n.length?["require","exports","module"]:e,f=0;f>>0;if("function"!=typeof t)throw new TypeError(t+" is not a function");for(arguments.length>1&&(n=e),i=0;i>2,o=(3&n)<<4|i>>4,a=(15&i)<<2|s>>6,h=63&s,isNaN(i)?(o=(3&n)<<4,a=h=64):isNaN(s)&&(h=64),c=c+e.charAt(r)+e.charAt(o)+e.charAt(a)+e.charAt(h);while(u>4,i=(15&o)<<4|a>>2,s=(3&a)<<6|h,c+=String.fromCharCode(n),64!==a&&(c+=String.fromCharCode(i)),64!==h&&(c+=String.fromCharCode(s));while(u>5]|=128<<24-i%32,t[(i+64>>9<<4)+15]=i;var o,a,h,c,u,l,d,_,f=new Array(80),p=1732584193,m=-271733879,g=-1732584194,S=271733878,b=-1009589776;for(o=0;o16&&(i=t(i,8*e.length));for(var s=new Array(16),r=new Array(16),a=0;a<16;a++)s[a]=909522486^i[a],r[a]=1549556828^i[a];var h=t(s.concat(o(n)),512+8*n.length);return t(r.concat(h),672)}function s(t,e){var n=(65535&t)+(65535&e),i=(t>>16)+(e>>16)+(n>>16);return i<<16|65535&n}function r(t,e){return t<>>32-e}function o(t){for(var e=[],n=255,i=0;i<8*t.length;i+=8)e[i>>5]|=(t.charCodeAt(i/8)&n)<<24-i%32;return e}function a(t){for(var e="",n=255,i=0;i<32*t.length;i+=8)e+=String.fromCharCode(t[i>>5]>>>24-i%32&n);return e}function h(t){for(var e,n,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s="",r=0;r<4*t.length;r+=3)for(e=(t[r>>2]>>8*(3-r%4)&255)<<16|(t[r+1>>2]>>8*(3-(r+1)%4)&255)<<8|t[r+2>>2]>>8*(3-(r+2)%4)&255,n=0;n<4;n++)s+=8*r+6*n>32*t.length?"=":i.charAt(e>>6*(3-n)&63);return s}return{b64_hmac_sha1:function(t,e){return h(i(t,e))},b64_sha1:function(e){return h(t(o(e),8*e.length))},binb2str:a,core_hmac_sha1:i,str_hmac_sha1:function(t,e){return a(i(t,e))},str_sha1:function(e){return a(t(o(e),8*e.length))}}}),function(t,e){"function"==typeof n&&n.amd?n("strophe-md5",[],function(){return e()}):t.MD5=e()}(this,function(){var t=function(t,e){var n=(65535&t)+(65535&e),i=(t>>16)+(e>>16)+(n>>16);return i<<16|65535&n},e=function(t,e){return t<>>32-e},n=function(t){for(var e=[],n=0;n<8*t.length;n+=8)e[n>>5]|=(255&t.charCodeAt(n/8))<>5]>>>n%32&255);return e},s=function(t){for(var e="0123456789abcdef",n="",i=0;i<4*t.length;i++)n+=e.charAt(t[i>>2]>>i%4*8+4&15)+e.charAt(t[i>>2]>>i%4*8&15);return n},r=function(n,i,s,r,o,a){return t(e(t(t(i,n),t(r,a)),o),s)},o=function(t,e,n,i,s,o,a){return r(e&n|~e&i,t,e,s,o,a)},a=function(t,e,n,i,s,o,a){return r(e&i|n&~i,t,e,s,o,a)},h=function(t,e,n,i,s,o,a){return r(e^n^i,t,e,s,o,a)},c=function(t,e,n,i,s,o,a){return r(n^(e|~i),t,e,s,o,a)},u=function(e,n){e[n>>5]|=128<>>9<<4)+14]=n;for(var i,s,r,u,l=1732584193,d=-271733879,_=-1732584194,f=271733878,p=0;p=0&&n<=127?i+=t.charAt(e):n>2047?(i+=String.fromCharCode(224|n>>12&15),i+=String.fromCharCode(128|n>>6&63),i+=String.fromCharCode(128|n>>0&63)):(i+=String.fromCharCode(192|n>>6&31),i+=String.fromCharCode(128|n>>0&63));return i},addCookies:function(t){var e,n,i,s,r,o,a;for(e in t||{})r="",o="",a="",n=t[e],i="object"==typeof n,s=escape(unescape(i?n.value:n)),i&&(r=n.expires?";expires="+n.expires:"",o=n.domain?";domain="+n.domain:"",a=n.path?";path="+n.path:""),document.cookie=e+"="+s+r+o+a}};return t}),function(t,e){if("function"==typeof n&&n.amd)n("strophe-core",["strophe-sha1","strophe-md5","strophe-utils"],function(){return e.apply(this,arguments)});else{var i=e(t.SHA1,t.MD5,t.stropheUtils);t.Strophe=i.Strophe,t.$build=i.$build,t.$iq=i.$iq,t.$msg=i.$msg,t.$pres=i.$pres,t.SHA1=i.SHA1,t.MD5=i.MD5,t.b64_hmac_sha1=i.SHA1.b64_hmac_sha1,t.b64_sha1=i.SHA1.b64_sha1,t.str_hmac_sha1=i.SHA1.str_hmac_sha1,t.str_sha1=i.SHA1.str_sha1}}(this,function(t,e,n){function i(t,e){return new a.Builder(t,e)}function s(t){return new a.Builder("message",t)}function r(t){return new a.Builder("iq",t)}function o(t){return new a.Builder("presence",t)}var a;return a={VERSION:"1.2.14",NS:{HTTPBIND:"http://jabber.org/protocol/httpbind",BOSH:"urn:xmpp:xbosh",CLIENT:"jabber:client",AUTH:"jabber:iq:auth",ROSTER:"jabber:iq:roster",PROFILE:"jabber:iq:profile",DISCO_INFO:"http://jabber.org/protocol/disco#info",DISCO_ITEMS:"http://jabber.org/protocol/disco#items",MUC:"http://jabber.org/protocol/muc",SASL:"urn:ietf:params:xml:ns:xmpp-sasl",STREAM:"http://etherx.jabber.org/streams",FRAMING:"urn:ietf:params:xml:ns:xmpp-framing",BIND:"urn:ietf:params:xml:ns:xmpp-bind",SESSION:"urn:ietf:params:xml:ns:xmpp-session",VERSION:"jabber:iq:version",STANZAS:"urn:ietf:params:xml:ns:xmpp-stanzas",XHTML_IM:"http://jabber.org/protocol/xhtml-im",XHTML:"http://www.w3.org/1999/xhtml"},XHTML:{tags:["a","blockquote","br","cite","em","img","li","ol","p","span","strong","ul","body"],attributes:{a:["href"],blockquote:["style"],br:[],cite:["style"],em:[],img:["src","alt","style","height","width"],li:["style"],ol:["style"],p:["style"],span:["style"],strong:[],ul:["style"],body:[]},css:["background-color","color","font-family","font-size","font-style","font-weight","margin-left","margin-right","text-align","text-decoration"],validTag:function(t){for(var e=0;e0)for(var n=0;n/g,">"),t=t.replace(/'/g,"'"),t=t.replace(/"/g,""")},xmlunescape:function(t){return t=t.replace(/\&/g,"&"),t=t.replace(/</g,"<"),t=t.replace(/>/g,">"),t=t.replace(/'/g,"'"),t=t.replace(/"/g,'"')},xmlTextNode:function(t){return a.xmlGenerator().createTextNode(t)},xmlHtmlNode:function(t){var e;if(DOMParser){var n=new DOMParser;e=n.parseFromString(t,"text/xml")}else e=new ActiveXObject("Microsoft.XMLDOM"),e.async="false",e.loadXML(t);return e},getText:function(t){if(!t)return null;var e="";0===t.childNodes.length&&t.nodeType===a.ElementType.TEXT&&(e+=t.nodeValue);for(var n=0;n0&&(o=h.join("; "),n.setAttribute(r,o))}else n.setAttribute(r,o);for(e=0;e/g,"\\3e").replace(/@/g,"\\40")},unescapeNode:function(t){return"string"!=typeof t?t:t.replace(/\\20/g," ").replace(/\\22/g,'"').replace(/\\26/g,"&").replace(/\\27/g,"'").replace(/\\2f/g,"/").replace(/\\3a/g,":").replace(/\\3c/g,"<").replace(/\\3e/g,">").replace(/\\40/g,"@").replace(/\\5c/g,"\\")},getNodeFromJid:function(t){return t.indexOf("@")<0?null:t.split("@")[0]},getDomainFromJid:function(t){var e=a.getBareJidFromJid(t);if(e.indexOf("@")<0)return e;var n=e.split("@");return n.splice(0,1),n.join("@")},getResourceFromJid:function(t){var e=t.split("/");return e.length<2?null:(e.splice(0,1),e.join("/"))},getBareJidFromJid:function(t){return t?t.split("/")[0]:null},_handleError:function(t){"undefined"!=typeof t.stack&&a.fatal(t.stack),t.sourceURL?a.fatal("error: "+this.handler+" "+t.sourceURL+":"+t.line+" - "+t.name+": "+t.message):t.fileName?a.fatal("error: "+this.handler+" "+t.fileName+":"+t.lineNumber+" - "+t.name+": "+t.message):a.fatal("error: "+t.message)},log:function(t,e){},debug:function(t){this.log(this.LogLevel.DEBUG,t)},info:function(t){this.log(this.LogLevel.INFO,t)},warn:function(t){this.log(this.LogLevel.WARN,t)},error:function(t){this.log(this.LogLevel.ERROR,t)},fatal:function(t){this.log(this.LogLevel.FATAL,t)},serialize:function(t){var e;if(!t)return null;"function"==typeof t.tree&&(t=t.tree());var n,i,s=t.nodeName;for(t.getAttribute("_realname")&&(s=t.getAttribute("_realname")),e="<"+s,n=0;n0){for(e+=">",n=0;n"}e+=""}else e+="/>";return e},_requestId:0,_connectionPlugins:{},addConnectionPlugin:function(t,e){a._connectionPlugins[t]=e}},a.Builder=function(t,e){"presence"!==t&&"message"!==t&&"iq"!==t||(e&&!e.xmlns?e.xmlns=a.NS.CLIENT:e||(e={xmlns:a.NS.CLIENT})),this.nodeTree=a.xmlElement(t,e),this.node=this.nodeTree},a.Builder.prototype={tree:function(){return this.nodeTree},toString:function(){return a.serialize(this.nodeTree)},up:function(){return this.node=this.node.parentNode,this},root:function(){return this.node=this.nodeTree,this},attrs:function(t){for(var e in t)t.hasOwnProperty(e)&&(void 0===t[e]?this.node.removeAttribute(e):this.node.setAttribute(e,t[e]));return this},c:function(t,e,n){var i=a.xmlElement(t,e,n);return this.node.appendChild(i),"string"!=typeof n&&"number"!=typeof n&&(this.node=i),this},cnode:function(t){var e,n=a.xmlGenerator();try{e=void 0!==n.importNode}catch(t){e=!1}var i=e?n.importNode(t,!0):a.copyElement(t);return this.node.appendChild(i),this.node=i,this},t:function(t){var e=a.xmlTextNode(t);return this.node.appendChild(e),this},h:function(t){var e=document.createElement("body");e.innerHTML=t;for(var n=a.createHtml(e);n.childNodes.length>0;)this.node.appendChild(n.childNodes[0]);return this}},a.Handler=function(t,e,n,i,s,r,o){this.handler=t,this.ns=e,this.name=n,this.type=i,this.id=s,this.options=o||{matchBareFromJid:!1,ignoreNamespaceFragment:!1},this.options.matchBare&&(a.warn('The "matchBare" option is deprecated, use "matchBareFromJid" instead.'),this.options.matchBareFromJid=this.options.matchBare,delete this.options.matchBare),this.options.matchBareFromJid?this.from=r?a.getBareJidFromJid(r):null:this.from=r,this.user=!0},a.Handler.prototype={getNamespace:function(t){var e=t.getAttribute("xmlns");return e&&this.options.ignoreNamespaceFragment&&(e=e.split("#")[0]),e},namespaceMatch:function(t){var e=!1;if(!this.ns)return!0;var n=this;return a.forEachChild(t,null,function(t){n.getNamespace(t)===n.ns&&(e=!0)}),e=e||this.getNamespace(t)===this.ns},isMatch:function(t){var e=t.getAttribute("from");this.options.matchBareFromJid&&(e=a.getBareJidFromJid(e));var n=t.getAttribute("type");return!(!this.namespaceMatch(t)||this.name&&!a.isTagEqual(t,this.name)||this.type&&(Array.isArray(this.type)?this.type.indexOf(n)===-1:n!==this.type)||this.id&&t.getAttribute("id")!==this.id||this.from&&e!==this.from)},run:function(t){var e=null;try{e=this.handler(t)}catch(t){throw a._handleError(t),t}return e},toString:function(){return"{Handler: "+this.handler+"("+this.name+","+this.id+","+this.ns+")}"}},a.TimedHandler=function(t,e){this.period=t,this.handler=e,this.lastCalled=(new Date).getTime(),this.user=!0},a.TimedHandler.prototype={run:function(){return this.lastCalled=(new Date).getTime(),this.handler()},reset:function(){this.lastCalled=(new Date).getTime()},toString:function(){return"{TimedHandler: "+this.handler+"("+this.period+")}"}},a.Connection=function(t,e){this.service=t,this.options=e||{};var i=this.options.protocol||"";0===t.indexOf("ws:")||0===t.indexOf("wss:")||0===i.indexOf("ws")?this._proto=new a.Websocket(this):this._proto=new a.Bosh(this),this.jid="",this.domain=null,this.features=null,this._sasl_data={},this.do_session=!1,this.do_bind=!1,this.timedHandlers=[],this.handlers=[],this.removeTimeds=[],this.removeHandlers=[],this.addTimeds=[],this.addHandlers=[],this.protocolErrorHandlers={HTTP:{},websocket:{}},this._idleTimeout=null,this._disconnectTimeout=null,this.authenticated=!1,this.connected=!1,this.disconnecting=!1,this.do_authentication=!0,this.paused=!1,this.restored=!1,this._data=[],this._uniqueId=0,this._sasl_success_handler=null,this._sasl_failure_handler=null,this._sasl_challenge_handler=null,this.maxRetries=5,this._idleTimeout=setTimeout(function(){this._onIdle()}.bind(this),100),n.addCookies(this.options.cookies),this.registerSASLMechanisms(this.options.mechanisms);for(var s in a._connectionPlugins)if(a._connectionPlugins.hasOwnProperty(s)){var r=a._connectionPlugins[s],o=function(){};o.prototype=r,this[s]=new o,this[s].init(this)}},a.Connection.prototype={reset:function(){this._proto._reset(),this.do_session=!1,this.do_bind=!1,this.timedHandlers=[],this.handlers=[],this.removeTimeds=[],this.removeHandlers=[],this.addTimeds=[],this.addHandlers=[],this.authenticated=!1,this.connected=!1,this.disconnecting=!1,this.restored=!1,this._data=[],this._requests=[],this._uniqueId=0},pause:function(){this.paused=!0},resume:function(){this.paused=!1},getUniqueId:function(t){var e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=16*Math.random()|0,n="x"===t?e:3&e|8;return n.toString(16)});return"string"==typeof t||"number"==typeof t?e+":"+t:e+""},addProtocolErrorHandler:function(t,e,n){this.protocolErrorHandlers[t][e]=n},connect:function(t,e,n,i,s,r,o){this.jid=t,this.authzid=a.getBareJidFromJid(this.jid),this.authcid=o||a.getNodeFromJid(this.jid),this.pass=e,this.servtype="xmpp",this.connect_callback=n,this.disconnecting=!1,this.connected=!1,this.authenticated=!1,this.restored=!1,this.domain=a.getDomainFromJid(this.jid),this._changeConnectStatus(a.Status.CONNECTING,null),this._proto._connect(i,s,r)},attach:function(t,e,n,i,s,r,o){if(!(this._proto instanceof a.Bosh))throw{name:"StropheSessionError",message:'The "attach" method can only be used with a BOSH connection.'};this._proto._attach(t,e,n,i,s,r,o)},restore:function(t,e,n,i,s){if(!this._sessionCachingSupported())throw{name:"StropheSessionError",message:'The "restore" method can only be used with a BOSH connection.'};this._proto._restore(t,e,n,i,s)},_sessionCachingSupported:function(){if(this._proto instanceof a.Bosh){if(!JSON)return!1;try{sessionStorage.setItem("_strophe_","_strophe_"),sessionStorage.removeItem("_strophe_")}catch(t){return!1}return!0}return!1},xmlInput:function(t){},xmlOutput:function(t){},rawInput:function(t){},rawOutput:function(t){},nextValidRid:function(t){},send:function(t){if(null!==t){if("function"==typeof t.sort)for(var e=0;e=0&&this.addHandlers.splice(e,1)},registerSASLMechanisms:function(t){this.mechanisms={},t=t||[a.SASLAnonymous,a.SASLExternal,a.SASLMD5,a.SASLOAuthBearer,a.SASLPlain,a.SASLSHA1],t.forEach(this.registerSASLMechanism.bind(this))},registerSASLMechanism:function(t){this.mechanisms[t.prototype.name]=t},disconnect:function(t){if(this._changeConnectStatus(a.Status.DISCONNECTING,t),a.info("Disconnect was called because: "+t),this.connected){var e=!1;this.disconnecting=!0,this.authenticated&&(e=o({xmlns:a.NS.CLIENT,type:"unavailable"})),this._disconnectTimeout=this._addSysTimedHandler(3e3,this._onDisconnectTimeout.bind(this)),this._proto._disconnect(e)}else a.info("Disconnect was called before Strophe connected to the server"),this._proto._abortAllRequests(),this._doDisconnect()},_changeConnectStatus:function(t,e){for(var n in a._connectionPlugins)if(a._connectionPlugins.hasOwnProperty(n)){var i=this[n];if(i.statusChanged)try{i.statusChanged(t,e)}catch(t){a.error(""+n+" plugin caused an exception changing status: "+t)}}if(this.connect_callback)try{this.connect_callback(t,e)}catch(t){a._handleError(t),a.error("User connection callback caused an exception: "+t)}},_doDisconnect:function(t){"number"==typeof this._idleTimeout&&clearTimeout(this._idleTimeout),null!==this._disconnectTimeout&&(this.deleteTimedHandler(this._disconnectTimeout),this._disconnectTimeout=null),a.info("_doDisconnect was called"),this._proto._doDisconnect(),this.authenticated=!1,this.disconnecting=!1,this.restored=!1,this.handlers=[],this.timedHandlers=[],this.removeTimeds=[],this.removeHandlers=[],this.addTimeds=[],this.addHandlers=[],this._changeConnectStatus(a.Status.DISCONNECTED,t),this.connected=!1},_dataRecv:function(t,e){a.info("_dataRecv called");var n=this._proto._reqToData(t);if(null!==n){this.xmlInput!==a.Connection.prototype.xmlInput&&(n.nodeName===this._proto.strip&&n.childNodes.length?this.xmlInput(n.childNodes[0]):this.xmlInput(n)),this.rawInput!==a.Connection.prototype.rawInput&&(e?this.rawInput(e):this.rawInput(a.serialize(n)));for(var i,s;this.removeHandlers.length>0;)s=this.removeHandlers.pop(),i=this.handlers.indexOf(s),i>=0&&this.handlers.splice(i,1);for(;this.addHandlers.length>0;)this.handlers.push(this.addHandlers.pop());if(this.disconnecting&&this._proto._emptyQueue())return void this._doDisconnect();var r,o,h=n.getAttribute("type");if(null!==h&&"terminate"===h){if(this.disconnecting)return;return r=n.getAttribute("condition"),o=n.getElementsByTagName("conflict"),null!==r?("remote-stream-error"===r&&o.length>0&&(r="conflict"),this._changeConnectStatus(a.Status.CONNFAIL,r)):this._changeConnectStatus(a.Status.CONNFAIL,"unknown"),void this._doDisconnect(r)}var c=this;a.forEachChild(n,null,function(t){var e,n;for(n=c.handlers,c.handlers=[],e=0;e0:i.getElementsByTagName("stream:features").length>0||i.getElementsByTagName("features").length>0,!r)return void this._proto._no_auth_received(e);var o,h,c=[],u=i.getElementsByTagName("mechanism");if(u.length>0)for(o=0;ot[i].prototype.priority&&(i=n);i!==e&&(s=t[e],t[e]=t[i],t[i]=s)}return t},_attemptSASLAuth:function(t){t=this.sortMechanismsByPriority(t||[]);var e=0,n=!1;for(e=0;e0&&(e="conflict"),this._changeConnectStatus(a.Status.AUTHFAIL,e),!1}var i,s=t.getElementsByTagName("bind");return s.length>0?(i=s[0].getElementsByTagName("jid"),void(i.length>0&&(this.jid=a.getText(i[0]),this.do_session?(this._addSysHandler(this._sasl_session_cb.bind(this),null,null,null,"_session_auth_2"),this.send(r({type:"set",id:"_session_auth_2"}).c("session",{xmlns:a.NS.SESSION}).tree())):(this.authenticated=!0,this._changeConnectStatus(a.Status.CONNECTED,null))))):(a.info("SASL binding failed."),this._changeConnectStatus(a.Status.AUTHFAIL,null),!1)},_sasl_session_cb:function(t){if("result"===t.getAttribute("type"))this.authenticated=!0,this._changeConnectStatus(a.Status.CONNECTED,null);else if("error"===t.getAttribute("type"))return a.info("Session creation failed."),this._changeConnectStatus(a.Status.AUTHFAIL,null),!1;return!1},_sasl_failure_cb:function(t){return this._sasl_success_handler&&(this.deleteHandler(this._sasl_success_handler),this._sasl_success_handler=null),this._sasl_challenge_handler&&(this.deleteHandler(this._sasl_challenge_handler),this._sasl_challenge_handler=null),this._sasl_mechanism&&this._sasl_mechanism.onFailure(),this._changeConnectStatus(a.Status.AUTHFAIL,null),!1},_auth2_cb:function(t){return"result"===t.getAttribute("type")?(this.authenticated=!0,this._changeConnectStatus(a.Status.CONNECTED,null)):"error"===t.getAttribute("type")&&(this._changeConnectStatus(a.Status.AUTHFAIL,null),this.disconnect("authentication failed")),!1},_addSysTimedHandler:function(t,e){var n=new a.TimedHandler(t,e);return n.user=!1,this.addTimeds.push(n),n},_addSysHandler:function(t,e,n,i,s){var r=new a.Handler(t,e,n,i,s);return r.user=!1,this.addHandlers.push(r),r},_onDisconnectTimeout:function(){return a.info("_onDisconnectTimeout was called"),this._changeConnectStatus(a.Status.CONNTIMEOUT,null),this._proto._onDisconnectTimeout(),this._doDisconnect(),!1},_onIdle:function(){for(var t,e,n,i;this.addTimeds.length>0;)this.timedHandlers.push(this.addTimeds.pop());for(;this.removeTimeds.length>0;)e=this.removeTimeds.pop(),t=this.timedHandlers.indexOf(e),t>=0&&this.timedHandlers.splice(t,1);var s=(new Date).getTime();for(i=[],t=0;t0&&(n="conflict"),this._conn._changeConnectStatus(t.Status.CONNFAIL,n)):this._conn._changeConnectStatus(t.Status.CONNFAIL,"unknown"),this._conn._doDisconnect(n),t.Status.CONNFAIL;this.sid||(this.sid=e.getAttribute("sid"));var r=e.getAttribute("requests");r&&(this.window=parseInt(r,10));var o=e.getAttribute("hold");o&&(this.hold=parseInt(o,10));var a=e.getAttribute("wait");a&&(this.wait=parseInt(a,10));var h=e.getAttribute("inactivity");h&&(this.inactivity=parseInt(h,10))},_disconnect:function(t){this._sendTerminate(t)},_doDisconnect:function(){this.sid=null,this.rid=Math.floor(4294967295*Math.random()),this._conn._sessionCachingSupported()&&window.sessionStorage.removeItem("strophe-bosh-session"),this._conn.nextValidRid(this.rid)},_emptyQueue:function(){return 0===this._requests.length},_callProtocolErrorHandlers:function(t){var e,n=this._getRequestStatus(t);e=this._conn.protocolErrorHandlers.HTTP[n],e&&e.call(this,n)},_hitError:function(e){this.errors++,t.warn("request errored, status: "+e+", number of errors: "+this.errors),this.errors>4&&this._conn._onDisconnectTimeout()},_no_auth_received:function(e){e=e?e.bind(this._conn):this._conn._connect_cb.bind(this._conn);var n=this._buildBody();this._requests.push(new t.Request(n.tree(),this._onRequestStateChange.bind(this,e.bind(this._conn)),n.tree().getAttribute("rid"))),this._throttledRequestHandler()},_onDisconnectTimeout:function(){this._abortAllRequests()},_abortAllRequests:function(){for(var t;this._requests.length>0;)t=this._requests.pop(),t.abort=!0,t.xhr.abort(),t.xhr.onreadystatechange=function(){}},_onIdle:function(){var e=this._conn._data;if(this._conn.authenticated&&0===this._requests.length&&0===e.length&&!this._conn.disconnecting&&(t.info("no requests during idle cycle, sending blank request"),e.push(null)),!this._conn.paused){if(this._requests.length<2&&e.length>0){for(var n=this._buildBody(),i=0;i0){var s=this._requests[0].age();null!==this._requests[0].dead&&this._requests[0].timeDead()>Math.floor(t.SECONDARY_TIMEOUT*this.wait)&&this._throttledRequestHandler(),s>Math.floor(t.TIMEOUT*this.wait)&&(t.warn("Request "+this._requests[0].id+" timed out, over "+Math.floor(t.TIMEOUT*this.wait)+" seconds since last activity"),this._throttledRequestHandler())}}},_getRequestStatus:function(e,n){var i;if(4===e.xhr.readyState)try{i=e.xhr.status}catch(e){t.error("Caught an error while retrieving a request's status, reqStatus: "+i)}return"undefined"==typeof i&&(i="number"==typeof n?n:0),i},_onRequestStateChange:function(e,n){if(t.debug("request id "+n.id+"."+n.sends+" state changed to "+n.xhr.readyState),n.abort)return void(n.abort=!1);if(4===n.xhr.readyState){var i=this._getRequestStatus(n);if(this.disconnecting&&i>=400)return this._hitError(i),void this._callProtocolErrorHandlers(n);var s=i>0&&i<500,r=n.sends>this._conn.maxRetries;if((s||r)&&(this._removeRequest(n),t.debug("request id "+n.id+" should now be removed")),200===i){var o=this._requests[0]===n,a=this._requests[1]===n;(a||o&&this._requests.length>0&&this._requests[0].age()>Math.floor(t.SECONDARY_TIMEOUT*this.wait))&&this._restartRequest(0),this._conn.nextValidRid(Number(n.rid)+1),t.debug("request id "+n.id+"."+n.sends+" got 200"),e(n),this.errors=0}else 0===i||i>=400&&i<600||i>=12e3?(t.error("request id "+n.id+"."+n.sends+" error "+i+" happened"),this._hitError(i),this._callProtocolErrorHandlers(n),i>=400&&i<500&&(this._conn._changeConnectStatus(t.Status.DISCONNECTING,null),this._conn._doDisconnect())):t.error("request id "+n.id+"."+n.sends+" error "+i+" happened");s||r?r&&!this._conn.connected&&this._conn._changeConnectStatus(t.Status.CONNFAIL,"giving-up"):this._throttledRequestHandler()}},_processRequest:function(e){var n=this,i=this._requests[e],s=this._getRequestStatus(i,-1);if(i.sends>this._conn.maxRetries)return void this._conn._onDisconnectTimeout();var r=i.age(),o=!isNaN(r)&&r>Math.floor(t.TIMEOUT*this.wait),a=null!==i.dead&&i.timeDead()>Math.floor(t.SECONDARY_TIMEOUT*this.wait),h=4===i.xhr.readyState&&(s<1||s>=500);if((o||a||h)&&(a&&t.error("Request "+this._requests[e].id+" timed out (secondary), restarting"),i.abort=!0,i.xhr.abort(),i.xhr.onreadystatechange=function(){},this._requests[e]=new t.Request(i.xmlData,i.origFunc,i.rid,i.sends),i=this._requests[e]),0===i.xhr.readyState){t.debug("request id "+i.id+"."+i.sends+" posting");try{var c=this._conn.options.contentType||"text/xml; charset=utf-8";i.xhr.open("POST",this._conn.service,!this._conn.options.sync),"undefined"!=typeof i.xhr.setRequestHeader&&i.xhr.setRequestHeader("Content-Type",c),this._conn.options.withCredentials&&(i.xhr.withCredentials=!0)}catch(e){return t.error("XHR open failed: "+e.toString()),this._conn.connected||this._conn._changeConnectStatus(t.Status.CONNFAIL,"bad-service"),void this._conn.disconnect()}var u=function(){if(i.date=new Date,n._conn.options.customHeaders){var t=n._conn.options.customHeaders;for(var e in t)t.hasOwnProperty(e)&&i.xhr.setRequestHeader(e,t[e])}i.xhr.send(i.data)};if(i.sends>1){var l=1e3*Math.min(Math.floor(t.TIMEOUT*this.wait),Math.pow(i.sends,3));setTimeout(function(){u()},l)}else u();i.sends++,this._conn.xmlOutput!==t.Connection.prototype.xmlOutput&&(i.xmlData.nodeName===this.strip&&i.xmlData.childNodes.length?this._conn.xmlOutput(i.xmlData.childNodes[0]):this._conn.xmlOutput(i.xmlData)),this._conn.rawOutput!==t.Connection.prototype.rawOutput&&this._conn.rawOutput(i.data)}else t.debug("_processRequest: "+(0===e?"first":"second")+" request has readyState of "+i.xhr.readyState)},_removeRequest:function(e){t.debug("removing request");var n;for(n=this._requests.length-1;n>=0;n--)e===this._requests[n]&&this._requests.splice(n,1);e.xhr.onreadystatechange=function(){},this._throttledRequestHandler()},_restartRequest:function(t){var e=this._requests[t];null===e.dead&&(e.dead=new Date),this._processRequest(t)},_reqToData:function(t){try{return t.getResponse()}catch(t){if("parsererror"!==t)throw t;this._conn.disconnect("strophe-parsererror")}},_sendTerminate:function(e){t.info("_sendTerminate was called");var n=this._buildBody().attrs({type:"terminate"});e&&n.cnode(e.tree());var i=new t.Request(n.tree(),this._onRequestStateChange.bind(this,this._conn._dataRecv.bind(this._conn)),n.tree().getAttribute("rid"));this._requests.push(i),this._throttledRequestHandler()},_send:function(){clearTimeout(this._conn._idleTimeout),this._throttledRequestHandler(),this._conn._idleTimeout=setTimeout(function(){this._onIdle()}.bind(this._conn),100)},_sendRestart:function(){this._throttledRequestHandler(),clearTimeout(this._conn._idleTimeout)},_throttledRequestHandler:function(){this._requests?t.debug("_throttledRequestHandler called with "+this._requests.length+" requests"):t.debug("_throttledRequestHandler called with undefined requests"),this._requests&&0!==this._requests.length&&(this._requests.length>0&&this._processRequest(0),this._requests.length>1&&Math.abs(this._requests[0].rid-this._requests[1].rid): "+i);var s=e.getAttribute("version");return"string"!=typeof s?n="Missing version in ":"1.0"!==s&&(n="Wrong version in : "+s),!n||(this._conn._changeConnectStatus(t.Status.CONNFAIL,n),this._conn._doDisconnect(),!1)},_connect_cb_wrapper:function(e){if(0===e.data.indexOf("\s*)*/,"");if(""===n)return;var i=(new DOMParser).parseFromString(n,"text/xml").documentElement;this._conn.xmlInput(i),this._conn.rawInput(e.data),this._handleStreamStart(i)&&this._connect_cb(i)}else if(0===e.data.indexOf(" tag.")}}this._conn._doDisconnect()},_doDisconnect:function(){t.info("WebSockets _doDisconnect was called"),this._closeSocket()},_streamWrap:function(t){return""+t+""},_closeSocket:function(){if(this.socket)try{this.socket.close()}catch(t){}this.socket=null},_emptyQueue:function(){return!0},_onClose:function(e){this._conn.connected&&!this._conn.disconnecting?(t.error("Websocket closed unexpectedly"),this._conn._doDisconnect()):e&&1006===e.code&&!this._conn.connected&&this.socket?(t.error("Websocket closed unexcectedly"),this._conn._changeConnectStatus(t.Status.CONNFAIL,"The WebSocket connection could not be established or was disconnected."),this._conn._doDisconnect()):t.info("Websocket closed")},_no_auth_received:function(e){t.error("Server did not send any auth methods"),this._conn._changeConnectStatus(t.Status.CONNFAIL,"Server did not send any auth methods"),e&&(e=e.bind(this._conn))(),this._conn._doDisconnect()},_onDisconnectTimeout:function(){},_abortAllRequests:function(){},_onError:function(e){t.error("Websocket error "+e),this._conn._changeConnectStatus(t.Status.CONNFAIL,"The WebSocket connection could not be established or was disconnected."),this._disconnect()},_onIdle:function(){var e=this._conn._data;if(e.length>0&&!this._conn.paused){for(var n=0;n