var p=require("@spacingbat3/disconnection"),d=require("../common/global"),S=require("events");const c=new S.EventEmitter,s=new p.WebSocket(d.knownInstancesList.map(o=>o[1].origin)),i=new Set;process.parentPort.on("message",({data:o})=>{(async()=>{const k=(await s.details)?.port;if(typeof o=="string"){s.log(o,k);return}const e=o,{hook:a}=e;switch(e.evt){case"hook-set":s.addHook(a,(...t)=>new Promise((g,m)=>{const n=Symbol();i.add(n);const f=[...i].indexOf(n);process.parentPort.postMessage({evt:"hook-trigger",hook:a,data:t,nonce:f,port:k}),c.once(n,r=>{r instanceof Error?m(r):g(r)})}));break;case"hook-return":{const t=[...i][e.nonce];t&&c.emit(t,e.data);break}}})()});
