import{bp as k,bq as g,i as h}from"./index-BTglIPU2.js?v=1773287522785";import{i as y}from"./data-BVsViUMm.js?v=1773287522785";function j(i,c={}){const n={},s=k(d(),{autoReconnect:{retries:0,delay:500},immediate:c.immediate,onConnected:()=>{m(),b()},onMessage:(e,t)=>{var a;if(y(t.data)){const o=JSON.parse(t.data),r=o.callback||o.ws_callback||o.def_name;r&&n[r]&&n[r].callback(e,t)}(a=c.onMessage)==null||a.call(c,e,t)},onDisconnected:c.onDisconnected});function d(){const{host:e,protocol:t}=window.location;return(t==="http:"?"ws://":"wss://")+e+""+"/v2"+i}function m(){var t;const e={};e["x-http-token"]=(t=document.getElementById("request_token_head"))==null?void 0:t.getAttribute("token"),c.verifyData&&Object.assign(e,c.verifyData),l(e)}const u=e=>s.status.value===e,f=(e,t)=>{if(t)n[t.action]={data:e,callback:t.callback};else{const a=g(10);n[a]={data:e,callback:()=>{}}}l(e)},l=e=>{u("OPEN")&&s.send(h(e)?JSON.stringify(e):e)},b=()=>{Object.entries(n).forEach(([,e])=>{l(e.data)})};return{...s,send:f,close:()=>{Object.keys(n).forEach(e=>{delete n[e]}),s.close()}}}export{j as u};
