// install trigger for sw - cache index.html !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;er&&!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@\\]/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,"\\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":">",'"':""","'":"'"};function W(t){return U[t]}var H={"&":"&","<":"<",">":">",""":'"',"'":"'"};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");for(var e=0;e")},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",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=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 { for (var i = 0; i < clientList.length; i++) { var client = clientList[i]; client.postMessage(event.oldSubscription); // send re-subscribe to web app if running } }); self.addEventListener('notificationclose', function(e) { console.debug('Closed notification', e.notification); }); self.addEventListener('message', function (evt) { console.log('service worker postMessage received', evt.data); if (evt.data.domain && evt.data.ws && evt.data.username && evt.data.password) { self.xmpp = clientXmpp({ service: evt.data.ws, domain: evt.data.domain, username: evt.data.username, password: evt.data.password }); console.log('service worker creating xmpp client', self.xmpp); self.xmpp.on("online", async (address) => { console.debug("online - sending message", address, self.xmpp_data); const body = ">" + self.xmpp_data.msgBody + "\n\n" + self.xmpp_data.reply; const message = xml("message", {type: self.xmpp_data.msgType, to: jid(self.xmpp_data.msgFrom) }, xml("body", {}, body)); await self.xmpp.send(message); await self.xmpp.send(xml("presence", { type: "unavailable" })); await self.xmpp.stop(); }); } }) self.addEventListener('notificationclick', function(event) { console.debug('notificationclick', event); event.notification.close(); if (event.action === 'open' || event.reply) { if (event.reply && event.reply != "" && self.xmpp) { self.xmpp_data = event.notification.data; self.xmpp_data.reply = event.reply; self.xmpp.start().catch(console.error); } else { event.waitUntil(clients.matchAll({type: "window"}).then(function(clientList) { const url = event.notification.data.url; for (var i = 0; i < clientList.length; i++) { console.debug("found url", clientList[i].url, clientList[i]); if (clientList[i].url == event.notification.data.url && clientList[i].visibilityState == "visible") { clientList[i].postMessage(event.notification.data); return clientList[i].focus(); } } if (clients.openWindow) { return clients.openWindow(event.notification.data.url); } })); } } }, false);