UNPKG

homebridge-config-ui-x

Version:

A web based management, configuration and control platform for Homebridge.

2 lines • 43.5 kB
import {g as g$1,a as ae$1,ac as Or,c as Eo,ad as x$1,ae as C$1,a4 as w$1,af as C$2}from'./main-ONDCASUV.js';var d=Object.create(null);d.open="0";d.close="1";d.ping="2";d.pong="3";d.message="4";d.upgrade="5";d.noop="6";var O=Object.create(null);Object.keys(d).forEach(s=>{O[d[s]]=s;});var S={type:"error",data:"parser error"};var _e=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",be=typeof ArrayBuffer=="function",we=s=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(s):s&&s.buffer instanceof ArrayBuffer,N=({type:s,data:e},t,r)=>_e&&e instanceof Blob?t?r(e):ye(e,r):be&&(e instanceof ArrayBuffer||we(e))?t?r(e):ye(new Blob([e]),r):r(d[s]+(e||"")),ye=(s,e)=>{let t=new FileReader;return t.onload=function(){let r=t.result.split(",")[1];e("b"+(r||""));},t.readAsDataURL(s)};function ge(s){return s instanceof Uint8Array?s:s instanceof ArrayBuffer?new Uint8Array(s):new Uint8Array(s.buffer,s.byteOffset,s.byteLength)}var j;function Ee(s,e){if(_e&&s.data instanceof Blob)return s.data.arrayBuffer().then(ge).then(e);if(be&&(s.data instanceof ArrayBuffer||we(s.data)))return e(ge(s.data));N(s,false,t=>{j||(j=new TextEncoder),e(j.encode(t));});}var ke="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",B=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let s=0;s<ke.length;s++)B[ke.charCodeAt(s)]=s;var ve=s=>{let e=s.length*.75,t=s.length,r,i=0,n,o,c,h;s[s.length-1]==="="&&(e--,s[s.length-2]==="="&&e--);let m=new ArrayBuffer(e),p=new Uint8Array(m);for(r=0;r<t;r+=4)n=B[s.charCodeAt(r)],o=B[s.charCodeAt(r+1)],c=B[s.charCodeAt(r+2)],h=B[s.charCodeAt(r+3)],p[i++]=n<<2|o>>4,p[i++]=(o&15)<<4|c>>2,p[i++]=(c&3)<<6|h&63;return m};var $e=typeof ArrayBuffer=="function",L=(s,e)=>{if(typeof s!="string")return {type:"message",data:xe(s,e)};let t=s.charAt(0);return t==="b"?{type:"message",data:ze(s.substring(1),e)}:O[t]?s.length>1?{type:O[t],data:s.substring(1)}:{type:O[t]}:S},ze=(s,e)=>{if($e){let t=ve(s);return xe(t,e)}else return {base64:true,data:s}},xe=(s,e)=>e==="blob"?s instanceof Blob?s:new Blob([s]):s instanceof ArrayBuffer?s:s.buffer;var Te="",Ae=(s,e)=>{let t=s.length,r=new Array(t),i=0;s.forEach((n,o)=>{N(n,false,c=>{r[o]=c,++i===t&&e(r.join(Te));});});},Ce=(s,e)=>{let t=s.split(Te),r=[];for(let i=0;i<t.length;i++){let n=L(t[i],e);if(r.push(n),n.type==="error")break}return r};function Re(){return new TransformStream({transform(s,e){Ee(s,t=>{let r=t.length,i;if(r<126)i=new Uint8Array(1),new DataView(i.buffer).setUint8(0,r);else if(r<65536){i=new Uint8Array(3);let n=new DataView(i.buffer);n.setUint8(0,126),n.setUint16(1,r);}else {i=new Uint8Array(9);let n=new DataView(i.buffer);n.setUint8(0,127),n.setBigUint64(1,BigInt(r));}s.data&&typeof s.data!="string"&&(i[0]|=128),e.enqueue(i),e.enqueue(t);});}})}var G;function U(s){return s.reduce((e,t)=>e+t.length,0)}function V(s,e){if(s[0].length===e)return s.shift();let t=new Uint8Array(e),r=0;for(let i=0;i<e;i++)t[i]=s[0][r++],r===s[0].length&&(s.shift(),r=0);return s.length&&r<s[0].length&&(s[0]=s[0].slice(r)),t}function Oe(s,e){G||(G=new TextDecoder);let t=[],r=0,i=-1,n=false;return new TransformStream({transform(o,c){for(t.push(o);;){if(r===0){if(U(t)<1)break;let h=V(t,1);n=(h[0]&128)===128,i=h[0]&127,i<126?r=3:i===126?r=1:r=2;}else if(r===1){if(U(t)<2)break;let h=V(t,2);i=new DataView(h.buffer,h.byteOffset,h.length).getUint16(0),r=3;}else if(r===2){if(U(t)<8)break;let h=V(t,8),m=new DataView(h.buffer,h.byteOffset,h.length),p=m.getUint32(0);if(p>Math.pow(2,21)-1){c.enqueue(S);break}i=p*Math.pow(2,32)+m.getUint32(4),r=3;}else {if(U(t)<i)break;let h=V(t,i);c.enqueue(L(n?h:G.decode(h),e)),r=0;}if(i===0||i>s){c.enqueue(S);break}}}})}var Z=4;function f(s){if(s)return Xe(s)}function Xe(s){for(var e in f.prototype)s[e]=f.prototype[e];return s}f.prototype.on=f.prototype.addEventListener=function(s,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+s]=this._callbacks["$"+s]||[]).push(e),this};f.prototype.once=function(s,e){function t(){this.off(s,t),e.apply(this,arguments);}return t.fn=e,this.on(s,t),this};f.prototype.off=f.prototype.removeListener=f.prototype.removeAllListeners=f.prototype.removeEventListener=function(s,e){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var t=this._callbacks["$"+s];if(!t)return this;if(arguments.length==1)return delete this._callbacks["$"+s],this;for(var r,i=0;i<t.length;i++)if(r=t[i],r===e||r.fn===e){t.splice(i,1);break}return t.length===0&&delete this._callbacks["$"+s],this};f.prototype.emit=function(s){this._callbacks=this._callbacks||{};for(var e=new Array(arguments.length-1),t=this._callbacks["$"+s],r=1;r<arguments.length;r++)e[r-1]=arguments[r];if(t){t=t.slice(0);for(var r=0,i=t.length;r<i;++r)t[r].apply(this,e);}return this};f.prototype.emitReserved=f.prototype.emit;f.prototype.listeners=function(s){return this._callbacks=this._callbacks||{},this._callbacks["$"+s]||[]};f.prototype.hasListeners=function(s){return !!this.listeners(s).length};var y=typeof Promise=="function"&&typeof Promise.resolve=="function"?e=>Promise.resolve().then(e):(e,t)=>t(e,0),u=typeof self<"u"?self:typeof window<"u"?window:Function("return this")(),Se="arraybuffer";function M(s,...e){return e.reduce((t,r)=>(s.hasOwnProperty(r)&&(t[r]=s[r]),t),{})}var Qe=u.setTimeout,je=u.clearTimeout;function g(s,e){e.useNativeTimers?(s.setTimeoutFn=Qe.bind(u),s.clearTimeoutFn=je.bind(u)):(s.setTimeoutFn=u.setTimeout.bind(u),s.clearTimeoutFn=u.clearTimeout.bind(u));}var Ge=1.33;function Ne(s){return typeof s=="string"?Ze(s):Math.ceil((s.byteLength||s.size)*Ge)}function Ze(s){let e=0,t=0;for(let r=0,i=s.length;r<i;r++)e=s.charCodeAt(r),e<128?t+=1:e<2048?t+=2:e<55296||e>=57344?t+=3:(r++,t+=4);return t}function H(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}function Be(s){let e="";for(let t in s)s.hasOwnProperty(t)&&(e.length&&(e+="&"),e+=encodeURIComponent(t)+"="+encodeURIComponent(s[t]));return e}function Le(s){let e={},t=s.split("&");for(let r=0,i=t.length;r<i;r++){let n=t[r].split("=");e[decodeURIComponent(n[0])]=decodeURIComponent(n[1]);}return e}var W=class extends Error{constructor(e,t,r){super(e),this.description=t,this.context=r,this.type="TransportError";}},_=class extends f{constructor(e){super(),this.writable=false,g(this,e),this.opts=e,this.query=e.query,this.socket=e.socket,this.supportsBinary=!e.forceBase64;}onError(e,t,r){return super.emitReserved("error",new W(e,t,r)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return (this.readyState==="opening"||this.readyState==="open")&&(this.doClose(),this.onClose()),this}send(e){this.readyState==="open"&&this.write(e);}onOpen(){this.readyState="open",this.writable=true,super.emitReserved("open");}onData(e){let t=L(e,this.socket.binaryType);this.onPacket(t);}onPacket(e){super.emitReserved("packet",e);}onClose(e){this.readyState="closed",super.emitReserved("close",e);}pause(e){}createUri(e,t={}){return e+"://"+this._hostname()+this._port()+this.opts.path+this._query(t)}_hostname(){let e=this.opts.hostname;return e.indexOf(":")===-1?e:"["+e+"]"}_port(){return this.opts.port&&(this.opts.secure&&Number(this.opts.port)!==443||!this.opts.secure&&Number(this.opts.port)!==80)?":"+this.opts.port:""}_query(e){let t=Be(e);return t.length?"?"+t:""}};var P=class extends _{constructor(){super(...arguments),this._polling=false;}get name(){return "polling"}doOpen(){this._poll();}pause(e){this.readyState="pausing";let t=()=>{this.readyState="paused",e();};if(this._polling||!this.writable){let r=0;this._polling&&(r++,this.once("pollComplete",function(){--r||t();})),this.writable||(r++,this.once("drain",function(){--r||t();}));}else t();}_poll(){this._polling=true,this.doPoll(),this.emitReserved("poll");}onData(e){let t=r=>{if(this.readyState==="opening"&&r.type==="open"&&this.onOpen(),r.type==="close")return this.onClose({description:"transport closed by the server"}),false;this.onPacket(r);};Ce(e,this.socket.binaryType).forEach(t),this.readyState!=="closed"&&(this._polling=false,this.emitReserved("pollComplete"),this.readyState==="open"&&this._poll());}doClose(){let e=()=>{this.write([{type:"close"}]);};this.readyState==="open"?e():this.once("open",e);}write(e){this.writable=false,Ae(e,t=>{this.doWrite(t,()=>{this.writable=true,this.emitReserved("drain");});});}uri(){let e=this.opts.secure?"https":"http",t=this.query||{};return this.opts.timestampRequests!==false&&(t[this.opts.timestampParam]=H()),!this.supportsBinary&&!t.sid&&(t.b64=1),this.createUri(e,t)}};var Pe=false;try{Pe=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest;}catch(s){}var qe=Pe;function et(){}var ee=class extends P{constructor(e){if(super(e),typeof location<"u"){let t=location.protocol==="https:",r=location.port;r||(r=t?"443":"80"),this.xd=typeof location<"u"&&e.hostname!==location.hostname||r!==e.port;}}doWrite(e,t){let r=this.request({method:"POST",data:e});r.on("success",t),r.on("error",(i,n)=>{this.onError("xhr post error",i,n);});}doPoll(){let e=this.request();e.on("data",this.onData.bind(this)),e.on("error",(t,r)=>{this.onError("xhr poll error",t,r);}),this.pollXhr=e;}},K=(()=>{class s extends f{constructor(t,r,i){super(),this.createRequest=t,g(this,i),this._opts=i,this._method=i.method||"GET",this._uri=r,this._data=i.data!==void 0?i.data:null,this._create();}_create(){var t;let r=M(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");r.xdomain=!!this._opts.xd;let i=this._xhr=this.createRequest(r);try{i.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){i.setDisableHeaderCheck&&i.setDisableHeaderCheck(!0);for(let n in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(n)&&i.setRequestHeader(n,this._opts.extraHeaders[n]);}}catch(n){}if(this._method==="POST")try{i.setRequestHeader("Content-type","text/plain;charset=UTF-8");}catch(n){}try{i.setRequestHeader("Accept","*/*");}catch(n){}(t=this._opts.cookieJar)===null||t===void 0||t.addCookies(i),"withCredentials"in i&&(i.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(i.timeout=this._opts.requestTimeout),i.onreadystatechange=()=>{var n;i.readyState===3&&((n=this._opts.cookieJar)===null||n===void 0||n.parseCookies(i.getResponseHeader("set-cookie"))),i.readyState===4&&(i.status===200||i.status===1223?this._onLoad():this.setTimeoutFn(()=>{this._onError(typeof i.status=="number"?i.status:0);},0));},i.send(this._data);}catch(n){this.setTimeoutFn(()=>{this._onError(n);},0);return}typeof document<"u"&&(this._index=s.requestsCount++,s.requests[this._index]=this);}_onError(t){this.emitReserved("error",t,this._xhr),this._cleanup(true);}_cleanup(t){if(!(typeof this._xhr>"u"||this._xhr===null)){if(this._xhr.onreadystatechange=et,t)try{this._xhr.abort();}catch(r){}typeof document<"u"&&delete s.requests[this._index],this._xhr=null;}}_onLoad(){let t=this._xhr.responseText;t!==null&&(this.emitReserved("data",t),this.emitReserved("success"),this._cleanup());}abort(){this._cleanup();}}return s.requestsCount=0,s.requests={},s})();if(typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",De);else if(typeof addEventListener=="function"){let s="onpagehide"in u?"pagehide":"unload";addEventListener(s,De,false);}}function De(){for(let s in K.requests)K.requests.hasOwnProperty(s)&&K.requests[s].abort();}var tt=(function(){let s=Ie({xdomain:false});return s&&s.responseType!==null})(),w=class extends ee{constructor(e){super(e);let t=e&&e.forceBase64;this.supportsBinary=tt&&!t;}request(e={}){return Object.assign(e,{xd:this.xd},this.opts),new K(Ie,this.uri(),e)}};function Ie(s){let e=s.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!e||qe))return new XMLHttpRequest}catch(t){}if(!e)try{return new u[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch(t){}}var Fe=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative",se=class extends _{get name(){return "websocket"}doOpen(){let e=this.uri(),t=this.opts.protocols,r=Fe?{}:M(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(r.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(e,t,r);}catch(i){return this.emitReserved("error",i)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners();}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen();},this.ws.onclose=e=>this.onClose({description:"websocket connection closed",context:e}),this.ws.onmessage=e=>this.onData(e.data),this.ws.onerror=e=>this.onError("websocket error",e);}write(e){this.writable=false;for(let t=0;t<e.length;t++){let r=e[t],i=t===e.length-1;N(r,this.supportsBinary,n=>{try{this.doWrite(r,n);}catch(o){}i&&y(()=>{this.writable=true,this.emitReserved("drain");},this.setTimeoutFn);});}}doClose(){typeof this.ws<"u"&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null);}uri(){let e=this.opts.secure?"wss":"ws",t=this.query||{};return this.opts.timestampRequests&&(t[this.opts.timestampParam]=H()),this.supportsBinary||(t.b64=1),this.createUri(e,t)}},te=u.WebSocket||u.MozWebSocket,E=class extends se{createSocket(e,t,r){return Fe?new te(e,t,r):t?new te(e,t):new te(e)}doWrite(e,t){this.ws.send(t);}};var v=class extends _{get name(){return "webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name]);}catch(e){return this.emitReserved("error",e)}this._transport.closed.then(()=>{this.onClose();}).catch(e=>{this.onError("webtransport error",e);}),this._transport.ready.then(()=>{this._transport.createBidirectionalStream().then(e=>{let t=Oe(Number.MAX_SAFE_INTEGER,this.socket.binaryType),r=e.readable.pipeThrough(t).getReader(),i=Re();i.readable.pipeTo(e.writable),this._writer=i.writable.getWriter();let n=()=>{r.read().then(({done:c,value:h})=>{c||(this.onPacket(h),n());}).catch(c=>{});};n();let o={type:"open"};this.query.sid&&(o.data=`{"sid":"${this.query.sid}"}`),this._writer.write(o).then(()=>this.onOpen());});});}write(e){this.writable=false;for(let t=0;t<e.length;t++){let r=e[t],i=t===e.length-1;this._writer.write(r).then(()=>{i&&y(()=>{this.writable=true,this.emitReserved("drain");},this.setTimeoutFn);});}}doClose(){var e;(e=this._transport)===null||e===void 0||e.close();}};var re={websocket:E,webtransport:v,polling:w};var st=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,rt=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function x(s){if(s.length>8e3)throw "URI too long";let e=s,t=s.indexOf("["),r=s.indexOf("]");t!=-1&&r!=-1&&(s=s.substring(0,t)+s.substring(t,r).replace(/:/g,";")+s.substring(r,s.length));let i=st.exec(s||""),n={},o=14;for(;o--;)n[rt[o]]=i[o]||"";return t!=-1&&r!=-1&&(n.source=e,n.host=n.host.substring(1,n.host.length-1).replace(/;/g,":"),n.authority=n.authority.replace("[","").replace("]","").replace(/;/g,":"),n.ipv6uri=true),n.pathNames=it(n,n.path),n.queryKey=nt(n,n.query),n}function it(s,e){let t=/\/{2,9}/g,r=e.replace(t,"/").split("/");return (e.slice(0,1)=="/"||e.length===0)&&r.splice(0,1),e.slice(-1)=="/"&&r.splice(r.length-1,1),r}function nt(s,e){let t={};return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(r,i,n){i&&(t[i]=n);}),t}var ie=typeof addEventListener=="function"&&typeof removeEventListener=="function",Y=[];ie&&addEventListener("offline",()=>{Y.forEach(s=>s());},false);var J=(()=>{class s extends f{constructor(t,r){if(super(),this.binaryType=Se,this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,t&&typeof t=="object"&&(r=t,t=null),t){let i=x(t);r.hostname=i.host,r.secure=i.protocol==="https"||i.protocol==="wss",r.port=i.port,i.query&&(r.query=i.query);}else r.host&&(r.hostname=x(r.host).host);g(this,r),this.secure=r.secure!=null?r.secure:typeof location<"u"&&location.protocol==="https:",r.hostname&&!r.port&&(r.port=this.secure?"443":"80"),this.hostname=r.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=r.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},r.transports.forEach(i=>{let n=i.prototype.name;this.transports.push(n),this._transportsByName[n]=i;}),this.opts=Object.assign({path:"/engine.io",agent:false,withCredentials:false,upgrade:true,timestampParam:"t",rememberUpgrade:false,addTrailingSlash:true,rejectUnauthorized:true,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:false},r),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=Le(this.opts.query)),ie&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close());},addEventListener("beforeunload",this._beforeunloadEventListener,false)),this.hostname!=="localhost"&&(this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"});},Y.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open();}createTransport(t){let r=Object.assign({},this.opts.query);r.EIO=Z,r.transport=t,this.id&&(r.sid=this.id);let i=Object.assign({},this.opts,{query:r,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[t]);return new this._transportsByName[t](i)}_open(){if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available");},0);return}let t=this.opts.rememberUpgrade&&s.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1?"websocket":this.transports[0];this.readyState="opening";let r=this.createTransport(t);r.open(),this.setTransport(r);}setTransport(t){this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",r=>this._onClose("transport close",r));}onOpen(){this.readyState="open",s.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush();}_onPacket(t){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")switch(this.emitReserved("packet",t),this.emitReserved("heartbeat"),t.type){case "open":this.onHandshake(JSON.parse(t.data));break;case "ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case "error":let r=new Error("server error");r.code=t.data,this._onError(r);break;case "message":this.emitReserved("data",t.data),this.emitReserved("message",t.data);break}}onHandshake(t){this.emitReserved("handshake",t),this.id=t.sid,this.transport.query.sid=t.sid,this._pingInterval=t.pingInterval,this._pingTimeout=t.pingTimeout,this._maxPayload=t.maxPayload,this.onOpen(),this.readyState!=="closed"&&this._resetPingTimeout();}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);let t=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+t,this._pingTimeoutTimer=this.setTimeoutFn(()=>{this._onClose("ping timeout");},t),this.opts.autoUnref&&this._pingTimeoutTimer.unref();}_onDrain(){this.writeBuffer.splice(0,this._prevBufferLen),this._prevBufferLen=0,this.writeBuffer.length===0?this.emitReserved("drain"):this.flush();}flush(){if(this.readyState!=="closed"&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){let t=this._getWritablePackets();this.transport.send(t),this._prevBufferLen=t.length,this.emitReserved("flush");}}_getWritablePackets(){if(!(this._maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let r=1;for(let i=0;i<this.writeBuffer.length;i++){let n=this.writeBuffer[i].data;if(n&&(r+=Ne(n)),i>0&&r>this._maxPayload)return this.writeBuffer.slice(0,i);r+=2;}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return true;let t=Date.now()>this._pingTimeoutTime;return t&&(this._pingTimeoutTime=0,y(()=>{this._onClose("ping timeout");},this.setTimeoutFn)),t}write(t,r,i){return this._sendPacket("message",t,r,i),this}send(t,r,i){return this._sendPacket("message",t,r,i),this}_sendPacket(t,r,i,n){if(typeof r=="function"&&(n=r,r=void 0),typeof i=="function"&&(n=i,i=null),this.readyState==="closing"||this.readyState==="closed")return;i=i||{},i.compress=i.compress!==false;let o={type:t,data:r,options:i};this.emitReserved("packetCreate",o),this.writeBuffer.push(o),n&&this.once("flush",n),this.flush();}close(){let t=()=>{this._onClose("forced close"),this.transport.close();},r=()=>{this.off("upgrade",r),this.off("upgradeError",r),t();},i=()=>{this.once("upgrade",r),this.once("upgradeError",r);};return (this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?i():t();}):this.upgrading?i():t()),this}_onError(t){if(s.priorWebsocketSuccess=false,this.opts.tryAllTransports&&this.transports.length>1&&this.readyState==="opening")return this.transports.shift(),this._open();this.emitReserved("error",t),this._onClose("transport error",t);}_onClose(t,r){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing"){if(this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),ie&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,false),this._offlineEventListener)){let i=Y.indexOf(this._offlineEventListener);i!==-1&&Y.splice(i,1);}this.readyState="closed",this.id=null,this.emitReserved("close",t,r),this.writeBuffer=[],this._prevBufferLen=0;}}}return s.protocol=Z,s})(),$=class extends J{constructor(){super(...arguments),this._upgrades=[];}onOpen(){if(super.onOpen(),this.readyState==="open"&&this.opts.upgrade)for(let e=0;e<this._upgrades.length;e++)this._probe(this._upgrades[e]);}_probe(e){let t=this.createTransport(e),r=false;J.priorWebsocketSuccess=false;let i=()=>{r||(t.send([{type:"ping",data:"probe"}]),t.once("packet",b=>{if(!r)if(b.type==="pong"&&b.data==="probe"){if(this.upgrading=true,this.emitReserved("upgrading",t),!t)return;J.priorWebsocketSuccess=t.name==="websocket",this.transport.pause(()=>{r||this.readyState!=="closed"&&(p(),this.setTransport(t),t.send([{type:"upgrade"}]),this.emitReserved("upgrade",t),t=null,this.upgrading=false,this.flush());});}else {let R=new Error("probe error");R.transport=t.name,this.emitReserved("upgradeError",R);}}));};function n(){r||(r=true,p(),t.close(),t=null);}let o=b=>{let R=new Error("probe error: "+b);R.transport=t.name,n(),this.emitReserved("upgradeError",R);};function c(){o("transport closed");}function h(){o("socket closed");}function m(b){t&&b.name!==t.name&&n();}let p=()=>{t.removeListener("open",i),t.removeListener("error",o),t.removeListener("close",c),this.off("close",h),this.off("upgrading",m);};t.once("open",i),t.once("error",o),t.once("close",c),this.once("close",h),this.once("upgrading",m),this._upgrades.indexOf("webtransport")!==-1&&e!=="webtransport"?this.setTimeoutFn(()=>{r||t.open();},200):t.open();}onHandshake(e){this._upgrades=this._filterUpgrades(e.upgrades),super.onHandshake(e);}_filterUpgrades(e){let t=[];for(let r=0;r<e.length;r++)~this.transports.indexOf(e[r])&&t.push(e[r]);return t}},T=class extends ${constructor(e,t={}){let r=typeof e=="object",i=r?w$1({},e):w$1({},t);(!i.transports||i.transports&&typeof i.transports[0]=="string")&&(i.transports=(i.transports||["polling","websocket","webtransport"]).map(n=>re[n]).filter(n=>!!n)),super(r?i:e,i);}};function Ue(s,e="",t){let r=s;t=t||typeof location<"u"&&location,s==null&&(s=t.protocol+"//"+t.host),typeof s=="string"&&(s.charAt(0)==="/"&&(s.charAt(1)==="/"?s=t.protocol+s:s=t.host+s),/^(https?|wss?):\/\//.test(s)||(typeof t<"u"?s=t.protocol+"//"+s:s="https://"+s),r=x(s)),r.port||(/^(http|ws)$/.test(r.protocol)?r.port="80":/^(http|ws)s$/.test(r.protocol)&&(r.port="443")),r.path=r.path||"/";let n=r.host.indexOf(":")!==-1?"["+r.host+"]":r.host;return r.id=r.protocol+"://"+n+":"+r.port+e,r.href=r.protocol+"://"+n+(t&&t.port===r.port?"":":"+r.port),r}var he={};C$2(he,{Decoder:()=>ce,Encoder:()=>oe,PacketType:()=>a,isPacketValid:()=>dt,protocol:()=>Ke});var ct=typeof ArrayBuffer=="function",at=s=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(s):s.buffer instanceof ArrayBuffer,Ve=Object.prototype.toString,ht=typeof Blob=="function"||typeof Blob<"u"&&Ve.call(Blob)==="[object BlobConstructor]",ft=typeof File=="function"||typeof File<"u"&&Ve.call(File)==="[object FileConstructor]";function D(s){return ct&&(s instanceof ArrayBuffer||at(s))||ht&&s instanceof Blob||ft&&s instanceof File}function q(s,e){if(!s||typeof s!="object")return false;if(Array.isArray(s)){for(let t=0,r=s.length;t<r;t++)if(q(s[t]))return true;return false}if(D(s))return true;if(s.toJSON&&typeof s.toJSON=="function"&&arguments.length===1)return q(s.toJSON(),true);for(let t in s)if(Object.prototype.hasOwnProperty.call(s,t)&&q(s[t]))return true;return false}function Me(s){let e=[],t=s.data,r=s;return r.data=z(t,e),r.attachments=e.length,{packet:r,buffers:e}}function z(s,e,t){if(!s)return s;if(D(s)){let r={_placeholder:true,num:e.length};return e.push(s),r}else if(Array.isArray(s)){let r=new Array(s.length);for(let i=0;i<s.length;i++)r[i]=z(s[i],e);return r}else if(typeof s=="object"&&!(s instanceof Date)){if(s.toJSON&&typeof s.toJSON=="function"&&!t)return z(s.toJSON(),e,true);let r={};for(let i in s)Object.prototype.hasOwnProperty.call(s,i)&&(r[i]=z(s[i],e));return r}return s}function He(s,e){return s.data=ne(s.data,e),delete s.attachments,s}function ne(s,e){if(!s)return s;if(s&&s._placeholder===true){if(typeof s.num=="number"&&s.num>=0&&s.num<e.length)return e[s.num];throw new Error("illegal attachments")}else if(Array.isArray(s))for(let t=0;t<s.length;t++)s[t]=ne(s[t],e);else if(typeof s=="object")for(let t in s)Object.prototype.hasOwnProperty.call(s,t)&&(s[t]=ne(s[t],e));return s}var We=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],Ke=5,a=(function(s){return s[s.CONNECT=0]="CONNECT",s[s.DISCONNECT=1]="DISCONNECT",s[s.EVENT=2]="EVENT",s[s.ACK=3]="ACK",s[s.CONNECT_ERROR=4]="CONNECT_ERROR",s[s.BINARY_EVENT=5]="BINARY_EVENT",s[s.BINARY_ACK=6]="BINARY_ACK",s})(a||{}),oe=class{constructor(e){this.replacer=e;}encode(e){return (e.type===a.EVENT||e.type===a.ACK)&&q(e)?this.encodeAsBinary({type:e.type===a.EVENT?a.BINARY_EVENT:a.BINARY_ACK,nsp:e.nsp,data:e.data,id:e.id}):[this.encodeAsString(e)]}encodeAsString(e){let t=""+e.type;return (e.type===a.BINARY_EVENT||e.type===a.BINARY_ACK)&&(t+=e.attachments+"-"),e.nsp&&e.nsp!=="/"&&(t+=e.nsp+","),e.id!=null&&(t+=e.id),e.data!=null&&(t+=JSON.stringify(e.data,this.replacer)),t}encodeAsBinary(e){let t=Me(e),r=this.encodeAsString(t.packet),i=t.buffers;return i.unshift(r),i}},ce=class s extends f{constructor(e){super(),this.opts=Object.assign({reviver:void 0,maxAttachments:10},typeof e=="function"?{reviver:e}:e);}add(e){let t;if(typeof e=="string"){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");t=this.decodeString(e);let r=t.type===a.BINARY_EVENT;r||t.type===a.BINARY_ACK?(t.type=r?a.EVENT:a.ACK,this.reconstructor=new ae(t)):super.emitReserved("decoded",t);}else if(D(e)||e.base64)if(this.reconstructor)t=this.reconstructor.takeBinaryData(e),t&&(this.reconstructor=null,super.emitReserved("decoded",t));else throw new Error("got binary data when not reconstructing a packet");else throw new Error("Unknown type: "+e)}decodeString(e){let t=0,r={type:Number(e.charAt(0))};if(a[r.type]===void 0)throw new Error("unknown packet type "+r.type);if(r.type===a.BINARY_EVENT||r.type===a.BINARY_ACK){let n=t+1;for(;e.charAt(++t)!=="-"&&t!=e.length;);let o=e.substring(n,t);if(o!=Number(o)||e.charAt(t)!=="-")throw new Error("Illegal attachments");let c=Number(o);if(!Ye(c)||c<1)throw new Error("Illegal attachments");if(c>this.opts.maxAttachments)throw new Error("too many attachments");r.attachments=c;}if(e.charAt(t+1)==="/"){let n=t+1;for(;++t&&!(e.charAt(t)===","||t===e.length););r.nsp=e.substring(n,t);}else r.nsp="/";let i=e.charAt(t+1);if(i!==""&&Number(i)==i){let n=t+1;for(;++t;){let o=e.charAt(t);if(o==null||Number(o)!=o){--t;break}if(t===e.length)break}r.id=Number(e.substring(n,t+1));}if(e.charAt(++t)){let n=this.tryParse(e.substr(t));if(s.isPayloadValid(r.type,n))r.data=n;else throw new Error("invalid payload")}return r}tryParse(e){try{return JSON.parse(e,this.opts.reviver)}catch(t){return false}}static isPayloadValid(e,t){switch(e){case a.CONNECT:return X(t);case a.DISCONNECT:return t===void 0;case a.CONNECT_ERROR:return typeof t=="string"||X(t);case a.EVENT:case a.BINARY_EVENT:return Array.isArray(t)&&(typeof t[0]=="number"||typeof t[0]=="string"&&We.indexOf(t[0])===-1);case a.ACK:case a.BINARY_ACK:return Array.isArray(t)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null);}},ae=class{constructor(e){this.packet=e,this.buffers=[],this.reconPack=e;}takeBinaryData(e){if(this.buffers.push(e),this.buffers.length===this.reconPack.attachments){let t=He(this.reconPack,this.buffers);return this.finishedReconstruction(),t}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[];}};function ut(s){return typeof s=="string"}var Ye=Number.isInteger||function(s){return typeof s=="number"&&isFinite(s)&&Math.floor(s)===s};function lt(s){return s===void 0||Ye(s)}function X(s){return Object.prototype.toString.call(s)==="[object Object]"}function pt(s,e){switch(s){case a.CONNECT:return e===void 0||X(e);case a.DISCONNECT:return e===void 0;case a.EVENT:return Array.isArray(e)&&(typeof e[0]=="number"||typeof e[0]=="string"&&We.indexOf(e[0])===-1);case a.ACK:return Array.isArray(e);case a.CONNECT_ERROR:return typeof e=="string"||X(e);default:return false}}function dt(s){return ut(s.nsp)&&lt(s.id)&&pt(s.type,s.data)}function l(s,e,t){return s.on(e,t),function(){s.off(e,t);}}var mt=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1}),A=class extends f{constructor(e,t,r){super(),this.connected=false,this.recovered=false,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=e,this.nsp=t,r&&r.auth&&(this.auth=r.auth),this._opts=Object.assign({},r),this.io._autoConnect&&this.open();}get disconnected(){return !this.connected}subEvents(){if(this.subs)return;let e=this.io;this.subs=[l(e,"open",this.onopen.bind(this)),l(e,"packet",this.onpacket.bind(this)),l(e,"error",this.onerror.bind(this)),l(e,"close",this.onclose.bind(this))];}get active(){return !!this.subs}connect(){return this.connected?this:(this.subEvents(),this.io._reconnecting||this.io.open(),this.io._readyState==="open"&&this.onopen(),this)}open(){return this.connect()}send(...e){return e.unshift("message"),this.emit.apply(this,e),this}emit(e,...t){var r,i,n;if(mt.hasOwnProperty(e))throw new Error('"'+e.toString()+'" is a reserved event name');if(t.unshift(e),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(t),this;let o={type:a.EVENT,data:t};if(o.options={},o.options.compress=this.flags.compress!==false,typeof t[t.length-1]=="function"){let p=this.ids++,b=t.pop();this._registerAckCallback(p,b),o.id=p;}let c=(i=(r=this.io.engine)===null||r===void 0?void 0:r.transport)===null||i===void 0?void 0:i.writable,h=this.connected&&!(!((n=this.io.engine)===null||n===void 0)&&n._hasPingExpired());return this.flags.volatile&&!c||(h?(this.notifyOutgoingListeners(o),this.packet(o)):this.sendBuffer.push(o)),this.flags={},this}_registerAckCallback(e,t){var r;let i=(r=this.flags.timeout)!==null&&r!==void 0?r:this._opts.ackTimeout;if(i===void 0){this.acks[e]=t;return}let n=this.io.setTimeoutFn(()=>{delete this.acks[e];for(let c=0;c<this.sendBuffer.length;c++)this.sendBuffer[c].id===e&&this.sendBuffer.splice(c,1);t.call(this,new Error("operation has timed out"));},i),o=(...c)=>{this.io.clearTimeoutFn(n),t.apply(this,c);};o.withError=true,this.acks[e]=o;}emitWithAck(e,...t){return new Promise((r,i)=>{let n=(o,c)=>o?i(o):r(c);n.withError=true,t.push(n),this.emit(e,...t);})}_addToQueue(e){let t;typeof e[e.length-1]=="function"&&(t=e.pop());let r={id:this._queueSeq++,tryCount:0,pending:false,args:e,flags:Object.assign({fromQueue:true},this.flags)};e.push((i,...n)=>(this._queue[0],i!==null?r.tryCount>this._opts.retries&&(this._queue.shift(),t&&t(i)):(this._queue.shift(),t&&t(null,...n)),r.pending=false,this._drainQueue())),this._queue.push(r),this._drainQueue();}_drainQueue(e=false){if(!this.connected||this._queue.length===0)return;let t=this._queue[0];t.pending&&!e||(t.pending=true,t.tryCount++,this.flags=t.flags,this.emit.apply(this,t.args));}packet(e){e.nsp=this.nsp,this.io._packet(e);}onopen(){typeof this.auth=="function"?this.auth(e=>{this._sendConnectPacket(e);}):this._sendConnectPacket(this.auth);}_sendConnectPacket(e){this.packet({type:a.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},e):e});}onerror(e){this.connected||this.emitReserved("connect_error",e);}onclose(e,t){this.connected=false,delete this.id,this.emitReserved("disconnect",e,t),this._clearAcks();}_clearAcks(){Object.keys(this.acks).forEach(e=>{if(!this.sendBuffer.some(r=>String(r.id)===e)){let r=this.acks[e];delete this.acks[e],r.withError&&r.call(this,new Error("socket has been disconnected"));}});}onpacket(e){if(e.nsp===this.nsp)switch(e.type){case a.CONNECT:e.data&&e.data.sid?this.onconnect(e.data.sid,e.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case a.EVENT:case a.BINARY_EVENT:this.onevent(e);break;case a.ACK:case a.BINARY_ACK:this.onack(e);break;case a.DISCONNECT:this.ondisconnect();break;case a.CONNECT_ERROR:this.destroy();let r=new Error(e.data.message);r.data=e.data.data,this.emitReserved("connect_error",r);break}}onevent(e){let t=e.data||[];e.id!=null&&t.push(this.ack(e.id)),this.connected?this.emitEvent(t):this.receiveBuffer.push(Object.freeze(t));}emitEvent(e){if(this._anyListeners&&this._anyListeners.length){let t=this._anyListeners.slice();for(let r of t)r.apply(this,e);}super.emit.apply(this,e),this._pid&&e.length&&typeof e[e.length-1]=="string"&&(this._lastOffset=e[e.length-1]);}ack(e){let t=this,r=false;return function(...i){r||(r=true,t.packet({type:a.ACK,id:e,data:i}));}}onack(e){let t=this.acks[e.id];typeof t=="function"&&(delete this.acks[e.id],t.withError&&e.data.unshift(null),t.apply(this,e.data));}onconnect(e,t){this.id=e,this.recovered=t&&this._pid===t,this._pid=t,this.connected=true,this.emitBuffered(),this._drainQueue(true),this.emitReserved("connect");}emitBuffered(){this.receiveBuffer.forEach(e=>this.emitEvent(e)),this.receiveBuffer=[],this.sendBuffer.forEach(e=>{this.notifyOutgoingListeners(e),this.packet(e);}),this.sendBuffer=[];}ondisconnect(){this.destroy(),this.onclose("io server disconnect");}destroy(){this.subs&&(this.subs.forEach(e=>e()),this.subs=void 0),this.io._destroy(this);}disconnect(){return this.connected&&this.packet({type:a.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(e){return this.flags.compress=e,this}get volatile(){return this.flags.volatile=true,this}timeout(e){return this.flags.timeout=e,this}onAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(e),this}prependAny(e){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(e),this}offAny(e){if(!this._anyListeners)return this;if(e){let t=this._anyListeners;for(let r=0;r<t.length;r++)if(e===t[r])return t.splice(r,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(e),this}prependAnyOutgoing(e){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(e),this}offAnyOutgoing(e){if(!this._anyOutgoingListeners)return this;if(e){let t=this._anyOutgoingListeners;for(let r=0;r<t.length;r++)if(e===t[r])return t.splice(r,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(e){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){let t=this._anyOutgoingListeners.slice();for(let r of t)r.apply(this,e.data);}}};function k(s){s=s||{},this.ms=s.min||100,this.max=s.max||1e4,this.factor=s.factor||2,this.jitter=s.jitter>0&&s.jitter<=1?s.jitter:0,this.attempts=0;}k.prototype.duration=function(){var s=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var e=Math.random(),t=Math.floor(e*this.jitter*s);s=(Math.floor(e*10)&1)==0?s-t:s+t;}return Math.min(s,this.max)|0};k.prototype.reset=function(){this.attempts=0;};k.prototype.setMin=function(s){this.ms=s;};k.prototype.setMax=function(s){this.max=s;};k.prototype.setJitter=function(s){this.jitter=s;};var C=class extends f{constructor(e,t){var r;super(),this.nsps={},this.subs=[],e&&typeof e=="object"&&(t=e,e=void 0),t=t||{},t.path=t.path||"/socket.io",this.opts=t,g(this,t),this.reconnection(t.reconnection!==false),this.reconnectionAttempts(t.reconnectionAttempts||1/0),this.reconnectionDelay(t.reconnectionDelay||1e3),this.reconnectionDelayMax(t.reconnectionDelayMax||5e3),this.randomizationFactor((r=t.randomizationFactor)!==null&&r!==void 0?r:.5),this.backoff=new k({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(t.timeout==null?2e4:t.timeout),this._readyState="closed",this.uri=e;let i=t.parser||he;this.encoder=new i.Encoder,this.decoder=new i.Decoder,this._autoConnect=t.autoConnect!==false,this._autoConnect&&this.open();}reconnection(e){return arguments.length?(this._reconnection=!!e,e||(this.skipReconnect=true),this):this._reconnection}reconnectionAttempts(e){return e===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=e,this)}reconnectionDelay(e){var t;return e===void 0?this._reconnectionDelay:(this._reconnectionDelay=e,(t=this.backoff)===null||t===void 0||t.setMin(e),this)}randomizationFactor(e){var t;return e===void 0?this._randomizationFactor:(this._randomizationFactor=e,(t=this.backoff)===null||t===void 0||t.setJitter(e),this)}reconnectionDelayMax(e){var t;return e===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=e,(t=this.backoff)===null||t===void 0||t.setMax(e),this)}timeout(e){return arguments.length?(this._timeout=e,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect();}open(e){if(~this._readyState.indexOf("open"))return this;this.engine=new T(this.uri,this.opts);let t=this.engine,r=this;this._readyState="opening",this.skipReconnect=false;let i=l(t,"open",function(){r.onopen(),e&&e();}),n=c=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",c),e?e(c):this.maybeReconnectOnOpen();},o=l(t,"error",n);if(this._timeout!==false){let c=this._timeout,h=this.setTimeoutFn(()=>{i(),n(new Error("timeout")),t.close();},c);this.opts.autoUnref&&h.unref(),this.subs.push(()=>{this.clearTimeoutFn(h);});}return this.subs.push(i),this.subs.push(o),this}connect(e){return this.open(e)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");let e=this.engine;this.subs.push(l(e,"ping",this.onping.bind(this)),l(e,"data",this.ondata.bind(this)),l(e,"error",this.onerror.bind(this)),l(e,"close",this.onclose.bind(this)),l(this.decoder,"decoded",this.ondecoded.bind(this)));}onping(){this.emitReserved("ping");}ondata(e){try{this.decoder.add(e);}catch(t){this.onclose("parse error",t);}}ondecoded(e){y(()=>{this.emitReserved("packet",e);},this.setTimeoutFn);}onerror(e){this.emitReserved("error",e);}socket(e,t){let r=this.nsps[e];return r?this._autoConnect&&!r.active&&r.connect():(r=new A(this,e,t),this.nsps[e]=r),r}_destroy(e){let t=Object.keys(this.nsps);for(let r of t)if(this.nsps[r].active)return;this._close();}_packet(e){let t=this.encoder.encode(e);for(let r=0;r<t.length;r++)this.engine.write(t[r],e.options);}cleanup(){this.subs.forEach(e=>e()),this.subs.length=0,this.decoder.destroy();}_close(){this.skipReconnect=true,this._reconnecting=false,this.onclose("forced close");}disconnect(){return this._close()}onclose(e,t){var r;this.cleanup(),(r=this.engine)===null||r===void 0||r.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",e,t),this._reconnection&&!this.skipReconnect&&this.reconnect();}reconnect(){if(this._reconnecting||this.skipReconnect)return this;let e=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=false;else {let t=this.backoff.duration();this._reconnecting=true;let r=this.setTimeoutFn(()=>{e.skipReconnect||(this.emitReserved("reconnect_attempt",e.backoff.attempts),!e.skipReconnect&&e.open(i=>{i?(e._reconnecting=false,e.reconnect(),this.emitReserved("reconnect_error",i)):e.onreconnect();}));},t);this.opts.autoUnref&&r.unref(),this.subs.push(()=>{this.clearTimeoutFn(r);});}}onreconnect(){let e=this.backoff.attempts;this._reconnecting=false,this.backoff.reset(),this.emitReserved("reconnect",e);}};var I={};function F(s,e){typeof s=="object"&&(e=s,s=void 0),e=e||{};let t=Ue(s,e.path||"/socket.io"),r=t.source,i=t.id,n=t.path,o=I[i]&&n in I[i].nsps,c=e.forceNew||e["force new connection"]||e.multiplex===false||o,h;return c?h=new C(r,e):(I[i]||(I[i]=new C(r,e)),h=I[i]),t.query&&!e.query&&(e.query=t.queryKey),h.socket(t.path,e)}Object.assign(F,{Manager:C,Socket:A,io:F,connect:F});var dr=(()=>{class s{$auth=g$1(ae$1);namespaceConnectionCache={};constructor(){this.$auth.tokenRotated.subscribe(()=>this.rotateTokenOnCachedSockets());}connectToNamespace(t){if(this.namespaceConnectionCache[t])return this.namespaceConnectionCache[t];let r=this.establishConnectionToNamespace(t);return r.connected=new Or(1),r.socket.on("connect",()=>{r.connected.next();}),r.end=()=>{r.socket.emit("end");},this.namespaceConnectionCache[t]=r,r}rotateTokenOnCachedSockets(){let t=this.$auth.token;for(let r of Object.values(this.namespaceConnectionCache)){let i=r.socket?.io?.opts;i?.query&&typeof i.query=="object"&&(i.query.token=t),r.socket.connected&&r.socket.disconnect().connect();}}getExistingNamespace(t){return this.namespaceConnectionCache[t]}establishConnectionToNamespace(t){let r=F(`${Eo.api.socket}/${t}`,{query:{token:this.$auth.token},reconnectionAttempts:10,reconnectionDelayMax:3e4});return {socket:r,request:(n,o)=>new x$1(c=>{r.emit(n,o,h=>{typeof h=="object"&&h.error?c.error(h):c.next(h),c.complete();});})}}static \u0275fac=function(r){return new(r||s)};static \u0275prov=C$1({token:s,factory:s.\u0275fac,providedIn:"root"})}return s})(); export{dr as d};