strophe.js
Version:
Strophe.js is an XMPP library for JavaScript
1 lines • 63.8 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).strophe={})}(this,function(e){"use strict";var t="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function m(e){return(m="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function a(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),e}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&n(e,t)}function s(e){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function n(e,t){return(n=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function c(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function u(n){var r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}();return function(){var e,t=s(n);return c(this,r?(e=s(this).constructor,Reflect.construct(t,arguments,e)):t.apply(this,arguments))}}function l(e){return function(e){if(Array.isArray(e))return h(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return h(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return h(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function h(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var d=function(){var e=t.WebSocket;if(void 0===e)try{e=require("ws")}catch(e){throw new Error('You must install the "ws" package to use Strophe in nodejs.')}return e}();var _=function(){var e=t.DOMParser;if(void 0===e)try{e=require("xmldom").DOMParser}catch(e){throw new Error('You must install the "xmldom" package to use Strophe in nodejs.')}return e}();function f(){if("undefined"==typeof document)try{return(new(require("xmldom").DOMImplementation)).createDocument("jabber:client","strophe",null)}catch(e){throw new Error('You must install the "xmldom" package to use Strophe in nodejs.')}if(void 0===document.implementation.createDocument||document.implementation.createDocument&&document.documentMode&&document.documentMode<10){var e=function(){for(var e=["Msxml2.DOMDocument.6.0","Msxml2.DOMDocument.5.0","Msxml2.DOMDocument.4.0","MSXML2.DOMDocument.3.0","MSXML2.DOMDocument","MSXML.DOMDocument","Microsoft.XMLDOM"],t=0;t<e.length;t++)try{return new ActiveXObject(e[t])}catch(e){}}();return e.appendChild(e.createElement("strophe")),e}return document.implementation.createDocument("jabber:client","strophe",null)}function p(e,t){var n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n}function g(e){if("string"!=typeof e)throw new Error("str2binl was passed a non-string");for(var t=[],n=0;n<8*e.length;n+=8)t[n>>5]|=(255&e.charCodeAt(n/8))<<n%32;return t}function v(e,t,n,r,s,i){return p((o=p(p(t,e),p(r,i)))<<(a=s)|o>>>32-a,n);var o,a}function y(e,t,n,r,s,i,o){return v(t&n|~t&r,e,t,s,i,o)}function S(e,t,n,r,s,i,o){return v(t&r|n&~r,e,t,s,i,o)}function b(e,t,n,r,s,i,o){return v(t^n^r,e,t,s,i,o)}function T(e,t,n,r,s,i,o){return v(n^(t|~r),e,t,s,i,o)}function x(e,t){e[t>>5]|=128<<t%32,e[14+(t+64>>>9<<4)]=t;for(var n,r,s,i,o=1732584193,a=-271733879,c=-1732584194,u=271733878,l=0;l<e.length;l+=16)o=y(n=o,r=a,s=c,i=u,e[l+0],7,-680876936),u=y(u,o,a,c,e[l+1],12,-389564586),c=y(c,u,o,a,e[l+2],17,606105819),a=y(a,c,u,o,e[l+3],22,-1044525330),o=y(o,a,c,u,e[l+4],7,-176418897),u=y(u,o,a,c,e[l+5],12,1200080426),c=y(c,u,o,a,e[l+6],17,-1473231341),a=y(a,c,u,o,e[l+7],22,-45705983),o=y(o,a,c,u,e[l+8],7,1770035416),u=y(u,o,a,c,e[l+9],12,-1958414417),c=y(c,u,o,a,e[l+10],17,-42063),a=y(a,c,u,o,e[l+11],22,-1990404162),o=y(o,a,c,u,e[l+12],7,1804603682),u=y(u,o,a,c,e[l+13],12,-40341101),c=y(c,u,o,a,e[l+14],17,-1502002290),a=y(a,c,u,o,e[l+15],22,1236535329),o=S(o,a,c,u,e[l+1],5,-165796510),u=S(u,o,a,c,e[l+6],9,-1069501632),c=S(c,u,o,a,e[l+11],14,643717713),a=S(a,c,u,o,e[l+0],20,-373897302),o=S(o,a,c,u,e[l+5],5,-701558691),u=S(u,o,a,c,e[l+10],9,38016083),c=S(c,u,o,a,e[l+15],14,-660478335),a=S(a,c,u,o,e[l+4],20,-405537848),o=S(o,a,c,u,e[l+9],5,568446438),u=S(u,o,a,c,e[l+14],9,-1019803690),c=S(c,u,o,a,e[l+3],14,-187363961),a=S(a,c,u,o,e[l+8],20,1163531501),o=S(o,a,c,u,e[l+13],5,-1444681467),u=S(u,o,a,c,e[l+2],9,-51403784),c=S(c,u,o,a,e[l+7],14,1735328473),a=S(a,c,u,o,e[l+12],20,-1926607734),o=b(o,a,c,u,e[l+5],4,-378558),u=b(u,o,a,c,e[l+8],11,-2022574463),c=b(c,u,o,a,e[l+11],16,1839030562),a=b(a,c,u,o,e[l+14],23,-35309556),o=b(o,a,c,u,e[l+1],4,-1530992060),u=b(u,o,a,c,e[l+4],11,1272893353),c=b(c,u,o,a,e[l+7],16,-155497632),a=b(a,c,u,o,e[l+10],23,-1094730640),o=b(o,a,c,u,e[l+13],4,681279174),u=b(u,o,a,c,e[l+0],11,-358537222),c=b(c,u,o,a,e[l+3],16,-722521979),a=b(a,c,u,o,e[l+6],23,76029189),o=b(o,a,c,u,e[l+9],4,-640364487),u=b(u,o,a,c,e[l+12],11,-421815835),c=b(c,u,o,a,e[l+15],16,530742520),a=b(a,c,u,o,e[l+2],23,-995338651),o=T(o,a,c,u,e[l+0],6,-198630844),u=T(u,o,a,c,e[l+7],10,1126891415),c=T(c,u,o,a,e[l+14],15,-1416354905),a=T(a,c,u,o,e[l+5],21,-57434055),o=T(o,a,c,u,e[l+12],6,1700485571),u=T(u,o,a,c,e[l+3],10,-1894986606),c=T(c,u,o,a,e[l+10],15,-1051523),a=T(a,c,u,o,e[l+1],21,-2054922799),o=T(o,a,c,u,e[l+8],6,1873313359),u=T(u,o,a,c,e[l+15],10,-30611744),c=T(c,u,o,a,e[l+6],15,-1560198380),a=T(a,c,u,o,e[l+13],21,1309151649),o=T(o,a,c,u,e[l+4],6,-145523070),u=T(u,o,a,c,e[l+11],10,-1120210379),c=T(c,u,o,a,e[l+2],15,718787259),a=T(a,c,u,o,e[l+9],21,-343485551),o=p(o,n),a=p(a,r),c=p(c,s),u=p(u,i);return[o,a,c,u]}var N={hexdigest:function(e){return function(e){for(var t="0123456789abcdef",n="",r=0;r<4*e.length;r++)n+=t.charAt(e[r>>2]>>r%4*8+4&15)+t.charAt(e[r>>2]>>r%4*8&15);return n}(x(g(e),8*e.length))},hash:function(e){return function(e){for(var t="",n=0;n<32*e.length;n+=8)t+=String.fromCharCode(e[n>>5]>>>n%32&255);return t}(x(g(e),8*e.length))}},A=function(){function r(e,t,n){o(this,r),this.mechname=e,this.isClientFirst=t,this.priority=n}return a(r,[{key:"test",value:function(){return!0}},{key:"onStart",value:function(e){this._connection=e}},{key:"onChallenge",value:function(){throw new Error("You should implement challenge handling!")}},{key:"clientChallenge",value:function(e){if(!this.isClientFirst)throw new Error("clientChallenge should not be called if isClientFirst is false!");return this.onChallenge(e)}},{key:"onFailure",value:function(){this._connection=null}},{key:"onSuccess",value:function(){this._connection=null}}]),r}(),C=function(){i(s,A);var r=u(s);function s(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"ANONYMOUS",t=1<arguments.length&&void 0!==arguments[1]&&arguments[1],n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:20;return o(this,s),r.call(this,e,t,n)}return a(s,[{key:"test",value:function(e){return null===e.authcid}}]),s}(),w=function(){i(s,A);var r=u(s);function s(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"EXTERNAL",t=!(1<arguments.length&&void 0!==arguments[1])||arguments[1],n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:10;return o(this,s),r.call(this,e,t,n)}return a(s,[{key:"onChallenge",value:function(e){return e.authcid===e.authzid?"":e.authzid}}]),s}(),k={utf16to8:function(e){for(var t,n="",r=e.length,s=0;s<r;s++)0<=(t=e.charCodeAt(s))&&t<=127?n+=e.charAt(s):(2047<t?(n+=String.fromCharCode(224|t>>12&15),n+=String.fromCharCode(128|t>>6&63)):n+=String.fromCharCode(192|t>>6&31),n+=String.fromCharCode(128|t>>0&63));return n},addCookies:function(e){for(var t in e=e||{}){var n,r,s,i,o,a;Object.prototype.hasOwnProperty.call(e,t)&&(s=r=n="",o="object"===m(i=e[t]),a=escape(unescape(o?i.value:i)),o&&(n=i.expires?";expires="+i.expires:"",r=i.domain?";domain="+i.domain:"",s=i.path?";path="+i.path:""),document.cookie=t+"="+a+n+r+s)}}},E=function(){i(s,A);var r=u(s);function s(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"OAUTHBEARER",t=!(1<arguments.length&&void 0!==arguments[1])||arguments[1],n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:40;return o(this,s),r.call(this,e,t,n)}return a(s,[{key:"test",value:function(e){return null!==e.pass}},{key:"onChallenge",value:function(e){var t="n,";return null!==e.authcid&&(t=t+"a="+e.authzid),t+=",",t+="",t+="auth=Bearer ",t+=e.pass,t+="",t+="",k.utf16to8(t)}}]),s}(),O=function(){i(s,A);var r=u(s);function s(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"PLAIN",t=!(1<arguments.length&&void 0!==arguments[1])||arguments[1],n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:50;return o(this,s),r.call(this,e,t,n)}return a(s,[{key:"test",value:function(e){return null!==e.authcid}},{key:"onChallenge",value:function(e){var t=e.authcid,n=e.authzid,r=e.domain,s=e.pass;if(!r)throw new Error("SASLPlain onChallenge: domain is not defined!");var i=n!=="".concat(t,"@").concat(r)?n:"";return i+="\0",i+=t,i+="\0",i+=s,k.utf16to8(i)}}]),s}();function I(e,t){e[t>>5]|=128<<24-t%32,e[15+(t+64>>9<<4)]=t;for(var n,r,s,i,o,a,c,u,l=new Array(80),h=1732584193,d=-271733879,_=-1732584194,f=271733878,m=-1009589776,p=0;p<e.length;p+=16){for(s=h,i=d,o=_,a=f,c=m,n=0;n<80;n++)l[n]=n<16?e[p+n]:M(l[n-3]^l[n-8]^l[n-14]^l[n-16],1),r=H(H(M(h,5),function(e,t,n,r){if(e<20)return t&n|~t&r;if(e<40)return t^n^r;if(e<60)return t&n|t&r|n&r;return t^n^r}(n,d,_,f)),H(H(m,l[n]),(u=n)<20?1518500249:u<40?1859775393:u<60?-1894007588:-899497514)),m=f,f=_,_=M(d,30),d=h,h=r;h=H(h,s),d=H(d,i),_=H(_,o),f=H(f,a),m=H(m,c)}return[h,d,_,f,m]}function R(e,t){var n=L(e);16<n.length&&(n=I(n,8*e.length));for(var r=new Array(16),s=new Array(16),i=0;i<16;i++)r[i]=909522486^n[i],s[i]=1549556828^n[i];var o=I(r.concat(L(t)),512+8*t.length);return I(s.concat(o),672)}function H(e,t){var n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n}function M(e,t){return e<<t|e>>>32-t}function L(e){for(var t=[],n=0;n<8*e.length;n+=8)t[n>>5]|=(255&e.charCodeAt(n/8))<<24-n%32;return t}function q(e){for(var t,n,r="",s=0;s<4*e.length;s+=3)for(t=(e[s>>2]>>8*(3-s%4)&255)<<16|(e[s+1>>2]>>8*(3-(s+1)%4)&255)<<8|e[s+2>>2]>>8*(3-(s+2)%4)&255,n=0;n<4;n++)8*s+6*n>32*e.length?r+="=":r+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(t>>6*(3-n)&63);return r}function D(e){for(var t="",n=0;n<32*e.length;n+=8)t+=String.fromCharCode(e[n>>5]>>>24-n%32&255);return t}var F={b64_hmac_sha1:function(e,t){return q(R(e,t))},b64_sha1:function(e){return q(I(L(e),8*e.length))},binb2str:D,core_hmac_sha1:R,str_hmac_sha1:function(e,t){return D(R(e,t))},str_sha1:function(e){return D(I(L(e),8*e.length))}},j=function(){i(s,A);var r=u(s);function s(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"SCRAM-SHA-1",t=!(1<arguments.length&&void 0!==arguments[1])||arguments[1],n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:60;return o(this,s),r.call(this,e,t,n)}return a(s,[{key:"test",value:function(e){return null!==e.authcid}},{key:"onChallenge",value:function(e,t){for(var n,r,s,i,o,a,c="c=biws,",u="".concat(e._sasl_data["client-first-message-bare"],",").concat(t,","),l=e._sasl_data.cnonce,h=/([a-z]+)=([^,]+)(,|$)/;t.match(h);){var d=t.match(h);switch(t=t.replace(d[0],""),d[1]){case"r":n=d[2];break;case"s":r=d[2];break;case"i":s=d[2]}}if(n.substr(0,l.length)!==l)return e._sasl_data={},e._sasl_failure_cb();u+=c+="r="+n,r=atob(r),r+="\0\0\0";for(var _=k.utf16to8(e.pass),f=o=F.core_hmac_sha1(_,r),m=1;m<s;m++){for(i=F.core_hmac_sha1(_,F.binb2str(o)),a=0;a<5;a++)f[a]^=i[a];o=i}f=F.binb2str(f);var p=F.core_hmac_sha1(f,"Client Key"),g=F.str_hmac_sha1(f,"Server Key"),v=F.core_hmac_sha1(F.str_sha1(F.binb2str(p)),u);for(e._sasl_data["server-signature"]=F.b64_hmac_sha1(g,u),a=0;a<5;a++)p[a]^=v[a];return c+=",p="+btoa(F.binb2str(p))}},{key:"clientChallenge",value:function(e,t){var n=t||N.hexdigest(""+1234567890*Math.random()),r="n="+k.utf16to8(e.authcid);return r+=",r=",r+=n,e._sasl_data.cnonce=n,r="n,,"+(e._sasl_data["client-first-message-bare"]=r)}}]),s}(),B=function(){i(s,A);var r=u(s);function s(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"X-OAUTH2",t=!(1<arguments.length&&void 0!==arguments[1])||arguments[1],n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:30;return o(this,s),r.call(this,e,t,n)}return a(s,[{key:"test",value:function(e){return null!==e.pass}},{key:"onChallenge",value:function(e){var t="\0";return null!==e.authcid&&(t+=e.authzid),t+="\0",t+=e.pass,k.utf16to8(t)}}]),s}();var P={atob:function(e){if((e=(e="".concat(e)).replace(/[ \t\n\f\r]/g,"")).length%4==0&&(e=e.replace(/==?$/,"")),e.length%4==1||/[^+/0-9A-Za-z]/.test(e))return null;for(var t="",n=0,r=0,s=0;s<e.length;s++)n<<=6,n|=function(e){if(/[A-Z]/.test(e))return e.charCodeAt(0)-"A".charCodeAt(0);if(/[a-z]/.test(e))return e.charCodeAt(0)-"a".charCodeAt(0)+26;if(/[0-9]/.test(e))return e.charCodeAt(0)-"0".charCodeAt(0)+52;if("+"===e)return 62;if("/"!==e)return;return 63}(e[s]),24===(r+=6)&&(t+=String.fromCharCode((16711680&n)>>16),t+=String.fromCharCode((65280&n)>>8),t+=String.fromCharCode(255&n),n=r=0);return 12===r?(n>>=4,t+=String.fromCharCode(n)):18===r&&(n>>=2,t+=String.fromCharCode((65280&n)>>8),t+=String.fromCharCode(255&n)),t},btoa:function(e){for(e="".concat(e),n=0;n<e.length;n++)if(255<e.charCodeAt(n))return null;for(var t="",n=0;n<e.length;n+=3){var r=[void 0,void 0,void 0,void 0];r[0]=e.charCodeAt(n)>>2,r[1]=(3&e.charCodeAt(n))<<4,e.length>n+1&&(r[1]|=e.charCodeAt(n+1)>>4,r[2]=(15&e.charCodeAt(n+1))<<2),e.length>n+2&&(r[2]|=e.charCodeAt(n+2)>>6,r[3]=63&e.charCodeAt(n+2));for(var s=0;s<r.length;s++)void 0===r[s]?t+="=":t+=function(e){if(e<26)return String.fromCharCode(e+"A".charCodeAt(0));if(e<52)return String.fromCharCode(e-26+"a".charCodeAt(0));if(e<62)return String.fromCharCode(e-52+"0".charCodeAt(0));if(62===e)return"+";if(63!==e)return;return"/"}(r[s])}return t}};function X(e,t){return new G.Builder(e,t)}function U(e){return new G.Builder("message",e)}function J(e){return new G.Builder("iq",e)}function W(e){return new G.Builder("presence",e)}var G={VERSION:"1.4.2",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(e){for(var t=0;t<G.XHTML.tags.length;t++)if(e===G.XHTML.tags[t])return!0;return!1},validAttribute:function(e,t){if(void 0!==G.XHTML.attributes[e]&&0<G.XHTML.attributes[e].length)for(var n=0;n<G.XHTML.attributes[e].length;n++)if(t===G.XHTML.attributes[e][n])return!0;return!1},validCSS:function(e){for(var t=0;t<G.XHTML.css.length;t++)if(e===G.XHTML.css[t])return!0;return!1}},Status:{ERROR:0,CONNECTING:1,CONNFAIL:2,AUTHENTICATING:3,AUTHFAIL:4,CONNECTED:5,DISCONNECTED:6,DISCONNECTING:7,ATTACHED:8,REDIRECT:9,CONNTIMEOUT:10,BINDREQUIRED:11,ATTACHFAIL:12},ErrorCondition:{BAD_FORMAT:"bad-format",CONFLICT:"conflict",MISSING_JID_NODE:"x-strophe-bad-non-anon-jid",NO_AUTH_MECH:"no-auth-mech",UNKNOWN_REASON:"unknown"},LogLevel:{DEBUG:0,INFO:1,WARN:2,ERROR:3,FATAL:4},ElementType:{NORMAL:1,TEXT:3,CDATA:4,FRAGMENT:11},TIMEOUT:1.1,SECONDARY_TIMEOUT:.1,addNamespace:function(e,t){G.NS[e]=t},forEachChild:function(e,t,n){for(var r=0;r<e.childNodes.length;r++){var s=e.childNodes[r];s.nodeType!==G.ElementType.NORMAL||t&&!this.isTagEqual(s,t)||n(s)}},isTagEqual:function(e,t){return e.tagName===t},_xmlGenerator:null,xmlGenerator:function(){return G._xmlGenerator||(G._xmlGenerator=f()),G._xmlGenerator},xmlElement:function(e){if(!e)return null;for(var t=G.xmlGenerator().createElement(e),n=1;n<arguments.length;n++){var r=arguments[n];if(r)if("string"==typeof r||"number"==typeof r)t.appendChild(G.xmlTextNode(r));else if("object"===m(r)&&"function"==typeof r.sort)for(var s=0;s<r.length;s++){var i=r[s];"object"===m(i)&&"function"==typeof i.sort&&void 0!==i[1]&&null!==i[1]&&t.setAttribute(i[0],i[1])}else if("object"===m(r))for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&void 0!==r[o]&&null!==r[o]&&t.setAttribute(o,r[o])}return t},xmlescape:function(e){return e=(e=(e=(e=(e=e.replace(/\&/g,"&")).replace(/</g,"<")).replace(/>/g,">")).replace(/'/g,"'")).replace(/"/g,""")},xmlunescape:function(e){return e=(e=(e=(e=(e=e.replace(/\&/g,"&")).replace(/</g,"<")).replace(/>/g,">")).replace(/'/g,"'")).replace(/"/g,'"')},xmlTextNode:function(e){return G.xmlGenerator().createTextNode(e)},xmlHtmlNode:function(e){var t;return _?t=(new _).parseFromString(e,"text/xml"):((t=new ActiveXObject("Microsoft.XMLDOM")).async="false",t.loadXML(e)),t},getText:function(e){if(!e)return null;var t="";0===e.childNodes.length&&e.nodeType===G.ElementType.TEXT&&(t+=e.nodeValue);for(var n=0;n<e.childNodes.length;n++)e.childNodes[n].nodeType===G.ElementType.TEXT&&(t+=e.childNodes[n].nodeValue);return G.xmlescape(t)},copyElement:function(e){var t;if(e.nodeType===G.ElementType.NORMAL){t=G.xmlElement(e.tagName);for(var n=0;n<e.attributes.length;n++)t.setAttribute(e.attributes[n].nodeName,e.attributes[n].value);for(var r=0;r<e.childNodes.length;r++)t.appendChild(G.copyElement(e.childNodes[r]))}else e.nodeType===G.ElementType.TEXT&&(t=G.xmlGenerator().createTextNode(e.nodeValue));return t},createHtml:function(e){var t;if(e.nodeType===G.ElementType.NORMAL){var n=e.nodeName.toLowerCase();if(G.XHTML.validTag(n))try{t=G.xmlElement(n);for(var r=0;r<G.XHTML.attributes[n].length;r++){var s=G.XHTML.attributes[n][r],i=e.getAttribute(s);if(null!=i&&""!==i&&!1!==i&&0!==i)if("style"===s&&"object"===m(i)&&void 0!==i.cssText&&(i=i.cssText),"style"===s){for(var o=[],a=i.split(";"),c=0;c<a.length;c++){var u,l=a[c].split(":"),h=l[0].replace(/^\s*/,"").replace(/\s*$/,"").toLowerCase();G.XHTML.validCSS(h)&&(u=l[1].replace(/^\s*/,"").replace(/\s*$/,""),o.push(h+": "+u))}0<o.length&&(i=o.join("; "),t.setAttribute(s,i))}else t.setAttribute(s,i)}for(var d=0;d<e.childNodes.length;d++)t.appendChild(G.createHtml(e.childNodes[d]))}catch(e){t=G.xmlTextNode("")}else{t=G.xmlGenerator().createDocumentFragment();for(var _=0;_<e.childNodes.length;_++)t.appendChild(G.createHtml(e.childNodes[_]))}}else if(e.nodeType===G.ElementType.FRAGMENT){t=G.xmlGenerator().createDocumentFragment();for(var f=0;f<e.childNodes.length;f++)t.appendChild(G.createHtml(e.childNodes[f]))}else e.nodeType===G.ElementType.TEXT&&(t=G.xmlTextNode(e.nodeValue));return t},escapeNode:function(e){return"string"!=typeof e?e:e.replace(/^\s+|\s+$/g,"").replace(/\\/g,"\\5c").replace(/ /g,"\\20").replace(/\"/g,"\\22").replace(/\&/g,"\\26").replace(/\'/g,"\\27").replace(/\//g,"\\2f").replace(/:/g,"\\3a").replace(/</g,"\\3c").replace(/>/g,"\\3e").replace(/@/g,"\\40")},unescapeNode:function(e){return"string"!=typeof e?e:e.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(e){return e.indexOf("@")<0?null:e.split("@")[0]},getDomainFromJid:function(e){var t=G.getBareJidFromJid(e);if(t.indexOf("@")<0)return t;var n=t.split("@");return n.splice(0,1),n.join("@")},getResourceFromJid:function(e){if(!e)return null;var t=e.split("/");return t.length<2?null:(t.splice(0,1),t.join("/"))},getBareJidFromJid:function(e){return e?e.split("/")[0]:null},_handleError:function(e){void 0!==e.stack&&G.fatal(e.stack),e.sourceURL?G.fatal("error: "+this.handler+" "+e.sourceURL+":"+e.line+" - "+e.name+": "+e.message):e.fileName?G.fatal("error: "+this.handler+" "+e.fileName+":"+e.lineNumber+" - "+e.name+": "+e.message):G.fatal("error: "+e.message)},log:function(e,t){var n;e===this.LogLevel.FATAL&&null!==(n=console)&&void 0!==n&&n.error(t)},debug:function(e){this.log(this.LogLevel.DEBUG,e)},info:function(e){this.log(this.LogLevel.INFO,e)},warn:function(e){this.log(this.LogLevel.WARN,e)},error:function(e){this.log(this.LogLevel.ERROR,e)},fatal:function(e){this.log(this.LogLevel.FATAL,e)},serialize:function(n){if(!n)return null;"function"==typeof n.tree&&(n=n.tree());var e=l(Array(n.attributes.length).keys()).map(function(e){return n.attributes[e].nodeName});e.sort();var t=e.reduce(function(e,t){return"".concat(e," ").concat(t,'="').concat(G.xmlescape(n.attributes.getNamedItem(t).value),'"')},"<".concat(n.nodeName));if(0<n.childNodes.length){t+=">";for(var r=0;r<n.childNodes.length;r++){var s=n.childNodes[r];switch(s.nodeType){case G.ElementType.NORMAL:t+=G.serialize(s);break;case G.ElementType.TEXT:t+=G.xmlescape(s.nodeValue);break;case G.ElementType.CDATA:t+="<![CDATA["+s.nodeValue+"]]>"}}t+="</"+n.nodeName+">"}else t+="/>";return t},_requestId:0,_connectionPlugins:{},addConnectionPlugin:function(e,t){G._connectionPlugins[e]=t}};G.Builder=function(){function n(e,t){o(this,n),"presence"!==e&&"message"!==e&&"iq"!==e||(t&&!t.xmlns?t.xmlns=G.NS.CLIENT:t=t||{xmlns:G.NS.CLIENT}),this.nodeTree=G.xmlElement(e,t),this.node=this.nodeTree}return a(n,[{key:"tree",value:function(){return this.nodeTree}},{key:"toString",value:function(){return G.serialize(this.nodeTree)}},{key:"up",value:function(){return this.node=this.node.parentNode,this}},{key:"root",value:function(){return this.node=this.nodeTree,this}},{key:"attrs",value:function(e){for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&(void 0===e[t]?this.node.removeAttribute(t):this.node.setAttribute(t,e[t]));return this}},{key:"c",value:function(e,t,n){var r=G.xmlElement(e,t,n);return this.node.appendChild(r),"string"!=typeof n&&"number"!=typeof n&&(this.node=r),this}},{key:"cnode",value:function(e){var t,n=G.xmlGenerator();try{t=void 0!==n.importNode}catch(e){t=!1}var r=t?n.importNode(e,!0):G.copyElement(e);return this.node.appendChild(r),this.node=r,this}},{key:"t",value:function(e){var t=G.xmlTextNode(e);return this.node.appendChild(t),this}},{key:"h",value:function(e){var t=G.xmlGenerator().createElement("body");t.innerHTML=e;for(var n=G.createHtml(t);0<n.childNodes.length;)this.node.appendChild(n.childNodes[0]);return this}}]),n}(),G.Handler=function(e,t,n,r,s,i,o){this.handler=e,this.ns=t,this.name=n,this.type=r,this.id=s,this.options=o||{matchBareFromJid:!1,ignoreNamespaceFragment:!1},this.options.matchBare&&(G.warn('The "matchBare" option is deprecated, use "matchBareFromJid" instead.'),this.options.matchBareFromJid=this.options.matchBare,delete this.options.matchBare),this.options.matchBareFromJid?this.from=i?G.getBareJidFromJid(i):null:this.from=i,this.user=!0},G.Handler.prototype={getNamespace:function(e){var t=e.getAttribute("xmlns");return t&&this.options.ignoreNamespaceFragment&&(t=t.split("#")[0]),t},namespaceMatch:function(e){var t=this,n=!1;return!this.ns||(G.forEachChild(e,null,function(e){t.getNamespace(e)===t.ns&&(n=!0)}),n||this.getNamespace(e)===this.ns)},isMatch:function(e){var t=e.getAttribute("from");this.options.matchBareFromJid&&(t=G.getBareJidFromJid(t));var n=e.getAttribute("type");return!(!this.namespaceMatch(e)||this.name&&!G.isTagEqual(e,this.name)||this.type&&(Array.isArray(this.type)?-1===this.type.indexOf(n):n!==this.type)||this.id&&e.getAttribute("id")!==this.id||this.from&&t!==this.from)},run:function(e){var t=null;try{t=this.handler(e)}catch(e){throw G._handleError(e),e}return t},toString:function(){return"{Handler: "+this.handler+"("+this.name+","+this.id+","+this.ns+")}"}},G.TimedHandler=function(){function n(e,t){o(this,n),this.period=e,this.handler=t,this.lastCalled=(new Date).getTime(),this.user=!0}return a(n,[{key:"run",value:function(){return this.lastCalled=(new Date).getTime(),this.handler()}},{key:"reset",value:function(){this.lastCalled=(new Date).getTime()}},{key:"toString",value:function(){return"{TimedHandler: "+this.handler+"("+this.period+")}"}}]),n}(),G.Connection=function(){function i(e,t){var n,r=this;for(var s in o(this,i),this.service=e,this.options=t||{},this.setProtocol(),this.jid="",this.domain=null,this.features=null,this._sasl_data={},this.do_bind=!1,this.do_session=!1,this.mechanisms={},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(){return r._onIdle()},100),k.addCookies(this.options.cookies),this.registerSASLMechanisms(this.options.mechanisms),G._connectionPlugins){Object.prototype.hasOwnProperty.call(G._connectionPlugins,s)&&((n=function(){}).prototype=G._connectionPlugins[s],this[s]=new n,this[s].init(this))}}return a(i,[{key:"setProtocol",value:function(){var e=this.options.protocol||"";this.options.worker?this._proto=new G.WorkerWebsocket(this):0===this.service.indexOf("ws:")||0===this.service.indexOf("wss:")||0===e.indexOf("ws")?this._proto=new G.Websocket(this):this._proto=new G.Bosh(this)}},{key:"reset",value: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}},{key:"pause",value:function(){this.paused=!0}},{key:"resume",value:function(){this.paused=!1}},{key:"getUniqueId",value:function(e){var t="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)});return"string"==typeof e||"number"==typeof e?t+":"+e:t+""}},{key:"addProtocolErrorHandler",value:function(e,t,n){this.protocolErrorHandlers[e][t]=n}},{key:"connect",value:function(e,t,n,r,s,i,o){this.jid=e,this.authzid=G.getBareJidFromJid(this.jid),this.authcid=o||G.getNodeFromJid(this.jid),this.pass=t,this.connect_callback=n,this.disconnecting=!1,this.connected=!1,this.authenticated=!1,this.restored=!1,this.domain=G.getDomainFromJid(this.jid),this._changeConnectStatus(G.Status.CONNECTING,null),this._proto._connect(r,s,i)}},{key:"attach",value:function(e,t,n,r,s,i,o){if(this._proto._attach)return this._proto._attach(e,t,n,r,s,i,o);var a=new Error('The "attach" method is not available for your connection protocol');throw a.name="StropheSessionError",a}},{key:"restore",value:function(e,t,n,r,s){if(!this._sessionCachingSupported()){var i=new Error('The "restore" method can only be used with a BOSH connection.');throw i.name="StropheSessionError",i}this._proto._restore(e,t,n,r,s)}},{key:"_sessionCachingSupported",value:function(){if(this._proto instanceof G.Bosh){if(!JSON)return!1;try{sessionStorage.setItem("_strophe_","_strophe_"),sessionStorage.removeItem("_strophe_")}catch(e){return!1}return!0}return!1}},{key:"xmlInput",value:function(){}},{key:"xmlOutput",value:function(){}},{key:"rawInput",value:function(){}},{key:"rawOutput",value:function(){}},{key:"nextValidRid",value:function(){}},{key:"send",value:function(e){if(null!==e){if("function"==typeof e.sort)for(var t=0;t<e.length;t++)this._queueData(e[t]);else"function"==typeof e.tree?this._queueData(e.tree()):this._queueData(e);this._proto._send()}}},{key:"flush",value:function(){clearTimeout(this._idleTimeout),this._onIdle()}},{key:"sendPresence",value:function(e,t,n,r){var s=this,i=null;"function"==typeof e.tree&&(e=e.tree());var o,a=e.getAttribute("id");return a||(a=this.getUniqueId("sendPresence"),e.setAttribute("id",a)),"function"!=typeof t&&"function"!=typeof n||(o=this.addHandler(function(e){i&&s.deleteTimedHandler(i),"error"===e.getAttribute("type")?n&&n(e):t&&t(e)},null,"presence",null,a),r&&(i=this.addTimedHandler(r,function(){return s.deleteHandler(o),n&&n(null),!1}))),this.send(e),a}},{key:"sendIQ",value:function(e,r,s,t){var i=this,o=null;"function"==typeof e.tree&&(e=e.tree());var n,a=e.getAttribute("id");return a||(a=this.getUniqueId("sendIQ"),e.setAttribute("id",a)),"function"!=typeof r&&"function"!=typeof s||(n=this.addHandler(function(e){o&&i.deleteTimedHandler(o);var t=e.getAttribute("type");if("result"===t)r&&r(e);else{if("error"!==t){var n=new Error("Got bad IQ type of ".concat(t));throw n.name="StropheError",n}s&&s(e)}},null,"iq",["error","result"],a),t&&(o=this.addTimedHandler(t,function(){return i.deleteHandler(n),s&&s(null),!1}))),this.send(e),a}},{key:"_queueData",value:function(e){if(null===e||!e.tagName||!e.childNodes){var t=new Error("Cannot queue non-DOMElement.");throw t.name="StropheError",t}this._data.push(e)}},{key:"_sendRestart",value:function(){var e=this;this._data.push("restart"),this._proto._sendRestart(),this._idleTimeout=setTimeout(function(){return e._onIdle()},100)}},{key:"addTimedHandler",value:function(e,t){var n=new G.TimedHandler(e,t);return this.addTimeds.push(n),n}},{key:"deleteTimedHandler",value:function(e){this.removeTimeds.push(e)}},{key:"addHandler",value:function(e,t,n,r,s,i,o){var a=new G.Handler(e,t,n,r,s,i,o);return this.addHandlers.push(a),a}},{key:"deleteHandler",value:function(e){this.removeHandlers.push(e);var t=this.addHandlers.indexOf(e);0<=t&&this.addHandlers.splice(t,1)}},{key:"registerSASLMechanisms",value:function(e){var t=this;this.mechanisms={},(e=e||[G.SASLAnonymous,G.SASLExternal,G.SASLOAuthBearer,G.SASLXOAuth2,G.SASLPlain,G.SASLSHA1]).forEach(function(e){return t.registerSASLMechanism(e)})}},{key:"registerSASLMechanism",value:function(e){var t=new e;this.mechanisms[t.mechname]=t}},{key:"disconnect",value:function(e){var t;this._changeConnectStatus(G.Status.DISCONNECTING,e),e?G.warn("Disconnect was called because: "+e):G.info("Disconnect was called"),this.connected?(t=!1,this.disconnecting=!0,this.authenticated&&(t=W({xmlns:G.NS.CLIENT,type:"unavailable"})),this._disconnectTimeout=this._addSysTimedHandler(3e3,this._onDisconnectTimeout.bind(this)),this._proto._disconnect(t)):(G.warn("Disconnect was called before Strophe connected to the server"),this._proto._abortAllRequests(),this._doDisconnect())}},{key:"_changeConnectStatus",value:function(e,t,n){for(var r in G._connectionPlugins)if(Object.prototype.hasOwnProperty.call(G._connectionPlugins,r)){var s=this[r];if(s.statusChanged)try{s.statusChanged(e,t)}catch(e){G.error("".concat(r," plugin caused an exception changing status: ").concat(e))}}if(this.connect_callback)try{this.connect_callback(e,t,n)}catch(e){G._handleError(e),G.error("User connection callback caused an exception: ".concat(e))}}},{key:"_doDisconnect",value:function(e){"number"==typeof this._idleTimeout&&clearTimeout(this._idleTimeout),null!==this._disconnectTimeout&&(this.deleteTimedHandler(this._disconnectTimeout),this._disconnectTimeout=null),G.debug("_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(G.Status.DISCONNECTED,e),this.connected=!1}},{key:"_dataRecv",value:function(e,t){var s=this,n=this._proto._reqToData(e);if(null!==n){for(this.xmlInput!==G.Connection.prototype.xmlInput&&(n.nodeName===this._proto.strip&&n.childNodes.length?this.xmlInput(n.childNodes[0]):this.xmlInput(n)),this.rawInput!==G.Connection.prototype.rawInput&&(t?this.rawInput(t):this.rawInput(G.serialize(n)));0<this.removeHandlers.length;){var r=this.removeHandlers.pop(),i=this.handlers.indexOf(r);0<=i&&this.handlers.splice(i,1)}for(;0<this.addHandlers.length;)this.handlers.push(this.addHandlers.pop());if(this.disconnecting&&this._proto._emptyQueue())this._doDisconnect();else{var o=n.getAttribute("type");if(null!==o&&"terminate"===o){if(this.disconnecting)return;var a=n.getAttribute("condition"),c=n.getElementsByTagName("conflict");return null!==a?("remote-stream-error"===a&&0<c.length&&(a="conflict"),this._changeConnectStatus(G.Status.CONNFAIL,a)):this._changeConnectStatus(G.Status.CONNFAIL,G.ErrorCondition.UNKOWN_REASON),void this._doDisconnect(a)}G.forEachChild(n,null,function(e){var t=s.handlers;s.handlers=[];for(var n=0;n<t.length;n++){var r=t[n];try{(!r.isMatch(e)||!s.authenticated&&r.user||r.run(e))&&s.handlers.push(r)}catch(e){G.warn("Removing Strophe handlers due to uncaught exception: "+e.message)}}})}}}},{key:"_connect_cb",value:function(e,t,n){var r,s,i=this;G.debug("_connect_cb was called"),this.connected=!0;try{r=this._proto._reqToData(e)}catch(e){if(e.name!==G.ErrorCondition.BAD_FORMAT)throw e;this._changeConnectStatus(G.Status.CONNFAIL,G.ErrorCondition.BAD_FORMAT),this._doDisconnect(G.ErrorCondition.BAD_FORMAT)}r&&(this.xmlInput!==G.Connection.prototype.xmlInput&&(r.nodeName===this._proto.strip&&r.childNodes.length?this.xmlInput(r.childNodes[0]):this.xmlInput(r)),this.rawInput!==G.Connection.prototype.rawInput&&(n?this.rawInput(n):this.rawInput(G.serialize(r))),this._proto._connect_cb(r)!==G.Status.CONNFAIL&&((r.getElementsByTagNameNS?0<r.getElementsByTagNameNS(G.NS.STREAM,"features").length:0<r.getElementsByTagName("stream:features").length||0<r.getElementsByTagName("features").length)&&(0!==(s=Array.from(r.getElementsByTagName("mechanism")).map(function(e){return i.mechanisms[e.textContent]}).filter(function(e){return e})).length||0!==r.getElementsByTagName("auth").length)?!1!==this.do_authentication&&this.authenticate(s):this._proto._no_auth_received(t)))}},{key:"sortMechanismsByPriority",value:function(e){for(var t=0;t<e.length-1;++t){for(var n,r=t,s=t+1;s<e.length;++s)e[s].priority>e[r].priority&&(r=s);r!==t&&(n=e[t],e[t]=e[r],e[r]=n)}return e}},{key:"authenticate",value:function(e){this._attemptSASLAuth(e)||this._attemptLegacyAuth()}},{key:"_attemptSASLAuth",value:function(e){e=this.sortMechanismsByPriority(e||[]);for(var t=!1,n=0;n<e.length;++n)if(e[n].test(this)){this._sasl_success_handler=this._addSysHandler(this._sasl_success_cb.bind(this),null,"success",null,null),this._sasl_failure_handler=this._addSysHandler(this._sasl_failure_cb.bind(this),null,"failure",null,null),this._sasl_challenge_handler=this._addSysHandler(this._sasl_challenge_cb.bind(this),null,"challenge",null,null),this._sasl_mechanism=e[n],this._sasl_mechanism.onStart(this);var r,s=X("auth",{xmlns:G.NS.SASL,mechanism:this._sasl_mechanism.mechname});this._sasl_mechanism.isClientFirst&&(r=this._sasl_mechanism.clientChallenge(this),s.t(P.btoa(r))),this.send(s.tree()),t=!0;break}return t}},{key:"_sasl_challenge_cb",value:function(e){var t=P.atob(G.getText(e)),n=this._sasl_mechanism.onChallenge(this,t),r=X("response",{xmlns:G.NS.SASL});return""!==n&&r.t(P.btoa(n)),this.send(r.tree()),!0}},{key:"_attemptLegacyAuth",value:function(){null===G.getNodeFromJid(this.jid)?(this._changeConnectStatus(G.Status.CONNFAIL,G.ErrorCondition.MISSING_JID_NODE),this.disconnect(G.ErrorCondition.MISSING_JID_NODE)):(this._changeConnectStatus(G.Status.AUTHENTICATING,null),this._addSysHandler(this._onLegacyAuthIQResult.bind(this),null,null,null,"_auth_1"),this.send(J({type:"get",to:this.domain,id:"_auth_1"}).c("query",{xmlns:G.NS.AUTH}).c("username",{}).t(G.getNodeFromJid(this.jid)).tree()))}},{key:"_onLegacyAuthIQResult",value:function(){var e=J({type:"set",id:"_auth_2"}).c("query",{xmlns:G.NS.AUTH}).c("username",{}).t(G.getNodeFromJid(this.jid)).up().c("password").t(this.pass);return G.getResourceFromJid(this.jid)||(this.jid=G.getBareJidFromJid(this.jid)+"/strophe"),e.up().c("resource",{}).t(G.getResourceFromJid(this.jid)),this._addSysHandler(this._auth2_cb.bind(this),null,null,null,"_auth_2"),this.send(e.tree()),!1}},{key:"_sasl_success_cb",value:function(e){var n=this;if(this._sasl_data["server-signature"]){var t,r=P.atob(G.getText(e)).match(/([a-z]+)=([^,]+)(,|$)/);if("v"===r[1]&&(t=r[2]),t!==this._sasl_data["server-signature"])return this.deleteHandler(this._sasl_failure_handler),this._sasl_failure_handler=null,this._sasl_challenge_handler&&(this.deleteHandler(this._sasl_challenge_handler),this._sasl_challenge_handler=null),this._sasl_data={},this._sasl_failure_cb(null)}G.info("SASL authentication succeeded."),this._sasl_mechanism&&this._sasl_mechanism.onSuccess(),this.deleteHandler(this._sasl_failure_handler),this._sasl_failure_handler=null,this._sasl_challenge_handler&&(this.deleteHandler(this._sasl_challenge_handler),this._sasl_challenge_handler=null);function s(e,t){for(;e.length;)n.deleteHandler(e.pop());return n._onStreamFeaturesAfterSASL(t),!1}var i=[];return i.push(this._addSysHandler(function(e){return s(i,e)},null,"stream:features",null,null)),i.push(this._addSysHandler(function(e){return s(i,e)},G.NS.STREAM,"features",null,null)),this._sendRestart(),!1}},{key:"_onStreamFeaturesAfterSASL",value:function(e){this.features=e;for(var t=0;t<e.childNodes.length;t++){var n=e.childNodes[t];"bind"===n.nodeName&&(this.do_bind=!0),"session"===n.nodeName&&(this.do_session=!0)}return this.do_bind?this.options.explicitResourceBinding?this._changeConnectStatus(G.Status.BINDREQUIRED,null):this.bind():this._changeConnectStatus(G.Status.AUTHFAIL,null),!1}},{key:"bind",value:function(){var e;this.do_bind?(this._addSysHandler(this._onResourceBindResultIQ.bind(this),null,null,null,"_bind_auth_2"),(e=G.getResourceFromJid(this.jid))?this.send(J({type:"set",id:"_bind_auth_2"}).c("bind",{xmlns:G.NS.BIND}).c("resource",{}).t(e).tree()):this.send(J({type:"set",id:"_bind_auth_2"}).c("bind",{xmlns:G.NS.BIND}).tree())):G.log(G.LogLevel.INFO,'Strophe.Connection.prototype.bind called but "do_bind" is false')}},{key:"_onResourceBindResultIQ",value:function(e){var t;if("error"===e.getAttribute("type"))return G.warn("Resource binding failed."),0<e.getElementsByTagName("conflict").length&&(t=G.ErrorCondition.CONFLICT),this._changeConnectStatus(G.Status.AUTHFAIL,t,e),!1;var n=e.getElementsByTagName("bind");if(!(0<n.length))return G.warn("Resource binding failed."),this._changeConnectStatus(G.Status.AUTHFAIL,null,e),!1;var r=n[0].getElementsByTagName("jid");0<r.length&&(this.authenticated=!0,this.jid=G.getText(r[0]),this.do_session?this._establishSession():this._changeConnectStatus(G.Status.CONNECTED,null))}},{key:"_establishSession",value:function(){if(!this.do_session)throw new Error("Strophe.Connection.prototype._establishSession "+"called but apparently ".concat(G.NS.SESSION," wasn't advertised by the server"));this._addSysHandler(this._onSessionResultIQ.bind(this),null,null,null,"_session_auth_2"),this.send(J({type:"set",id:"_session_auth_2"}).c("session",{xmlns:G.NS.SESSION}).tree())}},{key:"_onSessionResultIQ",value:function(e){if("result"===e.getAttribute("type"))this.authenticated=!0,this._changeConnectStatus(G.Status.CONNECTED,null);else if("error"===e.getAttribute("type"))return this.authenticated=!1,G.warn("Session creation failed."),this._changeConnectStatus(G.Status.AUTHFAIL,null,e),!1;return!1}},{key:"_sasl_failure_cb",value:function(e){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(G.Status.AUTHFAIL,null,e),!1}},{key:"_auth2_cb",value:function(e){return"result"===e.getAttribute("type")?(this.authenticated=!0,this._changeConnectStatus(G.Status.CONNECTED,null)):"error"===e.getAttribute("type")&&(this._changeConnectStatus(G.Status.AUTHFAIL,null,e),this.disconnect("authentication failed")),!1}},{key:"_addSysTimedHandler",value:function(e,t){var n=new G.TimedHandler(e,t);return n.user=!1,this.addTimeds.push(n),n}},{key:"_addSysHandler",value:function(e,t,n,r,s){var i=new G.Handler(e,t,n,r,s);return i.user=!1,this.addHandlers.push(i),i}},{key:"_onDisconnectTimeout",value:function(){return G.debug("_onDisconnectTimeout was called"),this._changeConnectStatus(G.Status.CONNTIMEOUT,null),this._proto._onDisconnectTimeout(),this._doDisconnect(),!1}},{key:"_onIdle",value:function(){for(var e=this;0<this.addTimeds.length;)this.timedHandlers.push(this.addTimeds.pop());for(;0<this.removeTimeds.length;){var t=this.removeTimeds.pop(),n=this.timedHandlers.indexOf(t);0<=n&&this.timedHandlers.splice(n,1)}for(var r=(new Date).getTime(),s=[],i=0;i<this.timedHandlers.length;i++){var o=this.timedHandlers[i];!this.authenticated&&o.user||o.lastCalled+o.period-r<=0&&!o.run()||s.push(o)}this.timedHandlers=s,clearTimeout(this._idleTimeout),this._proto._onIdle(),this.connected&&(this._idleTimeout=setTimeout(function(){return e._onIdle()},100))}}]),i}(),G.SASLMechanism=A,G.SASLAnonymous=C,G.SASLPlain=O,G.SASLSHA1=j,G.SASLOAuthBearer=E,G.SASLExternal=w,G.SASLXOAuth2=B;var z={Strophe:G,$build:X,$iq:J,$msg:U,$pres:W,SHA1:F,MD5:N,b64_hmac_sha1:F.b64_hmac_sha1,b64_sha1:F.b64_sha1,str_hmac_sha1:F.str_hmac_sha1,str_sha1:F.str_sha1};G.Request=function(){function s(e,t,n,r){o(this,s),this.id=++G._requestId,this.xmlData=e,this.data=G.serialize(e),this.origFunc=t,this.func=t,this.rid=n,this.date=NaN,this.sends=r||0,this.abort=!1,this.dead=null,this.age=function(){return this.date?(new Date-this.date)/1e3:0},this.timeDead=function(){return this.dead?(new Date-this.dead)/1e3:0},this.xhr=this._newXHR()}return a(s,[{key:"getResponse",value:function(){var e=null;if(this.xhr.responseXML&&this.xhr.responseXML.documentElement){if("parsererror"===(e=this.xhr.responseXML.documentElement).tagName)throw G.error("invalid response received"),G.error("responseText: "+this.xhr.responseText),G.error("responseXML: "+G.serialize(this.xhr.responseXML)),new Error("parsererror")}else if(this.xhr.responseText){if(G.debug("Got responseText but no responseXML; attempting to parse it with DOMParser..."),!(e=(new _).parseFromString(this.xhr.responseText,"application/xml").documentElement))throw new Error("Parsing produced null node");if(e.querySelector("parsererror")){G.error("invalid response received: "+e.querySelector("parsererror").textContent),G.error("responseText: "+this.xhr.responseText);var t=new Error;throw t.name=G.ErrorCondition.BAD_FORMAT,t}}return e}},{key:"_newXHR",value:function(){var e=null;return window.XMLHttpRequest?(e=new XMLHttpRequest).overrideMimeType&&e.overrideMimeType("text/xml; charset=utf-8"):window.ActiveXObject&&(e=new ActiveXObject("Microsoft.XMLHTTP")),e.onreadystatechange=this.func.bind(null,this),e}}]),s}(),G.Bosh=function(){function h(e){o(this,h),this._conn=e,this.rid=Math.floor(4294967295*Math.random()),this.sid=null,this.hold=1,this.wait=60,this.window=5,this.errors=0,this.inactivity=null,this.lastResponseHeaders=null,this._requests=[]}return a(h,[{key:"_buildBody",value:function(){var e=X("body",{rid:this.rid++,xmlns:G.NS.HTTPBIND});return null!==this.sid&&e.attrs({sid:this.sid}),this._conn.options.keepalive&&this._conn._sessionCachingSupported()&&this._cacheSession(),e}},{key:"_reset",value:function(){this.rid=Math.floor(4294967295*Math.random()),this.sid=null,this.errors=0,this._conn._sessionCachingSupported()&&window.sessionStorage.removeItem("strophe-bosh-session"),this._conn.nextValidRid(this.rid)}},{key:"_connect",value:function(e,t,n){this.wait=e||this.wait,this.hold=t||this.hold,this.errors=0;var r=this._buildBody().attrs({to:this._conn.domain,"xml:lang":"en",wait:this.wait,hold:this.hold,content:"text/xml; charset=utf-8",ver:"1.6","xmpp:version":"1.0","xmlns:xmpp":G.NS.BOSH});n&&r.attrs({route:n});var s=this._conn._connect_cb;this._requests.push(new G.Request(r.tree(),this._onRequestStateChange.bind(this,s.bind(this._conn)),r.tree().getAttribute("rid"))),this._throttledRequestHandler()}},{key:"_attach",value:function(e,t,n,r,s,i,o){this._conn.jid=e,this.sid=t,this.rid=n,this._conn.connect_callback=r,this._conn.domain=G.getDomainFromJid(this._conn.jid),this._conn.authenticated=!0,this._conn.connected=!0,this.wait=s||this.wait,this.hold=i||this.hold,this.window=o||this.window,this._conn._changeConnectStatus(G.Status.ATTACHED,null)}},{key:"_restore",value:function(e,t,n,r,s){var i=JSON.parse(window.sessionStorage.getItem("strophe-bosh-session"));if(!(null!=i&&i.rid&&i.sid&&i.jid&&(null==e||G.getBareJidFromJid(i.jid)===G.getBareJidFromJid(e)||null===G.getNodeFromJid(e)&&G.getDomainFromJid(i.jid)===e))){var o=new Error("_restore: no restoreable session.");throw o.name="StropheSessionError",o}this._conn.restored=!0,this._attach(i.jid,i.sid,i.rid,t,n,r,s)}},{key:"_cacheSession",value:function(){this._conn.authenticated?this._conn.jid&&this.rid&&this.sid&&window.sessionStorage.setItem("strophe-bosh-session",JSON.stringify({jid:this._conn.jid,rid:this.rid,sid:this.sid})):window.sessionStorage.removeItem("strophe-bosh-session")}},{key:"_connect_cb",value:function(e){var t=e.getAttribute("type");if(null!==t&&"terminate"===t){var n=e.getAttribute("condition");G.error("BOSH-Connection failed: "+n);var r=e.getElementsByTagName("conflict");return null!==n?("remote-stream-error"===n&&0<r.length&&(n="conflict"),this._conn._changeConnectStatus(G.Status.CONNFAIL,n)):this._conn._changeConnectStatus(G.Status.CONNFAIL,"unknown"),this._conn._doDisconnect(n),G.Status.CONNFAIL}this.sid||(this.sid=e.getAttribute("sid"));var s=e.getAttribute("requests");s&&(this.window=parseInt(s,10));var i=e.getAttribute("hold");i&&(this.hold=parseInt(i,10));var o=e.getAttribute("wait");o&&(this.wait=parseInt(o,10));var a=e.getAttribute("inactivity");a&&(this.inactivity=parseInt(a,10))}},{key:"_disconnect",value:function(e){this._sendTerminate(e)}},{key:"_doDisconnect",value: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)}},{key:"_emptyQueue",value:function(){return 0===this._requests.length}},{key:"_callProtocolErrorHandlers",value:function(e){var t=h._getRequestStatus(e),n=this._conn.protocolErrorHandlers.HTTP[t];n&&n.call(this,t)}},{key:"_hitError",value:function(e){this.errors++,G.warn("request errored, status: "+e+", number of errors: "+this.errors),4<this.errors&&this._conn._onDisconnectTimeout()}},{key:"_no_auth_received",value:function(e){G.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 t=this._buildBody();this._requests.push(new G.Request(t.tree(),this._onRequestStateChange.bind(this,e),t.tree().getAttribute("rid"))),this._throttledRequestHandler()}},{key:"_onDisconnectTimeout",value:function(){this._abortAllRequests()}},{key:"_abortAllRequests",value:function(){for(;0<this._requests.length;){var e=this._requests.pop();e.abort=!0,e.xhr.abort(),e.xhr.onreadystatechange=function(){}}}},{key:"_onIdle",value:function(){var e,t=this._conn._data;if(this._conn.authenticated&&0===this._requests.length&&0===t.length&&!this._conn.disconnecting&&(G.debug("no requests during idle cycle, sending blank request"),t.push(null)),!this._conn.paused){if(this._requests.length<2&&0<t.length){for(var n=this._buildBody(),r=0;r<t.length;r++)null!==t[r]&&("restart"===t[r]?n.attrs({to:this._conn.domain,"xml:lang":"en","xmpp:restart":"true","xmlns:xmpp":G.NS.BOSH}):n.cnode(t[r]).up());delete this._conn._data,this._conn._data=[],this._requests.push(new G.Request(n.tree(),this._onRequestStateChange.bind(this,this._conn._dataRecv.bind(this._conn)),n.tree().getAttribute("rid"))),this._throttledRequestHandler()}0<this._requests.length&&(e=this._requests[0].age(),null!==this._requests[0].dead&&this._requests[0].timeDead()>Math.floor(G.SECONDARY_TIMEOUT*this.wait)&&this._throttledRequestHandler(),e>Math.floor(G.TIMEOUT*this.wait)&&(G.warn("Request "+this._requests[0].id+" timed out, over "+Math.floor(G.TIMEOUT*this.wait)+" seconds since last activity"),this._throttledRequestHandler()))}}},{key:"_onRequestStateChange",value:function(e,t){if(G.debug("request id "+t.id+"."+t.sends+" state changed to "+t.xhr.readyState),t.abort)t.abort=!1;else if(4===t.xhr.readyState){var n=h._getRequestStatus(t);if(this.lastResponseHeaders=t.xhr.getAllResponseHeaders(),this._conn.disconnecting&&400<=n)return this._hitEr