@kelceyp/caw-server 1.1.1 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +4 -2
- package/dist/main.js +691 -646
- package/dist/public_html/live-events-worker.js +1 -0
- package/dist/public_html/main.js +644 -644
- package/dist/public_html/styles.css +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(()=>{var Z=Object.freeze({subscribe:"subscribe",unsubscribe:"unsubscribe",bye:"bye",open:"open",event:"event",projectNotFound:"projectNotFound"});var y=(W)=>`/api/events/live?projects=${W.join(",")}`,G=(W)=>typeof W==="string"&&W.length>0,N=(W)=>W===null||typeof W==="string"&&W.length>0,g=(W)=>Array.isArray(W)&&W.every((K)=>typeof K==="string"&&K.length>0),S=(W,K)=>{if(typeof W[K]!=="function")throw TypeError(`createLiveEventsHub requires ${K}`)},f=(W)=>{if(!W||typeof W!=="object")throw TypeError("createLiveEventsHub requires its dependencies");if(["EventSource","setTimeout","clearTimeout"].forEach((h)=>S(W,h)),!W.log||typeof W.log.debug!=="function"||typeof W.log.error!=="function")throw TypeError("createLiveEventsHub requires log with debug and error");let{EventSource:K,setTimeout:O,clearTimeout:M,log:z}=W,$=new Map,x=null,F=null,X=null,k=1000,q=()=>{let h=[];return $.forEach((H)=>H.forEach((B)=>h.push(B))),h},P=(h,H)=>H.project===null||h.projects.includes(H.project),w=(h,H)=>{h.port.postMessage({...H,subId:h.subId})},R=(h,H)=>{H.openedOn=h,w(H,{type:Z.open})},j=()=>{let h=q();if(h.length===0)return null;let H=new Set;return h.forEach((B)=>{if(B.project!==null)H.add(B.project)}),[...H].sort()},V=(h,H)=>{let B;try{B=JSON.parse(H)}catch(D){return z.error("[live-events-hub] unparseable envelope for %s: %s",h,D.message),null}if(B===null||typeof B!=="object"||!("payload"in B)||!N(B.project))return z.error("[live-events-hub] malformed envelope for %s: %s",h,H),null;return B},T=(h,H,B)=>{if(h!==x)return;let D=V(H,B.data);if(D===null)return;let Q=q().filter((J)=>J.openedOn===h);if(H==="projectNotFound"){Q.filter((J)=>D.project!==null&&J.project===D.project).forEach((J)=>w(J,{type:Z.projectNotFound}));return}let Y=JSON.stringify(D.payload);Q.filter((J)=>J.events.has(H)&&(D.project===null||D.project===J.project)).forEach((J)=>w(J,{type:Z.event,name:H,data:Y}))},C=(h,H)=>{if(h.listened.has(H))return;h.listened.add(H),h.es.addEventListener(H,(B)=>T(h,H,B))},_=(h)=>{if(h!==x)return;h.open=!0,k=1000,z.debug("[live-events-hub] stream opened %s",h.url),q().filter((H)=>P(h,H)).forEach((H)=>R(h,H))},I=(h)=>{if(h!==x)return;if(h.open=!1,h.es.readyState===0){z.debug("[live-events-hub] stream interrupted, browser retrying %s",h.url);return}if(h.es.readyState!==2)return;h.es.close(),x=null;let H=k;k=Math.min(k*2,30000),z.debug("[live-events-hub] stream failed %s; retry scheduled in %dms",h.url,H),X=O(()=>{X=null,L()},H)},i=()=>{let h=x;return x=null,h.es.close(),h},A=(h)=>{let H=y(h),B={es:new K(H),projects:h,url:H,listened:new Set,open:!1};return x=B,B.es.addEventListener("open",()=>_(B)),B.es.addEventListener("error",()=>I(B)),C(B,"projectNotFound"),q().forEach((D)=>D.events.forEach((Q)=>C(B,Q))),B},L=()=>{F=null;let h=j();if(h===null){if(X!==null)M(X),X=null;if(x!==null){let B=i();z.debug("[live-events-hub] stream closed, no subscriptions %s",B.url)}return}let H=y(h);if(x!==null&&x.url===H)return;if(x===null&&X!==null)return;if(x!==null){let B=i();A(h),z.debug("[live-events-hub] stream swapped %s -> %s",B.url,H)}else A(h),z.debug("[live-events-hub] stream opening %s",H)},U=()=>{if(F!==null)return;F=O(L,25)},v=(h,H)=>{let B=$.get(h);if(!B)return!1;return B.delete(H)},E=(h,{subId:H,project:B,events:D})=>{let Q=$.get(h);if(!Q)Q=new Map,$.set(h,Q);let Y={port:h,subId:H,project:B,events:new Set(D),openedOn:null};if(Q.set(H,Y),x!==null){if(Y.events.forEach((J)=>C(x,J)),x.open&&P(x,Y))R(x,Y)}U()},d=(h,H)=>{if(H===null||typeof H!=="object"){z.error("[live-events-hub] unparseable message: %o",H);return}switch(H.type){case Z.subscribe:if(!G(H.subId)||!N(H.project)||!g(H.events)){z.error("[live-events-hub] malformed subscribe: %o",H);return}E(h,H);return;case Z.unsubscribe:if(!G(H.subId)){z.error("[live-events-hub] malformed unsubscribe: %o",H);return}if(v(h,H.subId))U();return;case Z.bye:if($.delete(h))U();return;default:z.error("[live-events-hub] unknown message: %o",H)}};return Object.freeze({connect:(h)=>{h.addEventListener("message",(H)=>d(h,H.data)),h.start()}})};var c=f({EventSource,setTimeout:(W,K)=>setTimeout(W,K),clearTimeout:(W)=>clearTimeout(W),log:console});self.addEventListener("connect",(W)=>{c.connect(W.ports[0])});})();
|