import{i as e}from"./vendor-vue-D9nMs6_1.js";var t=`websocket`,n=e(`websocket`,{state(){return{socket:null,isConnected:!1,messages:[],latestMessage:``,latestParsedMessage:null,reconnectError:!1}},getters:{getSocket:e=>e.socket,getIsConnected:e=>e.isConnected,getLatestMessage:e=>e.messages[e.messages.length-1],getLatestParsedMessage:e=>e.latestParsedMessage,getMessages:e=>e.messages,getReconnectError:e=>e.reconnectError},actions:{connect(e){try{return this.socket=new WebSocket(e),this.socket.onmessage=e=>{if(e.data!==`KeepAlive`){this.messages.length>100&&this.messages.shift(),this.messages.push(e.data),this.latestMessage=e.data;try{let t=JSON.parse(e.data);t&&(this.latestParsedMessage=t)}catch{console.error(`Could not parse message: `,e.data,t)}}},this.socket.onclose=()=>{this.isConnected=!1,this.socket=null},this.socket.onerror=e=>{console.error(`Socket encountered error: `,e,t),this.reconnectError=!0},new Promise((e,t)=>{this.socket.onopen=()=>{this.isConnected=!0,e()},this.socket.onerror=e=>{t(e)}})}catch(e){return Promise.reject(e)}},sendMessage(e){this.socket&&this.socket.send(e)},sendObject(e){if(this.socket){let t=JSON.stringify(e);this.socket.send(t)}},disconnect(){this.socket&&this.socket.close()}}});export{n as t};