import"./mock-m0auDXaL.js";import{n as e,t}from"./definitions-COMiogoF.js";var n=class{listeners=new Map;intervalId=null;readyState=WebSocket.OPEN;constructor(e){this.url=e,setTimeout(()=>{this.dispatchEvent(`open`,new Event(`open`)),this.startMockData()},100)}sendInitialHistoryData(e,t,n){for(let r=0;r<t;r++)setTimeout(()=>{let t=e();this.dispatchEvent(`message`,new MessageEvent(`message`,{data:JSON.stringify(t)}))},r*n)}startMockData(){let n=this.url.replace(/^ws:\/\/mock\/?/,`/`);if(n.includes(`connections`))this.intervalId=setInterval(()=>{let e=t();this.dispatchEvent(`message`,new MessageEvent(`message`,{data:JSON.stringify(e)}))},1e3);else if(n.includes(`traffic`)){let e=()=>({up:Math.floor(Math.random()*2097152),down:Math.floor(Math.random()*10485760)});this.sendInitialHistoryData(e,30,50),setTimeout(()=>{this.intervalId=setInterval(()=>{let t=e();this.dispatchEvent(`message`,new MessageEvent(`message`,{data:JSON.stringify(t)}))},1e3)},1500)}else if(n.includes(`memory`)){let e=()=>({inuse:52428800+Math.floor(Math.random()*10485760),oslimit:0});this.sendInitialHistoryData(e,30,50),setTimeout(()=>{this.intervalId=setInterval(()=>{let t=e();this.dispatchEvent(`message`,new MessageEvent(`message`,{data:JSON.stringify(t)}))},1e3)},1500)}else if(n.includes(`logs`)){let t=0;for(let n=0;n<50;n++)setTimeout(()=>{let n=e[t%e.length];this.dispatchEvent(`message`,new MessageEvent(`message`,{data:JSON.stringify(n)})),t++},n*30);setTimeout(()=>{this.intervalId=setInterval(()=>{let n=e[t%e.length];this.dispatchEvent(`message`,new MessageEvent(`message`,{data:JSON.stringify(n)})),t++},500)},1500)}}addEventListener(e,t){this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t)}removeEventListener(e,t){this.listeners.get(e)?.delete(t)}dispatchEvent(e,t){this.listeners.get(e)?.forEach(e=>e(t))}close(){this.intervalId&&clearInterval(this.intervalId),this.readyState=WebSocket.CLOSED,this.dispatchEvent(`close`,new CloseEvent(`close`))}send(e){}};export{n as MockWebSocket};