(function(){"use strict";var u={};const r={},n={};class l{constructor(t){this.url=t,this.eventSource=new EventSource(t),this.listening={},this.clients=[],this.listen("open"),this.listen("close"),this.listen("logout"),this.listen("notification-count"),this.listen("stopwatches"),this.listen("error")}register(t){this.clients.includes(t)||(this.clients.push(t),t.postMessage({type:"status",message:`registered to ${this.url}`}))}deregister(t){const s=this.clients.indexOf(t);return s<0?this.clients.length:(this.clients.splice(s,1),this.clients.length)}close(){!this.eventSource||(this.eventSource.close(),this.eventSource=null)}listen(t){this.listening[t]||(this.listening[t]=!0,this.eventSource.addEventListener(t,s=>{this.notifyClients({type:t,data:s.data})}))}notifyClients(t){for(const s of this.clients)s.postMessage(t)}status(t){t.postMessage({type:"status",message:`url: ${this.url} readyState: ${this.eventSource.readyState}`})}}self.onconnect=c=>{for(const t of c.ports)t.addEventListener("message",s=>{if(s.data.type==="start"){const e=s.data.url;if(r[e]){const o=r[e];o.register(t),n[t]=o;return}let i=n[t];if(i){if(i.eventSource&&i.url===e)return;i.deregister(t)===0&&(i.close(),r[i.url]=null)}i=new l(e),i.register(t),r[e]=i,n[t]=i}else if(s.data.type==="listen")n[t].listen(s.data.eventType);else if(s.data.type==="close"){const e=n[t];if(!e)return;e.deregister(t)===0&&(e.close(),r[e.url]=null,n[t]=null)}else if(s.data.type==="status"){const e=n[t];if(!e){t.postMessage({type:"status",message:"not connected"});return}e.status(t)}else t.postMessage({type:"error",message:`received but don't know how to handle: ${s.data}`})}),t.start()}})();
