ERP-admin/build/admin/assets/engine.io-client.81030771.js

2 lines
24 KiB
JavaScript

import{n as w}from"./@babel.16688d44.js";import{r as H}from"./engine.io-parser.c748e159.js";import{r as z}from"./@socket.io.77accf6a.js";import{r as F}from"./debug.b392f131.js";var N={},O={},x={},q={},P={},T={},C={},$;function A(){return $||($=1,Object.defineProperty(C,"__esModule",{value:!0}),C.globalThisShim=void 0,C.globalThisShim=(()=>typeof self<"u"?self:typeof window<"u"?window:Function("return this")())()),C}var G;function U(){if(G)return T;G=1,Object.defineProperty(T,"__esModule",{value:!0}),T.byteLength=T.installTimerFunctions=T.pick=void 0;const o=A();function b(n,...r){return r.reduce((s,i)=>(n.hasOwnProperty(i)&&(s[i]=n[i]),s),{})}T.pick=b;const d=o.globalThisShim.setTimeout,m=o.globalThisShim.clearTimeout;function u(n,r){r.useNativeTimers?(n.setTimeoutFn=d.bind(o.globalThisShim),n.clearTimeoutFn=m.bind(o.globalThisShim)):(n.setTimeoutFn=o.globalThisShim.setTimeout.bind(o.globalThisShim),n.clearTimeoutFn=o.globalThisShim.clearTimeout.bind(o.globalThisShim))}T.installTimerFunctions=u;const h=1.33;function y(n){return typeof n=="string"?f(n):Math.ceil((n.byteLength||n.size)*h)}T.byteLength=y;function f(n){let r=0,s=0;for(let i=0,e=n.length;i<e;i++)r=n.charCodeAt(i),r<128?s+=1:r<2048?s+=2:r<55296||r>=57344?s+=3:(i++,s+=4);return s}return T}var R={},V;function ce(){if(V)return R;V=1,Object.defineProperty(R,"__esModule",{value:!0}),R.decode=R.encode=void 0;function o(d){let m="";for(let u in d)d.hasOwnProperty(u)&&(m.length&&(m+="&"),m+=encodeURIComponent(u)+"="+encodeURIComponent(d[u]));return m}R.encode=o;function b(d){let m={},u=d.split("&");for(let h=0,y=u.length;h<y;h++){let f=u[h].split("=");m[decodeURIComponent(f[0])]=decodeURIComponent(f[1])}return m}return R.decode=b,R}var K;function I(){if(K)return P;K=1;var o=w&&w.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(P,"__esModule",{value:!0}),P.Transport=P.TransportError=void 0;const b=H(),d=z,m=U(),u=o(F()),h=ce(),y=(0,u.default)("engine.io-client:transport");class f extends Error{constructor(s,i,e){super(s),this.description=i,this.context=e,this.type="TransportError"}}P.TransportError=f;class n extends d.Emitter{constructor(s){super(),this.writable=!1,(0,m.installTimerFunctions)(this,s),this.opts=s,this.query=s.query,this.socket=s.socket}onError(s,i,e){return super.emitReserved("error",new f(s,i,e)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return(this.readyState==="opening"||this.readyState==="open")&&(this.doClose(),this.onClose()),this}send(s){this.readyState==="open"?this.write(s):y("transport is not open, discarding packets")}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(s){const i=(0,b.decodePacket)(s,this.socket.binaryType);this.onPacket(i)}onPacket(s){super.emitReserved("packet",s)}onClose(s){this.readyState="closed",super.emitReserved("close",s)}pause(s){}createUri(s,i={}){return s+"://"+this._hostname()+this._port()+this.opts.path+this._query(i)}_hostname(){const s=this.opts.hostname;return s.indexOf(":")===-1?s:"["+s+"]"}_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(s){const i=(0,h.encode)(s);return i.length?"?"+i:""}}return P.Transport=n,P}var k={},Y;function he(){if(Y)return k;Y=1,Object.defineProperty(k,"__esModule",{value:!0}),k.yeast=k.decode=k.encode=void 0;const o="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),b=64,d={};let m=0,u=0,h;function y(r){let s="";do s=o[r%b]+s,r=Math.floor(r/b);while(r>0);return s}k.encode=y;function f(r){let s=0;for(u=0;u<r.length;u++)s=s*b+d[r.charAt(u)];return s}k.decode=f;function n(){const r=y(+new Date);return r!==h?(m=0,h=r):r+"."+y(m++)}for(k.yeast=n;u<b;u++)d[o[u]]=u;return k}var E={},L={},Q;function pe(){if(Q)return L;Q=1,Object.defineProperty(L,"__esModule",{value:!0}),L.hasCORS=void 0;let o=!1;try{o=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}return L.hasCORS=o,L}var Z;function de(){if(Z)return E;Z=1,Object.defineProperty(E,"__esModule",{value:!0}),E.createCookieJar=E.XHR=void 0;const o=pe(),b=A();function d(u){const h=u.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!h||o.hasCORS))return new XMLHttpRequest}catch{}if(!h)try{return new b.globalThisShim[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}E.XHR=d;function m(){}return E.createCookieJar=m,E}var ee;function fe(){if(ee)return q;ee=1;var o=w&&w.__importDefault||function(g){return g&&g.__esModule?g:{default:g}};Object.defineProperty(q,"__esModule",{value:!0}),q.Request=q.Polling=void 0;const b=I(),d=o(F()),m=he(),u=H(),h=de(),y=z,f=U(),n=A(),r=(0,d.default)("engine.io-client:polling");function s(){}const i=function(){return new h.XHR({xdomain:!1}).responseType!=null}();class e extends b.Transport{constructor(a){if(super(a),this.polling=!1,typeof location<"u"){const l=location.protocol==="https:";let _=location.port;_||(_=l?"443":"80"),this.xd=typeof location<"u"&&a.hostname!==location.hostname||_!==a.port}const p=a&&a.forceBase64;this.supportsBinary=i&&!p,this.opts.withCredentials&&(this.cookieJar=(0,h.createCookieJar)())}get name(){return"polling"}doOpen(){this.poll()}pause(a){this.readyState="pausing";const p=()=>{r("paused"),this.readyState="paused",a()};if(this.polling||!this.writable){let l=0;this.polling&&(r("we are currently polling - waiting to pause"),l++,this.once("pollComplete",function(){r("pre-pause polling complete"),--l||p()})),this.writable||(r("we are currently writing - waiting to pause"),l++,this.once("drain",function(){r("pre-pause writing complete"),--l||p()}))}else p()}poll(){r("polling"),this.polling=!0,this.doPoll(),this.emitReserved("poll")}onData(a){r("polling got data %s",a);const p=l=>{if(this.readyState==="opening"&&l.type==="open"&&this.onOpen(),l.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(l)};(0,u.decodePayload)(a,this.socket.binaryType).forEach(p),this.readyState!=="closed"&&(this.polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"?this.poll():r('ignoring poll - transport state "%s"',this.readyState))}doClose(){const a=()=>{r("writing close packet"),this.write([{type:"close"}])};this.readyState==="open"?(r("transport open - closing"),a()):(r("transport not open - deferring close"),this.once("open",a))}write(a){this.writable=!1,(0,u.encodePayload)(a,p=>{this.doWrite(p,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const a=this.opts.secure?"https":"http",p=this.query||{};return this.opts.timestampRequests!==!1&&(p[this.opts.timestampParam]=(0,m.yeast)()),!this.supportsBinary&&!p.sid&&(p.b64=1),this.createUri(a,p)}request(a={}){return Object.assign(a,{xd:this.xd,cookieJar:this.cookieJar},this.opts),new t(this.uri(),a)}doWrite(a,p){const l=this.request({method:"POST",data:a});l.on("success",p),l.on("error",(_,D)=>{this.onError("xhr post error",_,D)})}doPoll(){r("xhr poll");const a=this.request();a.on("data",this.onData.bind(this)),a.on("error",(p,l)=>{this.onError("xhr poll error",p,l)}),this.pollXhr=a}}q.Polling=e;class t extends y.Emitter{constructor(a,p){super(),(0,f.installTimerFunctions)(this,p),this.opts=p,this.method=p.method||"GET",this.uri=a,this.data=p.data!==void 0?p.data:null,this.create()}create(){var a;const p=(0,f.pick)(this.opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");p.xdomain=!!this.opts.xd;const l=this.xhr=new h.XHR(p);try{r("xhr open %s: %s",this.method,this.uri),l.open(this.method,this.uri,!0);try{if(this.opts.extraHeaders){l.setDisableHeaderCheck&&l.setDisableHeaderCheck(!0);for(let _ in this.opts.extraHeaders)this.opts.extraHeaders.hasOwnProperty(_)&&l.setRequestHeader(_,this.opts.extraHeaders[_])}}catch{}if(this.method==="POST")try{l.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{l.setRequestHeader("Accept","*/*")}catch{}(a=this.opts.cookieJar)===null||a===void 0||a.addCookies(l),"withCredentials"in l&&(l.withCredentials=this.opts.withCredentials),this.opts.requestTimeout&&(l.timeout=this.opts.requestTimeout),l.onreadystatechange=()=>{var _;l.readyState===3&&((_=this.opts.cookieJar)===null||_===void 0||_.parseCookies(l)),l.readyState===4&&(l.status===200||l.status===1223?this.onLoad():this.setTimeoutFn(()=>{this.onError(typeof l.status=="number"?l.status:0)},0))},r("xhr data %s",this.data),l.send(this.data)}catch(_){this.setTimeoutFn(()=>{this.onError(_)},0);return}typeof document<"u"&&(this.index=t.requestsCount++,t.requests[this.index]=this)}onError(a){this.emitReserved("error",a,this.xhr),this.cleanup(!0)}cleanup(a){if(!(typeof this.xhr>"u"||this.xhr===null)){if(this.xhr.onreadystatechange=s,a)try{this.xhr.abort()}catch{}typeof document<"u"&&delete t.requests[this.index],this.xhr=null}}onLoad(){const a=this.xhr.responseText;a!==null&&(this.emitReserved("data",a),this.emitReserved("success"),this.cleanup())}abort(){this.cleanup()}}if(q.Request=t,t.requestsCount=0,t.requests={},typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",c);else if(typeof addEventListener=="function"){const g="onpagehide"in n.globalThisShim?"pagehide":"unload";addEventListener(g,c,!1)}}function c(){for(let g in t.requests)t.requests.hasOwnProperty(g)&&t.requests[g].abort()}return q}var B={},v={},te;function X(){if(te)return v;te=1,Object.defineProperty(v,"__esModule",{value:!0}),v.defaultBinaryType=v.usingBrowserWebSocket=v.WebSocket=v.nextTick=void 0;const o=A();return v.nextTick=(()=>typeof Promise=="function"&&typeof Promise.resolve=="function"?d=>Promise.resolve().then(d):(d,m)=>m(d,0))(),v.WebSocket=o.globalThisShim.WebSocket||o.globalThisShim.MozWebSocket,v.usingBrowserWebSocket=!0,v.defaultBinaryType="arraybuffer",v}var re;function ge(){if(re)return B;re=1;var o=w&&w.__importDefault||function(s){return s&&s.__esModule?s:{default:s}};Object.defineProperty(B,"__esModule",{value:!0}),B.WS=void 0;const b=I(),d=he(),m=U(),u=X(),h=o(F()),y=H(),f=(0,h.default)("engine.io-client:websocket"),n=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative";class r extends b.Transport{constructor(i){super(i),this.supportsBinary=!i.forceBase64}get name(){return"websocket"}doOpen(){if(!this.check())return;const i=this.uri(),e=this.opts.protocols,t=n?{}:(0,m.pick)(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(t.headers=this.opts.extraHeaders);try{this.ws=u.usingBrowserWebSocket&&!n?e?new u.WebSocket(i,e):new u.WebSocket(i):new u.WebSocket(i,e,t)}catch(c){return this.emitReserved("error",c)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=i=>this.onClose({description:"websocket connection closed",context:i}),this.ws.onmessage=i=>this.onData(i.data),this.ws.onerror=i=>this.onError("websocket error",i)}write(i){this.writable=!1;for(let e=0;e<i.length;e++){const t=i[e],c=e===i.length-1;(0,y.encodePacket)(t,this.supportsBinary,g=>{const a={};u.usingBrowserWebSocket||(t.options&&(a.compress=t.options.compress),this.opts.perMessageDeflate&&(typeof g=="string"?Buffer.byteLength(g):g.length)<this.opts.perMessageDeflate.threshold&&(a.compress=!1));try{u.usingBrowserWebSocket?this.ws.send(g):this.ws.send(g,a)}catch{f("websocket closed before onclose event")}c&&(0,u.nextTick)(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.close(),this.ws=null)}uri(){const i=this.opts.secure?"wss":"ws",e=this.query||{};return this.opts.timestampRequests&&(e[this.opts.timestampParam]=(0,d.yeast)()),this.supportsBinary||(e.b64=1),this.createUri(i,e)}check(){return!!u.WebSocket}}return B.WS=r,B}var W={},se;function me(){if(se)return W;se=1;var o=w&&w.__importDefault||function(f){return f&&f.__esModule?f:{default:f}};Object.defineProperty(W,"__esModule",{value:!0}),W.WT=void 0;const b=I(),d=X(),m=H(),h=(0,o(F()).default)("engine.io-client:webtransport");class y extends b.Transport{get name(){return"webtransport"}doOpen(){typeof WebTransport=="function"&&(this.transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name]),this.transport.closed.then(()=>{h("transport closed gracefully"),this.onClose()}).catch(n=>{h("transport closed due to %s",n),this.onError("webtransport error",n)}),this.transport.ready.then(()=>{this.transport.createBidirectionalStream().then(n=>{const r=(0,m.createPacketDecoderStream)(Number.MAX_SAFE_INTEGER,this.socket.binaryType),s=n.readable.pipeThrough(r).getReader(),i=(0,m.createPacketEncoderStream)();i.readable.pipeTo(n.writable),this.writer=i.writable.getWriter();const e=()=>{s.read().then(({done:c,value:g})=>{if(c){h("session is closed");return}h("received chunk: %o",g),this.onPacket(g),e()}).catch(c=>{h("an error occurred while reading: %s",c)})};e();const t={type:"open"};this.query.sid&&(t.data=`{"sid":"${this.query.sid}"}`),this.writer.write(t).then(()=>this.onOpen())})}))}write(n){this.writable=!1;for(let r=0;r<n.length;r++){const s=n[r],i=r===n.length-1;this.writer.write(s).then(()=>{i&&(0,d.nextTick)(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var n;(n=this.transport)===null||n===void 0||n.close()}}return W.WT=y,W}var ie;function ue(){if(ie)return x;ie=1,Object.defineProperty(x,"__esModule",{value:!0}),x.transports=void 0;const o=fe(),b=ge(),d=me();return x.transports={websocket:b.WS,webtransport:d.WT,polling:o.Polling},x}var M={},oe;function le(){if(oe)return M;oe=1,Object.defineProperty(M,"__esModule",{value:!0}),M.parse=void 0;const o=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,b=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function d(h){if(h.length>2e3)throw"URI too long";const y=h,f=h.indexOf("["),n=h.indexOf("]");f!=-1&&n!=-1&&(h=h.substring(0,f)+h.substring(f,n).replace(/:/g,";")+h.substring(n,h.length));let r=o.exec(h||""),s={},i=14;for(;i--;)s[b[i]]=r[i]||"";return f!=-1&&n!=-1&&(s.source=y,s.host=s.host.substring(1,s.host.length-1).replace(/;/g,":"),s.authority=s.authority.replace("[","").replace("]","").replace(/;/g,":"),s.ipv6uri=!0),s.pathNames=m(s,s.path),s.queryKey=u(s,s.query),s}M.parse=d;function m(h,y){const f=/\/{2,9}/g,n=y.replace(f,"/").split("/");return(y.slice(0,1)=="/"||y.length===0)&&n.splice(0,1),y.slice(-1)=="/"&&n.splice(n.length-1,1),n}function u(h,y){const f={};return y.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(n,r,s){r&&(f[r]=s)}),f}return M}var ne;function ye(){if(ne)return O;ne=1;var o=w&&w.__importDefault||function(i){return i&&i.__esModule?i:{default:i}};Object.defineProperty(O,"__esModule",{value:!0}),O.Socket=void 0;const b=ue(),d=U(),m=ce(),u=le(),h=o(F()),y=z,f=H(),n=X(),r=(0,h.default)("engine.io-client:socket");class s extends y.Emitter{constructor(e,t={}){super(),this.binaryType=n.defaultBinaryType,this.writeBuffer=[],e&&typeof e=="object"&&(t=e,e=null),e?(e=(0,u.parse)(e),t.hostname=e.host,t.secure=e.protocol==="https"||e.protocol==="wss",t.port=e.port,e.query&&(t.query=e.query)):t.host&&(t.hostname=(0,u.parse)(t.host).host),(0,d.installTimerFunctions)(this,t),this.secure=t.secure!=null?t.secure:typeof location<"u"&&location.protocol==="https:",t.hostname&&!t.port&&(t.port=this.secure?"443":"80"),this.hostname=t.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=t.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=t.transports||["polling","websocket","webtransport"],this.writeBuffer=[],this.prevBufferLen=0,this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},t),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=(0,m.decode)(this.opts.query)),this.id=null,this.upgrades=null,this.pingInterval=null,this.pingTimeout=null,this.pingTimeoutTimer=null,typeof addEventListener=="function"&&(this.opts.closeOnBeforeunload&&(this.beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this.beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(this.offlineEventListener=()=>{this.onClose("transport close",{description:"network connection lost"})},addEventListener("offline",this.offlineEventListener,!1))),this.open()}createTransport(e){r('creating transport "%s"',e);const t=Object.assign({},this.opts.query);t.EIO=f.protocol,t.transport=e,this.id&&(t.sid=this.id);const c=Object.assign({},this.opts,{query:t,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[e]);return r("options: %j",c),new b.transports[e](c)}open(){let e;if(this.opts.rememberUpgrade&&s.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1)e="websocket";else if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}else e=this.transports[0];this.readyState="opening";try{e=this.createTransport(e)}catch(t){r("error while creating transport: %s",t),this.transports.shift(),this.open();return}e.open(),this.setTransport(e)}setTransport(e){r("setting transport %s",e.name),this.transport&&(r("clearing existing transport %s",this.transport.name),this.transport.removeAllListeners()),this.transport=e,e.on("drain",this.onDrain.bind(this)).on("packet",this.onPacket.bind(this)).on("error",this.onError.bind(this)).on("close",t=>this.onClose("transport close",t))}probe(e){r('probing transport "%s"',e);let t=this.createTransport(e),c=!1;s.priorWebsocketSuccess=!1;const g=()=>{c||(r('probe transport "%s" opened',e),t.send([{type:"ping",data:"probe"}]),t.once("packet",S=>{if(!c)if(S.type==="pong"&&S.data==="probe"){if(r('probe transport "%s" pong',e),this.upgrading=!0,this.emitReserved("upgrading",t),!t)return;s.priorWebsocketSuccess=t.name==="websocket",r('pausing current transport "%s"',this.transport.name),this.transport.pause(()=>{c||this.readyState!=="closed"&&(r("changing transport and sending upgrade packet"),J(),this.setTransport(t),t.send([{type:"upgrade"}]),this.emitReserved("upgrade",t),t=null,this.upgrading=!1,this.flush())})}else{r('probe transport "%s" failed',e);const j=new Error("probe error");j.transport=t.name,this.emitReserved("upgradeError",j)}}))};function a(){c||(c=!0,J(),t.close(),t=null)}const p=S=>{const j=new Error("probe error: "+S);j.transport=t.name,a(),r('probe transport "%s" failed because of error: %s',e,S),this.emitReserved("upgradeError",j)};function l(){p("transport closed")}function _(){p("socket closed")}function D(S){t&&S.name!==t.name&&(r('"%s" works - aborting "%s"',S.name,t.name),a())}const J=()=>{t.removeListener("open",g),t.removeListener("error",p),t.removeListener("close",l),this.off("close",_),this.off("upgrading",D)};t.once("open",g),t.once("error",p),t.once("close",l),this.once("close",_),this.once("upgrading",D),this.upgrades.indexOf("webtransport")!==-1&&e!=="webtransport"?this.setTimeoutFn(()=>{c||t.open()},200):t.open()}onOpen(){if(r("socket open"),this.readyState="open",s.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush(),this.readyState==="open"&&this.opts.upgrade){r("starting upgrade probes");let e=0;const t=this.upgrades.length;for(;e<t;e++)this.probe(this.upgrades[e])}}onPacket(e){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")switch(r('socket receive: type "%s", data "%s"',e.type,e.data),this.emitReserved("packet",e),this.emitReserved("heartbeat"),this.resetPingTimeout(),e.type){case"open":this.onHandshake(JSON.parse(e.data));break;case"ping":this.sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong");break;case"error":const t=new Error("server error");t.code=e.data,this.onError(t);break;case"message":this.emitReserved("data",e.data),this.emitReserved("message",e.data);break}else r('packet received with socket readyState "%s"',this.readyState)}onHandshake(e){this.emitReserved("handshake",e),this.id=e.sid,this.transport.query.sid=e.sid,this.upgrades=this.filterUpgrades(e.upgrades),this.pingInterval=e.pingInterval,this.pingTimeout=e.pingTimeout,this.maxPayload=e.maxPayload,this.onOpen(),this.readyState!=="closed"&&this.resetPingTimeout()}resetPingTimeout(){this.clearTimeoutFn(this.pingTimeoutTimer),this.pingTimeoutTimer=this.setTimeoutFn(()=>{this.onClose("ping timeout")},this.pingInterval+this.pingTimeout),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){const e=this.getWritablePackets();r("flushing %d packets in socket",e.length),this.transport.send(e),this.prevBufferLen=e.length,this.emitReserved("flush")}}getWritablePackets(){if(!(this.maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let t=1;for(let c=0;c<this.writeBuffer.length;c++){const g=this.writeBuffer[c].data;if(g&&(t+=(0,d.byteLength)(g)),c>0&&t>this.maxPayload)return r("only send %d out of %d packets",c,this.writeBuffer.length),this.writeBuffer.slice(0,c);t+=2}return r("payload size is %d (max: %d)",t,this.maxPayload),this.writeBuffer}write(e,t,c){return this.sendPacket("message",e,t,c),this}send(e,t,c){return this.sendPacket("message",e,t,c),this}sendPacket(e,t,c,g){if(typeof t=="function"&&(g=t,t=void 0),typeof c=="function"&&(g=c,c=null),this.readyState==="closing"||this.readyState==="closed")return;c=c||{},c.compress=c.compress!==!1;const a={type:e,data:t,options:c};this.emitReserved("packetCreate",a),this.writeBuffer.push(a),g&&this.once("flush",g),this.flush()}close(){const e=()=>{this.onClose("forced close"),r("socket closing - telling transport to close"),this.transport.close()},t=()=>{this.off("upgrade",t),this.off("upgradeError",t),e()},c=()=>{this.once("upgrade",t),this.once("upgradeError",t)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?c():e()}):this.upgrading?c():e()),this}onError(e){r("socket error %j",e),s.priorWebsocketSuccess=!1,this.emitReserved("error",e),this.onClose("transport error",e)}onClose(e,t){(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")&&(r('socket close with reason: "%s"',e),this.clearTimeoutFn(this.pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),typeof removeEventListener=="function"&&(removeEventListener("beforeunload",this.beforeunloadEventListener,!1),removeEventListener("offline",this.offlineEventListener,!1)),this.readyState="closed",this.id=null,this.emitReserved("close",e,t),this.writeBuffer=[],this.prevBufferLen=0)}filterUpgrades(e){const t=[];let c=0;const g=e.length;for(;c<g;c++)~this.transports.indexOf(e[c])&&t.push(e[c]);return t}}return O.Socket=s,s.protocol=f.protocol,O}var ae;function Te(){return ae||(ae=1,function(o){Object.defineProperty(o,"__esModule",{value:!0}),o.nextTick=o.parse=o.installTimerFunctions=o.transports=o.TransportError=o.Transport=o.protocol=o.Socket=void 0;const b=ye();Object.defineProperty(o,"Socket",{enumerable:!0,get:function(){return b.Socket}}),o.protocol=b.Socket.protocol;var d=I();Object.defineProperty(o,"Transport",{enumerable:!0,get:function(){return d.Transport}}),Object.defineProperty(o,"TransportError",{enumerable:!0,get:function(){return d.TransportError}});var m=ue();Object.defineProperty(o,"transports",{enumerable:!0,get:function(){return m.transports}});var u=U();Object.defineProperty(o,"installTimerFunctions",{enumerable:!0,get:function(){return u.installTimerFunctions}});var h=le();Object.defineProperty(o,"parse",{enumerable:!0,get:function(){return h.parse}});var y=X();Object.defineProperty(o,"nextTick",{enumerable:!0,get:function(){return y.nextTick}})}(N)),N}export{Te as r};