/** * Minified by jsDelivr using Terser v5.39.0. * Original file: /npm/strophe@1.2.4/strophe.js * * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files */ !function(t){var e,n;if(e=this,n=function(){var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";return{encode:function(e){var n,s,i,r,o,a,h,c="",u=0;do{r=(n=e.charCodeAt(u++))>>2,o=(3&n)<<4|(s=e.charCodeAt(u++))>>4,a=(15&s)<<2|(i=e.charCodeAt(u++))>>6,h=63&i,isNaN(s)?(o=(3&n)<<4,a=h=64):isNaN(i)&&(h=64),c=c+t.charAt(r)+t.charAt(o)+t.charAt(a)+t.charAt(h)}while(u>4,s=(15&r)<<4|(o=t.indexOf(e.charAt(c++)))>>2,i=(3&o)<<6|(a=t.indexOf(e.charAt(c++))),h+=String.fromCharCode(n),64!=o&&(h+=String.fromCharCode(s)),64!=a&&(h+=String.fromCharCode(i))}while(c>5]|=128<<24-s%32,t[15+(s+64>>9<<4)]=s;var o,a,h,c,u,l,d,_,f=new Array(80),m=1732584193,p=-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);return(t>>16)+(e>>16)+(n>>16)<<16|65535&n}function r(t,e){return t<>>32-e}function o(t){for(var e=[],n=0;n<8*t.length;n+=8)e[n>>5]|=(255&t.charCodeAt(n/8))<<24-n%32;return e}function a(t){for(var e="",n=0;n<32*t.length;n+=8)e+=String.fromCharCode(t[n>>5]>>>24-n%32&255);return e}function h(t){for(var e,n,s="",i=0;i<4*t.length;i+=3)for(e=(t[i>>2]>>8*(3-i%4)&255)<<16|(t[i+1>>2]>>8*(3-(i+1)%4)&255)<<8|t[i+2>>2]>>8*(3-(i+2)%4)&255,n=0;n<4;n++)8*i+6*n>32*t.length?s+="=":s+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(e>>6*(3-n)&63);return s}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 define&&define.amd?define("strophe-md5",(function(){return e()})):t.MD5=e()}(this,(function(t){var e=function(t,e){var n=(65535&t)+(65535&e);return(t>>16)+(e>>16)+(n>>16)<<16|65535&n},n=function(t){for(var e=[],n=0;n<8*t.length;n+=8)e[n>>5]|=(255&t.charCodeAt(n/8))<>>32-h,s);var a,h},i=function(t,e,n,i,r,o,a){return s(e&n|~e&i,t,e,r,o,a)},r=function(t,e,n,i,r,o,a){return s(e&i|n&~i,t,e,r,o,a)},o=function(t,e,n,i,r,o,a){return s(e^n^i,t,e,r,o,a)},a=function(t,e,n,i,r,o,a){return s(n^(e|~i),t,e,r,o,a)},h=function(t,n){t[n>>5]|=128<>>9<<4)]=n;for(var s,h,c,u,l=1732584193,d=-271733879,_=-1732584194,f=271733878,m=0;m>2]>>s%4*8+4&15)+e.charAt(t[s>>2]>>s%4*8&15);return n}(h(n(t),8*t.length))},hash:function(t){return function(t){for(var e="",n=0;n<32*t.length;n+=8)e+=String.fromCharCode(t[n>>5]>>>n%32&255);return e}(h(n(t),8*t.length))}}})),function(t,e){"function"==typeof define&&define.amd?define("strophe-utils",(function(){return e()})):t.stropheUtils=e()}(this,(function(){return{utf16to8:function(t){var e,n,s="",i=t.length;for(e=0;e=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|63&n)):(s+=String.fromCharCode(192|n>>6&31),s+=String.fromCharCode(128|63&n));return s}}})),function(t,e){if("function"!=typeof define||!define.amd)return e();define("strophe-polyfill",[],(function(){return e()}))}(0,(function(){Function.prototype.bind||(Function.prototype.bind=function(t){var e=this,n=Array.prototype.slice,s=Array.prototype.concat,i=n.call(arguments,1);return function(){return e.apply(t||this,s.call(i,n.call(arguments,0)))}}),Array.isArray||(Array.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)}),Array.prototype.indexOf||(Array.prototype.indexOf=function(t){var e=this.length,n=Number(arguments[1])||0;for((n=n<0?Math.ceil(n):Math.floor(n))<0&&(n+=e);n0)for(var n=0;n/g,">")).replace(/'/g,"'")).replace(/"/g,""")},xmlunescape:function(t){return t=(t=(t=(t=(t=t.replace(/\&/g,"&")).replace(/</g,"<")).replace(/>/g,">")).replace(/'/g,"'")).replace(/"/g,'"')},xmlTextNode:function(t){return i.xmlGenerator().createTextNode(t)},xmlHtmlNode:function(t){var e;window.DOMParser?e=(new DOMParser).parseFromString(t,"text/xml"):((e=new ActiveXObject("Microsoft.XMLDOM")).async="false",e.loadXML(t));return e},getText:function(t){if(!t)return null;var e="";0===t.childNodes.length&&t.nodeType==i.ElementType.TEXT&&(e+=t.nodeValue);for(var n=0;n0&&(a=h.join("; "),n.setAttribute(o,a))}else n.setAttribute(o,a);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=i.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},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,s,r=t.nodeName;for(t.getAttribute("_realname")&&(r=t.getAttribute("_realname")),e="<"+r,n=0;n/g,">").replace(/0){for(e+=">",n=0;n"}e+=""}else e+="/>";return e},_requestId:0,_connectionPlugins:{},addConnectionPlugin:function(t,e){i._connectionPlugins[t]=e}},i.Builder=function(t,e){"presence"!=t&&"message"!=t&&"iq"!=t||(e&&!e.xmlns?e.xmlns=i.NS.CLIENT:e||(e={xmlns:i.NS.CLIENT})),this.nodeTree=i.xmlElement(t,e),this.node=this.nodeTree},i.Builder.prototype={tree:function(){return this.nodeTree},toString:function(){return i.serialize(this.nodeTree)},up:function(){return this.node=this.node.parentNode,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=i.xmlElement(t,e,n);return this.node.appendChild(s),"string"!=typeof n&&(this.node=s),this},cnode:function(t){var e,n=i.xmlGenerator();try{e=void 0!==n.importNode}catch(t){e=!1}var s=e?n.importNode(t,!0):i.copyElement(t);return this.node.appendChild(s),this.node=s,this},t:function(t){var e=i.xmlTextNode(t);return this.node.appendChild(e),this},h:function(t){var e=document.createElement("body");e.innerHTML=t;for(var n=i.createHtml(e);n.childNodes.length>0;)this.node.appendChild(n.childNodes[0]);return this}},i.Handler=function(t,e,n,s,r,o,a){this.handler=t,this.ns=e,this.name=n,this.type=s,this.id=r,this.options=a||{matchBare:!1},this.options.matchBare||(this.options.matchBare=!1),this.options.matchBare?this.from=o?i.getBareJidFromJid(o):null:this.from=o,this.user=!0},i.Handler.prototype={isMatch:function(t){var e,n=null;if(n=this.options.matchBare?i.getBareJidFromJid(t.getAttribute("from")):t.getAttribute("from"),e=!1,this.ns){var s=this;i.forEachChild(t,null,(function(t){t.getAttribute("xmlns")==s.ns&&(e=!0)})),e=e||t.getAttribute("xmlns")==this.ns}else e=!0;var r=t.getAttribute("type");return!(!e||this.name&&!i.isTagEqual(t,this.name)||this.type&&(Array.isArray(this.type)?-1==this.type.indexOf(r):r!=this.type)||this.id&&t.getAttribute("id")!=this.id||this.from&&n!=this.from)},run:function(t){var e=null;try{e=this.handler(t)}catch(t){throw t.sourceURL?i.fatal("error: "+this.handler+" "+t.sourceURL+":"+t.line+" - "+t.name+": "+t.message):t.fileName?("undefined"!=typeof console&&(console.trace(),console.error(this.handler," - error - ",t,t.message)),i.fatal("error: "+this.handler+" "+t.fileName+":"+t.lineNumber+" - "+t.name+": "+t.message)):i.fatal("error: "+t.message+"\n"+t.stack),t}return e},toString:function(){return"{Handler: "+this.handler+"("+this.name+","+this.id+","+this.ns+")}"}},i.TimedHandler=function(t,e){this.period=t,this.handler=e,this.lastCalled=(new Date).getTime(),this.user=!0},i.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+")}"}},i.Connection=function(t,e){this.service=t,this.options=e||{};var n=this.options.protocol||"";for(var s in 0===t.indexOf("ws:")||0===t.indexOf("wss:")||0===n.indexOf("ws")?this._proto=new i.Websocket(this):this._proto=new i.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._authentication={},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(this._onIdle.bind(this),100),i._connectionPlugins)if(i._connectionPlugins.hasOwnProperty(s)){var r=i._connectionPlugins[s],o=function(){};o.prototype=r,this[s]=new o,this[s].init(this)}},i.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._authentication={},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;return("x"==t?e:3&e|8).toString(16)}));return"string"==typeof t||"number"==typeof t?e+":"+t:e+""},connect:function(t,e,n,s,r,o,a){this.jid=t,this.authzid=i.getBareJidFromJid(this.jid),this.authcid=a||i.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=i.getDomainFromJid(this.jid),this._changeConnectStatus(i.Status.CONNECTING,null),this._proto._connect(s,r,o)},attach:function(t,e,n,s,r,o,a){if(!(this._proto instanceof i.Bosh))throw{name:"StropheSessionError",message:'The "attach" method can only be used with a BOSH connection.'};this._proto._attach(t,e,n,s,r,o,a)},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 i.Bosh){if(!JSON)return!1;try{window.sessionStorage.setItem("_strophe_","_strophe_"),window.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)},disconnect:function(t){if(this._changeConnectStatus(i.Status.DISCONNECTING,t),i.info("Disconnect was called because: "+t),this.connected){var e=!1;this.disconnecting=!0,this.authenticated&&(e=a({xmlns:i.NS.CLIENT,type:"unavailable"})),this._disconnectTimeout=this._addSysTimedHandler(3e3,this._onDisconnectTimeout.bind(this)),this._proto._disconnect(e)}else i.info("Disconnect was called before Strophe connected to the server"),this._proto._abortAllRequests()},_changeConnectStatus:function(t,e){for(var n in i._connectionPlugins)if(i._connectionPlugins.hasOwnProperty(n)){var s=this[n];if(s.statusChanged)try{s.statusChanged(t,e)}catch(t){i.error(n+" plugin caused an exception changing status: "+t)}}if(this.connect_callback)try{this.connect_callback(t,e)}catch(t){i.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),i.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(i.Status.DISCONNECTED,t),this.connected=!1},_dataRecv:function(t,e){i.info("_dataRecv called");var n=this._proto._reqToData(t);if(null!==n){var s,r;for(this.xmlInput!==i.Connection.prototype.xmlInput&&(n.nodeName===this._proto.strip&&n.childNodes.length?this.xmlInput(n.childNodes[0]):this.xmlInput(n)),this.rawInput!==i.Connection.prototype.rawInput&&(e?this.rawInput(e):this.rawInput(i.serialize(n)));this.removeHandlers.length>0;)r=this.removeHandlers.pop(),(s=this.handlers.indexOf(r))>=0&&this.handlers.splice(s,1);for(;this.addHandlers.length>0;)this.handlers.push(this.addHandlers.pop());if(this.disconnecting&&this._proto._emptyQueue())this._doDisconnect();else{var o,a,h=n.getAttribute("type");if(null!==h&&"terminate"==h){if(this.disconnecting)return;return o=n.getAttribute("condition"),a=n.getElementsByTagName("conflict"),null!==o?("remote-stream-error"==o&&a.length>0&&(o="conflict"),this._changeConnectStatus(i.Status.CONNFAIL,o)):this._changeConnectStatus(i.Status.CONNFAIL,"unknown"),void this._doDisconnect(o)}var c=this;i.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;var o,a,h=s.getElementsByTagName("mechanism"),c=[];if(r){if(h.length>0)for(o=0;o0,this._authentication.legacy_auth||c.length>0?!1!==this.do_authentication&&this.authenticate(c):this._proto._no_auth_received(e)}else this._proto._no_auth_received(e)}},authenticate:function(t){var n;for(n=0;nt[s].prototype.priority&&(s=a);if(s!=n){var h=t[n];t[n]=t[s],t[s]=h}}var c=!1;for(n=0;n0&&(e="conflict"),this._changeConnectStatus(i.Status.AUTHFAIL,e),!1;var n,s=t.getElementsByTagName("bind");if(!(s.length>0))return i.info("SASL binding failed."),this._changeConnectStatus(i.Status.AUTHFAIL,null),!1;(n=s[0].getElementsByTagName("jid")).length>0&&(this.jid=i.getText(n[0]),this.do_session?(this._addSysHandler(this._sasl_session_cb.bind(this),null,null,null,"_session_auth_2"),this.send(o({type:"set",id:"_session_auth_2"}).c("session",{xmlns:i.NS.SESSION}).tree())):(this.authenticated=!0,this._changeConnectStatus(i.Status.CONNECTED,null)))},_sasl_session_cb:function(t){if("result"==t.getAttribute("type"))this.authenticated=!0,this._changeConnectStatus(i.Status.CONNECTED,null);else if("error"==t.getAttribute("type"))return i.info("Session creation failed."),this._changeConnectStatus(i.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(i.Status.AUTHFAIL,null),!1},_auth2_cb:function(t){return"result"==t.getAttribute("type")?(this.authenticated=!0,this._changeConnectStatus(i.Status.CONNECTED,null)):"error"==t.getAttribute("type")&&(this._changeConnectStatus(i.Status.AUTHFAIL,null),this.disconnect("authentication failed")),!1},_addSysTimedHandler:function(t,e){var n=new i.TimedHandler(t,e);return n.user=!1,this.addTimeds.push(n),n},_addSysHandler:function(t,e,n,s,r){var o=new i.Handler(t,e,n,s,r);return o.user=!1,this.addHandlers.push(o),o},_onDisconnectTimeout:function(){return i.info("_onDisconnectTimeout was called"),this._proto._onDisconnectTimeout(),this._doDisconnect(),!1},_onIdle:function(){for(var t,e,n;this.addTimeds.length>0;)this.timedHandlers.push(this.addTimeds.pop());for(;this.removeTimeds.length>0;)e=this.removeTimeds.pop(),(t=this.timedHandlers.indexOf(e))>=0&&this.timedHandlers.splice(t,1);var s=(new Date).getTime();for(n=[],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))},_disconnect:function(t){this._sendTerminate(t)},_doDisconnect:function(){this.sid=null,this.rid=Math.floor(4294967295*Math.random()),window.sessionStorage.removeItem("strophe-bosh-session"),this._conn.nextValidRid(this.rid)},_emptyQueue:function(){return 0===this._requests.length},_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()).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())}}},_onRequestStateChange:function(e,n){var s;if(t.debug("request id "+n.id+"."+n.sends+" state changed to "+n.xhr.readyState),n.abort)n.abort=!1;else if(4==n.xhr.readyState){s=0;try{s=n.xhr.status}catch(t){}if(void 0===s&&(s=0),this.disconnecting&&s>=400)return void this._hitError(s);var i=this._requests[0]==n,r=this._requests[1]==n;(s>0&&s<500||n.sends>5)&&(this._removeRequest(n),t.debug("request id "+n.id+" should now be removed")),200==s?((r||i&&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):(t.error("request id "+n.id+"."+n.sends+" error "+s+" happened"),(0===s||s>=400&&s<600||s>=12e3)&&(this._hitError(s),s>=400&&s<500&&(this._conn._changeConnectStatus(t.Status.DISCONNECTING,null),this._conn._doDisconnect()))),s>0&&s<500||n.sends>5||this._throttledRequestHandler()}},_processRequest:function(e){var n=this,s=this._requests[e],i=-1;try{4==s.xhr.readyState&&(i=s.xhr.status)}catch(n){t.error("caught an error in _requests["+e+"], reqStatus: "+i)}if(void 0===i&&(i=-1),s.sends>this._conn.maxRetries)this._conn._onDisconnectTimeout();else{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{s.xhr.open("POST",this._conn.service,!this._conn.options.sync),s.xhr.setRequestHeader("Content-Type","text/xml; charset=utf-8")}catch(e){return t.error("XHR open failed."),this._conn.connected||this._conn._changeConnectStatus(t.Status.CONNFAIL,"bad-service"),void this._conn.disconnect()}var c=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 u=1e3*Math.min(Math.floor(t.TIMEOUT*this.wait),Math.pow(s.sends,3));setTimeout(c,u)}else c();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){var n;for(t.debug("removing request"),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(this._conn._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(" 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 unexcectedly"),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 was disconnected."),this._disconnect()},_onIdle:function(){var e=this._conn._data;if(e.length>0&&!this._conn.paused){for(var n=0;n