Files
socket.io/packages/engine.io-client/dist/engine.io.min.js
2024-07-08 10:59:50 +02:00

8 lines
26 KiB
JavaScript

/*!
* Engine.IO v6.6.0
* (c) 2014-2024 Guillermo Rauch
* Released under the MIT License.
*/
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t="undefined"!=typeof globalThis?globalThis:t||self).eio=n()}(this,(function(){"use strict";function t(n){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(n)}function n(t,n){for(var i=0;i<n.length;i++){var r=n[i];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function i(t,i,r){return i&&n(t.prototype,i),r&&n(t,r),t}function r(){return r=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var i=arguments[n];for(var r in i)Object.prototype.hasOwnProperty.call(i,r)&&(t[r]=i[r])}return t},r.apply(this,arguments)}function e(t,n){t.prototype=Object.create(n.prototype),t.prototype.constructor=t,t.__proto__=n}function o(t){return o=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},o(t)}function s(t,n){return s=Object.setPrototypeOf||function(t,n){return t.__proto__=n,t},s(t,n)}function u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function f(t,n,i){return f=u()?Reflect.construct:function(t,n,i){var r=[null];r.push.apply(r,n);var e=new(Function.bind.apply(t,r));return i&&s(e,i.prototype),e},f.apply(null,arguments)}function h(t){var n="function"==typeof Map?new Map:void 0;return h=function(t){if(null===t||(i=t,-1===Function.toString.call(i).indexOf("[native code]")))return t;var i;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==n){if(n.has(t))return n.get(t);n.set(t,r)}function r(){return f(t,arguments,o(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),s(r,t)},h(t)}function c(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}var a=Object.create(null);a.open="0",a.close="1",a.ping="2",a.pong="3",a.message="4",a.upgrade="5",a.noop="6";var p=Object.create(null);Object.keys(a).forEach((function(t){p[a[t]]=t}));var l,v={type:"error",data:"parser error"},d="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Object.prototype.toString.call(Blob),y="function"==typeof ArrayBuffer,b=function(t){return"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):t&&t.buffer instanceof ArrayBuffer},w=function(t,n,i){var r=t.type,e=t.data;return d&&e instanceof Blob?n?i(e):g(e,i):y&&(e instanceof ArrayBuffer||b(e))?n?i(e):g(new Blob([e]),i):i(a[r]+(e||""))},g=function(t,n){var i=new FileReader;return i.onload=function(){var t=i.result.split(",")[1];n("b"+(t||""))},i.readAsDataURL(t)};function m(t){return t instanceof Uint8Array?t:t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength)}for(var k="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",A="undefined"==typeof Uint8Array?[]:new Uint8Array(256),E=0;E<k.length;E++)A[k.charCodeAt(E)]=E;var j,B="function"==typeof ArrayBuffer,U=function(t,n){if("string"!=typeof t)return{type:"message",data:R(t,n)};var i=t.charAt(0);return"b"===i?{type:"message",data:O(t.substring(1),n)}:p[i]?t.length>1?{type:p[i],data:t.substring(1)}:{type:p[i]}:v},O=function(t,n){if(B){var i=function(t){var n,i,r,e,o,s=.75*t.length,u=t.length,f=0;"="===t[t.length-1]&&(s--,"="===t[t.length-2]&&s--);var h=new ArrayBuffer(s),c=new Uint8Array(h);for(n=0;n<u;n+=4)i=A[t.charCodeAt(n)],r=A[t.charCodeAt(n+1)],e=A[t.charCodeAt(n+2)],o=A[t.charCodeAt(n+3)],c[f++]=i<<2|r>>4,c[f++]=(15&r)<<4|e>>2,c[f++]=(3&e)<<6|63&o;return h}(t);return R(i,n)}return{base64:!0,data:t}},R=function(t,n){return"blob"===n?t instanceof Blob?t:new Blob([t]):t instanceof ArrayBuffer?t:t.buffer},T=String.fromCharCode(30);function x(){return new TransformStream({transform:function(t,n){!function(t,n){d&&t.data instanceof Blob?t.data.arrayBuffer().then(m).then(n):y&&(t.data instanceof ArrayBuffer||b(t.data))?n(m(t.data)):w(t,!1,(function(t){l||(l=new TextEncoder),n(l.encode(t))}))}(t,(function(i){var r,e=i.length;if(e<126)r=new Uint8Array(1),new DataView(r.buffer).setUint8(0,e);else if(e<65536){r=new Uint8Array(3);var o=new DataView(r.buffer);o.setUint8(0,126),o.setUint16(1,e)}else{r=new Uint8Array(9);var s=new DataView(r.buffer);s.setUint8(0,127),s.setBigUint64(1,BigInt(e))}t.data&&"string"!=typeof t.data&&(r[0]|=128),n.enqueue(r),n.enqueue(i)}))}})}function M(t){return t.reduce((function(t,n){return t+n.length}),0)}function S(t,n){if(t[0].length===n)return t.shift();for(var i=new Uint8Array(n),r=0,e=0;e<n;e++)i[e]=t[0][r++],r===t[0].length&&(t.shift(),r=0);return t.length&&r<t[0].length&&(t[0]=t[0].slice(r)),i}function L(t){if(t)return function(t){for(var n in L.prototype)t[n]=L.prototype[n];return t}(t)}L.prototype.on=L.prototype.addEventListener=function(t,n){return this.t=this.t||{},(this.t["$"+t]=this.t["$"+t]||[]).push(n),this},L.prototype.once=function(t,n){function i(){this.off(t,i),n.apply(this,arguments)}return i.fn=n,this.on(t,i),this},L.prototype.off=L.prototype.removeListener=L.prototype.removeAllListeners=L.prototype.removeEventListener=function(t,n){if(this.t=this.t||{},0==arguments.length)return this.t={},this;var i,r=this.t["$"+t];if(!r)return this;if(1==arguments.length)return delete this.t["$"+t],this;for(var e=0;e<r.length;e++)if((i=r[e])===n||i.fn===n){r.splice(e,1);break}return 0===r.length&&delete this.t["$"+t],this},L.prototype.emit=function(t){this.t=this.t||{};for(var n=new Array(arguments.length-1),i=this.t["$"+t],r=1;r<arguments.length;r++)n[r-1]=arguments[r];if(i){r=0;for(var e=(i=i.slice(0)).length;r<e;++r)i[r].apply(this,n)}return this},L.prototype.emitReserved=L.prototype.emit,L.prototype.listeners=function(t){return this.t=this.t||{},this.t["$"+t]||[]},L.prototype.hasListeners=function(t){return!!this.listeners(t).length};var C="function"==typeof Promise&&"function"==typeof Promise.resolve?function(t){return Promise.resolve().then(t)}:function(t,n){return n(t,0)},D="undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")();function P(t){for(var n=arguments.length,i=new Array(n>1?n-1:0),r=1;r<n;r++)i[r-1]=arguments[r];return i.reduce((function(n,i){return t.hasOwnProperty(i)&&(n[i]=t[i]),n}),{})}var I=D.setTimeout,$=D.clearTimeout;function q(t,n){n.useNativeTimers?(t.setTimeoutFn=I.bind(D),t.clearTimeoutFn=$.bind(D)):(t.setTimeoutFn=D.setTimeout.bind(D),t.clearTimeoutFn=D.clearTimeout.bind(D))}function V(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}var X=function(t){function n(n,i,r){var e;return(e=t.call(this,n)||this).description=i,e.context=r,e.type="TransportError",e}return e(n,t),n}(h(Error)),F=function(t){function n(n){var i;return(i=t.call(this)||this).writable=!1,q(c(i),n),i.opts=n,i.query=n.query,i.socket=n.socket,i.supportsBinary=!n.forceBase64,i}e(n,t);var i=n.prototype;return i.onError=function(n,i,r){return t.prototype.emitReserved.call(this,"error",new X(n,i,r)),this},i.open=function(){return this.readyState="opening",this.doOpen(),this},i.close=function(){return"opening"!==this.readyState&&"open"!==this.readyState||(this.doClose(),this.onClose()),this},i.send=function(t){"open"===this.readyState&&this.write(t)},i.onOpen=function(){this.readyState="open",this.writable=!0,t.prototype.emitReserved.call(this,"open")},i.onData=function(t){var n=U(t,this.socket.binaryType);this.onPacket(n)},i.onPacket=function(n){t.prototype.emitReserved.call(this,"packet",n)},i.onClose=function(n){this.readyState="closed",t.prototype.emitReserved.call(this,"close",n)},i.pause=function(t){},i.createUri=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return t+"://"+this.i()+this.o()+this.opts.path+this.u(n)},i.i=function(){var t=this.opts.hostname;return-1===t.indexOf(":")?t:"["+t+"]"},i.o=function(){return this.opts.port&&(this.opts.secure&&Number(443!==this.opts.port)||!this.opts.secure&&80!==Number(this.opts.port))?":"+this.opts.port:""},i.u=function(t){var n=function(t){var n="";for(var i in t)t.hasOwnProperty(i)&&(n.length&&(n+="&"),n+=encodeURIComponent(i)+"="+encodeURIComponent(t[i]));return n}(t);return n.length?"?"+n:""},n}(L),H=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).h=!1,n}e(n,t);var r=n.prototype;return r.doOpen=function(){this.p()},r.pause=function(t){var n=this;this.readyState="pausing";var i=function(){n.readyState="paused",t()};if(this.h||!this.writable){var r=0;this.h&&(r++,this.once("pollComplete",(function(){--r||i()}))),this.writable||(r++,this.once("drain",(function(){--r||i()})))}else i()},r.p=function(){this.h=!0,this.doPoll(),this.emitReserved("poll")},r.onData=function(t){var n=this;(function(t,n){for(var i=t.split(T),r=[],e=0;e<i.length;e++){var o=U(i[e],n);if(r.push(o),"error"===o.type)break}return r})(t,this.socket.binaryType).forEach((function(t){if("opening"===n.readyState&&"open"===t.type&&n.onOpen(),"close"===t.type)return n.onClose({description:"transport closed by the server"}),!1;n.onPacket(t)})),"closed"!==this.readyState&&(this.h=!1,this.emitReserved("pollComplete"),"open"===this.readyState&&this.p())},r.doClose=function(){var t=this,n=function(){t.write([{type:"close"}])};"open"===this.readyState?n():this.once("open",n)},r.write=function(t){var n=this;this.writable=!1,function(t,n){var i=t.length,r=new Array(i),e=0;t.forEach((function(t,o){w(t,!1,(function(t){r[o]=t,++e===i&&n(r.join(T))}))}))}(t,(function(t){n.doWrite(t,(function(){n.writable=!0,n.emitReserved("drain")}))}))},r.uri=function(){var t=this.opts.secure?"https":"http",n=this.query||{};return!1!==this.opts.timestampRequests&&(n[this.opts.timestampParam]=V()),this.supportsBinary||n.sid||(n.b64=1),this.createUri(t,n)},i(n,[{key:"name",get:function(){return"polling"}}]),n}(F),N=!1;try{N="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(t){}var z=N;function G(){}var J=function(t){function n(n){var i;if(i=t.call(this,n)||this,"undefined"!=typeof location){var r="https:"===location.protocol,e=location.port;e||(e=r?"443":"80"),i.xd="undefined"!=typeof location&&n.hostname!==location.hostname||e!==n.port}return i}e(n,t);var i=n.prototype;return i.doWrite=function(t,n){var i=this,r=this.request({method:"POST",data:t});r.on("success",n),r.on("error",(function(t,n){i.onError("xhr post error",t,n)}))},i.doPoll=function(){var t=this,n=this.request();n.on("data",this.onData.bind(this)),n.on("error",(function(n,i){t.onError("xhr poll error",n,i)})),this.pollXhr=n},n}(H),W=function(t){function n(n,i,r){var e;return(e=t.call(this)||this).createRequest=n,q(c(e),r),e.l=r,e.v=r.method||"GET",e.g=i,e.m=void 0!==r.data?r.data:null,e.k(),e}e(n,t);var i=n.prototype;return i.k=function(){var t,i=this,r=P(this.l,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");r.xdomain=!!this.l.xd;var e=this.A=this.createRequest(r);try{e.open(this.v,this.g,!0);try{if(this.l.extraHeaders)for(var o in e.setDisableHeaderCheck&&e.setDisableHeaderCheck(!0),this.l.extraHeaders)this.l.extraHeaders.hasOwnProperty(o)&&e.setRequestHeader(o,this.l.extraHeaders[o])}catch(t){}if("POST"===this.v)try{e.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(t){}try{e.setRequestHeader("Accept","*/*")}catch(t){}null===(t=this.l.cookieJar)||void 0===t||t.addCookies(e),"withCredentials"in e&&(e.withCredentials=this.l.withCredentials),this.l.requestTimeout&&(e.timeout=this.l.requestTimeout),e.onreadystatechange=function(){var t;3===e.readyState&&(null===(t=i.l.cookieJar)||void 0===t||t.parseCookies(e.getResponseHeader("set-cookie"))),4===e.readyState&&(200===e.status||1223===e.status?i.j():i.setTimeoutFn((function(){i.B("number"==typeof e.status?e.status:0)}),0))},e.send(this.m)}catch(t){return void this.setTimeoutFn((function(){i.B(t)}),0)}"undefined"!=typeof document&&(this.U=n.requestsCount++,n.requests[this.U]=this)},i.B=function(t){this.emitReserved("error",t,this.A),this.O(!0)},i.O=function(t){if(void 0!==this.A&&null!==this.A){if(this.A.onreadystatechange=G,t)try{this.A.abort()}catch(t){}"undefined"!=typeof document&&delete n.requests[this.U],this.A=null}},i.j=function(){var t=this.A.responseText;null!==t&&(this.emitReserved("data",t),this.emitReserved("success"),this.O())},i.abort=function(){this.O()},n}(L);if(W.requestsCount=0,W.requests={},"undefined"!=typeof document)if("function"==typeof attachEvent)attachEvent("onunload",K);else if("function"==typeof addEventListener){addEventListener("onpagehide"in D?"pagehide":"unload",K,!1)}function K(){for(var t in W.requests)W.requests.hasOwnProperty(t)&&W.requests[t].abort()}var Q,Y=(Q=_({xdomain:!1}))&&null!==Q.responseType,Z=function(t){function n(n){var i;i=t.call(this,n)||this;var r=n&&n.forceBase64;return i.supportsBinary=Y&&!r,i}return e(n,t),n.prototype.request=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return r(t,{xd:this.xd},this.opts),new W(_,this.uri(),t)},n}(J);function _(t){var n=t.xdomain;try{if("undefined"!=typeof XMLHttpRequest&&(!n||z))return new XMLHttpRequest}catch(t){}if(!n)try{return new(D[["Active"].concat("Object").join("X")])("Microsoft.XMLHTTP")}catch(t){}}var tt="undefined"!=typeof navigator&&"string"==typeof navigator.product&&"reactnative"===navigator.product.toLowerCase(),nt=function(t){function n(){return t.apply(this,arguments)||this}e(n,t);var r=n.prototype;return r.doOpen=function(){var t=this.uri(),n=this.opts.protocols,i=tt?{}:P(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(i.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(t,n,i)}catch(t){return this.emitReserved("error",t)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()},r.addEventListeners=function(){var t=this;this.ws.onopen=function(){t.opts.autoUnref&&t.ws.R.unref(),t.onOpen()},this.ws.onclose=function(n){return t.onClose({description:"websocket connection closed",context:n})},this.ws.onmessage=function(n){return t.onData(n.data)},this.ws.onerror=function(n){return t.onError("websocket error",n)}},r.write=function(t){var n=this;this.writable=!1;for(var i=function(i){var r=t[i],e=i===t.length-1;w(r,n.supportsBinary,(function(t){try{n.doWrite(r,t)}catch(t){}e&&C((function(){n.writable=!0,n.emitReserved("drain")}),n.setTimeoutFn)}))},r=0;r<t.length;r++)i(r)},r.doClose=function(){void 0!==this.ws&&(this.ws.close(),this.ws=null)},r.uri=function(){var t=this.opts.secure?"wss":"ws",n=this.query||{};return this.opts.timestampRequests&&(n[this.opts.timestampParam]=V()),this.supportsBinary||(n.b64=1),this.createUri(t,n)},i(n,[{key:"name",get:function(){return"websocket"}}]),n}(F),it=D.WebSocket||D.MozWebSocket,rt=function(t){function n(){return t.apply(this,arguments)||this}e(n,t);var i=n.prototype;return i.createSocket=function(t,n,i){return tt?new it(t,n,i):n?new it(t,n):new it(t)},i.doWrite=function(t,n){this.ws.send(n)},n}(nt),et=function(t){function n(){return t.apply(this,arguments)||this}e(n,t);var r=n.prototype;return r.doOpen=function(){var t=this;try{this.T=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(t){return this.emitReserved("error",t)}this.T.closed.then((function(){t.onClose()})).catch((function(n){t.onError("webtransport error",n)})),this.T.ready.then((function(){t.T.createBidirectionalStream().then((function(n){var i=function(t,n){j||(j=new TextDecoder);var i=[],r=0,e=-1,o=!1;return new TransformStream({transform:function(s,u){for(i.push(s);;){if(0===r){if(M(i)<1)break;var f=S(i,1);o=128==(128&f[0]),e=127&f[0],r=e<126?3:126===e?1:2}else if(1===r){if(M(i)<2)break;var h=S(i,2);e=new DataView(h.buffer,h.byteOffset,h.length).getUint16(0),r=3}else if(2===r){if(M(i)<8)break;var c=S(i,8),a=new DataView(c.buffer,c.byteOffset,c.length),p=a.getUint32(0);if(p>Math.pow(2,21)-1){u.enqueue(v);break}e=p*Math.pow(2,32)+a.getUint32(4),r=3}else{if(M(i)<e)break;var l=S(i,e);u.enqueue(U(o?l:j.decode(l),n)),r=0}if(0===e||e>t){u.enqueue(v);break}}}})}(Number.MAX_SAFE_INTEGER,t.socket.binaryType),r=n.readable.pipeThrough(i).getReader(),e=x();e.readable.pipeTo(n.writable),t.M=e.writable.getWriter();!function n(){r.read().then((function(i){var r=i.done,e=i.value;r||(t.onPacket(e),n())})).catch((function(t){}))}();var o={type:"open"};t.query.sid&&(o.data='{"sid":"'.concat(t.query.sid,'"}')),t.M.write(o).then((function(){return t.onOpen()}))}))}))},r.write=function(t){var n=this;this.writable=!1;for(var i=function(i){var r=t[i],e=i===t.length-1;n.M.write(r).then((function(){e&&C((function(){n.writable=!0,n.emitReserved("drain")}),n.setTimeoutFn)}))},r=0;r<t.length;r++)i(r)},r.doClose=function(){var t;null===(t=this.T)||void 0===t||t.close()},i(n,[{key:"name",get:function(){return"webtransport"}}]),n}(F),ot={websocket:rt,webtransport:et,polling:Z},st=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,ut=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function ft(t){if(t.length>8e3)throw"URI too long";var n=t,i=t.indexOf("["),r=t.indexOf("]");-1!=i&&-1!=r&&(t=t.substring(0,i)+t.substring(i,r).replace(/:/g,";")+t.substring(r,t.length));for(var e,o,s=st.exec(t||""),u={},f=14;f--;)u[ut[f]]=s[f]||"";return-1!=i&&-1!=r&&(u.source=n,u.host=u.host.substring(1,u.host.length-1).replace(/;/g,":"),u.authority=u.authority.replace("[","").replace("]","").replace(/;/g,":"),u.ipv6uri=!0),u.pathNames=function(t,n){var i=/\/{2,9}/g,r=n.replace(i,"/").split("/");"/"!=n.slice(0,1)&&0!==n.length||r.splice(0,1);"/"==n.slice(-1)&&r.splice(r.length-1,1);return r}(0,u.path),u.queryKey=(e=u.query,o={},e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,(function(t,n,i){n&&(o[n]=i)})),o),u}var ht=function(n){function i(i,e){var o;if((o=n.call(this)||this).binaryType="arraybuffer",o.writeBuffer=[],o.S=0,o.L=-1,o.C=-1,o.D=-1,i&&"object"===t(i)&&(e=i,i=null),i){var s=ft(i);e.hostname=s.host,e.secure="https"===s.protocol||"wss"===s.protocol,e.port=s.port,s.query&&(e.query=s.query)}else e.host&&(e.hostname=ft(e.host).host);return q(c(o),e),o.secure=null!=e.secure?e.secure:"undefined"!=typeof location&&"https:"===location.protocol,e.hostname&&!e.port&&(e.port=o.secure?"443":"80"),o.hostname=e.hostname||("undefined"!=typeof location?location.hostname:"localhost"),o.port=e.port||("undefined"!=typeof location&&location.port?location.port:o.secure?"443":"80"),o.transports=[],o.P={},e.transports.forEach((function(t){var n=t.prototype.name;o.transports.push(n),o.P[n]=t})),o.opts=r({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},e),o.opts.path=o.opts.path.replace(/\/$/,"")+(o.opts.addTrailingSlash?"/":""),"string"==typeof o.opts.query&&(o.opts.query=function(t){for(var n={},i=t.split("&"),r=0,e=i.length;r<e;r++){var o=i[r].split("=");n[decodeURIComponent(o[0])]=decodeURIComponent(o[1])}return n}(o.opts.query)),"function"==typeof addEventListener&&(o.opts.closeOnBeforeunload&&(o.I=function(){o.transport&&(o.transport.removeAllListeners(),o.transport.close())},addEventListener("beforeunload",o.I,!1)),"localhost"!==o.hostname&&(o.$=function(){o.q("transport close",{description:"network connection lost"})},addEventListener("offline",o.$,!1))),o.opts.withCredentials&&(o.V=void 0),o.X(),o}e(i,n);var o=i.prototype;return o.createTransport=function(t){var n=r({},this.opts.query);n.EIO=4,n.transport=t,this.id&&(n.sid=this.id);var i=r({},this.opts,{query:n,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[t]);return new this.P[t](i)},o.X=function(){var t=this;if(0!==this.transports.length){var n=this.opts.rememberUpgrade&&i.priorWebsocketSuccess&&-1!==this.transports.indexOf("websocket")?"websocket":this.transports[0];this.readyState="opening";var r=this.createTransport(n);r.open(),this.setTransport(r)}else this.setTimeoutFn((function(){t.emitReserved("error","No transports available")}),0)},o.setTransport=function(t){var n=this;this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",this.F.bind(this)).on("packet",this.H.bind(this)).on("error",this.B.bind(this)).on("close",(function(t){return n.q("transport close",t)}))},o.onOpen=function(){this.readyState="open",i.priorWebsocketSuccess="websocket"===this.transport.name,this.emitReserved("open"),this.flush()},o.H=function(t){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState)switch(this.emitReserved("packet",t),this.emitReserved("heartbeat"),this.N(),t.type){case"open":this.onHandshake(JSON.parse(t.data));break;case"ping":this.G("pong"),this.emitReserved("ping"),this.emitReserved("pong");break;case"error":var n=new Error("server error");n.code=t.data,this.B(n);break;case"message":this.emitReserved("data",t.data),this.emitReserved("message",t.data)}},o.onHandshake=function(t){this.emitReserved("handshake",t),this.id=t.sid,this.transport.query.sid=t.sid,this.L=t.pingInterval,this.C=t.pingTimeout,this.D=t.maxPayload,this.onOpen(),"closed"!==this.readyState&&this.N()},o.N=function(){var t=this;this.clearTimeoutFn(this.J),this.J=this.setTimeoutFn((function(){t.q("ping timeout")}),this.L+this.C),this.opts.autoUnref&&this.J.unref()},o.F=function(){this.writeBuffer.splice(0,this.S),this.S=0,0===this.writeBuffer.length?this.emitReserved("drain"):this.flush()},o.flush=function(){if("closed"!==this.readyState&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){var t=this.W();this.transport.send(t),this.S=t.length,this.emitReserved("flush")}},o.W=function(){if(!(this.D&&"polling"===this.transport.name&&this.writeBuffer.length>1))return this.writeBuffer;for(var t,n=1,i=0;i<this.writeBuffer.length;i++){var r=this.writeBuffer[i].data;if(r&&(n+="string"==typeof(t=r)?function(t){for(var n=0,i=0,r=0,e=t.length;r<e;r++)(n=t.charCodeAt(r))<128?i+=1:n<2048?i+=2:n<55296||n>=57344?i+=3:(r++,i+=4);return i}(t):Math.ceil(1.33*(t.byteLength||t.size))),i>0&&n>this.D)return this.writeBuffer.slice(0,i);n+=2}return this.writeBuffer},o.write=function(t,n,i){return this.G("message",t,n,i),this},o.send=function(t,n,i){return this.G("message",t,n,i),this},o.G=function(t,n,i,r){if("function"==typeof n&&(r=n,n=void 0),"function"==typeof i&&(r=i,i=null),"closing"!==this.readyState&&"closed"!==this.readyState){(i=i||{}).compress=!1!==i.compress;var e={type:t,data:n,options:i};this.emitReserved("packetCreate",e),this.writeBuffer.push(e),r&&this.once("flush",r),this.flush()}},o.close=function(){var t=this,n=function(){t.q("forced close"),t.transport.close()},i=function i(){t.off("upgrade",i),t.off("upgradeError",i),n()},r=function(){t.once("upgrade",i),t.once("upgradeError",i)};return"opening"!==this.readyState&&"open"!==this.readyState||(this.readyState="closing",this.writeBuffer.length?this.once("drain",(function(){t.upgrading?r():n()})):this.upgrading?r():n()),this},o.B=function(t){if(i.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&"opening"===this.readyState)return this.transports.shift(),this.X();this.emitReserved("error",t),this.q("transport error",t)},o.q=function(t,n){"opening"!==this.readyState&&"open"!==this.readyState&&"closing"!==this.readyState||(this.clearTimeoutFn(this.J),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),"function"==typeof removeEventListener&&(removeEventListener("beforeunload",this.I,!1),removeEventListener("offline",this.$,!1)),this.readyState="closed",this.id=null,this.emitReserved("close",t,n),this.writeBuffer=[],this.S=0)},i}(L);ht.protocol=4;var ct=function(t){function n(){var n;return(n=t.apply(this,arguments)||this).K=[],n}e(n,t);var i=n.prototype;return i.onOpen=function(){if(t.prototype.onOpen.call(this),"open"===this.readyState&&this.opts.upgrade)for(var n=0;n<this.K.length;n++)this.Y(this.K[n])},i.Y=function(t){var n=this,i=this.createTransport(t),r=!1;ht.priorWebsocketSuccess=!1;var e=function(){r||(i.send([{type:"ping",data:"probe"}]),i.once("packet",(function(t){if(!r)if("pong"===t.type&&"probe"===t.data){if(n.upgrading=!0,n.emitReserved("upgrading",i),!i)return;ht.priorWebsocketSuccess="websocket"===i.name,n.transport.pause((function(){r||"closed"!==n.readyState&&(c(),n.setTransport(i),i.send([{type:"upgrade"}]),n.emitReserved("upgrade",i),i=null,n.upgrading=!1,n.flush())}))}else{var e=new Error("probe error");e.transport=i.name,n.emitReserved("upgradeError",e)}})))};function o(){r||(r=!0,c(),i.close(),i=null)}var s=function(t){var r=new Error("probe error: "+t);r.transport=i.name,o(),n.emitReserved("upgradeError",r)};function u(){s("transport closed")}function f(){s("socket closed")}function h(t){i&&t.name!==i.name&&o()}var c=function(){i.removeListener("open",e),i.removeListener("error",s),i.removeListener("close",u),n.off("close",f),n.off("upgrading",h)};i.once("open",e),i.once("error",s),i.once("close",u),this.once("close",f),this.once("upgrading",h),-1!==this.K.indexOf("webtransport")&&"webtransport"!==t?this.setTimeoutFn((function(){r||i.open()}),200):i.open()},i.onHandshake=function(n){this.K=this.Z(n.upgrades),t.prototype.onHandshake.call(this,n)},i.Z=function(t){for(var n=[],i=0;i<t.length;i++)~this.transports.indexOf(t[i])&&n.push(t[i]);return n},n}(ht),at=function(n){function i(i){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},e="object"===t(i)?i:r;return(!e.transports||e.transports&&"string"==typeof e.transports[0])&&(e.transports=(e.transports||["polling","websocket","webtransport"]).map((function(t){return ot[t]})).filter((function(t){return!!t}))),n.call(this,i,e)||this}return e(i,n),i}(ct);return function(t,n){return new at(t,n)}}));
//# sourceMappingURL=engine.io.min.js.map