import{V as h}from"./chunk-5FKT6LFT.js";import{a as i}from"./chunk-KWGZHGOP.js";import{Ib as r,J as l,M as c,e as s}from"./chunk-FLIJEKW7.js";var S=(()=>{let t=class t{constructor(e,n){this.http=e,this.authRefService=n,this.onlineCheckInitialized=!1,this.online=new s(!1),this.connectOnlineSocket()}get onlineSocketUrl(){return`${i.API_URL.replace(/^http/,"ws")}/helpers/talk-to-me-goose`}scheduleReconnect(){window.clearTimeout(this.reconnectTimer),this.reconnectTimer=window.setTimeout(()=>{this.connectOnlineSocket()},t.RECONNECT_DELAY_MS)}connectOnlineSocket(){window.clearTimeout(this.reconnectTimer);try{this.onlineSocket?.close()}catch{}try{let e=new WebSocket(this.onlineSocketUrl);this.onlineSocket=e,e.onopen=()=>{this.online.next(!0)},e.onclose=()=>{this.online.next(!1),(this.onlineCheckInitialized||this.onlineSocket===e)&&this.scheduleReconnect()},e.onerror=()=>{this.online.next(!1);try{e.close()}catch{}}}catch{this.online.next(!1),this.scheduleReconnect()}}stopOnlineCheck(){window.clearTimeout(this.reconnectTimer),this.onlineCheckInitialized=!1;try{this.onlineSocket?.close()}catch{}this.onlineSocket=void 0}initOnlineCheck(){this.onlineCheckInitialized||(this.onlineCheckInitialized=!0,(this.onlineSocket==null||this.onlineSocket.readyState===WebSocket.CLOSED)&&this.connectOnlineSocket())}get apiUrl(){return i.API_URL}getContentUrl(e){let n=btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"");return`${i.CONTENT_URL}/${n}`}ngOnDestroy(){this.stopOnlineCheck()}};t.RECONNECT_DELAY_MS=2500,t.\u0275fac=function(n){return new(n||t)(c(r),c(h))},t.\u0275prov=l({token:t,factory:t.\u0275fac});let o=t;return o})();export{S as a};
