import{H as a,a as r}from"./vendor-@microsoft.9e93d44a.js";class c{constructor(){this.reconnectTime=5e3,this.tries=1,this.maxTries=8,this.isChatConnected=!1}init(){let e=abp.appPath+"realtime-data";abp.signalr.remoteServiceBaseUrl&&(e=abp.signalr.remoteServiceBaseUrl+e),abp.signalr.qs&&(e+=(e.indexOf("?")===-1?"?":"&")+abp.signalr.qs),this.startConnection(e).then(()=>{abp.event.trigger("app.printRecord.refresh"),abp.event.on("abp.print.refreshList",()=>{this.chatHub.invoke("RefreshList")}),this.isChatConnected=!0})}configureConnection(e){this.chatHub=e,e.onclose(t=>{this.isChatConnected=!1,t?abp.log.debug("Chat connection closed with error: "+t):abp.log.debug("Chat disconnected"),this.reconnectHub(e).then(()=>{this.isChatConnected=!0})}),this.registerChatEvents(e),this.close(e)}registerChatEvents(e){e.on("EchartsData",t=>{abp.event.trigger("app.echarts.data",t)})}startConnection(e){return new Promise((t,s)=>{const n=new a().withUrl(e,{skipNegotiation:!0,transport:r.WebSockets}).build();this.configureConnection(n),n.start().then(function(){return t(n)}).catch(function(i){return abp.log.debug("Cannot start the connection using "+r[r.WebSockets]+" transport. "+i.message),s(i)})})}reconnectHub(e){return this.reconnectstart(e)}reconnectstart(e){const t=this;return new Promise(function(s,n){t.tries>t.maxTries?n():e.start().then(s).then(()=>{t.reconnectTime=5e3,t.tries=1}).catch(()=>{setTimeout(()=>{t.reconnectstart(e).then(s)},t.reconnectTime),t.reconnectTime*=2,t.tries+=1})})}close(e){abp.event.on("app.echarts.end",t=>{e.connection.stop()})}}const o=new c;var u=o;export{u as default};
