1var u=Object.defineProperty;var d=(o,e,t)=>e in o?u(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var s=(o,e,t)=>d(o,typeof e!="symbol"?e+"":e,t);import{sI as h,fD as c,qR as m}from"./commonChunk.Dhe5lqYh.js";import{a3 as p}from"./vendorChunk.BdsO83GQ.js";import"../vendors/vendor-stable.B8ub4Ug6.js";import"../vendors/vendor-swiper.T_wbf2QY.js";class a{constructor(e,t){s(this,"target");s(this,"type");this.target=t,this.type=e}}class f extends a{constructor(t,i){super("error",i);s(this,"message");s(this,"error");this.message=t.message,this.error=t}}class w extends a{constructor(t=1e3,i="",n=null){super("close",n);s(this,"code");s(this,"reason");s(this,"wasClean",!0);this.code=t,this.reason=i}}const g=()=>{if(typeof WebSocket!="undefined")return WebSocket},y=o=>typeof o!="undefined"&&!!o&&o.CLOSING===2,r={maxReconnectionDelay:1e4,minReconnectionDelay:1e3+Math.random()*4e3,minUptime:5e3,reconnectionDelayGrowFactor:1.3,connectionTimeout:4e3,maxRetries:1/0,maxEnqueuedMessages:1/0};class E{constructor(e,t,i={}){s(this,"_ws");s(this,"_listeners",{error:[],message:[],open:[],close:[]});s(this,"_retryCount",-1);s(this,"_uptimeTimeout");s(this,"_connectTimeout");s(this,"_shouldReconnect",!0);s(this,"_connectLock",!1);s(this,"_binaryType","blob");s(this,"_closeCalled",!1);s(this,"_messageQueue",[]);s(this,"_url");s(this,"_protocols");s(this,"_options");s(this,"onclose",null);s(this,"onerror",null);s(this,"onmessage",null);s(this,"onopen",null);s(this,"_handleOpen",e=>{this._debug("open event");const{minUptime:t=r.minUptime}=this._options;clearTimeout(this._connectTimeout),this._uptimeTimeout=setTimeout(()=>this._acceptOpen(),t),this._ws.binaryType=this._binaryType,this._messageQueue.forEach(i=>{var n;return(n=this._ws)==null?void 0:n.send(i)}),this._messageQueue=[],this.onopen&&this.onopen(e),this._listeners.open.forEach(i=>this._callEventListener(e,i))});s(this,"_handleMessage",e=>{this._debug("message event"),this.onmessage&&this.onmessage(e),this._listeners.message.forEach(t=>this._callEventListener(e,t))});s(this,"_handleError",e=>{this._debug("error event",e.message),this._disconnect(void 0,e.message==="TIMEOUT"?"timeout":void 0),this.onerror&&this.onerror(e),this._debug("exec error listeners"),this._listeners.error.forEach(t=>this._callEventListener(e,t)),this._connect()});s(this,"_handleClose",e=>{this._debug("close event"),this._clearTimeouts(),this._shouldReconnect&&this._connect(),this.onclose&&this.onclose(e),this._listeners.close.forEach(t=>this._callEventListener(e,t))});this._url=e,this._protocols=t,this._options=i,this._options.startClosed&&(this._shouldReconnect=!1),this._connect()}get binaryType(){return this._ws?this._ws.binaryType:this._binaryType}set binaryType(e){this._binaryType=e,this._ws&&(this._ws.binaryType=e)}get retryCount(){return Math.max(this._retryCount,0)}get bufferedAmount(){return this._messageQueue.reduce((t,i)=>(typeof i=="string"?t+=i.length:i instanceof Blob?t+=i.size:t+=i.byteLength,t),0)+(this._ws?this._ws.bufferedAmount:0)}get extensions(){return this._ws?this._ws.extensions:""}get protocol(){return this._ws?this._ws.protocol:""}get readyState(){return this._ws?this._ws.readyState:this._options.startClosed?h.CLOSED:h.CONNECTING}get url(){return this._ws?this._ws.url:""}close(e=1e3,t){if(this._closeCalled=!0,this._shouldReconnect=!1,this._clearTimeouts(),!this._ws){this._debug("close enqueued: no ws instance");return}if(this._ws.readyState===h.CLOSED){this._debug("close: already closed");return}this._ws.close(e,t)}reconnect(e,t){this._shouldReconnect=!0,this._closeCalled=!1,this._retryCount=-1,!this._ws||this._ws.readyState===h.CLOSED?this._connect():(this._disconnect(e,t),this._connect())}send(e){if(this._ws&&this._ws.readyState===h.OPEN)this._debug("send",e),this._ws.send(e);else{const{maxEnqueuedMessages:t=r.maxEnqueuedMessages}=this._options;this._messageQueue.length<t&&(this._debug("enqueue",e),this._messageQueue.push(e))}}addEventListener(e,t){this._listeners[e]&&this._listeners[e].push(t)}dispatchEvent(e){const t=this._listeners[e.type];if(t)for(const i of t)this._callEventListener(e,i);return!0}removeEventListener(e,t){this._listeners[e]&&(this._listeners[e]=this._listeners[e].filter(i=>i!==t))}_debug(...e){this._options.debug&&console.log.apply(console,["RWS>",...e])}_getNextDelay(){const{reconnectionDelayGrowFactor:e=r.reconnectionDelayGrowFactor,minReconnectionDelay:t=r.minReconnectionDelay,maxReconnectionDelay:i=r.maxReconnectionDelay}=this._options;let n=0;return this._retryCount>0&&(n=t*Math.pow(e,this._retryCount-1),n>i&&(n=i)),this._debug("next delay",n),n}_wait(){return new Promise(e=>{setTimeout(e,this._getNextDelay())})}_getNextUrl(e){if(typeof e=="string")return Promise.resolve(e);if(typeof e=="function"){const t=e(this);if(typeof t=="string")return Promise.resolve(t);if(t.then)return t}throw Error("Invalid URL")}_connect(){if(this._connectLock||!this._shouldReconnect)return;this._connectLock=!0;
1const{maxRetries:e=r.maxRetries,connectionTimeout:t=r.connectionTimeout,WebSocket:i=g()}=this._options;if(this._retryCount>=e){this._debug("max retries reached",this._retryCount,">=",e);return}if(this._retryCount++,this._debug("connect",this._retryCount),this._removeListeners(),!y(i))throw Error("No valid WebSocket class provided");this._wait().then(()=>this._getNextUrl(this._url)).then(n=>{this._closeCalled||(this._debug("connect",{url:n,protocols:this._protocols}),this._ws=this._protocols?new i(n,this._protocols):new i(n),this._ws.binaryType=this._binaryType,this._connectLock=!1,this._addListeners(),this._connectTimeout=setTimeout(()=>this._handleTimeout(),t))})}_handleTimeout(){this._debug("timeout event"),this._handleError(new f(Error("TIMEOUT"),this))}_disconnect(e=1e3,t){if(this._clearTimeouts(),!!this._ws){this._removeListeners();try{this._ws.close(e,t),this._handleClose(new w(e,t,this))}catch(i){}}}_acceptOpen(){this._debug("accept open"),this._retryCount=0}_callEventListener(e,t){"handleEvent"in t?t.handleEvent(e):t(e)}_removeListeners(){this._ws&&(this._debug("removeListeners"),this._ws.removeEventListener("open",this._handleOpen),this._ws.removeEventListener("close",this._handleClose),this._ws.removeEventListener("message",this._handleMessage),this._ws.removeEventListener("error",this._handleError))}_addListeners(){this._ws&&(this._debug("addListeners"),this._ws.addEventListener("open",this._handleOpen),this._ws.addEventListener("close",this._handleClose),this._ws.addEventListener("message",this._handleMessage),this._ws.addEventListener("error",this._handleError))}_clearTimeouts(){clearTimeout(this._connectTimeout),clearTimeout(this._uptimeTimeout)}}const b=4e3,T=20;class v{constructor(){s(this,"_siteId","");s(this,"_auth","");s(this,"_domains",[]);s(this,"_prefix","/ws/websocket");s(this,"_url","");s(this,"ws");s(this,"heartbeatHandler");s(this,"emitter");this.emitter=p()}connectWS(e,t,i=[window.location.origin],n){this._auth=t,this._siteId=e,this._domains=i,n&&(this._prefix=n),this.setUrl(0),this.connect()}connect(){this.disconnect(),this.ws=new E(e=>this.setUrl(e.retryCount),[],{maxRetries:T,debug:!1}),this.eventBind()}disconnect(){var e;try{(e=this.ws)==null||e.close()}catch(t){}}setUrl(e){const t=this._domains.length;e=e%t;let i="";e>=t||isNaN(e)?i=window.location.origin:i=this._domains[e]||this._domains[0];const{protocol:n,host:_}=new URL(i),l=n==="http:"?"ws":"wss";return this._url=`${l}://${_}${this._prefix}?authStr=${this._siteId}-${this._auth}`,this._url}eventBind(){this.ws&&(this.ws.addEventListener("open",()=>{this.startHeartbeat(),this.emitter.emit(c.CONNECTED,h.OPEN)}),this.ws.addEventListener("error",e=>{this.stopHeartbeat(),this.emitter.emit(c.ERROR,e)}),this.ws.addEventListener("message",e=>{this.emitter.emit(c.MESSAGE,e),this.dispatchMessage(e.data)}),this.ws.addEventListener("close",()=>{this.stopHeartbeat(),this.emitter.emit(c.CLOSED,h.CLOSED)}))}startHeartbeat(){this.heartbeatHandler=window.setInterval(()=>{this.ws.send(this.pack({event:"ping"}))},b)}stopHeartbeat(){this.heartbeatHandler&&(window.clearInterval(this.heartbeatHandler),this.heartbeatHandler=void 0)}_send(e){this.ws.send(this.pack(e))}pack(e){return JSON.stringify(e)}ack(e){this._send({event:"ack",msgId:e})}dispatchMessage(e){try{const t=JSON.parse(e);if(t.event==="notice"){const i=JSON.parse(t.content);this.emitter.emit(i.type,i.data),this.ack(t.msgId)}else this.emitter.emit(t.event,t)}catch(t){console.error("[long connection error]",t)}}on(e,t){return this.emitter.on(e,t)}off(e,t){return this.emitter.off(e,t)}send(e){this._send(e)}}const x=m.getInstance("Websocket",v);export{v as default,x as websocket};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.