serviceworker.js 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // install trigger for sw - cache index.html
  2. !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(){var t=function(e){var r;return function(t){return r||e(r={exports:{},parent:t},r.exports),r.exports}},e=t(function(t,e){"use strict";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||"",e+="\0",e+=t.username,e+="\0",e+=t.password},r.prototype.challenge=function(t){return this},e.exports=r},"object"==typeof e&&r(0,t)}),r=t(function(t,e){"use strict";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)}),n=t(function(t,e){"use strict";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)});var s=function(t){return t&&t.__esModule?t:{default:t}};var o=function(t,e){if(null==t)return{};for(var r,n={},o=Object.keys(t),i=0;i<o.length;i++)r=o[i],0<=e.indexOf(r)||(n[r]=t[r]);return n};function u(t,e){t.prototype=Object.create(e.prototype),(t.prototype.constructor=t).__proto__=e}var i={};function a(t){return i=a=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},a(t)}i=a;var c={};function l(t,e){return c=l=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},l(t,e)}c=l;var f=function(t){return-1!==Function.toString.call(t).indexOf("[native code]")};var h=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(t){return!1}},p={};function m(t,e,r){return p=m=h()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);n=new(Function.bind.apply(t,n));return r&&c(n,r.prototype),n},m.apply(null,arguments)}p=m;var d={};function v(t){var r="function"==typeof Map?new Map:void 0;return d=v=function(t){if(null===t||!f(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 p(t,arguments,i(this).constructor)}return e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),c(e,t)},v(t)}d=v;function y(e){var r,t=new Promise(function(t){r=setTimeout(t,e)});return t.timeout=r,t}var g,b=s(u),w=function(e){function t(t){t=e.call(this,t)||this;return t.name="TimeoutError",t}return(0,b.default)(t,e),t}((0,s(d).default)(Error)),x={},_="object"==typeof Reflect?Reflect:null,P=_&&"function"==typeof _.apply?_.apply:function(t,e,r){return Function.prototype.apply.call(t,e,r)};g=_&&"function"==typeof _.ownKeys?_.ownKeys:Object.getOwnPropertySymbols?function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:function(t){return Object.getOwnPropertyNames(t)};var j=Number.isNaN||function(t){return t!=t};function E(){E.init.call(this)}(x=E).once=function(o,i){return new Promise(function(t,e){function r(){void 0!==n&&o.removeListener("error",n),t([].slice.call(arguments))}var n;"error"!==i&&(n=function(t){o.removeListener(i,r),e(t)},o.once("error",n)),o.once(i,r)})},(E.EventEmitter=E).prototype._events=void 0,E.prototype._eventsCount=0,E.prototype._maxListeners=void 0;var O=10;function L(t){if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}function S(t){return void 0===t._maxListeners?E.defaultMaxListeners:t._maxListeners}function k(t,e,r,n){var o,i;return L(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<(r=S(t))&&i.length>r&&!i.warned&&(i.warned=!0,(r=new Error("Possible EventEmitter memory leak detected. "+i.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit")).name="MaxListenersExceededWarning",r.emitter=t,r.type=e,r.count=i.length,r=r,console&&console.warn&&console.warn(r))),t}function C(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 A(t,e,r){t=t._events;if(void 0===t)return[];e=t[e];return void 0===e?[]:"function"==typeof e?r?[e.listener||e]:[e]:r?function(t){for(var e=new Array(t.length),r=0;r<e.length;++r)e[r]=t[r].listener||t[r];return e}(e):M(e,e.length)}function T(t){var e=this._events;if(void 0!==e){t=e[t];if("function"==typeof t)return 1;if(void 0!==t)return t.length}return 0}function M(t,e){for(var r=new Array(e),n=0;n<e;++n)r[n]=t[n];return r}Object.defineProperty(E,"defaultMaxListeners",{enumerable:!0,get:function(){return O},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+".");O=t}}),E.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},E.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},E.prototype.getMaxListeners=function(){return S(this)},E.prototype.emit=function(t){for(var e=[],r=1;r<arguments.length;r++)e.push(arguments[r]);var n,o="error"===t,i=this._events;if(void 0!==i)o=o&&void 0===i.error;else if(!o)return!1;if(o){if(0<e.length&&(n=e[0]),n instanceof Error)throw n;o=new Error("Unhandled error."+(n?" ("+n.message+")":""));throw o.context=n,o}i=i[t];if(void 0===i)return!1;if("function"==typeof i)P(i,this,e);else for(var s=i.length,u=M(i,s),r=0;r<s;++r)P(u[r],this,e);return!0},E.prototype.addListener=function(t,e){return k(this,t,e,!1)},E.prototype.on=E.prototype.addListener,E.prototype.prependListener=function(t,e){return k(this,t,e,!0)},E.prototype.once=function(t,e){return L(e),this.on(t,C(this,t,e)),this},E.prototype.prependOnceListener=function(t,e){return L(e),this.prependListener(t,C(this,t,e)),this},E.prototype.removeListener=function(t,e){var r,n,o,i,s;if(L(e),void 0===(n=this._events))return this;if(void 0===(r=n[t]))return this;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;0===o?r.shift():function(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}(r,o),1===r.length&&(n[t]=r[0]),void 0!==n.removeListener&&this.emit("removeListener",t,s||e)}return this},E.prototype.off=E.prototype.removeListener,E.prototype.removeAllListeners=function(t){var e,r=this._events;if(void 0===r)return this;if(void 0===r.removeListener)return 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]),this;if(0===arguments.length){for(var n,o=Object.keys(r),i=0;i<o.length;++i)"removeListener"!==(n=o[i])&&this.removeAllListeners(n);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}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},E.prototype.listeners=function(t){return A(this,t,!0)},E.prototype.rawListeners=function(t){return A(this,t,!1)},E.listenerCount=function(t,e){return"function"==typeof t.listenerCount?t.listenerCount(e):T.call(t,e)},E.prototype.listenerCount=T,E.prototype.eventNames=function(){return 0<this._eventsCount?g(this._events):[]};var N={};N.EventEmitter=x,N.timeout=function(t,e){var r=y(e);return Promise.race([t.finally(function(){clearTimeout(r.timeout)}),r.then(function(){throw new w})])},N.promise=function(s,u,a,c){return void 0===a&&(a="error"),new Promise(function(e,r){var t,n=function(){clearTimeout(t),s.removeListener(u,i),s.removeListener(a,o)};function o(t){r(t),n()}function i(t){e(t),n()}s.once(u,i),a&&s.once(a,o),c&&(t=setTimeout(function(){n(),r(new w)},c))})},N.Deferred=function(){var r=this;this.promise=new Promise(function(t,e){r.resolve=t,r.reject=e})};var q={detect:function(t){return!!t&&-1!==t.replace(/\\20/g,"").replace(/\\22/g,"").replace(/\\26/g,"").replace(/\\27/g,"").replace(/\\2f/g,"").replace(/\\3a/g,"").replace(/\\3c/g,"").replace(/\\3e/g,"").replace(/\\40/g,"").replace(/\\5c/g,"").search(/[ "&'/:<>@\\]/g)},escape:function(t){return null===t?null:t.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").replace(/\3a/g,"c3a")},unescape:function(t){return null===t?null:t.replace(/\\20/g," ").replace(/\\22/g,'"').replace(/\\26/g,"&").replace(/\\27/g,"'").replace(/\\2f/g,"/").replace(/\\3a/g,":").replace(/\\3c/g,"<").replace(/\\3e/g,">").replace(/\\40/g,"@").replace(/\\5c/g,"\\")}},R=function(){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),this._resource&&(e=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||q.detect(t))&&(t=q.escape(t)),this._local=t&&t.toLowerCase(),this},e.getLocal=function(t){return(t=t||!1)?q.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}();Object.defineProperty(R.prototype,"local",{get:R.prototype.getLocal,set:R.prototype.setLocal}),Object.defineProperty(R.prototype,"domain",{get:R.prototype.getDomain,set:R.prototype.setDomain}),Object.defineProperty(R.prototype,"resource",{get:R.prototype.getResource,set:R.prototype.setResource});var X=R,F=function(t){var e,r,n=t.indexOf("/");-1!==n&&(r=t.slice(n+1),t=t.slice(0,n));n=t.indexOf("@");return-1!==n&&(e=t.slice(0,n),t=t.slice(n+1)),new X(e,t,r)},z={},D=s(p);function I(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];return e[1]||e[2]?(0,D.default)(X,e):F.apply(void 0,e)}(z=I.bind()).jid=I,z.JID=X,z.equal=function(t,e){return t.equals(e)},z.detectEscape=q.detect,z.escapeLocal=q.escape,z.unescapeLocal=q.unescape,z.parse=F;var B={},U={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&apos;"};function W(t){return U[t]}var H={"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&apos;":"'"};function J(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(H[t])return H[t]||t;throw new Error("Illegal XML entity "+t)}B.escapeXML=function(t){return t.replace(/&|<|>|"|'/g,W)},B.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.substring(o,e)+J(t.substring(e,n+1)),o=n+1;return 0===o?t:r+=t.substring(o)},B.escapeXMLText=function(t){return t.replace(/&|<|>/g,W)},B.unescapeXMLText=function(t){return t.replace(/&(amp|#38|lt|#60|gt|#62);/g,J)};t={};function K(t,e){return t.name===e.name}function Y(t,e){var r=t.attrs,n=Object.keys(r),t=n.length;if(t!==Object.keys(e.attrs).length)return!1;for(var o=0,i=t;o<i;o++){var s=n[o],u=r[s];if(null==u||null==e.attrs[s]){if(u!==e.attrs[s])return!1}else if(u.toString()!==e.attrs[s].toString())return!1}return!0}function $(t,e){var r=t.children,t=r.length;if(t!==e.children.length)return!1;for(var n=0,o=t;n<o;n++){var i=r[n];if("string"==typeof i){if(i!==e.children[n])return!1}else if(!i.equals(e.children[n]))return!1}return!0}t.name=K,t.attrs=Y,t.children=$,t.equal=function(t,e){return!!K(t,e)&&(!!Y(t,e)&&!!$(t,e))};var G=B.escapeXML,Q=B.escapeXMLText,V=t.equal,Z=t.name,tt=t.attrs,et=t.children;function rt(t,e){this.name=t,this.parent=null,this.children=[],this.attrs={},this.setAttrs(e)}rt.prototype.is=function(t,e){return this.getName()===t&&(!e||this.getNS()===e)},rt.prototype.getName=function(){return 0<=this.name.indexOf(":")?this.name.substr(this.name.indexOf(":")+1):this.name},rt.prototype.getNS=function(){if(0<=this.name.indexOf(":")){var t=this.name.substr(0,this.name.indexOf(":"));return this.findNS(t)}return this.findNS()},rt.prototype.findNS=function(t){if(t){var e="xmlns:"+t;return this.attrs[e]?this.attrs[e]:this.parent?this.parent.findNS(t):void 0}return this.attrs.xmlns||(this.parent?this.parent.findNS():void 0)},rt.prototype.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},rt.prototype.setAttrs=function(e){"string"==typeof e?this.attrs.xmlns=e:e&&Object.keys(e).forEach(function(t){this.attrs[t]=e[t]},this)},rt.prototype.getAttr=function(t,e){if(!e)return this.attrs[t];var r=this.getXmlns();return r[e]?this.attrs[[r[e],t].join(":")]:null},rt.prototype.getChild=function(t,e){return this.getChildren(t,e)[0]},rt.prototype.getChildren=function(t,e){for(var r=[],n=0;n<this.children.length;n++){var o=this.children[n];!o.getName||o.getName()!==t||e&&o.getNS()!==e||r.push(o)}return r},rt.prototype.getChildByAttr=function(t,e,r,n){return this.getChildrenByAttr(t,e,r,n)[0]},rt.prototype.getChildrenByAttr=function(t,e,r,n){for(var o=[],i=0;i<this.children.length;i++){var s=this.children[i];!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 n&&(o=[].concat.apply([],o)),o},rt.prototype.getChildrenByFilter=function(t,e){for(var r=[],n=0;n<this.children.length;n++){var o=this.children[n];t(o)&&r.push(o),e&&o.getChildrenByFilter&&r.push(o.getChildrenByFilter(t,!0))}return e&&(r=[].concat.apply([],r)),r},rt.prototype.getText=function(){for(var t="",e=0;e<this.children.length;e++){var r=this.children[e];"string"!=typeof r&&"number"!=typeof r||(t+=r)}return t},rt.prototype.getChildText=function(t,e){e=this.getChild(t,e);return e?e.getText():null},rt.prototype.getChildElements=function(){return this.getChildrenByFilter(function(t){return t instanceof rt})},rt.prototype.tree=rt.prototype.root=function(){return this.parent?this.parent.root():this},rt.prototype.up=function(){return this.parent||this},rt.prototype.c=function(t,e){return this.cnode(new rt(t,e))},rt.prototype.cnode=function(t){return this.children.push(t),"object"==typeof t&&(t.parent=this),t},rt.prototype.t=function(t){return this.children.push(t),this},rt.prototype.remove=function(e,r){var t="string"==typeof e?function(t){return!(t.is&&t.is(e,r))}:function(t){return t!==e};return this.children=this.children.filter(t),this},rt.prototype.clone=function(){return function(t){for(var e=new t.constructor(t.name,t.attrs),r=0;r<t.children.length;r++){var n=t.children[r];e.cnode(n.clone?n.clone():n)}return e}(this)},rt.prototype.text=function(t){return t&&1===this.children.length?(this.children[0]=t,this):this.getText()},rt.prototype.attr=function(t,e){return void 0!==e||null===e?(this.attrs||(this.attrs={}),this.attrs[t]=e,this):this.attrs[t]},rt.prototype.toString=function(){var e="";return this.write(function(t){e+=t}),e},rt.prototype.toJSON=function(){return{name:this.name,attrs:this.attrs,children:this.children.map(function(t){return t&&t.toJSON?t.toJSON():t})}},rt.prototype._addChildren=function(t){t(">");for(var e=0;e<this.children.length;e++){var r=this.children[e];!r&&0!==r||(r.write?r.write(t):"string"==typeof r?t(Q(r)):r.toString&&t(Q(r.toString(10))))}t("</"),t(this.name),t(">")},rt.prototype.write=function(t){for(var e in t("<"),t(this.name),this.attrs){var r=this.attrs[e];null!=r&&(t(" "),t(e),t('="'),"string"!=typeof r&&(r=r.toString()),t(G(r)),t('"'))}0===this.children.length?t("/>"):this._addChildren(t)},rt.prototype.nameEquals=function(t){return Z(this,t)},rt.prototype.attrsEquals=function(t){return tt(this,t)},rt.prototype.childrenEquals=function(t){return et(this,t)},rt.prototype.equals=function(t){return V(this,t)};var _=rt,nt=s(u),ot=function(t){function e(){return t.apply(this,arguments)||this}(0,nt.default)(e,t);var r=e.prototype;return r.setAttrs=function(r){var n=this;"string"==typeof r?this.attrs.xmlns=r:r&&Object.keys(r).forEach(function(t){var e;"__source"===t||"__self"===t||null!=(e=r[t])&&(n.attrs[t.toString()]=e.toString())},this)},r.append=function(t){var e=this;return(t=Array.isArray(t)?t:[t]).forEach(function(t){e.children.push(t),"object"==typeof t&&(t.parent=e)}),this},r.prepend=function(t){var e=this;return(t=Array.isArray(t)?t:[t]).forEach(function(t){e.children.unshift(t),"object"==typeof t&&(t.parent=e)}),this},e}(_);var it=function(t,e){for(var r=new ot(t,e),n=0;n<(arguments.length<=2?0:arguments.length-2);n++)!function e(r,t){!1!==t&&null!=t&&(t instanceof ot?r.append(t):Array.isArray(t)?t.forEach(function(t){return e(r,t)}):r.append(String(t)))}(r,n+2<2||arguments.length<=n+2?void 0:arguments[n+2]);return r};var st,R=function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t},t={},t="function"==typeof Object.create?function(t,e){e&&(t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:function(t,e){var r;e&&(t.super_=e,(r=function(){}).prototype=e.prototype,t.prototype=new r,t.prototype.constructor=t)},ut=x.EventEmitter,at=B.unescapeXML,_=st=function(){ut.call(this);var c,l,f,h,p,m,d,v,y=0,g=0;this._handleTagOpening=function(t,e,r){t?this.emit("endElement",e):(this.emit("startElement",e,r),p&&this.emit("endElement",e))},this.write=function(e){"string"!=typeof e&&(e=e.toString());var t,r,n=0;function o(){if("number"==typeof g){var t=e.substring(g,n);return g=void 0,t}}for(c&&(e=c+e,n+=c.length,c=null);n<e.length;n++){0===y?-1!==(t=e.indexOf("<",n))&&n!==t&&(n=t):8===y?-1!==(t=e.indexOf(d,n))&&(n=t):1===y?-1!==(r=e.indexOf("--\x3e",n))&&(n=r+2):10!==y||-1!==(r=e.indexOf("]]>",n))&&(n=r+2);var i,s,u,a=e.charCodeAt(n);switch(y){case 0:60===a&&((i=o())&&this.emit("text",at(i)),y=3,g=n+1,f={});break;case 9:93===a&&"]>"===e.substr(n+1,2)&&((s=o())&&this.emit("text",s),y=0);break;case 3:47===a&&g===n?(g=n+1,h=!0):33===a?y="[CDATA["===e.substr(n+1,7)?(g=n+8,9):(g=void 0,1):63===a?(g=void 0,y=2):(a<=32||47===a||62===a)&&(l=o(),n--,y=4);break;case 1:62===a&&(s=e.charCodeAt(n-1),u=e.charCodeAt(n-2),(45===s&&45===u||93===s&&93===u)&&(y=0));break;case 2:62===a&&63===e.charCodeAt(n-1)&&(y=0);break;case 4:62===a?(this._handleTagOpening(h,l,f),p=h=f=l=void 0,y=0,g=n+1):47===a?p=!0:32<a&&(g=n,y=5);break;case 5:(a<=32||61===a)&&(v=o(),n--,y=6);break;case 6:61===a&&(y=7);break;case 7:34!==a&&39!==a||(d=34===(m=a)?'"':"'",y=8,g=n+1);break;case 8:a===m&&(u=at(o()),f[v]=u,v=void 0,y=4)}}"number"==typeof g&&g<=e.length&&(c=e.slice(g),g=0)}};t(_,ut),_.prototype.end=function(t){t&&this.write(t),this.write=function(){}};var ct=s(u),lt=function(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,ct.default)(t,o),t}((0,s(d).default)(Error)),ft=s(R),ht=s(u),t=function(r){function t(){var t=r.call(this)||this,e=new st;return t.root=null,t.cursor=null,e.on("startElement",t.onStartElement.bind((0,ft.default)(t))),e.on("endElement",t.onEndElement.bind((0,ft.default)(t))),e.on("text",t.onText.bind((0,ft.default)(t))),t.parser=e,t}(0,ht.default)(t,r);var e=t.prototype;return e.onStartElement=function(t,e){var r=new ot(t,e),t=this.root,e=this.cursor;t?e!==t&&e.append(r):(this.root=r,this.emit("start",r)),this.cursor=r},e.onEndElement=function(t){var e=this.root,r=this.cursor;if(t===r.name){if(r!==e)return r.parent?void(this.cursor=r.parent):(r.parent=e,this.emit("element",r),void(this.cursor=e));this.emit("end",e)}else this.emit("error",new lt(r.name+" must be closed."))},e.onText=function(t){var e=this.cursor;e?e.t(t):this.emit("error",new lt(t+" must be a child."))},e.write=function(t){this.parser.write(t)},e.end=function(t){t&&this.parser.write(t)},t}(x);t.XMLError=lt;var pt=t,mt={},_=B.escapeXML,R=B.unescapeXML,t=B.escapeXMLText,B=B.unescapeXMLText;mt=function(){return it.apply(void 0,arguments)},Object.assign(mt,{x:it,Element:ot,Parser:pt,escapeXML:_,unescapeXML:R,escapeXMLText:t,unescapeXMLText:B,XMLError:lt});var dt=s(u),_=function(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,dt.default)(t,o),t.fromElement=function(t){var e,r=t.children,n=r[0],o=r[1],r=r[2];o&&(o.is("text")?e=o:o&&(i=o),r&&(i=r));var i=new this(n.name,e?e.text():"",i);return i.element=t,i},t}((0,s(d).default)(Error)),vt=s(u),yt=function(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,vt.default)(t,o),t}(_),R={};function gt(t){var e=new URL(t),r=e.port,t=e.hostname;return"[::1]"===t&&(t="::1"),{port:r,hostname:t,protocol:e.protocol}}function bt(t){t=gt("http://"+t);return{port:t.port,hostname:t.hostname}}Object.assign(R,{parseURI:gt,parseHost:bt,parseService:function(t){return(t.includes("://")?gt:bt)(t)}});var wt=s(u);function xt(){}var t=N.EventEmitter,_t=N.promise;function Pt(t,e){if(!e)return t&&t.then?t.then(xt):Promise.resolve()}function jt(t,e){try{var r=t()}catch(t){return e(t)}return r&&r.then?r.then(void 0,e):r}function Et(t,e){return t&&t.then?t.then(e):e(t)}function Ot(t,e,r){return r?e?e(t):t:(t&&t.then||(t=Promise.resolve(t)),e?t.then(e):t)}var Lt=R.parseHost,St=R.parseService;B=function(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,wt.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 Et(jt(function(){return Pt(r.send(mt("stream:error",{},[mt(t,{xmlns:"urn:ietf:params:xml:ns:xmpp-streams"},e)])))},xt),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;this.socket=t;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(){var e=this.socketListeners,r=this.socket;return Object.getOwnPropertyNames(e).forEach(function(t){r.removeListener(t,e[t]),delete e[t]}),this.socket=null,r},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=yt.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=St(n.options.service).protocol,r=t.element.getChildText("see-other-host"),o=Lt(r).port?(e||"xmpp:")+"//"+r:(e?e+"//":"")+r;return function(t){if(t&&t.then)return t.then(xt)}(jt(function(){return Ot(_t(n,"disconnect"),function(){var t=n.options,e=t.domain,r=t.lang;return Ot(n.connect(o),function(){return Pt(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;this.parser=t;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(){var e=this,r=this.parserListeners;Object.getOwnPropertyNames(r).forEach(function(t){e.parser.removeListener(t,r[t]),delete r[t]}),this.parser=null},e._jid=function(t){return this.jid=z(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 Et(jt(function(){return Ot(t.close(),function(t){e=t})},xt),function(){return Et(jt(function(){return Pt(t.disconnect())},xt),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 Ot(e.connect(r),function(){var t=_t(e,"online");return Ot(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)),_t(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(),Pt(_t(e.socket,"close","error",t))}catch(t){return Promise.reject(t)}},e.open=function(t){try{var e=this;e._status("opening"),"string"==typeof t&&(t={domain:t});var r=t.domain,n=t.lang,o=t.timeout,i=void 0===o?e.timeout:o,o=e.headerElement();return o.attrs.to=r,o.attrs["xml:lang"]=n,e.root=o,e._attachParser(new e.Parser),Ot(e.write(e.header(o)),function(){return _t(e,"open","error",i)})}catch(t){return Promise.reject(t)}},e.stop=function(){try{var e=this;return Ot(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;void 0===t&&(t=e.timeout);var r=Promise.all([_t(e.parser,"end","error",t),e.write(e.footer(e.footerElement()))]);return e.parser&&e.socket&&e._status("closing"),Ot(r,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,t=t.lang;return this.open({domain:e,lang:t})}catch(t){return Promise.reject(t)}},e.send=function(t){try{var e=this;return t.parent=e.root,e.emit("outgoing",t),Ot(e.write(t),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),_t(this,"element","error",e)]).then(function(t){return t[1]})},e.write=function(t){var o=this;return new Promise(function(e,r){var n;"closing"!==o.status?(n=t.toString("utf8"),o.socket.write(n,function(t){return t?r(t):(o.emit("output",n),void e())})):r(new Error("Connection is closing"))})},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 mt.Element("",{version:"1.0",xmlns:this.NS})},e.footer=function(t){return t.toString()},e.footerElement=function(){},e.socketParameters=function(){},t}(t);B.prototype.NS="",B.prototype.Socket=null,B.prototype.Parser=null;var R=B,kt=s(u),t=function(r){function t(t){t=r.call(this,t)||this;return t.transports=[],t}(0,kt.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._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)throw new Error("No compatible connection method found.");return this.Transport=e,this.Socket=e.prototype.Socket,this.Parser=e.prototype.Parser,r.prototype.connect.call(this,t)},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}(R);t.prototype.NS="jabber:client";B={};B.Client=t,B.xml=mt,B.jid=z;var Ct=function(t){return(t.split("://")[1]||t).split(":")[0].split("/")[0]},At=s(u);function Tt(){}var Mt=function(r){function t(t){var e=r.call(this)||this;return e.delay=1e3,e.entity=t,e._timeout=null,e}(0,At.default)(t,r);var e=t.prototype;return e.scheduleReconnect=function(){var r,t=this,e=this.entity,n=this.delay,o=this._timeout;clearTimeout(o),this._timeout=setTimeout((r=function(){if("disconnect"===e.status)return function(t){if(t&&t.then)return t.then(Tt)}(function(t,e){try{var r=t()}catch(t){return e(t)}if(r&&r.then)return r.then(void 0,e);return r}(function(){return function(t,e){if(!e)return t&&t.then?t.then(Tt):Promise.resolve()}(t.reconnect())},Tt))},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)}}),n)},e.reconnect=function(){try{var t=this,e=t.entity;t.emit("reconnecting");var r=e.options,n=r.service,o=r.domain,i=r.lang;return Nt(e.connect(n),function(){return Nt(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}(N.EventEmitter);function Nt(t,e,r){return r?e?e(t):t:(t&&t.then||(t=Promise.resolve(t)),e?t.then(e):t)}var qt=function(t){t=t.entity,t=new Mt(t);return t.start(),t},Rt={},Xt={};(function(t){(function(){"use strict";var n=s(u),o=t.WebSocket||Rt,i="ECONNERROR";Xt=function(e){function t(){var t=e.call(this)||this;return t.listeners=Object.create(null),t}(0,n.default)(t,e);var r=t.prototype;return r.connect=function(t){this.url=t,this._attachSocket(new o(t,["xmpp"]))},r._attachSocket=function(t){var r=this;this.socket=t;t=this.listeners;t.open=function(){r.emit("connect")},t.message=function(t){t=t.data;return r.emit("data",t)},t.error=function(t){var e=t.error;e||((e=new Error("WebSocket "+i+" "+r.url)).errno=i,e.code=i),e.event=t,e.url=r.url,r.emit("error",e)},t.close=function(t){r._detachSocket(),r.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;var e=this.socket,r=this.listeners;Object.getOwnPropertyNames(r).forEach(function(t){e.removeEventListener(t,r[t]),delete r[t]}),delete this.socket},r.end=function(){this.socket.close()},r.write=function(t,e){o===Rt?this.socket.send(t,e):(this.socket.send(t),e())},t}(x)}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{});var Ft=s(u),t=mt.Parser,zt=mt.Element,Dt=mt.XMLError,t=function(t){function e(){return t.apply(this,arguments)||this}(0,Ft.default)(e,t);var r=e.prototype;return r.onStartElement=function(t,e){t=new zt(t,e),e=this.cursor;e&&e.append(t),this.cursor=t},r.onEndElement=function(t){var e=this.cursor;t===e.name?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):this.emit("error",new Dt(e.name+" must be closed."))},e}(t),It=s(u),Bt="urn:ietf:params:xml:ns:xmpp-framing",R=function(i){function t(){return i.apply(this,arguments)||this}(0,It.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.footerElement=function(){return new mt.Element("close",{xmlns:Bt})},e.headerElement=function(){var t=i.prototype.headerElement.call(this);return t.name="open",t.attrs.xmlns=Bt,t},e.socketParameters=function(t){return t.match(/^wss?:\/\//)?t:void 0},t}(R);R.prototype.Socket=Xt,R.prototype.NS="jabber:client",R.prototype.Parser=t;var Ut=R,Wt=function(t){t.entity.transports.push(Ut)};function Ht(t,e){var r;if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator])return(r=t[Symbol.iterator]()).next.bind(r);if(Array.isArray(t)||(r=function(t,e){if(!t)return;if("string"==typeof t)return Jt(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return Jt(t,e)}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}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 Jt(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}var Kt=function(s){if(!Array.isArray(s))throw new TypeError("Middleware stack must be an array!");for(var t,e=Ht(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(t===s.length&&(e=n),!e)return Promise.resolve();try{return Promise.resolve(e(r,i.bind(null,t+1)))}catch(t){return Promise.reject(t)}}}};var R=function(t,e){this.stanza=e,this.entity=t;var r=e.name,t=e.attrs,e=t.type,t=t.id;this.name=r,this.id=t||"",this.type="message"===r?e||"normal":"presence"===r?e||"available":e||"",this.from=null,this.to=null,this.local="",this.domain="",this.resource=""},Yt=s(u),$t=function(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(),t=e.attrs.from||t;return n&&(r.to=new z(n)),t&&(r.from=new z(t),r.local=r.from.local,r.domain=r.from.domain,r.resource=r.from.resource),r}return(0,Yt.default)(t,o),t}(R),Gt=s(u),Qt=function(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(),t=e.attrs.to||t;return n&&(r.from=new z(n)),t&&(r.to=new z(t),r.local=r.to.local,r.domain=r.to.domain,r.resource=r.to.resource),r}return(0,Gt.default)(t,o),t}(R);function Vt(e,r,n){return function(t){t=new n(e,t);return Kt(r)(t)}}var Zt=function(t){var r,e=t.entity,n=[function(t,e){e().then(function(t){return t&&r.send(t)}).catch(function(t){return r.emit("error",t)})}],o=[],i=Vt(r=e,n,$t),t=Vt(e,o,Qt);return e.on("element",i),e.hookOutgoing=t,{use:function(t){return n.push(t),t},filter:function(t){return o.push(t),t}}};function te(){return r=function(t,e){var r=t.stanza,n=t.entity;return r.is("features","http://etherx.jabber.org/streams")?function(t,e,r){if(r)return e?e(t()):t();try{var n=Promise.resolve(t());return e?n.then(e):n}catch(t){return Promise.reject(t)}}(e,function(t){!t&&n.jid&&n._status("online",n.jid)}):e()},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}var ee=function(t){var e=t.middleware;return e.use(te()),{use:function(n,o,i){return e.use(function(t,e){var r=t.stanza;if(!r.is("features","http://etherx.jabber.org/streams"))return e();r=r.getChild(n,o);return r?i(t,e,r):e()})}}},re=s(u),ne=function(o){function t(t,e,r,n){r=o.call(this,t,e,r)||this;return r.type=n,r.name="StanzaError",r}return(0,re.default)(t,o),t.fromElement=function(t){var e=o.fromElement.call(this,t);return e.type=t.attrs.type,e},t}(_),oe=s(p);function ie(){}var se=N.Deferred;var ue=N.timeout;var ae=function(){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=t.type,n=t.name,o=t.id,i=t.stanza;if(n=(t={name:n,type:r}).name,t=t.type,"iq"!==n||"error"!==t&&"result"!==t)return e();t=this.handlers.get(o);if(!t)return e();"error"===r?t.reject(ne.fromElement(i.getChild("error"))):t.resolve(i),this.handlers.delete(o)},e.request=function(n,o){void 0===o&&(o=3e4);try{var i=this;n.attrs.id||(n.attrs.id=function(){for(var t;!t;)t=Math.random().toString(36).slice(2,12);return t}());var s=new se;return i.handlers.set(n.attrs.id,s),t=function(t,e){try{var r=t()}catch(t){return e(t)}return r&&r.then?r.then(void 0,e):r}(function(){return t=i.entity.send(n),e=function(){return function(t,e){if(!e)return t&&t.then?t.then(ie):Promise.resolve()}(ue(s.promise,o))},r?e?e(t):t:(t&&t.then||(t=Promise.resolve(t)),e?t.then(e):t);var t,e,r},function(t){throw i.handlers.delete(n.attrs.id),t}),e=function(t){return s.promise},t&&t.then?t.then(e):e(t)}catch(t){return Promise.reject(t)}var t,e},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),u=3;u<i;u++)s[u-3]=arguments[u];return this.request.apply(this,[mt("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 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 this._childRequest.apply(this,["set"].concat(e))}catch(t){return Promise.reject(t)}},t}(),ce=function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];var n=(0,oe.default)(ae,e);return n.start(),n};var le="urn:ietf:params:xml:ns:xmpp-stanzas";function fe(t){t=t.stanza;return mt("iq",{to:t.attrs.from,from:t.attrs.to,id:t.attrs.id})}function he(t,e,r){t=fe(t);return t.attrs.type="error",r&&t.append(r),t.append(e),t}function pe(t,e){return mt("error",{type:t},mt(e,le))}function me(u){return function(r,t){try{if(s=(i=r).name,i=i.type,"iq"!==s||("error"===i||"result"===i))return t();var n,e=r.stanza.getChildElements(),o=e[0];return(s=e,i=o,"get"!==(e=(e=r).type)&&"set"!==e||(1!==s.length||!i))?he(r,pe("modify","bad-request"),o):(r.element=o,s=function(t,e){try{var r=t()}catch(t){return e(t)}return r&&r.then?r.then(void 0,e):r}(function(){return function(t,e,r){if(r)return e?e(t()):t();try{var n=Promise.resolve(t());return e?n.then(e):n}catch(t){return Promise.reject(t)}}(t,function(t){n=t})},function(t){u.emit("error",t),n=pe("cancel","internal-server-error")}),i=function(){return(n=n||pe("cancel","service-unavailable"))instanceof mt.Element&&n.is("error")?he(r,n,o):(t=r,e=n instanceof mt.Element?n:void 0,(t=fe(t)).attrs.type="result",e&&t.append(e),t);var t,e},s&&s.then?s.then(i):i(s))}catch(t){return Promise.reject(t)}var i,s}}function de(r,n,o,i){return function(t,e){return t.type!==r|!t.element||!t.element.is(o,n)?e():i(t,e)}}var ve=function(t){var n=t.middleware,t=t.entity;return n.use(me(t)),{get:function(t,e,r){n.use(de("get",t,e,r))},set:function(t,e,r){n.use(de("set",t,e,r))}}},ye={};function ge(t){return t.startsWith("https")||t.startsWith("wss")}ye.compare=function(t,e){var r=ge(t.uri)&&!ge(e.uri)?-1:!ge(t.uri)&&ge(e.uri)?1:0;return 0!==r?r:0!==(e=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)?e:0};var be={};(function(t){(function(){"use strict";var e=t.fetch||Rt,r=ye.compare;be.resolve=function(t){return e("https://"+t+"/.well-known/host-meta").then(function(t){return t.text()}).then(function(t){return function(t){var e=new pt,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(r)}).catch(function(){return[]})}}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{});var we;function xe(){}we=function(){return Promise.all([Rt.resolve?Rt.resolve.apply(Rt,arguments):Promise.resolve([]),be.resolve.apply(be,arguments)]).then(function(t){var e=t[0],t=t[1];return e.concat(t)})},Rt.resolve&&(we.dns=Rt),we.http=be;var _e=Se(function(e,t){var r=!1;if(0===t.length)throw new Error("Couldn't connect");var n=t.shift(),o=e._findTransport(n);if(!o)return _e(e,t);e._status("connecting",n);var i,s=o.prototype.socketParameters(n),u=new o.prototype.Socket;return i=Ee(function(){return u.connect(s),Pe(Le(u,"connect"))},function(){return r=!0,_e(e,t)}),n=function(t){return r?t:(e._attachSocket(u),u.emit("connect"),e.Transport=o,e.Socket=o.prototype.Socket,void(e.Parser=o.prototype.Parser))},i&&i.then?i.then(n):n(i)});function Pe(t,e){if(!e)return t&&t.then?t.then(xe):Promise.resolve()}var je=Se(function(t){return Oe(we(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 Ee(t,e){try{var r=t()}catch(t){return e(t)}return r&&r.then?r.then(void 0,e):r}function Oe(t,e,r){return r?e?e(t):t:(t&&t.then||(t=Promise.resolve(t)),e?t.then(e):t)}var Le=N.promise;function Se(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)}}}var ke=function(t){var n=t.entity,e=n.connect;n.connect=function(t){try{return!t||t.match(/:\/\//)?e.call(this,t):Oe(je(t),function(t){var e,r=(e=n,t.filter(function(t){return e._findTransport(t)}));if(0===r.length)throw new Error("No compatible transport found.");return Ee(function(){return Pe(_e(n,r))},function(t){throw n._reset(),n._status("disconnect"),t})})}catch(t){return Promise.reject(t)}}};var Ce=function(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t},Ae={};(function(e){(function(){"use strict";Ae.encode=function(t){return e.btoa(t)},Ae.decode=function(t){return e.atob(t)}}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{});var Te=s(u),Me=function(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,Te.default)(t,o),t}(_),Ne={exports:{}};function qe(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 Re(){}_=function(t,e,r){(e.exports=r).Factory=r},"object"==typeof Ne.exports&&_(Ne.exports,Ne,n({})),Ne=Ne.exports;var Xe=Ie(function(t,o,e,r){var i=t.create([e]);if(!i)throw new Error("No compatible mechanism");var e=o.options.domain,s=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?qe(Object(r),!0).forEach(function(t){Ce(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):qe(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}({username:null,password:null,server:e,host:e,realm:e,serviceType:"xmpp",serviceName:e},r);return new Promise(function(e,r){function n(t){t.attrs.xmlns===Be&&("challenge"!==t.name?("failure"===t.name?r(Me.fromElement(t)):"success"===t.name&&e(),o.removeListener("nonza",n)):(i.challenge(De(t.text())),t=i.response(s),o.send(mt("response",{xmlns:Be,mechanism:i.name},"string"==typeof t?ze(t):""))))}o.on("nonza",n),i.clientFirst&&o.send(mt("auth",{xmlns:Be,mechanism:i.name},ze(i.response(s))))})});function Fe(t,e){if(!e)return t&&t.then?t.then(Re):Promise.resolve()}var ze=Ae.encode,De=Ae.decode;function Ie(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)}}}var Be="urn:ietf:params:xml:ns:xmpp-sasl";var Ue=function(t,s){var t=t.streamFeatures,u=new Ne;return t.use("mechanisms",Be,Ie(function(t){var e,r=t.stanza,n=t.entity,o=r.getChild("mechanisms",Be).children.map(function(t){return t.text()}),i=u._mechs.map(function(t){return t.name}).filter(function(t){return o.includes(t)})[0];return e=function(){return Fe(n.restart())},(t=(t=function(){return"function"==typeof s?Fe(s(function(t){return Xe(u,n,i,t,r)},i)):(s.username||s.password||(i="ANONYMOUS"),Fe(Xe(u,n,i,s,r)))})())&&t.then?t.then(e):e(t)})),{use:function(){return u.use.apply(u,arguments)}}};function We(t,e,r){return r?e?e(t):t:(t&&t.then||(t=Promise.resolve(t)),e?t.then(e):t)}var He=Je(function(e,t,r){return We(t.set(mt("bind",{xmlns:Ke},(r=r)&&mt("resource",{},r))),function(t){t=t.getChildText("jid");return e._jid(t),t})});function Je(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)}}}var Ke="urn:ietf:params:xml:ns:xmpp-bind";var Ye=function(t,e){var n,o,r=t.streamFeatures,t=t.iqCaller;r.use("bind",Ke,(n=e,o={iqCaller:t}.iqCaller,Je(function(t,e){var r=t.entity;return We("function"==typeof n?n(function(t){return He(r,o,t)}):He(r,o,n),function(){e()})})))};var $e="urn:ietf:params:xml:ns:xmpp-session",Ge=function(t){var r,i=t.iqCaller;t.streamFeatures.use("session",$e,(r=function(t,e,r){return r.getChild("optional")?e():(n=i.set(mt("session",$e)),r=function(){return e()},o?r?r(n):n:(n&&n.then||(n=Promise.resolve(n)),r?n.then(r):n));var n,o},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 Qe(t,e,r){return r?e?e(t):t:(t&&t.then||(t=Promise.resolve(t)),e?t.then(e):t)}var Ve=rr(function(t,e,r){return Qe(t.sendReceive(mt("resume",{xmlns:er,h:e,previd:r})),function(t){if(!t.is("resumed",er))throw t;return t})});function Ze(t,e){try{var r=t()}catch(t){return e(t)}return r&&r.then?r.then(void 0,e):r}var tr=rr(function(o,t,e){return o.send(mt("enable",{xmlns:er,max:e,resume:t?"true":void 0})),new Promise(function(r,n){o.on("nonza",function t(e){if(e.is("enabled",er))r(e);else{if(!e.is("failed",er))return;n(e)}o.removeListener("nonza",t)})})});var er="urn:xmpp:sm:3";function rr(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)}}}var nr=function(t){var e=t.streamFeatures,i=t.entity,t=t.middleware,s=null,u={allowResume:!0,preferredMaximum:null,enabled:!1,id:"",outbound:0,inbound:0,max:null};return i.on("online",function(t){s=t,u.outbound=0,u.inbound=0}),i.on("offline",function(){u.outbound=0,u.inbound=0,u.enabled=!1,u.id=""}),t.use(function(t,e){t=t.stanza;return["presence","message","iq"].includes(t.name)?u.inbound+=1:t.is("r",er)?i.send(mt("a",{xmlns:er,h:u.inbound})).catch(function(){}):t.is("a",er)&&(u.outbound=t.attrs.h),e()}),e.use("sm",er,rr(function(t,e){var r,n,o=!1;return n=function(t){return o?t:function(t,e,r){if(r)return e?e(t()):t();try{var n=Promise.resolve(t());return e?n.then(e):n}catch(t){return Promise.reject(t)}}(e,function(){var t,e,r=tr(i,u.allowResume,u.preferredMaximum);return u.outbound=0,t=Ze(function(){return Qe(r,function(t){u.enabled=!0,u.id=t.attrs.id,u.max=t.attrs.max})},function(){u.enabled=!1}),e=function(){u.inbound=0},t&&t.then?t.then(e):e(t)})},(r=(r=function(){if(u.id)return Ze(function(){return Qe(Ve(i,u.inbound,u.id),function(){return u.enabled=!0,i.jid=s,i.status="online",o=!0})},function(){u.id="",u.enabled=!1,u.outbound=0})})())&&r.then?r.then(n):n(r)})),u},or={exports:{}};n=function(t,e,r){(e.exports=r).Mechanism=r},"object"==typeof or.exports&&n(or.exports,or,r({})),or=or.exports;var ir=function(t){t.use(or)},sr={exports:{}};r=function(t,e,r){(e.exports=r).Mechanism=r},"object"==typeof sr.exports&&r(sr.exports,sr,e({})),sr=sr.exports;var ur=function(t){t.use(sr)},r={},ar=s(o),e=B.xml,o=B.jid,cr=B.Client;return r.xml=e,r.jid=o,r.clientXmpp=function(t){void 0===t&&(t={});var e=t.resource,r=t.credentials,n=t.username,o=t.password,i=(f=(0,ar.default)(t,["resource","credentials","username","password"])).domain,s=f.service;!i&&s&&(f.domain=Ct(s));var u=new cr(f),a=qt({entity:u}),c=Wt({entity:u}),l=Zt({entity:u}),t=ee({middleware:l}),i=ce({middleware:l,entity:u}),s=ve({middleware:l,entity:u}),f=ke({entity:u}),h=Ue({streamFeatures:t},r||{username:n,password:o}),r=nr({streamFeatures:t,entity:u,middleware:l}),n=Ye({iqCaller:i,streamFeatures:t},e),o=Ge({iqCaller:i,streamFeatures:t}),e=Object.entries({plain:ur,anonymous:ir}).map(function(t){var e=t[0],r=t[1],t={};return t[e]=r(h),t});return Object.assign(u,{entity:u,reconnect:a,websocket:c,middleware:l,streamFeatures:t,iqCaller:i,iqCallee:s,resolve:f,sasl:h,resourceBinding:n,sessionEstablishment:o,streamManagement:r,mechanisms:e})},r});
  3. const { clientXmpp, xml, jid } = (self || this).XMPP;
  4. console.debug('xmppjs objects', clientXmpp);
  5. self.addEventListener('install', function(event) {
  6. var indexPage = new Request('index.html');
  7. event.waitUntil(
  8. fetch(indexPage).then(function(response) {
  9. return caches.open('offline').then(function(cache) {
  10. return cache.put(indexPage, response);
  11. });
  12. }));
  13. });
  14. // activate trigger
  15. self.addEventListener('activate', function (event) {
  16. console.debug('Activated', event);
  17. });
  18. // fetch trigger - serve from cache or fetch from server, cache the file if not previously cached
  19. self.addEventListener('fetch', function(event) {
  20. if (event.request.method == "GET") event.respondWith(
  21. fetch(event.request).then(function(response) {
  22. return caches.open('offline').then(function(cache) {
  23. try {
  24. cache.put(event.request, response.clone());
  25. } catch (e) {};
  26. return response;
  27. });
  28. }).catch(function (error) {
  29. caches.match(event.request).then(function(resp) {
  30. return resp;
  31. });
  32. })
  33. );
  34. });
  35. // push trigger
  36. self.addEventListener('push', function (event) {
  37. console.debug('push', event);
  38. const data = event.data.json();
  39. const pos = location.href.lastIndexOf('/') + 1;
  40. data.url = location.href.substring(0, pos);
  41. console.debug('Push message', data);
  42. const options = {
  43. body: data.msgBody,
  44. icon: data.avatar ? data.avatar : './packages/offline-reply/converse.png',
  45. vibrate: [100, 50, 100],
  46. data: data,
  47. actions: [
  48. {action: 'open', title: 'Open', type: 'button', icon: './packages/offline-reply/arrow_right.png'},
  49. {action: 'reply', title: 'Reply', type: 'text', icon: './packages/offline-reply/arrow_back.png', placeholder: 'Type reply here..'}
  50. ]
  51. };
  52. event.waitUntil(
  53. self.registration.showNotification("Converse: " + data.fullname, options)
  54. );
  55. });
  56. self.addEventListener('pushsubscriptionchange', function(event) {
  57. console.log('[Service Worker]: \'pushsubscriptionchange\' event fired.');
  58. });
  59. self.addEventListener("pushsubscriptionchange", event => {
  60. for (var i = 0; i < clientList.length; i++) {
  61. var client = clientList[i];
  62. client.postMessage(event.oldSubscription); // send re-subscribe to web app if running
  63. }
  64. });
  65. self.addEventListener('notificationclose', function(e) {
  66. console.debug('Closed notification', e.notification);
  67. });
  68. self.addEventListener('message', function (evt) {
  69. console.log('service worker postMessage received', evt.data);
  70. if (evt.data.domain && evt.data.ws && evt.data.username && evt.data.password)
  71. {
  72. self.xmpp = clientXmpp({ service: evt.data.ws, domain: evt.data.domain, username: evt.data.username, password: evt.data.password });
  73. console.log('service worker creating xmpp client', self.xmpp);
  74. self.xmpp.on("online", async (address) => {
  75. console.debug("online - sending message", address, self.xmpp_data);
  76. const body = ">" + self.xmpp_data.msgBody + "\n\n" + self.xmpp_data.reply;
  77. const message = xml("message", {type: self.xmpp_data.msgType, to: jid(self.xmpp_data.msgFrom) }, xml("body", {}, body));
  78. await self.xmpp.send(message);
  79. await self.xmpp.send(xml("presence", { type: "unavailable" }));
  80. await self.xmpp.stop();
  81. });
  82. }
  83. })
  84. self.addEventListener('notificationclick', function(event) {
  85. console.debug('notificationclick', event);
  86. event.notification.close();
  87. if (event.action === 'open' || event.reply)
  88. {
  89. if (event.reply && event.reply != "" && self.xmpp)
  90. {
  91. self.xmpp_data = event.notification.data;
  92. self.xmpp_data.reply = event.reply;
  93. self.xmpp.start().catch(console.error);
  94. }
  95. else {
  96. event.waitUntil(clients.matchAll({type: "window"}).then(function(clientList)
  97. {
  98. const url = event.notification.data.url;
  99. for (var i = 0; i < clientList.length; i++) {
  100. console.debug("found url", clientList[i].url, clientList[i]);
  101. if (clientList[i].url == event.notification.data.url && clientList[i].visibilityState == "visible") {
  102. clientList[i].postMessage(event.notification.data);
  103. return clientList[i].focus();
  104. }
  105. }
  106. if (clients.openWindow) {
  107. return clients.openWindow(event.notification.data.url);
  108. }
  109. }));
  110. }
  111. }
  112. }, false);