UNPKG

@xmpp/client

Version:
1 lines 56.7 kB
!function(t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).XMPP=t()}(function(){function X(e){var r;return function(t){return r||e(r={exports:{},parent:t},r.exports),r.exports}}var q=X(function(t,e){var r;r=function(t,e){function r(){}r.prototype.name="PLAIN",r.prototype.clientFirst=!0,r.prototype.response=function(t){var e="";return(e+=t.authzid||"")+"\0"+t.username+"\0"+t.password},r.prototype.challenge=function(t){return this},e.exports=r},"object"==typeof e&&r(0,t)}),I=X(function(t,e){var r;r=function(t,e){function r(){}r.prototype.name="ANONYMOUS",r.prototype.clientFirst=!0,r.prototype.response=function(t){return t.trace||""},r.prototype.challenge=function(t){},e.exports=r},"object"==typeof e&&r(0,t)}),F=X(function(t,e){var r;r=function(t,e){function r(){this._mechs=[]}r.prototype.use=function(t,e){return e||(t=(e=t).prototype.name),this._mechs.push({name:t,mech:e}),this},r.prototype.create=function(t){for(var e=0,r=this._mechs.length;e<r;e++)for(var n=0,o=t.length;n<o;n++){var i=this._mechs[e];if(i.name==t[n])return new i.mech}return null},e.exports=r},"object"==typeof e&&r(0,t)}),t={};(t=function(t){return t&&t.__esModule?t:{default:t}}).__esModule=!0,t.default=t;var e={};(e=function(t,e){if(null==t)return{};var r,n={};for(r in t)if({}.hasOwnProperty.call(t,r)){if(e.includes(r))continue;n[r]=t[r]}return n}).__esModule=!0,e.default=e;var o={};function z(t,e){return(o=z=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t}).__esModule=!0,o.default=o,z(t,e)}(o=z).__esModule=!0,o.default=o;var r={};(r=function(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,o(t,e)}).__esModule=!0,r.default=r;var n={};function D(t){return(n=D=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)}).__esModule=!0,n.default=n,D(t)}(n=D).__esModule=!0,n.default=n;var i={};(i=function(e){try{return-1!==Function.toString.call(e).indexOf("[native code]")}catch(t){return"function"==typeof e}}).__esModule=!0,i.default=i;var s={};function B(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(s=function(){return!!t}).__esModule=!0,(s.default=s)()}(s=B).__esModule=!0,s.default=s;var a={};(a=function(t,e,r){var n;return s()?Reflect.construct.apply(null,arguments):((n=[null]).push.apply(n,e),e=new(t.bind.apply(t,n)),r&&o(e,r.prototype),e)}).__esModule=!0,a.default=a;var u={};function U(t){var r="function"==typeof Map?new Map:void 0;return(u=U=function(t){if(null===t||!i(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(t))return r.get(t);r.set(t,e)}function e(){return a(t,arguments,n(this).constructor)}return e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),o(e,t)}).__esModule=!0,u.default=u,U(t)}(u=U).__esModule=!0,u.default=u;function W(e){var r,t=new Promise(function(t){r=setTimeout(t,e)});return t.timeout=r,t}var $=t(r),H=(e=>{function t(t){t=e.call(this,t)||this;return t.name="TimeoutError",t}return(0,$.default)(t,e),t})((0,t(u).default)(Error)),c={},l="object"==typeof Reflect?Reflect:null,K=l&&"function"==typeof l.apply?l.apply:function(t,e,r){return Function.prototype.apply.call(t,e,r)};var Y=l&&"function"==typeof l.ownKeys?l.ownKeys:Object.getOwnPropertySymbols?function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:function(t){return Object.getOwnPropertyNames(t)},J=Number.isNaN||function(t){return t!=t};function f(){f.init.call(this)}(c=f).once=function(a,u){return new Promise(function(t,e){function r(t){a.removeListener(u,n),e(t)}function n(){"function"==typeof a.removeListener&&a.removeListener("error",r),t([].slice.call(arguments))}var o,i,s;nt(a,u,n,{once:!0}),"error"!==u&&(i=r,s={once:!0},"function"==typeof(o=a).on)&&nt(o,"error",i,s)})},(f.EventEmitter=f).prototype._events=void 0,f.prototype._eventsCount=0,f.prototype._maxListeners=void 0;var G=10;function h(t){if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}function Q(t){return void 0===t._maxListeners?f.defaultMaxListeners:t._maxListeners}function V(t,e,r,n){var o,i;return h(r),void 0===(o=t._events)?(o=t._events=Object.create(null),t._eventsCount=0):(void 0!==o.newListener&&(t.emit("newListener",e,r.listener||r),o=t._events),i=o[e]),void 0===i?(i=o[e]=r,++t._eventsCount):("function"==typeof i?i=o[e]=n?[r,i]:[i,r]:n?i.unshift(r):i.push(r),0<(o=Q(t))&&i.length>o&&!i.warned&&(i.warned=!0,(n=new Error("Possible EventEmitter memory leak detected. "+i.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit")).name="MaxListenersExceededWarning",n.emitter=t,n.type=e,n.count=i.length,r=n,console)&&console.warn&&console.warn(r)),t}function Z(t,e,r){t={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},e=function(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}.bind(t);return e.listener=r,t.wrapFn=e}function tt(t,e,r){t=t._events;if(void 0===t)return[];t=t[e];if(void 0===t)return[];if("function"==typeof t)return r?[t.listener||t]:[t];if(r){for(var n=t,o=new Array(n.length),i=0;i<o.length;++i)o[i]=n[i].listener||n[i];return o}return rt(t,t.length)}function et(t){var e=this._events;if(void 0!==e){e=e[t];if("function"==typeof e)return 1;if(void 0!==e)return e.length}return 0}function rt(t,e){for(var r=new Array(e),n=0;n<e;++n)r[n]=t[n];return r}function nt(r,n,o,i){if("function"==typeof r.on)i.once?r.once(n,o):r.on(n,o);else{if("function"!=typeof r.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof r);r.addEventListener(n,function t(e){i.once&&r.removeEventListener(n,t),o(e)})}}Object.defineProperty(f,"defaultMaxListeners",{enumerable:!0,get:function(){return G},set:function(t){if("number"!=typeof t||t<0||J(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");G=t}}),f.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},f.prototype.setMaxListeners=function(t){if("number"!=typeof t||t<0||J(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this},f.prototype.getMaxListeners=function(){return Q(this)},f.prototype.emit=function(t){for(var e=[],r=1;r<arguments.length;r++)e.push(arguments[r]);var n="error"===t,o=this._events;if(void 0!==o)n=n&&void 0===o.error;else if(!n)return!1;if(n){if((i=0<e.length?e[0]:i)instanceof Error)throw i;n=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw n.context=i,n}var i=o[t];if(void 0===i)return!1;if("function"==typeof i)K(i,this,e);else for(var s=i.length,a=rt(i,s),r=0;r<s;++r)K(a[r],this,e);return!0},f.prototype.on=f.prototype.addListener=function(t,e){return V(this,t,e,!1)},f.prototype.prependListener=function(t,e){return V(this,t,e,!0)},f.prototype.once=function(t,e){return h(e),this.on(t,Z(this,t,e)),this},f.prototype.prependOnceListener=function(t,e){return h(e),this.prependListener(t,Z(this,t,e)),this},f.prototype.off=f.prototype.removeListener=function(t,e){var r,n,o,i,s;if(h(e),void 0!==(n=this._events)&&void 0!==(r=n[t]))if(r===e||r.listener===e)0==--this._eventsCount?this._events=Object.create(null):(delete n[t],n.removeListener&&this.emit("removeListener",t,r.listener||e));else if("function"!=typeof r){for(o=-1,i=r.length-1;0<=i;i--)if(r[i]===e||r[i].listener===e){s=r[i].listener,o=i;break}if(o<0)return this;if(0===o)r.shift();else{for(var a=r,u=o;u+1<a.length;u++)a[u]=a[u+1];a.pop()}1===r.length&&(n[t]=r[0]),void 0!==n.removeListener&&this.emit("removeListener",t,s||e)}return this},f.prototype.removeAllListeners=function(t){var e,r=this._events;if(void 0!==r)if(void 0===r.removeListener)0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==r[t]&&(0==--this._eventsCount?this._events=Object.create(null):delete r[t]);else if(0===arguments.length){for(var n,o=Object.keys(r),i=0;i<o.length;++i)"removeListener"!==(n=o[i])&&this.removeAllListeners(n);this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0}else if("function"==typeof(e=r[t]))this.removeListener(t,e);else if(void 0!==e)for(i=e.length-1;0<=i;i--)this.removeListener(t,e[i]);return this},f.prototype.listeners=function(t){return tt(this,t,!0)},f.prototype.rawListeners=function(t){return tt(this,t,!1)},f.listenerCount=function(t,e){return"function"==typeof t.listenerCount?t.listenerCount(e):et.call(t,e)},f.prototype.listenerCount=et,f.prototype.eventNames=function(){return 0<this._eventsCount?Y(this._events):[]};var l={},p=(l.EventEmitter=c,l.timeout=function(t,e){var r=W(e);return Promise.race([t.finally(function(){clearTimeout(r.timeout)}),r.then(function(){throw new H})])},l.promise=function(s,a,u,c){return void 0===u&&(u="error"),new Promise(function(e,r){var t,n=function(){clearTimeout(t),s.removeListener(a,i),s.removeListener(u,o)};function o(t){r(t),n()}function i(t){e(t),n()}s.once(a,i),u&&s.once(u,o),c&&(t=setTimeout(function(){n(),r(new H)},c))})},l.Deferred=function(){var r=this;this.promise=new Promise(function(t,e){r.resolve=t,r.reject=e})},{});(p=function(t,e){return e=e||t.slice(0),t.raw=e,t}).__esModule=!0;function ot(t){var e,r,n=t.indexOf("/");return-1!==n&&(r=t.slice(n+1),t=t.slice(0,n)),-1!==(n=t.indexOf("@"))&&(e=t.slice(0,n),t=t.slice(n+1)),new Rt(e,t,r)}var it,st,at,ut,ct,lt,ft,ht,pt,dt,mt,vt,yt,gt,bt,wt,_t,xt,St,Pt,jt,Et,At,Ot,Lt,kt,Mt,Ct,Tt,Nt,d={},m=t(p.default=p),p=(d.detect=function(t){return!!t&&-1!==t.replaceAll(String.raw(it=it||(0,m.default)([void 0],["\\20"])),"").replaceAll(String.raw(st=st||(0,m.default)([void 0],["\\22"])),"").replaceAll(String.raw(at=at||(0,m.default)([void 0],["\\26"])),"").replaceAll(String.raw(ut=ut||(0,m.default)([void 0],["\\27"])),"").replaceAll(String.raw(ct=ct||(0,m.default)([void 0],["\\2f"])),"").replaceAll(String.raw(lt=lt||(0,m.default)([void 0],["\\3a"])),"").replaceAll(String.raw(ft=ft||(0,m.default)([void 0],["\\3c"])),"").replaceAll(String.raw(ht=ht||(0,m.default)([void 0],["\\3e"])),"").replaceAll(String.raw(pt=pt||(0,m.default)([void 0],["\\40"])),"").replaceAll(String.raw(dt=dt||(0,m.default)([void 0],["\\5c"])),"").search(/[ "&'/:<>@\\]/g)},d.escape=function(t){return null===t?null:t.replaceAll(/^\s+|\s+$/g,"").replaceAll("\\",String.raw(mt=mt||(0,m.default)([void 0],["\\5c"]))).replaceAll(" ",String.raw(vt=vt||(0,m.default)([void 0],["\\20"]))).replaceAll('"',String.raw(yt=yt||(0,m.default)([void 0],["\\22"]))).replaceAll("&",String.raw(gt=gt||(0,m.default)([void 0],["\\26"]))).replaceAll("'",String.raw(bt=bt||(0,m.default)([void 0],["\\27"]))).replaceAll("/",String.raw(wt=wt||(0,m.default)([void 0],["\\2f"]))).replaceAll(":",String.raw(_t=_t||(0,m.default)([void 0],["\\3a"]))).replaceAll("<",String.raw(xt=xt||(0,m.default)([void 0],["\\3c"]))).replaceAll(">",String.raw(St=St||(0,m.default)([void 0],["\\3e"]))).replaceAll("@",String.raw(Pt=Pt||(0,m.default)([void 0],["\\40"])))},d.unescape=function(t){return null===t?null:t.replaceAll(String.raw(jt=jt||(0,m.default)([void 0],["\\20"]))," ").replaceAll(String.raw(Et=Et||(0,m.default)([void 0],["\\22"])),'"').replaceAll(String.raw(At=At||(0,m.default)([void 0],["\\26"])),"&").replaceAll(String.raw(Ot=Ot||(0,m.default)([void 0],["\\27"])),"'").replaceAll(String.raw(Lt=Lt||(0,m.default)([void 0],["\\2f"])),"/").replaceAll(String.raw(kt=kt||(0,m.default)([void 0],["\\3a"])),":").replaceAll(String.raw(Mt=Mt||(0,m.default)([void 0],["\\3c"])),"<").replaceAll(String.raw(Ct=Ct||(0,m.default)([void 0],["\\3e"])),">").replaceAll(String.raw(Tt=Tt||(0,m.default)([void 0],["\\40"])),"@").replaceAll(String.raw(Nt=Nt||(0,m.default)([void 0],["\\5c"])),"\\")},(()=>{function t(t,e,r){if("string"!=typeof e||!e)throw new TypeError("Invalid domain.");this.setDomain(e),this.setLocal("string"==typeof t?t:""),this.setResource("string"==typeof r?r:"")}var e=t.prototype;return e[Symbol.toPrimitive]=function(t){return"number"===t?NaN:this.toString()},e.toString=function(t){var e=this._domain;return this._local&&(e=this.getLocal(t)+"@"+e),e=this._resource?e+"/"+this._resource:e},e.bare=function(){return this._resource?new t(this._local,this._domain,null):this},e.equals=function(t){return this._local===t._local&&this._domain===t._domain&&this._resource===t._resource},e.setLocal=function(t,e){return(e=e||d.detect(t))&&(t=d.escape(t)),this._local=t&&t.toLowerCase(),this},e.getLocal=function(t){return(t=void 0===t?!1:t)?d.unescape(this._local):this._local},e.setDomain=function(t){return this._domain=t.toLowerCase(),this},e.getDomain=function(){return this._domain},e.setResource=function(t){return this._resource=t,this},e.getResource=function(){return this._resource},t})()),Rt=(Object.defineProperty(p.prototype,"local",{get:p.prototype.getLocal,set:p.prototype.setLocal}),Object.defineProperty(p.prototype,"domain",{get:p.prototype.getDomain,set:p.prototype.setDomain}),Object.defineProperty(p.prototype,"resource",{get:p.prototype.getResource,set:p.prototype.setResource}),p),v={},Xt=t(a);function qt(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return e[1]||e[2]?(0,Xt.default)(Rt,e):ot.apply(void 0,e)}(v=qt.bind()).jid=qt,v.JID=Rt,v.equal=function(t,e){return t.equals(e)},v.detectEscape=d.detect,v.escapeLocal=d.escape,v.unescapeLocal=d.unescape,v.parse=ot;var w={},It={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&apos;"};function Ft(t){return It[t]}var zt={"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&apos;":"'"};function Dt(t){if("#"===t[1]){var e="x"===t[2]?parseInt(t.slice(3),16):parseInt(t.slice(2),10);if(9===e||10===e||13===e||32<=e&&e<=55295||57344<=e&&e<=65533||65536<=e&&e<=1114111)return String.fromCodePoint(e);throw new Error("Illegal XML character 0x"+e.toString(16))}if(zt[t])return zt[t];throw new Error("Illegal XML entity "+t)}function y(t,e){var r,n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=((t,e)=>{var r;if(t)return"string"==typeof t?Bt(t,e):"Map"===(r="Object"===(r={}.toString.call(t).slice(8,-1))&&t.constructor?t.constructor.name:r)||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?Bt(t,e):void 0})(t))||e&&t&&"number"==typeof t.length)return n&&(t=n),r=0,function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function Bt(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}w.escapeXML=function(t){return t.replace(/["&'<>]/g,Ft)},w.escapeXMLText=function(t){return t.replace(/[&<>]/g,Ft)},w.unescapeXML=function(t){for(var e,r="",n=-1,o=0;-1!==(e=t.indexOf("&",o))&&-1!==(n=t.indexOf(";",e+1));)r=r+t.slice(o,e)+Dt(t.slice(e,n+1)),o=n+1;return 0===o?t:r+t.substring(o)},w.unescapeXMLText=function(t){return t.replace(/&(amp|#38|lt|#60|gt|#62);/g,Dt)};var p=(()=>{function r(t,e){this.name=t,this.parent=null,this.children=[],this.attrs={},this.setAttrs(e)}var t=r.prototype;return t.is=function(t,e){return this.getName()===t&&(!e||this.getNS()===e)},t.getName=function(){var t=this.name.indexOf(":");return 0<=t?this.name.slice(t+1):this.name},t.getNS=function(){var t=this.name.indexOf(":");return 0<=t?(t=this.name.slice(0,t),this.findNS(t)):this.findNS()},t.findNS=function(t){return t?this.attrs["xmlns:"+t]||(this.parent?this.parent.findNS(t):void 0):this.attrs.xmlns||(this.parent?this.parent.findNS():void 0)},t.getXmlns=function(){var t,e={};for(t in this.parent&&(e=this.parent.getXmlns()),this.attrs){var r=t.match("xmlns:?(.*)");this.attrs.hasOwnProperty(t)&&r&&(e[this.attrs[t]]=r[1])}return e},t.setAttrs=function(t){"string"==typeof t?this.attrs.xmlns=t:t&&Object.assign(this.attrs,t)},t.getAttr=function(t,e){var r;return e?(r=this.getXmlns())[e]?this.attrs[[r[e],t].join(":")]:null:this.attrs[t]},t.getChild=function(t,e){return this.getChildren(t,e)[0]},t.getChildren=function(t,e){for(var r=[],n=y(this.children);!(o=n()).done;){var o=o.value;!o.getName||o.getName()!==t||e&&o.getNS()!==e||r.push(o)}return r},t.getChildByAttr=function(t,e,r,n){return this.getChildrenByAttr(t,e,r,n)[0]},t.getChildrenByAttr=function(t,e,r,n){for(var o=[],i=y(this.children);!(s=i()).done;){var s=s.value;!s.attrs||s.attrs[t]!==e||r&&s.getNS()!==r||o.push(s),n&&s.getChildrenByAttr&&o.push(s.getChildrenByAttr(t,e,r,!0))}return o=n?o.flat():o},t.getChildrenByFilter=function(t,e){for(var r=[],n=y(this.children);!(o=n()).done;){var o=o.value;t(o)&&r.push(o),e&&o.getChildrenByFilter&&r.push(o.getChildrenByFilter(t,!0))}return r=e?r.flat():r},t.getText=function(){for(var t="",e=y(this.children);!(r=e()).done;){var r=r.value;"string"!=typeof r&&"number"!=typeof r||(t+=r)}return t},t.getChildText=function(t,e){t=this.getChild(t,e);return t?t.getText():null},t.getChildElements=function(){return this.getChildrenByFilter(function(t){return t instanceof r})},t.root=function(){return this.parent?this.parent.root():this},t.up=function(){return this.parent||this},t.c=function(t,e){return this.cnode(new r(t,e))},t.cnode=function(t){return this.children.push(t),"object"==typeof t&&(t.parent=this),t},t.append=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];for(var n=0,o=e;n<o.length;n++){var i=o[n];this.children.push(i),"object"==typeof i&&(i.parent=this)}},t.prepend=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];for(var n=0,o=e;n<o.length;n++){var i=o[n];this.children.unshift(i),"object"==typeof i&&(i.parent=this)}},t.t=function(t){return this.children.push(t),this},t.remove=function(e,r){return this.children=this.children.filter("string"==typeof e?function(t){return!(t.is&&t.is(e,r))}:function(t){return t!==e}),this},t.text=function(t){return t&&1===this.children.length?(this.children[0]=t,this):this.getText()},t.attr=function(t,e){return void 0!==e||null===e?(this.attrs||(this.attrs={}),this.attrs[t]=e,this):this.attrs[t]},t.toString=function(){var e="";return this.write(function(t){e+=t}),e},t._addChildren=function(t){t(">");for(var e=y(this.children);!(r=e()).done;){var r=r.value;null!=r&&(r.write?r.write(t):"string"==typeof r?t(w.escapeXMLText(r)):r.toString&&t(w.escapeXMLText(r.toString(10))))}t("</"),t(this.name),t(">")},t.write=function(t){for(var e in t("<"),t(this.name),this.attrs){var r=this.attrs[e];null!=r&&(t(" "),t(e),t('="'),t(w.escapeXML("string"==typeof r?r:r.toString(10))),t('"'))}0===this.children.length?t("/>"):this._addChildren(t)},r})(),Ut=(p.prototype.tree=p.prototype.root,p);function Wt(t,e){var r,n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=((t,e)=>{var r;if(t)return"string"==typeof t?$t(t,e):"Map"===(r="Object"===(r={}.toString.call(t).slice(8,-1))&&t.constructor?t.constructor.name:r)||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?$t(t,e):void 0})(t))||e&&t&&"number"==typeof t.length)return n&&(t=n),r=0,function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function $t(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}var Ht=function(t,e){if("object"==typeof e&&null!==e){delete e.__source,delete e.__self;for(var r=0,n=Object.entries(e);r<n.length;r++){var o=n[r],i=o[0],o=o[1];null==o?delete e[i]:e[i]=o.toString(10)}}for(var s=new Ut(t,e),a=arguments.length,u=new Array(2<a?a-2:0),c=2;c<a;c++)u[c-2]=arguments[c];for(var l=0,f=u;l<f.length;l++)!function t(e,r){if(Array.isArray(r))for(var n,o=Wt(r);!(n=o()).done;)t(e,n.value);else""!==r&&null!=r&&!0!==r&&!1!==r&&e.cnode(r)}(s,f[l]);return s},Kt=t(r),Yt=(e=>{function t(){var c,l,f,h,p,d,m,v,y,t=e.call(this)||this,g=0,b=0;return t._handleTagOpening=function(t,e,r){t?this.emit("endElement",e,!1):(this.emit("startElement",e,r),d&&this.emit("endElement",e,!0))},t.write=function(e){"string"!=typeof e&&(e=e.toString());var r=0;function t(){var t;if("number"==typeof b)return t=e.slice(b,r),b=void 0,t}for(c&&(e=c+e,r+=l?0:c.length,l=!1,c=null);r<e.length;r++){switch(g){case 0:var n=e.indexOf("<",r);-1!==n&&r!==n&&(r=n);break;case 8:n=e.indexOf(v,r);-1!==n&&(r=n);break;case 1:var o=e.indexOf("--\x3e",r);-1!==o&&(r=o+2);break;case 10:o=e.indexOf("]]>",r);-1!==o&&(r=o+2)}var i,s,a,u=e.charCodeAt(r);switch(g){case 0:60===u&&((i=t())&&this.emit("text",w.unescapeXML(i)),g=3,b=r+1,h={});break;case 9:93===u&&("]>"===e.substr(r+1,2)?((i=t())&&this.emit("text",i),g=0):e.length<r+2&&(l=!0,r=e.length));break;case 3:47===u&&b===r?(b=r+1,p=!0):33===u?"[CDATA["===e.substr(r+1,7)?(b=r+8,g=9):e.length<r+8&&"[CDATA[".startsWith(e.slice(r+1))?(l=!0,r=e.length):(b=void 0,g=1):63===u?(b=void 0,g=2):(u<=32||47===u||62===u)&&(f=t(),r--,g=4);break;case 1:62===u&&(a=e.charCodeAt(r-1),s=e.charCodeAt(r-2),45===a&&45===s||93===a&&93===s)&&(g=0);break;case 2:62===u&&63===e.charCodeAt(r-1)&&(g=0);break;case 4:62===u?(this._handleTagOpening(p,f,h),d=p=h=f=void 0,g=0,b=r+1):47===u?d=!0:32<u&&(b=r,g=5);break;case 5:(u<=32||61===u)&&(y=t(),r--,g=6);break;case 6:61===u&&(g=7);break;case 7:34!==u&&39!==u||(v=34===(m=u)?'"':"'",g=8,b=r+1);break;case 8:u===m&&(a=w.unescapeXML(t()),h[y]=a,y=void 0,g=4)}}"number"==typeof b&&b<=e.length&&(c=e.slice(b),b=0)},t}return(0,Kt.default)(t,e),t.prototype.end=function(t){t&&this.write(t),this.write=function(){}},t})(c.EventEmitter),Jt=t(r),g=(o=>{function t(){for(var t,e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];return(t=o.call.apply(o,[this].concat(r))||this).name="XMLError",t}return(0,Jt.default)(t,o),t})((0,t(u).default)(Error)),Gt=t(r),p=(r=>{function t(){var t=r.call(this)||this,e=new Yt;return t.root=null,t.cursor=null,e.on("startElement",t.onStartElement.bind(t)),e.on("endElement",t.onEndElement.bind(t)),e.on("text",t.onText.bind(t)),t.parser=e,t}(0,Gt.default)(t,r);var e=t.prototype;return e.onStartElement=function(t,e){var t=new Ut(t,e),e=this.root,r=this.cursor;e?r!==e&&r.append(t):(this.root=t,this.emit("start",t)),this.cursor=t},e.onEndElement=function(t){var e=this.root,r=this.cursor;t!==r.name?this.emit("error",new g(r.name+" must be closed.")):r===e?this.emit("end",e):r.parent?this.cursor=r.parent:(r.parent=e,this.emit("element",r),this.cursor=e)},e.onText=function(t){var e=this.cursor;e?e.t(t):this.emit("error",new g(t+" must be a child."))},e.write=function(t){this.parser.write(t)},e.end=function(t){t&&this.parser.write(t)},t})(c),Qt=(p.XMLError=g,p),b={};b=function(){return Ht.apply(void 0,arguments)},Object.assign(b,{Element:Ut,createElement:Ht,Parser:Qt,escapeXML:w.escapeXML,unescapeXML:w.unescapeXML,escapeXMLText:w.escapeXMLText,unescapeXMLText:w.unescapeXMLText,XMLError:g});var Vt=t(r),p=(o=>{function t(t,e,r){var n=o.call(this,t+(e?" - "+e:""))||this;return n.name="XMPPError",n.condition=t,n.text=e,n.application=r,n}return(0,Vt.default)(t,o),t.fromElement=function(t){var e,r,n=t.getChildElements(),o=n[0],i=n[1],n=n[2],i=(i&&(i.is("text")?e=i:i&&(r=i),n)&&(r=n),new this(o.name,e?e.text():"",r));return i.element=t,i},t})((0,t(u).default)(Error)),Zt=t(r),te=(o=>{function t(){for(var t,e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];return(t=o.call.apply(o,[this].concat(r))||this).name="StreamError",t}return(0,Zt.default)(t,o),t})(p),_={};function ee(t){var t=new URL(t),e=t.port,r=t.hostname;return{port:e,hostname:r="[::1]"===r?"::1":r,protocol:t.protocol}}function re(t){t=ee("http://"+t);return{port:t.port,hostname:t.hostname}}Object.assign(_,{parseURI:ee,parseHost:re,parseService:function(t){return(t.includes("://")?ee:re)(t)}});var ne=t(r);function x(){}function oe(t,e){if(!e)return t&&t.then?t.then(x):Promise.resolve()}function ie(t,e){try{var r=t()}catch(t){return e(t)}return r&&r.then?r.then(void 0,e):r}function se(t,e){return t&&t.then?t.then(e):e(t)}function S(t,e,r){return r?e?e(t):t:(t&&t.then||(t=Promise.resolve(t)),e?t.then(e):t)}function ae(t,e){var r,n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=((t,e)=>{var r;if(t)return"string"==typeof t?ue(t,e):"Map"===(r="Object"===(r={}.toString.call(t).slice(8,-1))&&t.constructor?t.constructor.name:r)||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?ue(t,e):void 0})(t))||e&&t&&"number"==typeof t.length)return n&&(t=n),r=0,function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function ue(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}var P=l.promise,ce=_.parseHost,le=_.parseService,_=(r=>{function t(t){var e;return void 0===t&&(t={}),(e=r.call(this)||this).jid=null,e.timeout=2e3,e.options=t,e.socketListeners=Object.create(null),e.parserListeners=Object.create(null),e.status="offline",e.socket=null,e.parser=null,e.root=null,e}(0,ne.default)(t,r);var e=t.prototype;return e._reset=function(){this.jid=null,this.status="offline",this._detachSocket(),this._detachParser()},e._streamError=function(t,e){try{var r=this;return S(se(ie(function(){return oe(r.send(b("stream:error",{},[b(t,{xmlns:"urn:ietf:params:xml:ns:xmpp-streams"},e)])))},x),function(){return r._end()}))}catch(t){return Promise.reject(t)}},e._onData=function(t){t=t.toString("utf8");this.emit("input",t),this.parser.write(t)},e._onParserError=function(t){this._streamError("bad-format"),this._detachParser(),this.emit("error",t)},e._attachSocket=function(t){var r=this,t=(this.socket=t,this.socketListeners);t.data=this._onData.bind(this),t.close=function(t,e){r._reset(),r._status("disconnect",{clean:!t,event:e})},t.connect=function(){r._status("connect")},t.error=function(t){r.emit("error",t)},this.socket.on("close",t.close),this.socket.on("data",t.data),this.socket.on("error",t.error),this.socket.on("connect",t.connect)},e._detachSocket=function(){for(var t=this.socketListeners,e=this.socket,r=ae(Object.getOwnPropertyNames(t));!(n=r()).done;){var n=n.value;e.removeListener(n,t[n]),delete t[n]}return this.socket=null,e},e._onElement=function(t){var e=t.is("error","http://etherx.jabber.org/streams");e&&this._onStreamError(t),this.emit("element",t),this.emit(this.isStanza(t)?"stanza":"nonza",t),e&&this._end()},e._onStreamError=function(t){t=te.fromElement(t);if("see-other-host"===t.condition)return this._onSeeOtherHost(t);this.emit("error",t)},e._onSeeOtherHost=function(t){try{var n=this,e=le(n.options.service).protocol,r=t.element.getChildText("see-other-host"),o=ce(r).port?(e||"xmpp:")+"//"+r:(e?e+"//":"")+r;return S((t=>{if(t&&t.then)return t.then(x)})(ie(function(){return S(P(n,"disconnect"),function(){var t=n.options,e=t.domain,r=t.lang;return S(n.connect(o),function(){return oe(n.open({domain:e,lang:r}))})})},function(t){n.emit("error",t)})))}catch(t){return Promise.reject(t)}},e._attachParser=function(t){var e=this,t=(this.parser=t,this.parserListeners);t.element=this._onElement.bind(this),t.error=this._onParserError.bind(this),t.end=function(t){e._detachParser(),e._status("close",t)},t.start=function(t){e._status("open",t)},this.parser.on("error",t.error),this.parser.on("element",t.element),this.parser.on("end",t.end),this.parser.on("start",t.start)},e._detachParser=function(){for(var t=this.parserListeners,e=ae(Object.getOwnPropertyNames(t));!(r=e()).done;){var r=r.value;this.parser.removeListener(r,t[r]),delete t[r]}this.parser=null},e._jid=function(t){return this.jid=v(t),this.jid},e._status=function(t){this.status=t;for(var e=arguments.length,r=new Array(1<e?e-1:0),n=1;n<e;n++)r[n-1]=arguments[n];this.emit.apply(this,["status",t].concat(r)),this.emit.apply(this,[t].concat(r))},e._end=function(){try{var e,t=this;return S(se(ie(function(){return S(t.close(),function(t){e=t})},x),function(){return se(ie(function(){return oe(t.disconnect())},x),function(){return e})}))}catch(t){return Promise.reject(t)}},e.start=function(){try{var e=this;if("offline"!==e.status)throw new Error("Connection is not offline");var t=e.options,r=t.service,n=t.domain,o=t.lang;return S(e.connect(r),function(){var t=P(e,"online");return S(e.open({domain:n,lang:o}),function(){return t})})}catch(t){return Promise.reject(t)}},e.connect=function(t){try{this._status("connecting",t);var e=new this.Socket;return this._attachSocket(e),e.connect(this.socketParameters(t)),S(P(e,"connect"))}catch(t){return Promise.reject(t)}},e.disconnect=function(t){try{var e=this;return void 0===t&&(t=e.timeout),e.socket&&e._status("disconnecting"),e.socket.end(),S(oe(P(e.socket,"close","error",t)))}catch(t){return Promise.reject(t)}},e.open=function(t){try{var e=this,r=(e._status("opening"),t="string"==typeof t?{domain:t}:t),n=r.domain,o=r.lang,i=r.timeout,s=void 0===i?e.timeout:i,a=e.headerElement();return a.attrs.to=n,a.attrs["xml:lang"]=o,e.root=a,e._attachParser(new e.Parser),S(e.write(e.header(a)),function(){return P(e,"open","error",s)})}catch(t){return Promise.reject(t)}},e.stop=function(){try{var e=this;return S(e._end(),function(t){return"offline"!==e.status&&e._status("offline",t),t})}catch(t){return Promise.reject(t)}},e.close=function(t){try{var e=this,r=(void 0===t&&(t=e.timeout),e.footer(e.footerElement())),n=Promise.all([P(e.parser,"end","error",t),e.write(r)]);return e.parser&&e.socket&&e._status("closing"),S(n,function(t){t=t[0];return e.root=null,t})}catch(t){return Promise.reject(t)}},e.restart=function(){try{this._detachParser();var t=this.options,e=t.domain,r=t.lang;return S(this.open({domain:e,lang:r}))}catch(t){return Promise.reject(t)}},e.send=function(t){try{var e=this;return t.parent=e.root,S(e.write(t.toString()),function(){e.emit("send",t)})}catch(t){return Promise.reject(t)}},e.sendReceive=function(t,e){return void 0===e&&(e=this.timeout),Promise.all([this.send(t),P(this,"element","error",e)]).then(function(t){return t[1]})},e.write=function(n){var o=this;return new Promise(function(e,r){"closing"===o.status?r(new Error("Connection is closing")):o.socket.write(n,function(t){if(t)return r(t);o.emit("output",n),e()})})},e.isStanza=function(t){t=t.name;return"iq"===t||"message"===t||"presence"===t},e.isNonza=function(t){return!this.isStanza(t)},e.header=function(t){return t.toString()},e.headerElement=function(){return new b.Element("",{version:"1.0",xmlns:this.NS})},e.footer=function(t){return t.toString()},e.footerElement=function(){},e.socketParameters=function(){},t})(l.EventEmitter),fe=(_.prototype.NS="",_.prototype.Socket=null,_.prototype.Parser=null,t(r)),j=(r=>{function t(t){t=r.call(this,t)||this;return t.transports=[],t}(0,fe.default)(t,r);var e=t.prototype;return e.send=function(t){for(var e,r=arguments.length,n=new Array(1<r?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];return(e=this.Transport.prototype.send).call.apply(e,[this,t].concat(n))},e.sendMany=function(){for(var t,e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];return(t=this.Transport.prototype.sendMany).call.apply(t,[this].concat(r))},e._findTransport=function(e){return this.transports.find(function(t){try{return void 0!==t.prototype.socketParameters(e)}catch(t){return!1}})},e.connect=function(t){var e=this._findTransport(t);if(e)return this.Transport=e,this.Socket=e.prototype.Socket,this.Parser=e.prototype.Parser,r.prototype.connect.call(this,t);throw new Error("No compatible connection method found.")},e.socketParameters=function(){var t;return(t=this.Transport.prototype).socketParameters.apply(t,arguments)},e.header=function(){var t;return(t=this.Transport.prototype).header.apply(t,arguments)},e.headerElement=function(){var t;return(t=this.Transport.prototype).headerElement.apply(t,arguments)},e.footer=function(){var t;return(t=this.Transport.prototype).footer.apply(t,arguments)},e.footerElement=function(){var t;return(t=this.Transport.prototype).footerElement.apply(t,arguments)},t})(_);j.prototype.NS="jabber:client";var E={},he=(E.Client=j,E.xml=b,E.jid=v,t(r));function pe(){}var de=(r=>{function t(t){var e=r.call(this)||this;return e.delay=1e3,e.entity=t,e._timeout=null,e}(0,he.default)(t,r);var e=t.prototype;return e.scheduleReconnect=function(){var r,e=this,n=this.entity,t=this.delay,o=this._timeout;clearTimeout(o),this._timeout=setTimeout((r=function(){if("disconnect"===n.status){var t=((t,e)=>{try{var r=t()}catch(t){return e(t)}return r&&r.then?r.then(void 0,e):r})(function(){var t=e.reconnect();if(!void 0)return t&&t.then?t.then(pe):Promise.resolve()},pe);if(t&&t.then)return t.then(pe)}},function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];try{return Promise.resolve(r.apply(this,t))}catch(t){return Promise.reject(t)}}),t)},e.reconnect=function(){try{var t=this,e=t.entity,r=(t.emit("reconnecting"),e.options),n=r.service,o=r.domain,i=r.lang;return me(e.connect(n),function(){return me(e.open({domain:o,lang:i}),function(){t.emit("reconnected")})})}catch(t){return Promise.reject(t)}},e.start=function(){var t=this,e=this.entity,r={disconnect:function(){t.scheduleReconnect()}};this.listeners=r,e.on("disconnect",r.disconnect)},e.stop=function(){var t=this.entity,e=this.listeners,r=this._timeout;t.removeListener("disconnect",e.disconnect),clearTimeout(r)},t})(l.EventEmitter);function me(t,e,r){return r?e?e(t):t:(t&&t.then||(t=Promise.resolve(t)),e?t.then(e):t)}var A={},ve=t(r);function ye(t,e){var r,n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=((t,e)=>{var r;if(t)return"string"==typeof t?ge(t,e):"Map"===(r="Object"===(r={}.toString.call(t).slice(8,-1))&&t.constructor?t.constructor.name:r)||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?ge(t,e):void 0})(t))||e&&t&&"number"==typeof t.length)return n&&(t=n),r=0,function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function ge(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}var be=globalThis.WebSocket||A,we="ECONNERROR",j=(e=>{function t(){var t=e.call(this)||this;return t.listeners=Object.create(null),t}(0,ve.default)(t,e);var r=t.prototype;return r.connect=function(t){this.url=t,this._attachSocket(new be(t,["xmpp"]))},r._attachSocket=function(t){var n=this,t=(this.socket=t,this.listeners);t.open=function(){n.emit("connect")},t.message=function(t){t=t.data;return n.emit("data",t)},t.error=function(t){var e=n.url,r=t.error;r||((r=new Error("WebSocket "+we+" "+e)).errno=we,r.code=we),r.event=t,r.url=e,n.emit("error",r)},t.close=function(t){n._detachSocket(),n.emit("close",!t.wasClean,t)},this.socket.addEventListener("open",t.open),this.socket.addEventListener("message",t.message),this.socket.addEventListener("error",t.error),this.socket.addEventListener("close",t.close)},r._detachSocket=function(){delete this.url;for(var t=this.socket,e=this.listeners,r=ye(Object.getOwnPropertyNames(e));!(n=r()).done;){var n=n.value;t.removeEventListener(n,e[n]),delete e[n]}delete this.socket},r.end=function(){this.socket.close()},r.write=function(t,e){be===A?this.socket.send(t,e):(this.socket.send(t),e())},t})(c),_e=t(r),c=b.Parser,xe=b.Element,Se=b.XMLError,c=(t=>{function e(){return t.apply(this,arguments)||this}(0,_e.default)(e,t);var r=e.prototype;return r.onStartElement=function(t,e){t=new xe(t,e),e=this.cursor;e&&e.append(t),this.cursor=t},r.onEndElement=function(t){var e=this.cursor;t!==e.name?this.emit("error",new Se(e.name+" must be closed.")):e.parent?this.cursor=e.parent:(e.is("open","urn:ietf:params:xml:ns:xmpp-framing")?this.emit("start",e):e.is("close","urn:ietf:params:xml:ns:xmpp-framing")?this.emit("end",e):this.emit("element",e),this.cursor=null)},e})(c),Pe=t(r);function je(){}var Ee="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function O(t,e,r){if(!t.s){if(r instanceof L){if(!r.s)return void(r.o=O.bind(null,t,e));1&e&&(e=r.s),r=r.v}r&&r.then?r.then(O.bind(null,t,e),O.bind(null,t,2)):(t.s=e,t.v=r,(e=t.o)&&e(t))}}var L=(()=>{function e(){}return e.prototype.then=function(r,n){var o=new e,t=this.s;if(t){t=1&t?r:n;if(t){try{O(o,1,t(this.v))}catch(t){O(o,2,t)}return o}return this}return this.o=function(t){try{var e=t.v;1&t.s?O(o,1,r?r(e):e):n?O(o,1,n(e)):O(o,2,e)}catch(t){O(o,2,t)}},o},e})();function Ae(t){return t instanceof L&&1&t.s}function Oe(r,n,o){var i,s,a=-1;return function t(e){try{for(;++a<r.length&&(!o||!o());)if((e=n(a))&&e.then){if(!Ae(e))return void e.then(t,s=s||O.bind(null,i=new L,2));e=e.v}i?O(i,1,e):i=e}catch(t){O(i=i||new L,2,t)}}(),i}var Le="urn:ietf:params:xml:ns:xmpp-framing";var _=(i=>{function t(){return i.apply(this,arguments)||this}(0,Pe.default)(t,i);var e=t.prototype;return e.send=function(t){var e;!t.attrs.xmlns&&i.prototype.isStanza.call(this,t)&&(t.attrs.xmlns="jabber:client");for(var r=arguments.length,n=new Array(1<r?r-1:0),o=1;o<r;o++)n[o-1]=arguments[o];return(e=i.prototype.send).call.apply(e,[this,t].concat(n))},e.sendMany=function(t){try{var e=this;return r=(t=>{if(t&&t.then)return t.then(je)})(((t,e,r)=>{if("function"==typeof t[Ee]){var n,o,i,s=function(t){try{for(;!((n=a.next()).done||r&&r());)if((t=e(n.value))&&t.then){if(!Ae(t))return void t.then(s,i=i||O.bind(null,o=new L,2));t=t.v}o?O(o,1,t):o=t}catch(t){O(o=o||new L,2,t)}},a=t[Ee]();if(s(),a.return){var u=function(t){try{n.done||a.return()}catch(t){}return t};if(o&&o.then)return o.then(u,function(t){throw u(t)});u()}return o}if(!("length"in t))throw new TypeError("Object is not iterable");for(var c=[],l=0;l<t.length;l++)c.push(t[l]);return Oe(c,function(t){return e(c[t])},r)})(t,function(t){t=e.send(t);if(!void 0)return t&&t.then?t.then(je):Promise.resolve()})),o?n?n(r):r:(r&&r.then||(r=Promise.resolve(r)),n?r.then(n):r)}catch(t){return Promise.reject(t)}var r,n,o},e.footerElement=function(){return new b.Element("close",{xmlns:Le})},e.headerElement=function(){var t=i.prototype.headerElement.call(this);return t.name="open",t.attrs.xmlns=Le,t},e.socketParameters=function(t){return/^wss?:\/\//.test(t)?t:void 0},t})(_),ke=(_.prototype.Socket=j,_.prototype.NS="jabber:client",_.prototype.Parser=c,_);function Me(t,e){var r,n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=((t,e)=>{var r;if(t)return"string"==typeof t?Ce(t,e):"Map"===(r="Object"===(r={}.toString.call(t).slice(8,-1))&&t.constructor?t.constructor.name:r)||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?Ce(t,e):void 0})(t))||e&&t&&"number"==typeof t.length)return n&&(t=n),r=0,function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function Ce(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}var Te=function(s){if(!Array.isArray(s))throw new TypeError("Middleware stack must be an array!");for(var t,e=Me(s);!(t=e()).done;)if("function"!=typeof t.value)throw new TypeError("Middleware must be composed of functions!");return function(r,n){var o=-1;return i(0);function i(t){if(t<=o)return Promise.reject(new Error("next() called multiple times"));var e=s[o=t];if(!(e=t===s.length?n:e))return Promise.resolve();try{return Promise.resolve(e(r,i.bind(null,t+1)))}catch(t){return Promise.reject(t)}}}};function Ne(t,e){this.stanza=e,this.entity=t;var t=e.name,r=(e=e.attrs).type,e=e.id;this.name=t,this.id=e||"",this.type="message"===t?r||"normal":"presence"===t?r||"available":r||"",this.from=null,this.to=null,this.local="",this.domain="",this.resource=""}var Re=t(r),Xe=(o=>{function t(t,e){var r=o.call(this,t,e)||this,n=t.jid,t=t.domain,n=e.attrs.to||n&&n.toString(),e=e.attrs.from||t;return n&&(r.to=new v(n)),e&&(r.from=new v(e),r.local=r.from.local,r.domain=r.from.domain,r.resource=r.from.resource),r}return(0,Re.default)(t,o),t})(Ne),qe=t(r),Ie=(o=>{function t(t,e){var r=o.call(this,t,e)||this,n=t.jid,t=t.domain,n=e.attrs.from||n&&n.toString(),e=e.attrs.to||t;return n&&(r.from=new v(n)),e&&(r.to=new v(e),r.local=r.to.local,r.domain=r.to.domain,r.resource=r.to.resource),r}return(0,qe.default)(t,o),t})(Ne);function Fe(e,r,n){return function(t){t=new n(e,t);return Te(r)(t)}}function ze(t){var e=t.middleware;return e.use(De()),{use:function(n,o,i){return e.use(function(t,e){var r=t.stanza;return r.is("features","http://etherx.jabber.org/streams")&&(r=r.getChild(n,o))?i(t,e,r):e()})}}}var De=function(){return r=function(t,e){var r=t.stanza,n=t.entity;if(!r.is("features","http://etherx.jabber.org/streams"))return e();t=e,r=function(t){!t&&n.jid&&n._status("online",n.jid)};if(void 0)return r?r(t()):t();try{var o=Promise.resolve(t());return r?o.then(r):o}catch(t){return Promise.reject(t)}},function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];try{return Promise.resolve(r.apply(this,t))}catch(t){return Promise.reject(t)}};var r},j={};(j=function(t){throw new TypeError('"'+t+'" is read-only')}).__esModule=!0,j.default=j;var Be=t(r),Ue=(o=>{function t(t,e,r,n){t=o.call(this,t,e,r)||this;return t.type=n,t.name="StanzaError",t}return(0,Be.default)(t,o),t.fromElement=function(t){var e=o.fromElement.call(this,t);return e.type=t.attrs.type,e},t})(p),We=t(a);t(j);function $e(){}function He(t,e,r){return r?e?e(t):t:(t&&t.then||(t=Promise.resolve(t)),e?t.then(e):t)}var Ke=l.Deferred;var Ye=l.timeout;var Je=(()=>{function t(t){var e=t.entity,t=t.middleware;this.handlers=new Map,this.entity=e,this.middleware=t}var e=t.prototype;return e.start=function(){this.middleware.use(this._route.bind(this))},e._route=function(t,e){var r,n=t.type,o=t.id,i=t.stanza;return r=(t={name:t.name,type:n}).name,t=t.type,"iq"===r&&("error"===t||"result"===t)&&(r=this.handlers.get(o))?("error"===n?r.reject(Ue.fromElement(i.getChild("error"))):r.resolve(i),void this.handlers.delete(o)):e()},e.request=function(e,r){void 0===r&&(r=3e4);try{var n=this,o=(e.attrs.id||(e.attrs.id=(()=>{for(var t;!t;)t=Math.random().toString(36).slice(2,12);return t})()),new Ke);return n.handlers.set(e.attrs.id,o),He((t=((t,e)=>{try{var r=t()}catch(t){return e(t)}return r&&r.then?r.then(void 0,e):r})(function(){return He(n.entity.send(e),function(){var t=Ye(o.promise,r);if(!void 0)return t&&t.then?t.then($e):Promise.resolve()})},function(t){throw n.handlers.delete(e.attrs.id),t}),i=function(t){return o.promise},t&&t.then?t.then(i):i(t)))}catch(t){return Promise.reject(t)}var t,i},e._childRequest=function(t,e,r){for(var n=e.name,o=e.attrs.xmlns,i=arguments.length,s=new Array(3<i?i-3:0),a=3;a<i;a++)s[a-3]=arguments[a];return this.request.apply(this,[b("iq",{type:t,to:r},e)].concat(s)).then(function(t){return t.getChild(n,o)})},e.get=function(){try{for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return He(this._childRequest.apply(this,["get"].concat(e)))}catch(t){return Promise.reject(t)}},e.set=function(){try{for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return He(this._childRequest.apply(this,["set"].concat(e)))}catch(t){return Promise.reject(t)}},t})();var Ge="urn:ietf:params:xml:ns:xmpp-stanzas";function Qe(t,e,r){return r?e?e(t):t:(t&&t.then||(t=Promise.resolve(t)),e?t.then(e):t)}function Ve(t){t=t.stanza;return b("iq",{to:t.attrs.from,from:t.attrs.to,id:t.attrs.id})}function Ze(t,e,r){t=Ve(t);return t.attrs.type="error",r&&t.append(r),t.append(e),t}function tr(t,e){return b("error",{type:t},b(e,Ge))}function er(h){return function(r,n){try{var t,o,i;return(f=(l=r).name,l=l.type,"iq"!==f||"error"===l||"result"===l)?Qe(n()):(t=r.stanza.getChildElements(),o=t[0],u=t,c=o,"get"!==(a=(a=r).type)&&"set"!==a||1!==u.length||!c?Qe(Ze(r,tr("modify","bad-request"),o)):(r.element=o,Qe((e=((t,e)=>{try{var r=t()}catch(t){return e(t)}return r&&r.then?r.then(void 0,e):r})(function(){var t=n,e=function(t){i=t};if(void 0)return e?e(t()):t();try{var r=Promise.resolve(t());return e?r.then(e):r}catch(t){return Promise.reject(t)}},function(t){h.emit("error",t),i=tr("cancel","internal-server-error")}),s=function(){return(i=i||tr("cancel","service-unavailable"))instanceof b.Element&&i.is("error")?Ze(r,i,o):(t=r,e=i instanceof b.Element?i:void 0,(t=Ve(t)).attrs.type="result",e&&t.append(e),t);var t,e},e&&e.then?e.then(s):s(e)))))}catch(t){return Promise.reject(t)}var e,s,a,u,c,l,f}}function rr(r,n,o,i){return function(t,e){return t.type!==r|!t.element||!t.element.is(o,n)?e():i(t,e)}}c={};function nr(t){return t.startsWith("https")||t.startsWith("wss")}c.compare=function(t,e){var r=nr(t.uri)&&!nr(e.uri)?-1:!nr(t.uri)&&nr(e.uri)?1:0;return 0!==r||0!==(r=t.method===e.method?0:"websocket"===t.method?-1:"websocket"===e.method?1:"xbosh"===t.method?-1:"xbosh"===e.method?1:"httppoll"===t.method?-1:"httppoll"===e.method?1:0)?r:0};var or={},ir=globalThis.fetch||A,sr=c.compare;or.resolve=function(t){return ir("https://"+t+"/.well-known/host-meta").then(function(t){return t.text()}).then(function(t){return(t=>{var e=new Qt,r=null,n=null;if(e.on("start",function(t){r=t}),e.on("element",function(t){r.append(t)}),e.on("error",function(t){n=t}),e.write(t),e.end(),n)throw n;return r})(t).getChildren("Link").filter(function(t){return["urn:xmpp:alt-connections:websocket","urn:xmpp:alt-connections:httppoll","urn:xmpp:alt-connections:xbosh"].includes(t.attrs.rel)}).map(function(t){t=t.attrs;return{rel:t.rel,href:t.href,method:t.rel.split(":").pop(),uri:t.href}}).sort(sr)}).catch(function(){return[]})};var ar;function ur(){}ar=function(){return Promise.all([A.resolve?A.resolve.apply(A,arguments):Promise.resolve([]),or.resolve.apply(or,arguments)]).then(function(t){var e=t[0];return[].concat(e,t[1])})},A.resolve&&(ar.dns=A),ar.http=or;var cr=mr(function(e,r){var n=!1;if(0===r.length)throw new Error("Couldn't connect");var t=r.shift(),o=e._findTransport(t);if(!o)return cr(e,r);e._status("connecting",t);var i,s=o.prototype.socketParameters(t),a=new o.prototype.Socket;return t=hr(function(){return a.connect(s),lr(dr(a,"connect"))},function(){var t=cr(e,r);return n=!0,t}),i=function(t){if(n)return t;e._attachSocket(a),a.emit("connect"),e.Transport=o,e.Socket=o.prototype.Socket,e.Parser=o.prototype.Parser},t&&t.then?t.then(i):i(t)});function lr(t,e){if(!e)return t&&t.then?t.then(ur):Promise.resolve()}var fr=mr(function(t){return pr(ar(t,{srv:[{service:"xmpps-client",protocol:"tcp"},{service:"xmpp-client",protocol:"tcp"}]}),function(t){return[].concat(new Set(t.map(function(t){return t.uri})))})});function hr(t,e){try{var r=t()}catch(t){return e(t)}return r&&r.then?r.then(void 0,e):r}function pr(t,e,r){return r?e?e(t):t:(t&&t.then||(t=Promise.resolve(t)),e?t.then(e):t)}var dr=l.promise;function mr(r){return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];try{return Promise.resolve(r.apply(this,t))}catch(t){return Promise.reject(t)}}}function vr(t){var n=t.entity,e=n.connect;n.connect=function(t){try{return!t||/:\/\//.test(t)?pr(e.call(this,t)):pr(fr(t),function(t){e=n;var e,r=t.filter(function(t){return e._findTransport(t)});if(0===r.length)throw new Error("No compatible transport found.");return hr(function(){return lr(cr(n,r))},function(t){throw n._reset(),n._status("disconnect"),t})})}catch(t){return Promise.reject(t)}}}var k={};function yr(t){return(k=yr="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t}).__esModule=!0,k.default=k,yr(t)}(k=yr).__esModule=!0;var gr={},br=(k.default=k).default;(gr=function(t,e){if("object"!=br(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0===r)return("string"===e?String:Number)(t);if(r=r.call(t,e||"default"),"object"!=br(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}).__esModule=!0,gr.default=gr;var wr={},_r=k.default;(wr=function(t){return t=gr(t,"string"),"symbol"==_r(t)?t:t+""}).__esModule=!0,wr.default=wr;var xr={};(xr=function(t,e,r){return(e=wr(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}).__esModule=!0,xr.default=xr;var _={encode:function(t){return globalThis.btoa(t)},decode:function(t){return globalThis.atob(t)}},Sr=t(r),Pr=(o=>{function t(){for(var t,e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];return(t=o.call.apply(o,[this].concat(r))||this).name="SASLError",t}return(0,Sr.default)(t,o),t})(p);function jr(e,t){var r,n=Object.keys(e);return Object.getOwnPropertySymbols&&(r=Object.getOwnPropertySymbols(e),t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)),n}function Er(){}j=function(t,e,r){(e.exports=r).Factory=r},"object"==typeof(M={exports:{}}).exports&&j(M.exports,M,F({}));var M=M.exports,Ar=Mr(function(t,i,e,r){var s,a=t.create([e]);if(a)return t=i.options.domain,s=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?jr(Object(