const o=new Map,c=new Map,r=new Map;async function u(){const e=await self.clients.matchAll(),n=new Set(e.map(t=>t.id));Array.from(o.keys()).forEach(t=>{n.has(t)||(o.delete(t),c.delete(t),r.delete(t))})}function h(e,n,t){typeof n=="string"&&typeof t=="string"?o.set(e,{accessToken:n,baseUrl:t}):o.delete(e);const s=c.get(e);s&&(s(o.get(e)),c.delete(e),r.delete(e))}function m(e){const n=r.get(e.id)??new Promise(t=>{c.set(e.id,t),e.postMessage({type:"requestSession"})});return r.has(e.id)||r.set(e.id,n),n}async function w(e,n=3e3){const t=await self.clients.get(e);if(!t)return;const s=m(t),i=new Promise(a=>{setTimeout(()=>a(void 0),n)});return Promise.race([s,i])}self.addEventListener("install",()=>{self.skipWaiting()});self.addEventListener("activate",e=>{e.waitUntil((async()=>{await self.clients.claim(),await u()})())});self.addEventListener("message",e=>{const n=e.source;if(!n)return;const{type:t,accessToken:s,baseUrl:i}=e.data||{};t==="setSession"&&(h(n.id,s,i),u())});self.addEventListener("notificationclick",e=>{e.notification.close();const n=e.notification.data&&typeof e.notification.data.url=="string"&&e.notification.data.url?e.notification.data.url:"/app/sessions",t=new URL(n,self.location.origin).href;e.waitUntil((async()=>{const s=await self.clients.matchAll({type:"window",includeUncontrolled:!0});for(const i of s){if("navigate"in i&&i.url!==t)try{await i.navigate(t)}catch{}if("focus"in i)return i.focus()}if(self.clients.openWindow)return self.clients.openWindow(t)})())});const d=["/_matrix/client/v1/media/download","/_matrix/client/v1/media/thumbnail"];function p(e){try{const{pathname:n}=new URL(e);return d.some(t=>n.startsWith(t))}catch{return!1}}function f(e,n){return d.some(t=>{const s=new URL(t,n);return e.startsWith(s.href)})}function l(e){return{headers:{Authorization:`Bearer ${e}`},cache:"default"}}self.addEventListener("fetch",e=>{const{url:n,method:t}=e.request;if(t!=="GET"||!p(n))return;const{clientId:s}=e;if(!s)return;const i=o.get(s);if(i){f(n,i.baseUrl)&&e.respondWith(fetch(n,l(i.accessToken)));return}e.respondWith(w(s).then(a=>a&&f(n,a.baseUrl)?fetch(n,l(a.accessToken)):fetch(e.request)))});
//# sourceMappingURL=sw.js.map
