From 4eadadd6c5208e6c8dd60bc3ec2224eaf289c733 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Sun, 16 Sep 2018 10:45:43 +0200 Subject: [PATCH] New release 1.2.16 --- CHANGELOG.md | 2 +- Makefile | 1 - README.md | 2 +- package-lock.json | 2 +- package.json | 2 +- strophe.js | 93 +++++++++++++++++++++++++++++++---------------- strophe.min.js | 4 +- 7 files changed, 67 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d1075eb..e9dd57ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Strophe.js Change Log -## Version 1.2.16 - (Unreleased) +## Version 1.2.16 - (2018-09-16) * #299 'no-auth-mech' error. Server did not offer a supported authentication mechanism * #306 Fix websocket close handler exception and reporting diff --git a/Makefile b/Makefile index 020591e5..fa2f82fe 100644 --- a/Makefile +++ b/Makefile @@ -52,7 +52,6 @@ doc: .PHONY: release release: $(SED) -i 's/\"version\":\ \"[0-9]\+\.[0-9]\+\.[0-9]\+\"/\"version\":\ \"$(VERSION)\"/' package.json - $(SED) -i 's/\"version\":\ \"[0-9]\+\.[0-9]\+\.[0-9]\+\"/\"version\":\ \"$(VERSION)\"/' package-lock.json $(SED) -i "s/Unreleased/`date +%Y-%m-%d`/" CHANGELOG.md make dist make doc diff --git a/README.md b/README.md index c4eeffb7..d4a089db 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ covers Strophe in detail in the context of web applications. ## Quick Links * [Homepage](http://strophe.im/strophejs) -* [Documentation](http://strophe.im/strophejs/doc/1.2.15/files/strophe-js.html) +* [Documentation](http://strophe.im/strophejs/doc/1.2.16/files/strophe-js.html) * [Mailing list](http://groups.google.com/group/strophe) * [Community Plugins](http://github.com/strophe/strophejs-plugins) diff --git a/package-lock.json b/package-lock.json index 932371bd..ec873a04 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "strophe.js", - "version": "1.2.15", + "version": "1.2.16", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 7131062a..75c0caed 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.15", + "version": "1.2.16", "homepage": "http://strophe.im/strophejs", "repository": { "type": "git", diff --git a/strophe.js b/strophe.js index 5b30dd9b..e655b362 100644 --- a/strophe.js +++ b/strophe.js @@ -1289,7 +1289,7 @@ function $pres(attrs) { return new Strophe.Builder("presence", attrs); } */ Strophe = { /** Constant: VERSION */ - VERSION: "1.2.15", + VERSION: "1.2.16", /** Constants: XMPP Namespace Constants * Common namespace constants from the XMPP RFCs and XEPs. @@ -3839,26 +3839,6 @@ Strophe.Connection.prototype = { */ mechanisms: {}, - /** PrivateFunction: _no_auth_received - * - * Called on stream start/restart when no stream:features - * has been received or when no viable authentication mechanism is offered. - * - * Sends a blank poll request. - */ - _no_auth_received: function (_callback) { - var error_msg = "Server did not offer a supported authentication mechanism"; - Strophe.error(error_msg); - this._changeConnectStatus( - Strophe.Status.CONNFAIL, - Strophe.ErrorCondition.NO_AUTH_MECH - ); - if (_callback) { - _callback.call(this); - } - this._doDisconnect(); - }, - /** PrivateFunction: _connect_cb * _Private_ handler for initial connection request. * @@ -3921,7 +3901,7 @@ Strophe.Connection.prototype = { bodyWrap.getElementsByTagName("features").length > 0; } if (!hasFeatures) { - this._no_auth_received(_callback); + this._proto._no_auth_received(_callback); return; } @@ -3937,7 +3917,7 @@ Strophe.Connection.prototype = { if (bodyWrap.getElementsByTagName("auth").length === 0) { // There are no matching SASL mechanisms and also no legacy // auth available. - this._no_auth_received(_callback); + this._proto._no_auth_received(_callback); return; } } @@ -5386,6 +5366,30 @@ Strophe.Bosh.prototype = { } }, + /** PrivateFunction: _no_auth_received + * + * Called on stream start/restart when no stream:features + * has been received and sends a blank poll request. + */ + _no_auth_received: function (callback) { + Strophe.warn("Server did not yet offer a supported authentication "+ + "mechanism. Sending a blank poll request."); + if (callback) { + callback = callback.bind(this._conn); + } else { + callback = this._conn._connect_cb.bind(this._conn); + } + var body = this._buildBody(); + this._requests.push( + new Strophe.Request( + body.tree(), + this._onRequestStateChange.bind(this, callback), + body.tree().getAttribute("rid") + ) + ); + this._throttledRequestHandler(); + }, + /** PrivateFunction: _onDisconnectTimeout * _Private_ timeout handler for handling non-graceful disconnection. * @@ -6089,17 +6093,25 @@ Strophe.Websocket.prototype = { this._connect_cb(streamStart); } } else if (message.data.indexOf("WSS, WS->ANY + var isSecureRedirect = (service.indexOf("wss:") >= 0 && see_uri.indexOf("wss:") >= 0) || (service.indexOf("ws:") >= 0); + if(isSecureRedirect) { + this._conn._changeConnectStatus( + Strophe.Status.REDIRECT, + "Received see-other-uri, resetting connection" + ); + this._conn.reset(); + this._conn.service = see_uri; + this._connect(); + } } else { this._conn._changeConnectStatus( Strophe.Status.CONNFAIL, @@ -6208,6 +6220,23 @@ Strophe.Websocket.prototype = { } }, + /** PrivateFunction: _no_auth_received + * + * Called on stream start/restart when no stream:features + * has been received. + */ + _no_auth_received: function (callback) { + Strophe.error("Server did not offer a supported authentication mechanism"); + this._changeConnectStatus( + Strophe.Status.CONNFAIL, + Strophe.ErrorCondition.NO_AUTH_MECH + ); + if (callback) { + callback.call(this._conn); + } + this._conn._doDisconnect(); + }, + /** PrivateFunction: _onDisconnectTimeout * _Private_ timeout handler for handling non-graceful disconnection. * diff --git a/strophe.min.js b/strophe.min.js index 956b1408..fdc92199 100644 --- a/strophe.min.js +++ b/strophe.min.js @@ -28,5 +28,5 @@ * See http://pajhome.org.uk/crypt/md5 for more info. */ -!function(t,e){if("function"==typeof define&&define.amd)define([],e);else{var n=e();t.Strophe=n.Strophe,t.$build=n.$build,t.$iq=n.$iq,t.$msg=n.$msg,t.$pres=n.$pres,t.SHA1=n.SHA1,t.MD5=n.MD5,t.b64_hmac_sha1=n.b64_hmac_sha1,t.b64_sha1=n.b64_sha1,t.str_hmac_sha1=n.str_hmac_sha1,t.str_sha1=n.str_sha1}}(this,function(){var t,e,n;return function(i){function s(t,e){return v.call(t,e)}function r(t,e){var n,i,s,r,o,a,h,c,u,l,d,_,f=e&&e.split("/"),p=b.map,m=p&&p["*"]||{};if(t){for(t=t.split("/"),o=t.length-1,b.nodeIdCompat&&x.test(t[o])&&(t[o]=t[o].replace(x,"")),"."===t[0].charAt(0)&&f&&(_=f.slice(0,f.length-1),t=_.concat(t)),u=0;u0&&(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;n0&&(t.splice(u-1,2),u-=2)}t=t.join("/")}if((f||m)&&_){for(n=t.split("/"),u=n.length;u>0;u-=1){if(s=n.slice(0,u).join("/"),f)for(l=f.length;l>0;l-=1)if(i=_[f.slice(0,l).join("/")],i&&(i=i[s])){r=i,a=u;break}if(r)break;!h&&m&&m[s]&&(h=m[s],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=x.call(arguments,0);return"string"!=typeof n[0]&&1===n.length&&n.push(null),f.apply(s,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(i(S,t)){var e=S[t];delete S[t],y[t]=!0,p.apply(s,e)}if(!i(g,t)&&!i(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 p,f,_,m,g={},S={},b={},y={},v=Object.prototype.hasOwnProperty,x=[].slice,T=/\.js$/;_=function(t,e){var n,s=u(t),i=s[0],o=e[1];return t=s[1],i&&(i=r(i,o),n=c(i)),i?t=n&&n.normalize?n.normalize(t,a(o)):r(t,o):(t=r(t,o),s=u(t),i=s[0],t=s[1],i&&(n=c(i))),{f:i?i+"!"+t:t,n:t,pr:i,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)}}},p=function(t,e,n,r){var a,u,d,p,f,b,v,x=[],T=typeof n;if(r=r||t,b=l(r),"undefined"===T||"function"===T){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),s=0;s>2,o=(3&n)<<4|s>>4,a=(15&s)<<2|i>>6,h=63&i,isNaN(s)?(o=(3&n)<<4,a=h=64):isNaN(i)&&(h=64),c=c+e.charAt(r)+e.charAt(o)+e.charAt(a)+e.charAt(h);while(u>4,s=(15&o)<<4|a>>2,i=(3&a)<<6|h,c+=String.fromCharCode(n),64!==a&&(c+=String.fromCharCode(s)),64!==h&&(c+=String.fromCharCode(i));while(u>5]|=128<<24-s%32,t[(s+64>>9<<4)+15]=s;var o,a,h,c,u,l,d,p,f=new Array(80),_=1732584193,m=-271733879,g=-1732584194,S=271733878,b=-1009589776;for(o=0;o16&&(s=t(s,8*e.length));for(var i=new Array(16),r=new Array(16),a=0;a<16;a++)i[a]=909522486^s[a],r[a]=1549556828^s[a];var h=t(i.concat(o(n)),512+8*n.length);return t(r.concat(h),672)}function i(t,e){var n=(65535&t)+(65535&e),s=(t>>16)+(e>>16)+(n>>16);return s<<16|65535&n}function r(t,e){return t<>>32-e}function o(t){for(var e=[],n=255,s=0;s<8*t.length;s+=8)e[s>>5]|=(t.charCodeAt(s/8)&n)<<24-s%32;return e}function a(t){for(var e="",n=255,s=0;s<32*t.length;s+=8)e+=String.fromCharCode(t[s>>5]>>>24-s%32&n);return e}function h(t){for(var e,n,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i="",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++)i+=8*r+6*n>32*t.length?"=":s.charAt(e>>6*(3-n)&63);return i}return{b64_hmac_sha1:function(t,e){return h(s(t,e))},b64_sha1:function(e){return h(t(o(e),8*e.length))},binb2str:a,core_hmac_sha1:s,str_hmac_sha1:function(t,e){return a(s(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()}):"object"==typeof exports?module.exports=e():t.MD5=e()}(this,function(){var t=function(t,e){var n=(65535&t)+(65535&e),s=(t>>16)+(e>>16)+(n>>16);return s<<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},i=function(t){for(var e="0123456789abcdef",n="",s=0;s<4*t.length;s++)n+=e.charAt(t[s>>2]>>s%4*8+4&15)+e.charAt(t[s>>2]>>s%4*8&15);return n},r=function(n,s,i,r,o,a){return t(e(t(t(s,n),t(r,a)),o),i)},o=function(t,e,n,s,i,o,a){return r(e&n|~e&s,t,e,i,o,a)},a=function(t,e,n,s,i,o,a){return r(e&s|n&~s,t,e,i,o,a)},h=function(t,e,n,s,i,o,a){return r(e^n^s,t,e,i,o,a)},c=function(t,e,n,s,i,o,a){return r(n^(e|~s),t,e,i,o,a)},u=function(e,n){e[n>>5]|=128<>>9<<4)+14]=n;for(var s,i,r,u,l=1732584193,d=-271733879,p=-1732584194,f=271733878,_=0;_=0&&n<=127?s+=t.charAt(e):n>2047?(s+=String.fromCharCode(224|n>>12&15),s+=String.fromCharCode(128|n>>6&63),s+=String.fromCharCode(128|n>>0&63)):(s+=String.fromCharCode(192|n>>6&31),s+=String.fromCharCode(128|n>>0&63));return s},addCookies:function(t){var e,n,s,i,r,o,a;for(e in t||{})r="",o="",a="",n=t[e],s="object"==typeof n,i=escape(unescape(s?n.value:n)),s&&(r=n.expires?";expires="+n.expires:"",o=n.domain?";domain="+n.domain:"",a=n.path?";path="+n.path:""),document.cookie=e+"="+i+r+o+a}};return t}),function(t,s){if("function"==typeof n&&n.amd)n("strophe-core",["strophe-sha1","strophe-md5","strophe-utils"],function(){return s.apply(this,arguments)});else if("object"==typeof exports)module.exports=s(e("./sha1"),e("./md5"),e("./utils"));else{var i=s(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 s(t,e){return new a.Builder(t,e)}function i(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.16",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){t===this.LogLevel.FATAL&&"object"==typeof window.console&&"function"==typeof window.console.error&&window.console.error(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,s,i=t.nodeName;for(t.getAttribute("_realname")&&(i=t.getAttribute("_realname")),e="<"+i,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 s=a.xmlElement(t,e,n);return this.node.appendChild(s),"string"!=typeof n&&"number"!=typeof n&&(this.node=s),this},cnode:function(t){var e,n=a.xmlGenerator();try{e=void 0!==n.importNode}catch(t){e=!1}var s=e?n.importNode(t,!0):a.copyElement(t);return this.node.appendChild(s),this.node=s,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,s,i,r,o){this.handler=t,this.ns=e,this.name=n,this.type=s,this.id=i,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 s=this.options.protocol||"";0===t.indexOf("ws:")||0===t.indexOf("wss:")||0===s.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 i in a._connectionPlugins)if(a._connectionPlugins.hasOwnProperty(i)){var r=a._connectionPlugins[i],o=function(){};o.prototype=r,this[i]=new o,this[i].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,s,i,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(s,i,r)},attach:function(t,e,n,s,i,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,s,i,r,o)},restore:function(t,e,n,s,i){if(!this._sessionCachingSupported())throw{name:"StropheSessionError",message:'The "restore" method can only be used with a BOSH connection.'};this._proto._restore(t,e,n,s,i)},_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.SASLXOAuth2,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,n){for(var s in a._connectionPlugins)if(a._connectionPlugins.hasOwnProperty(s)){var i=this[s];if(i.statusChanged)try{i.statusChanged(t,e)}catch(t){a.error(""+s+" plugin caused an exception changing status: "+t)}}if(this.connect_callback)try{this.connect_callback(t,e,n)}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 s,i;this.removeHandlers.length>0;)i=this.removeHandlers.pop(),s=this.handlers.indexOf(i),s>=0&&this.handlers.splice(s,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,a.ErrorCondition.UNKOWN_REASON),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:s.getElementsByTagName("stream:features").length>0||s.getElementsByTagName("features").length>0,!r)return void this._proto._no_auth_received(e);var o,h,c=[],u=s.getElementsByTagName("mechanism");if(u.length>0)for(o=0;ot[s].prototype.priority&&(s=n);s!==e&&(i=t[e],t[e]=t[s],t[s]=i)}return t},_attemptSASLAuth:function(t){t=this.sortMechanismsByPriority(t||[]); +var e=0,n=!1;for(e=0;e0&&(e=a.ErrorCondition.CONFLICT),this._changeConnectStatus(a.Status.AUTHFAIL,e,t),!1}var s,i=t.getElementsByTagName("bind");return i.length>0?(s=i[0].getElementsByTagName("jid"),void(s.length>0&&(this.jid=a.getText(s[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,t),!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,t),!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,t),!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,t),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,s,i){var r=new a.Handler(t,e,n,s,i);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,s;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 i=(new Date).getTime();for(s=[],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){t.warn("Server did not yet offer a supported authentication mechanism. Sending a blank poll request."),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),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(),s=0;s0){var i=this._requests[0].age();null!==this._requests[0].dead&&this._requests[0].timeDead()>Math.floor(t.SECONDARY_TIMEOUT*this.wait)&&this._throttledRequestHandler(),i>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 s;if(4===e.xhr.readyState)try{s=e.xhr.status}catch(e){t.error("Caught an error while retrieving a request's status, reqStatus: "+s)}return"undefined"==typeof s&&(s="number"==typeof n?n:0),s},_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 s=this._getRequestStatus(n);if(this.lastResponseHeaders=n.xhr.getAllResponseHeaders(),this.disconnecting&&s>=400)return this._hitError(s),void this._callProtocolErrorHandlers(n);var i=s>0&&s<500,r=n.sends>this._conn.maxRetries;if((i||r)&&(this._removeRequest(n),t.debug("request id "+n.id+" should now be removed")),200===s){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===s||s>=400&&s<600||s>=12e3?(t.error("request id "+n.id+"."+n.sends+" error "+s+" happened"),this._hitError(s),this._callProtocolErrorHandlers(n),s>=400&&s<500&&(this._conn._changeConnectStatus(t.Status.DISCONNECTING,null),this._conn._doDisconnect())):t.error("request id "+n.id+"."+n.sends+" error "+s+" happened");i||r?r&&!this._conn.connected&&this._conn._changeConnectStatus(t.Status.CONNFAIL,"giving-up"):this._throttledRequestHandler()}},_processRequest:function(e){var n=this,s=this._requests[e],i=this._getRequestStatus(s,-1);if(s.sends>this._conn.maxRetries)return void this._conn._onDisconnectTimeout();var r=s.age(),o=!isNaN(r)&&r>Math.floor(t.TIMEOUT*this.wait),a=null!==s.dead&&s.timeDead()>Math.floor(t.SECONDARY_TIMEOUT*this.wait),h=4===s.xhr.readyState&&(i<1||i>=500);if((o||a||h)&&(a&&t.error("Request "+this._requests[e].id+" timed out (secondary), restarting"),s.abort=!0,s.xhr.abort(),s.xhr.onreadystatechange=function(){},this._requests[e]=new t.Request(s.xmlData,s.origFunc,s.rid,s.sends),s=this._requests[e]),0===s.xhr.readyState){t.debug("request id "+s.id+"."+s.sends+" posting");try{var c=this._conn.options.contentType||"text/xml; charset=utf-8";s.xhr.open("POST",this._conn.service,!this._conn.options.sync),"undefined"!=typeof s.xhr.setRequestHeader&&s.xhr.setRequestHeader("Content-Type",c),this._conn.options.withCredentials&&(s.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(s.date=new Date,n._conn.options.customHeaders){var t=n._conn.options.customHeaders;for(var e in t)t.hasOwnProperty(e)&&s.xhr.setRequestHeader(e,t[e])}s.xhr.send(s.data)};if(s.sends>1){var l=1e3*Math.min(Math.floor(t.TIMEOUT*this.wait),Math.pow(s.sends,3));setTimeout(function(){u()},l)}else u();s.sends++,this._conn.xmlOutput!==t.Connection.prototype.xmlOutput&&(s.xmlData.nodeName===this.strip&&s.xmlData.childNodes.length?this._conn.xmlOutput(s.xmlData.childNodes[0]):this._conn.xmlOutput(s.xmlData)),this._conn.rawOutput!==t.Connection.prototype.rawOutput&&this._conn.rawOutput(s.data)}else t.debug("_processRequest: "+(0===e?"first":"second")+" request has readyState of "+s.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 s=new t.Request(n.tree(),this._onRequestStateChange.bind(this,this._conn._dataRecv.bind(this._conn)),n.tree().getAttribute("rid"));this._requests.push(s),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): "+s);var i=e.getAttribute("version");return"string"!=typeof i?n="Missing version in ":"1.0"!==i&&(n="Wrong version in : "+i),!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 s=(new DOMParser).parseFromString(n,"text/xml").documentElement;this._conn.xmlInput(s),this._conn.rawInput(e.data),this._handleStreamStart(s)&&this._connect_cb(s)}else if(0===e.data.indexOf("=0&&r.indexOf("wss:")>=0||o.indexOf("ws:")>=0;a&&(this._conn._changeConnectStatus(t.Status.REDIRECT,"Received see-other-uri, resetting connection"),this._conn.reset(),this._conn.service=r,this._connect())}else this._conn._changeConnectStatus(t.Status.CONNFAIL,"Received closing stream"),this._conn._doDisconnect()}else{var h=this._streamWrap(e.data),c=(new DOMParser).parseFromString(h,"text/xml").documentElement;this.socket.onmessage=this._onMessage.bind(this),this._conn._connect_cb(c,null,e.data)}},_disconnect:function(n){if(this.socket&&this.socket.readyState!==WebSocket.CLOSED){n&&this._conn.send(n);var s=e("close",{xmlns:t.NS.FRAMING});this._conn.xmlOutput(s.tree());var i=t.serialize(s);this._conn.rawOutput(i);try{this.socket.send(i)}catch(e){t.info("Couldn't send 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.onerror=null,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 offer a supported authentication mechanism"),this._changeConnectStatus(t.Status.CONNFAIL,t.ErrorCondition.NO_AUTH_MECH),e&&e.call(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