System.register(["./vue-legacy.js?v=1723125373998","./index-legacy.js?v=1723125373998","./data-legacy.js?v=1723125373998"],(function(e,t){"use strict";var n,s,o,c,a,i;return{setters:[e=>{n=e.at,s=e.y},e=>{o=e.n,c=e.j,a=e.cz},e=>{i=e.i}],execute:function(){e("u",(function({url:e,onMessage:t,onDisconnected:n}){let o=null;const c=()=>{o&&(o.close(),o=null)};return s((()=>{c()})),{getSocket:()=>o,sendSocket:e=>{o?.send(e)},closeWebSocket:c,createWebSocket:()=>{o=r({url:e,onMessage:(e,n)=>{t(e,n)},onDisconnected:()=>{o=null,n?.()}})}}}));class t{socket=null;url="";connectURL=(()=>{const{host:e,protocol:t}=window.location;return("http:"===t?"ws://":"wss://")+e+"/v2"})();sendData={};constructor(e){this.url=e.url,this.connectURL+=e.url,this.init(e)}init(e){"WebSocket"in window?this.socket=n(this.connectURL,{autoReconnect:{retries:3,delay:500},onConnected:t=>{e.onConnected&&e.onConnected(t),this.onConnected(t,e)},onMessage:(t,n)=>{e.onMessage&&e.onMessage(t,n),this.onMessage(t,n)},onDisconnected:(t,n)=>{e.onDisconnected&&e.onDisconnected(t,n),this.onDisconnected()},onError:(t,n)=>{e.onError&&e.onError(t,n),this.onError()}}):o.error("The browser does not support Websocket")}isStatus(e){return(this.socket?.status.value||this.socket?.status)===e}channelVerify(){const e={};e["x-http-token"]=document.getElementById("request_token_head")?.getAttribute("token"),this.send(e)}send(e){if(this.isStatus("OPEN"))this.socket?.send(c(e)?JSON.stringify(e):e);else{const t=a(10);this.sendData[t]={data:e,status:!1,request:!1,callback:()=>{}}}}onConnected(e,t){t.noInit||this.channelVerify(),this.onSendData()}onSendData(){Object.entries(this.sendData).forEach((([e,t])=>{this.send(t.data),delete this.sendData[e]}))}onMessage(e,t){if("/ws_home"===this.url||"/ws_model"===this.url)try{if(i(t.data)){const n=JSON.parse(t.data),s=n.callback||n.ws_callback;s&&this.sendData[s]&&this.sendData[s].callback(e,t)}}catch(n){console.log(n)}}onDisconnected(){this.close(),console.log("断开连接")}onError(){console.log("连接错误")}close(){this.socket?.close()}}const r=e=>new t(e)}}}));
