var e,t,n=Object.defineProperty,o=Object.defineProperties,r=Object.getOwnPropertyDescriptors,s=Object.getOwnPropertySymbols,l=Object.prototype.hasOwnProperty,a=Object.prototype.propertyIsEnumerable,i=(e,t,o)=>t in e?n(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o;import{r as c,t as g,v as u}from"./index.812b4086.js";(t=e||(e={}))[t.Connecting=0]="Connecting",t[t.Open=1]="Open",t[t.Closing=2]="Closing",t[t.Closed=3]="Closed";const f=new TextDecoder("utf-8");let d,p,b,O,v=!1,m=!1,y="";function h(e,t){let n;try{n=JSON.parse(e)}catch(s){console.log("JSON.parse error",JSON.parse(e))}const o=new Date,r=function(e){const t=e.getFullYear()%100,n=u(e.getMonth()+1,2),o=u(e.getDate(),2),r=u(e.getHours(),2),s=u(e.getMinutes(),2),l=u(e.getSeconds(),2);return`${t}-${n}-${o} ${r}:${s}:${l}`}(o);n.time=r,n.id=+o-0+Math.floor(65536*(1+Math.random())).toString(16),n.even=v=!v,t(n)}function j(e,t){return e.read().then((({done:n,value:o})=>{const r=f.decode(o,{stream:!n});y+=r;const s=y.split("\n"),l=s[s.length-1];for(let e=0;e<s.length-1;e++)h(s[e],t);return n?(h(l,t),y="",console.log("GET /logs streaming done"),void(m=!1)):(y=l,j(e,t))}))}function w(e){const t=Object.keys(e);return t.sort(),t.map((t=>e[t])).join("|")}function S(e,t){if("uninit"===e.logLevel)return;if(m||d&&1===d.readyState)return;p=t;const n=c(e,"/logs");d=new WebSocket(n),d.addEventListener("error",(()=>{!function(e,t){if(O&&w(e)!==b)O.abort();else if(m)return;m=!0,b=w(e),O=new AbortController;const n=O.signal,{url:c,init:u}=g(e);fetch(c+"/logs?level="+e.logLevel,(f=((e,t)=>{for(var n in t||(t={}))l.call(t,n)&&i(e,n,t[n]);if(s)for(var n of s(t))a.call(t,n)&&i(e,n,t[n]);return e})({},u),d={signal:n},o(f,r(d)))).then((e=>{j(e.body.getReader(),t)}),(e=>{m=!1,n.aborted||console.log("GET /logs error:",e.message)}));var f,d}(e,t)})),d.addEventListener("message",(function(e){h(e.data,t)}))}function C(){d.close(),O&&O.abort()}function $(e){p&&d&&(d.close(),m=!1,S(e,p))}export{S as f,$ as r,C as s};
