-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathsocketcluster-client.min.js
21 lines (21 loc) · 91.2 KB
/
socketcluster-client.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function t(t,e){return e.forEach((function(e){e&&"string"!=typeof e&&!Array.isArray(e)&&Object.keys(e).forEach((function(r){if("default"!==r&&!(r in t)){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}))})),Object.freeze(t)}function e(t){if(t.__esModule)return t;var e=t.default;if("function"==typeof e){var r=function t(){return this instanceof t?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};r.prototype=e.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(t).forEach((function(e){var n=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(r,e,n.get?n:{enumerable:!0,get:function(){return t[e]}})})),r}var r={};var n=class{async next(t){let e=this.createConsumer(t),r=await e.next();return e.return(),r}async once(t){let e=await this.next(t);if(e.done){if(null!=t){let t=new Error("Stream consumer operation timed out early because stream ended");throw t.name="TimeoutError",t}await new Promise((()=>{}))}return e.value}createConsumer(){throw new TypeError("Method must be overriden by subclass")}[Symbol.asyncIterator](){return this.createConsumer()}};let o=class{constructor(t,e,r,n){this.id=e,this._backpressure=0,this.currentNode=r,this.timeout=n,this.isAlive=!0,this.stream=t,this.stream.setConsumer(this.id,this)}getStats(){let t={id:this.id,backpressure:this._backpressure};return null!=this.timeout&&(t.timeout=this.timeout),t}_resetBackpressure(){this._backpressure=0}applyBackpressure(t){this._backpressure++}releaseBackpressure(t){this._backpressure--}getBackpressure(){return this._backpressure}clearActiveTimeout(){clearTimeout(this._timeoutId),delete this._timeoutId}write(t){void 0!==this._timeoutId&&this.clearActiveTimeout(t),this.applyBackpressure(t),this._resolve&&(this._resolve(),delete this._resolve)}kill(t){this._killPacket={value:t,done:!0},void 0!==this._timeoutId&&this.clearActiveTimeout(this._killPacket),this._destroy(),this._resolve&&(this._resolve(),delete this._resolve)}_destroy(){this.isAlive=!1,this._resetBackpressure(),this.stream.removeConsumer(this.id)}async _waitForNextItem(t){return new Promise(((e,r)=>{let n;if(this._resolve=e,void 0!==t){let e=new Error("Stream consumer iteration timed out");(async()=>{let o=function(t){let e,r=new Promise((r=>{e=setTimeout(r,t)}));return{timeoutId:e,promise:r}}(t);n=o.timeoutId,await o.promise,e.name="TimeoutError",delete this._resolve,r(e)})()}this._timeoutId=n}))}async next(){for(this.stream.setConsumer(this.id,this);;){if(!this.currentNode.next)try{await this._waitForNextItem(this.timeout)}catch(t){throw this._destroy(),t}if(this._killPacket){this._destroy();let t=this._killPacket;return delete this._killPacket,t}if(this.currentNode=this.currentNode.next,this.releaseBackpressure(this.currentNode.data),!this.currentNode.consumerId||this.currentNode.consumerId===this.id)return this.currentNode.data.done&&this._destroy(),this.currentNode.data}}return(){return delete this.currentNode,this._destroy(),{}}[Symbol.asyncIterator](){return this}};const i=n,s=o;var a=class extends i{constructor(t){super(),t=t||{},this._nextConsumerId=1,this.generateConsumerId=t.generateConsumerId,this.generateConsumerId||(this.generateConsumerId=()=>this._nextConsumerId++),this.removeConsumerCallback=t.removeConsumerCallback,this._consumers=new Map,this.tailNode={next:null,data:{value:void 0,done:!1}}}_write(t,e,r){let n={data:{value:t,done:e},next:null};r&&(n.consumerId=r),this.tailNode.next=n,this.tailNode=n;for(let t of this._consumers.values())t.write(n.data)}write(t){this._write(t,!1)}close(t){this._write(t,!0)}writeToConsumer(t,e){this._write(e,!1,t)}closeConsumer(t,e){this._write(e,!0,t)}kill(t){for(let e of this._consumers.keys())this.killConsumer(e,t)}killConsumer(t,e){let r=this._consumers.get(t);r&&r.kill(e)}getBackpressure(){let t=0;for(let e of this._consumers.values()){let r=e.getBackpressure();r>t&&(t=r)}return t}getConsumerBackpressure(t){let e=this._consumers.get(t);return e?e.getBackpressure():0}hasConsumer(t){return this._consumers.has(t)}setConsumer(t,e){this._consumers.set(t,e),e.currentNode||(e.currentNode=this.tailNode)}removeConsumer(t){let e=this._consumers.delete(t);return this.removeConsumerCallback&&this.removeConsumerCallback(t),e}getConsumerStats(t){let e=this._consumers.get(t);if(e)return e.getStats()}getConsumerStatsList(){let t=[];for(let e of this._consumers.values())t.push(e.getStats());return t}createConsumer(t){return new s(this,this.generateConsumerId(),this.tailNode,t)}getConsumerList(){return[...this._consumers.values()]}getConsumerCount(){return this._consumers.size}};const u=class{async next(t){let e=this.createConsumer(t),r=await e.next();return e.return(),r}async once(t){let e=await this.next(t);if(e.done){if(null!=t){let t=new Error("Stream consumer operation timed out early because stream ended");throw t.name="TimeoutError",t}await new Promise((()=>{}))}return e.value}createConsumer(){throw new TypeError("Method must be overriden by subclass")}[Symbol.asyncIterator](){return this.createConsumer()}};var c=class extends u{constructor(t,e){super(),this._streamDemux=t,this.name=e}createConsumer(t){return this._streamDemux.createConsumer(this.name,t)}};const h=a,l=c;var p=class{constructor(){this.streams={},this._nextConsumerId=1,this.generateConsumerId=()=>this._nextConsumerId++}write(t,e){this.streams[t]&&this.streams[t].write(e)}close(t,e){this.streams[t]&&this.streams[t].close(e)}closeAll(t){for(let e of Object.values(this.streams))e.close(t)}writeToConsumer(t,e){for(let r of Object.values(this.streams))if(r.hasConsumer(t))return r.writeToConsumer(t,e)}closeConsumer(t,e){for(let r of Object.values(this.streams))if(r.hasConsumer(t))return r.closeConsumer(t,e)}getConsumerStats(t){for(let[e,r]of Object.entries(this.streams))if(r.hasConsumer(t))return{...r.getConsumerStats(t),stream:e}}getConsumerStatsList(t){return this.streams[t]?this.streams[t].getConsumerStatsList().map((e=>({...e,stream:t}))):[]}getConsumerStatsListAll(){let t=[];for(let e of Object.keys(this.streams)){let r=this.getConsumerStatsList(e);for(let e of r)t.push(e)}return t}kill(t,e){this.streams[t]&&this.streams[t].kill(e)}killAll(t){for(let e of Object.values(this.streams))e.kill(t)}killConsumer(t,e){for(let r of Object.values(this.streams))if(r.hasConsumer(t))return r.killConsumer(t,e)}getBackpressure(t){return this.streams[t]?this.streams[t].getBackpressure():0}getBackpressureAll(){return Object.values(this.streams).reduce(((t,e)=>Math.max(t,e.getBackpressure())),0)}getConsumerBackpressure(t){for(let e of Object.values(this.streams))if(e.hasConsumer(t))return e.getConsumerBackpressure(t);return 0}hasConsumer(t,e){return!!this.streams[t]&&this.streams[t].hasConsumer(e)}hasConsumerAll(t){return Object.values(this.streams).some((e=>e.hasConsumer(t)))}getConsumerCount(t){return this.streams[t]?this.streams[t].getConsumerCount():0}getConsumerCountAll(){return Object.values(this.streams).reduce(((t,e)=>t+e.getConsumerCount()),0)}createConsumer(t,e){return this.streams[t]||(this.streams[t]=new h({generateConsumerId:this.generateConsumerId,removeConsumerCallback:()=>{this.getConsumerCount(t)||delete this.streams[t]}})),this.streams[t].createConsumer(e)}stream(t){return new l(this,t)}unstream(t){delete this.streams[t]}};const f=p;function m(t){this._listenerDemux=new f}m.prototype.emit=function(t,e){this._listenerDemux.write(t,e)},m.prototype.listener=function(t){return this._listenerDemux.stream(t)},m.prototype.closeListener=function(t){this._listenerDemux.close(t)},m.prototype.closeAllListeners=function(){this._listenerDemux.closeAll()},m.prototype.removeListener=function(t){this._listenerDemux.unstream(t)},m.prototype.getListenerConsumerStats=function(t){return this._listenerDemux.getConsumerStats(t)},m.prototype.getListenerConsumerStatsList=function(t){return this._listenerDemux.getConsumerStatsList(t)},m.prototype.getAllListenersConsumerStatsList=function(){return this._listenerDemux.getConsumerStatsListAll()},m.prototype.getListenerConsumerCount=function(t){return this._listenerDemux.getConsumerCount(t)},m.prototype.getAllListenersConsumerCount=function(){return this._listenerDemux.getConsumerCountAll()},m.prototype.killListener=function(t){this._listenerDemux.kill(t)},m.prototype.killAllListeners=function(){this._listenerDemux.killAll()},m.prototype.killListenerConsumer=function(t){this._listenerDemux.killConsumer(t)},m.prototype.getListenerBackpressure=function(t){return this._listenerDemux.getBackpressure(t)},m.prototype.getAllListenersBackpressure=function(){return this._listenerDemux.getBackpressureAll()},m.prototype.getListenerConsumerBackpressure=function(t){return this._listenerDemux.getConsumerBackpressure(t)},m.prototype.hasListenerConsumer=function(t,e){return this._listenerDemux.hasConsumer(t,e)},m.prototype.hasAnyListenerConsumer=function(t){return this._listenerDemux.hasConsumerAll(t)};var d=m;const y=class{async next(t){let e=this.createConsumer(t),r=await e.next();return e.return(),r}async once(t){let e=await this.next(t);return e.done&&await new Promise((()=>{})),e.value}createConsumer(){throw new TypeError("Method must be overriden by subclass")}[Symbol.asyncIterator](){return this.createConsumer()}};let g=class t extends y{constructor(e,r,n,o){super(),this.PENDING=t.PENDING,this.SUBSCRIBED=t.SUBSCRIBED,this.UNSUBSCRIBED=t.UNSUBSCRIBED,this.name=e,this.client=r,this._eventDemux=n,this._dataStream=o.stream(this.name)}createConsumer(t){return this._dataStream.createConsumer(t)}listener(t){return this._eventDemux.stream(`${this.name}/${t}`)}close(){this.client.closeChannel(this.name)}kill(){this.client.killChannel(this.name)}killOutputConsumer(t){this.hasOutputConsumer(t)&&this.client.killChannelOutputConsumer(t)}killListenerConsumer(t){this.hasAnyListenerConsumer(t)&&this.client.killChannelListenerConsumer(t)}getOutputConsumerStats(t){if(this.hasOutputConsumer(t))return this.client.getChannelOutputConsumerStats(t)}getListenerConsumerStats(t){if(this.hasAnyListenerConsumer(t))return this.client.getChannelListenerConsumerStats(t)}getBackpressure(){return this.client.getChannelBackpressure(this.name)}getListenerConsumerBackpressure(t){return this.hasAnyListenerConsumer(t)?this.client.getChannelListenerConsumerBackpressure(t):0}getOutputConsumerBackpressure(t){return this.hasOutputConsumer(t)?this.client.getChannelOutputConsumerBackpressure(t):0}closeOutput(){this.client.channelCloseOutput(this.name)}closeListener(t){this.client.channelCloseListener(this.name,t)}closeAllListeners(){this.client.channelCloseAllListeners(this.name)}killOutput(){this.client.channelKillOutput(this.name)}killListener(t){this.client.channelKillListener(this.name,t)}killAllListeners(){this.client.channelKillAllListeners(this.name)}getOutputConsumerStatsList(){return this.client.channelGetOutputConsumerStatsList(this.name)}getListenerConsumerStatsList(t){return this.client.channelGetListenerConsumerStatsList(this.name,t)}getAllListenersConsumerStatsList(){return this.client.channelGetAllListenersConsumerStatsList(this.name)}getOutputBackpressure(){return this.client.channelGetOutputBackpressure(this.name)}getListenerBackpressure(t){return this.client.channelGetListenerBackpressure(this.name,t)}getAllListenersBackpressure(){return this.client.channelGetAllListenersBackpressure(this.name)}hasOutputConsumer(t){return this.client.channelHasOutputConsumer(this.name,t)}hasListenerConsumer(t,e){return this.client.channelHasListenerConsumer(this.name,t,e)}hasAnyListenerConsumer(t){return this.client.channelHasAnyListenerConsumer(this.name,t)}get state(){return this.client.getChannelState(this.name)}set state(t){throw new Error("Cannot directly set channel state")}get options(){return this.client.getChannelOptions(this.name)}set options(t){throw new Error("Cannot directly set channel options")}subscribe(t){this.client.subscribe(this.name,t)}unsubscribe(){this.client.unsubscribe(this.name)}isSubscribed(t){return this.client.isSubscribed(this.name,t)}transmitPublish(t){return this.client.transmitPublish(this.name,t)}invokePublish(t){return this.client.invokePublish(this.name,t)}};g.PENDING="pending",g.SUBSCRIBED="subscribed",g.UNSUBSCRIBED="unsubscribed";var b=g;function v(){this._internalStorage={},this.isLocalStorageEnabled=this._checkLocalStorageEnabled()}v.prototype._checkLocalStorageEnabled=function(){let t;try{localStorage.setItem("__scLocalStorageTest",1),localStorage.removeItem("__scLocalStorageTest")}catch(e){t=e}return!t},v.prototype.saveToken=function(t,e,r){return this.isLocalStorageEnabled?localStorage.setItem(t,e):this._internalStorage[t]=e,Promise.resolve(e)},v.prototype.removeToken=function(t){let e=this.loadToken(t);return this.isLocalStorageEnabled?localStorage.removeItem(t):delete this._internalStorage[t],e},v.prototype.loadToken=function(t){let e;return e=this.isLocalStorageEnabled?localStorage.getItem(t):this._internalStorage[t]||null,Promise.resolve(e)};var k=v,E={};const C="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",_=/^[ \n\r\t]*[{\[]/;let w=function(t){let e=new Uint8Array(t),r=e.length,n="";for(let t=0;t<r;t+=3)n+=C[e[t]>>2],n+=C[(3&e[t])<<4|e[t+1]>>4],n+=C[(15&e[t+1])<<2|e[t+2]>>6],n+=C[63&e[t+2]];return r%3==2?n=n.substring(0,n.length-1)+"=":r%3==1&&(n=n.substring(0,n.length-2)+"=="),n},S=function(t,e){if("undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer)return{base64:!0,data:w(e)};if("undefined"!=typeof Buffer){if(e instanceof Buffer)return{base64:!0,data:e.toString("base64")};if(e&&"Buffer"===e.type&&Array.isArray(e.data)){let t;return t=Buffer.from?Buffer.from(e.data):new Buffer(e.data),{base64:!0,data:t.toString("base64")}}}return e};E.decode=function(t){if(null==t)return null;if("#1"===t||"#2"===t)return t;let e=t.toString();if(!_.test(e))return e;try{return JSON.parse(e)}catch(t){}return e},E.encode=function(t){return"#1"===t||"#2"===t?t:JSON.stringify(t,S)};var A={exports:{}};const T=function(t){var e=[],r=[];return function t(n,o){var i,s,a;if(!("object"!=typeof n||null===n||n instanceof Boolean||n instanceof Date||n instanceof Number||n instanceof RegExp||n instanceof String)){for(i=0;i<e.length;i+=1)if(e[i]===n)return{$ref:r[i]};if(e.push(n),r.push(o),"[object Array]"===Object.prototype.toString.apply(n))for(a=[],i=0;i<n.length;i+=1)a[i]=t(n[i],o+"["+i+"]");else for(s in a={},n)Object.prototype.hasOwnProperty.call(n,s)&&(a[s]=t(n[s],o+"["+JSON.stringify(s)+"]"));return a}return n}(t,"$")},B=function(){return!this}();function O(t,e){this.name="AuthTokenExpiredError",this.message=t,this.expiry=e,Error.captureStackTrace&&!B?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function I(t){this.name="AuthTokenInvalidError",this.message=t,Error.captureStackTrace&&!B?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function D(t,e){this.name="AuthTokenNotBeforeError",this.message=t,this.date=e,Error.captureStackTrace&&!B?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function x(t){this.name="AuthTokenError",this.message=t,Error.captureStackTrace&&!B?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function L(t){this.name="AuthError",this.message=t,Error.captureStackTrace&&!B?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function N(t,e){this.name="SilentMiddlewareBlockedError",this.message=t,this.type=e,Error.captureStackTrace&&!B?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function P(t){this.name="InvalidActionError",this.message=t,Error.captureStackTrace&&!B?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function U(t){this.name="InvalidArgumentsError",this.message=t,Error.captureStackTrace&&!B?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function R(t){this.name="InvalidOptionsError",this.message=t,Error.captureStackTrace&&!B?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function j(t){this.name="InvalidMessageError",this.message=t,Error.captureStackTrace&&!B?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function M(t,e){this.name="SocketProtocolError",this.message=t,this.code=e,Error.captureStackTrace&&!B?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function H(t){this.name="ServerProtocolError",this.message=t,Error.captureStackTrace&&!B?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function G(t){this.name="HTTPServerError",this.message=t,Error.captureStackTrace&&!B?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function $(t){this.name="ResourceLimitError",this.message=t,Error.captureStackTrace&&!B?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function F(t){this.name="TimeoutError",this.message=t,Error.captureStackTrace&&!B?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function z(t,e,r,n){this.name="BadConnectionError",this.message=t,this.type=e,this.code=r||1001,this.reason=n||Y[this.code]||"",Error.captureStackTrace&&!B?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function q(t){this.name="BrokerError",this.message=t,Error.captureStackTrace&&!B?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function V(t,e){this.name="ProcessExitError",this.message=t,this.code=e,Error.captureStackTrace&&!B?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}function W(t){this.name="UnknownError",this.message=t,Error.captureStackTrace&&!B?Error.captureStackTrace(this,arguments.callee):this.stack=(new Error).stack}O.prototype=Object.create(Error.prototype),I.prototype=Object.create(Error.prototype),D.prototype=Object.create(Error.prototype),x.prototype=Object.create(Error.prototype),L.prototype=Object.create(Error.prototype),N.prototype=Object.create(Error.prototype),P.prototype=Object.create(Error.prototype),U.prototype=Object.create(Error.prototype),R.prototype=Object.create(Error.prototype),j.prototype=Object.create(Error.prototype),M.prototype=Object.create(Error.prototype),H.prototype=Object.create(Error.prototype),G.prototype=Object.create(Error.prototype),$.prototype=Object.create(Error.prototype),F.prototype=Object.create(Error.prototype),z.prototype=Object.create(Error.prototype),q.prototype=Object.create(Error.prototype),V.prototype=Object.create(Error.prototype),W.prototype=Object.create(Error.prototype),A.exports={AuthTokenExpiredError:O,AuthTokenInvalidError:I,AuthTokenNotBeforeError:D,AuthTokenError:x,AuthError:L,SilentMiddlewareBlockedError:N,InvalidActionError:P,InvalidArgumentsError:U,InvalidOptionsError:R,InvalidMessageError:j,SocketProtocolError:M,ServerProtocolError:H,HTTPServerError:G,ResourceLimitError:$,TimeoutError:F,BadConnectionError:z,BrokerError:q,ProcessExitError:V,UnknownError:W};const K={1001:"Socket was disconnected",1002:"A WebSocket protocol error was encountered",1003:"Server terminated socket because it received invalid data",1005:"Socket closed without status code",1006:"Socket hung up",1007:"Message format was incorrect",1008:"Encountered a policy violation",1009:"Message was too big to process",1010:"Client ended the connection because the server did not comply with extension requirements",1011:"Server encountered an unexpected fatal condition",4e3:"Server ping timed out",4001:"Client pong timed out",4002:"Server failed to sign auth token",4003:"Failed to complete handshake",4004:"Client failed to save auth token",4005:"Did not receive #handshake from client before timeout",4006:"Failed to bind socket to message broker",4007:"Client connection establishment timed out",4008:"Server rejected handshake from client",4009:"Server received a message before the client handshake"},Y={1e3:"Socket closed normally",1001:K[1001]};A.exports.socketProtocolErrorStatuses=K,A.exports.socketProtocolIgnoreStatuses=Y,A.exports.dehydrateError=function(t){let e;if(t&&"object"==typeof t){e={message:t.message};for(let r of Object.keys(t))e[r]=t[r]}else e="function"==typeof t?"[function "+("string"==typeof t.name?t.name:"anonymous")+"]":t;return T(e)},A.exports.hydrateError=function(t){let e=null;if(null!=t)if("object"==typeof t){e=new Error("string"==typeof t.message?t.message:"Invalid error message format"),"string"==typeof t.name&&(e.name=t.name);for(let r of Object.keys(t))void 0===e[r]&&(e[r]=t[r])}else e=t;return e},A.exports.decycle=T;var J=A.exports;const X=J,Z=X.InvalidActionError;var Q,tt;const et=function(t,e,r,n){this.socket=t,this.id=e,this.procedure=r,this.data=n,this.sent=!1,this._respond=(t,e)=>{if(this.sent)throw new Z(`Response to request ${this.id} has already been sent`);this.sent=!0,this.socket.sendObject(t,e)},this.end=(t,e)=>{let r={rid:this.id};void 0!==t&&(r.data=t),this._respond(r,e)},this.error=(t,e)=>{let r={rid:this.id,error:X.dehydrateError(t)};this._respond(r,e)}};let rt;if("undefined"!=typeof WebSocket)rt=function(t,e){return new WebSocket(t)};else{let t=function(){if(tt)return Q;let t;tt=1,t="undefined"!=typeof WorkerGlobalScope?self:"undefined"!=typeof window&&window||function(){return this}();const e=t.WebSocket||t.MozWebSocket;function r(t,r,n){let o;return o=r?new e(t,r):new e(t),o}return e&&(r.prototype=e.prototype),Q=e?r:null}();rt=function(e,r){return new t(e,[],r)}}const nt=J,ot=nt.TimeoutError,it=nt.BadConnectionError;function st(t,e,r,n,o){this.state=this.CLOSED,this.auth=t,this.codec=e,this.options=r,this.wsOptions=n,this.protocolVersion=r.protocolVersion,this.connectTimeout=r.connectTimeout,this.pingTimeout=r.pingTimeout,this.pingTimeoutDisabled=!!r.pingTimeoutDisabled,this.callIdGenerator=r.callIdGenerator,this.authTokenName=r.authTokenName,this.isBufferingBatch=!1,this._pingTimeoutTicker=null,this._callbackMap={},this._batchBuffer=[],o||(o={}),this._onOpenHandler=o.onOpen||function(){},this._onOpenAbortHandler=o.onOpenAbort||function(){},this._onCloseHandler=o.onClose||function(){},this._onEventHandler=o.onEvent||function(){},this._onErrorHandler=o.onError||function(){},this._onInboundInvokeHandler=o.onInboundInvoke||function(){},this._onInboundTransmitHandler=o.onInboundTransmit||function(){},this.state=this.CONNECTING;let i=this.uri(),s=rt(i,n);s.binaryType=this.options.binaryType,this.socket=s,s.onopen=()=>{this._onOpen()},s.onclose=async t=>{let e;e=null==t.code?1005:t.code,this._destroy(e,t.reason)},s.onmessage=(t,e)=>{this._onMessage(t.data)},s.onerror=t=>{this.state===this.CONNECTING&&this._destroy(1006)},this._connectTimeoutRef=setTimeout((()=>{this._destroy(4007),this.socket.close(4007)}),this.connectTimeout),1===this.protocolVersion?this._handlePing=t=>"#1"===t&&(this._resetPingTimeout(),this.socket.readyState===this.socket.OPEN&&this.send("#2"),!0):this._handlePing=t=>""===t&&(this._resetPingTimeout(),this.socket.readyState===this.socket.OPEN&&this.send(""),!0)}st.CONNECTING=st.prototype.CONNECTING="connecting",st.OPEN=st.prototype.OPEN="open",st.CLOSED=st.prototype.CLOSED="closed",st.computeURI=function(t){let e,r=t.query||{};e=null==t.protocolScheme?t.secure?"wss":"ws":t.protocolScheme,t.timestampRequests&&(r[t.timestampParam]=(new Date).getTime());let n,o,i=new URLSearchParams;for(let[t,e]of Object.entries(r))if(Array.isArray(e))for(let r of e)i.append(t,r);else i.set(t,e);if(r=i.toString(),r.length&&(r="?"+r),null==t.socketPath){if(t.host)n=t.host;else{let r="";t.port&&("wss"===e&&443!==t.port||"ws"===e&&80!==t.port)&&(r=":"+t.port),n=t.hostname+r}o=t.path}else n=t.socketPath,o=`:${t.path}`;return e+"://"+n+o+r},st.prototype.uri=function(){return st.computeURI(this.options)},st.prototype._onOpen=async function(){let t;clearTimeout(this._connectTimeoutRef),this._resetPingTimeout();try{t=await this._handshake()}catch(t){return null==t.statusCode&&(t.statusCode=4003),this._onError(t),this._destroy(t.statusCode,t.toString()),void this.socket.close(t.statusCode)}this.state=this.OPEN,t&&(this.pingTimeout=t.pingTimeout),this._resetPingTimeout(),this._onOpenHandler(t)},st.prototype._handshake=async function(){let t=await this.auth.loadToken(this.authTokenName),e=await this.invoke("#handshake",{authToken:t},{force:!0});return e&&(e.authToken=t,e.authError&&(e.authError=nt.hydrateError(e.authError))),e},st.prototype._abortAllPendingEventsDueToBadConnection=function(t,e,r){Object.keys(this._callbackMap||{}).forEach((n=>{let o=this._callbackMap[n];delete this._callbackMap[n],clearTimeout(o.timeout),delete o.timeout;let i=`Event ${o.event} was aborted due to a bad connection`,s=new it(i,t,e,r),a=o.callback;a&&(delete o.callback,a.call(o,s,o))}))},st.prototype._destroy=function(t,e){nt.socketProtocolErrorStatuses[t],!e&&nt.socketProtocolErrorStatuses[t]&&(e=nt.socketProtocolErrorStatuses[t]),delete this.socket.onopen,delete this.socket.onclose,delete this.socket.onmessage,delete this.socket.onerror,clearTimeout(this._connectTimeoutRef),clearTimeout(this._pingTimeoutTicker),this.state===this.OPEN?(this.state=this.CLOSED,this._abortAllPendingEventsDueToBadConnection("disconnect",t,e),this._onCloseHandler({code:t,reason:e})):this.state===this.CONNECTING?(this.state=this.CLOSED,this._abortAllPendingEventsDueToBadConnection("connectAbort",t,e),this._onOpenAbortHandler({code:t,reason:e})):this.state===this.CLOSED&&this._abortAllPendingEventsDueToBadConnection("connectAbort",t,e)},st.prototype._processInboundPacket=function(t,e){if(t&&"string"==typeof t.event)if("number"==typeof t.cid){let e=new et(this,t.cid,t.event,t.data);this._onInboundInvokeHandler(e)}else this._onInboundTransmitHandler({...t});else if(t&&"number"==typeof t.rid){let e=this._callbackMap[t.rid];if(e&&(clearTimeout(e.timeout),delete e.timeout,delete this._callbackMap[t.rid],e.callback)){let r=nt.hydrateError(t.error);e.callback(r,t.data)}}else this._onEventHandler({event:"raw",data:{message:e}})},st.prototype._onMessage=function(t){if(this._onEventHandler({event:"message",data:{message:t}}),this._handlePing(t))return;let e=this.decode(t);if(Array.isArray(e)){let r=e.length;for(let n=0;n<r;n++)this._processInboundPacket(e[n],t)}else this._processInboundPacket(e,t)},st.prototype._onError=function(t){this._onErrorHandler({error:t})},st.prototype._resetPingTimeout=function(){this.pingTimeoutDisabled||((new Date).getTime(),clearTimeout(this._pingTimeoutTicker),this._pingTimeoutTicker=setTimeout((()=>{this._destroy(4e3),this.socket.close(4e3)}),this.pingTimeout))},st.prototype.clearAllListeners=function(){this._onOpenHandler=function(){},this._onOpenAbortHandler=function(){},this._onCloseHandler=function(){},this._onEventHandler=function(){},this._onErrorHandler=function(){},this._onInboundInvokeHandler=function(){},this._onInboundTransmitHandler=function(){}},st.prototype.startBatch=function(){this.isBufferingBatch=!0,this._batchBuffer=[]},st.prototype.flushBatch=function(){if(this.isBufferingBatch=!1,!this._batchBuffer.length)return;let t=this.serializeObject(this._batchBuffer);this._batchBuffer=[],this.send(t)},st.prototype.cancelBatch=function(){this.isBufferingBatch=!1,this._batchBuffer=[]},st.prototype.getBytesReceived=function(){return this.socket.bytesReceived},st.prototype.close=function(t,e){this.state!==this.OPEN&&this.state!==this.CONNECTING||(t=t||1e3,this._destroy(t,e),this.socket.close(t,e))},st.prototype.transmitObject=function(t){let e={event:t.event,data:t.data};return t.callback&&(e.cid=t.cid=this.callIdGenerator(),this._callbackMap[t.cid]=t),this.sendObject(e),t.cid||null},st.prototype._handleEventAckTimeout=function(t){t.cid&&delete this._callbackMap[t.cid],delete t.timeout;let e=t.callback;if(e){delete t.callback;let r=new ot(`Event response for ${t.event} event timed out`);e.call(t,r,t)}},st.prototype.transmit=function(t,e,r){let n={event:t,data:e};return(this.state===this.OPEN||r.force)&&this.transmitObject(n),Promise.resolve()},st.prototype.invokeRaw=function(t,e,r,n){let o={event:t,data:e,callback:n};r.noTimeout||(o.timeout=setTimeout((()=>{this._handleEventAckTimeout(o)}),this.options.ackTimeout));let i=null;return(this.state===this.OPEN||r.force)&&(i=this.transmitObject(o)),i},st.prototype.invoke=function(t,e,r){return new Promise(((n,o)=>{this.invokeRaw(t,e,r,((t,e)=>{t?o(t):n(e)}))}))},st.prototype.cancelPendingResponse=function(t){delete this._callbackMap[t]},st.prototype.decode=function(t){return this.codec.decode(t)},st.prototype.encode=function(t){return this.codec.encode(t)},st.prototype.send=function(t){this.socket.readyState!==this.socket.OPEN?this._destroy(1005):this.socket.send(t)},st.prototype.serializeObject=function(t){let e;try{e=this.encode(t)}catch(t){return this._onError(t),null}return e},st.prototype.sendObject=function(t){if(this.isBufferingBatch)return void this._batchBuffer.push(t);let e=this.serializeObject(t);null!=e&&this.send(e)};var at=st,ut=mt;mt.Item=yt;var ct=mt.prototype,ht=yt.prototype,lt=gt.prototype,pt="undefined"==typeof Symbol?void 0:Symbol.iterator;ct.tail=ct.head=null,mt.of=function(){return dt(new this,arguments)},mt.from=function(t){return dt(new this,t)},ct.toArray=function(){var t=this.head,e=[];for(;t;)e.push(t),t=t.next;return e},ct.prepend=function(t){var e=this,r=e.head;if(!t)return!1;if(!t.append||!t.prepend||!t.detach)throw new Error(ft+"#prepend`.");if(r)return r.prepend(t);return t.detach(),t.list=e,e.head=t,e.size++,t},ct.append=function(t){if(!t)return!1;if(!t.append||!t.prepend||!t.detach)throw new Error(ft+"#append`.");var e=this,r=e.head,n=e.tail;if(n)return n.append(t);if(r)return r.append(t);return t.detach(),t.list=e,e.head=t,e.size++,t},void 0!==pt&&(ct[pt]=function(){return new gt(this.head)}),ht.next=ht.prev=ht.list=null,ht.prepend=function(t){if(!(t&&t.append&&t.prepend&&t.detach))throw new Error(ft+"Item#prepend`.");var e=this,r=e.list,n=e.prev;if(!r)return!1;t.detach(),n&&(t.prev=n,n.next=t);t.next=e,t.list=r,e.prev=t,e===r.head&&(r.head=t);r.tail||(r.tail=e);return r.size++,t},ht.append=function(t){if(!(t&&t.append&&t.prepend&&t.detach))throw new Error(ft+"Item#append`.");var e=this,r=e.list,n=e.next;if(!r)return!1;t.detach(),n&&(t.next=n,n.prev=t);t.prev=e,t.list=r,e.next=t,e!==r.tail&&r.tail||(r.tail=t);return r.size++,t},ht.detach=function(){var t=this,e=t.list,r=t.prev,n=t.next;if(!e)return t;e.tail===t&&(e.tail=r);e.head===t&&(e.head=n);e.tail===e.head&&(e.tail=null);r&&(r.next=n);n&&(n.prev=r);return t.prev=t.next=t.list=null,e.size--,t},lt.next=function(){var t=this.item;return this.value=t,this.done=!t,this.item=t?t.next:void 0,this};var ft="An argument without append, prepend, or detach methods was given to `List";function mt(){this.size=0,0!==arguments.length&&dt(this,arguments)}function dt(t,e){var r,n,o,i;if(!e)return t;if(void 0!==pt&&e[pt])for(i=e[pt](),o={};!o.done;)o=i.next(),t.append(o&&o.value);else for(r=e.length,n=-1;++n<r;)t.append(e[n]);return t}function yt(){}function gt(t){this.item=t}var bt=Object.prototype.toString,vt=function(t){if(void 0===t)return"undefined";if(null===t)return"null";var e=typeof t;if("boolean"===e)return"boolean";if("string"===e)return"string";if("number"===e)return"number";if("symbol"===e)return"symbol";if("function"===e)return"GeneratorFunction"===kt(t)?"generatorfunction":"function";if(function(t){return Array.isArray?Array.isArray(t):t instanceof Array}(t))return"array";if(function(t){if(t.constructor&&"function"==typeof t.constructor.isBuffer)return t.constructor.isBuffer(t);return!1}
/*!
* shallow-clone <https://github.com/jonschlinkert/shallow-clone>
*
* Copyright (c) 2015-present, Jon Schlinkert.
* Released under the MIT License.
*/(t))return"buffer";if(function(t){try{if("number"==typeof t.length&&"function"==typeof t.callee)return!0}catch(t){if(-1!==t.message.indexOf("callee"))return!0}return!1}(t))return"arguments";if(function(t){return t instanceof Date||"function"==typeof t.toDateString&&"function"==typeof t.getDate&&"function"==typeof t.setDate}(t))return"date";if(function(t){return t instanceof Error||"string"==typeof t.message&&t.constructor&&"number"==typeof t.constructor.stackTraceLimit}(t))return"error";if(function(t){return t instanceof RegExp||"string"==typeof t.flags&&"boolean"==typeof t.ignoreCase&&"boolean"==typeof t.multiline&&"boolean"==typeof t.global}(t))return"regexp";switch(kt(t)){case"Symbol":return"symbol";case"Promise":return"promise";case"WeakMap":return"weakmap";case"WeakSet":return"weakset";case"Map":return"map";case"Set":return"set";case"Int8Array":return"int8array";case"Uint8Array":return"uint8array";case"Uint8ClampedArray":return"uint8clampedarray";case"Int16Array":return"int16array";case"Uint16Array":return"uint16array";case"Int32Array":return"int32array";case"Uint32Array":return"uint32array";case"Float32Array":return"float32array";case"Float64Array":return"float64array"}if(function(t){return"function"==typeof t.throw&&"function"==typeof t.return&&"function"==typeof t.next}(t))return"generator";switch(e=bt.call(t)){case"[object Object]":return"object";case"[object Map Iterator]":return"mapiterator";case"[object Set Iterator]":return"setiterator";case"[object String Iterator]":return"stringiterator";case"[object Array Iterator]":return"arrayiterator"}return e.slice(8,-1).toLowerCase().replace(/\s/g,"")};function kt(t){return"function"==typeof t.constructor?t.constructor.name:null}const Et=Symbol.prototype.valueOf,Ct=vt;var _t=function(t,e){switch(Ct(t)){case"array":return t.slice();case"object":return Object.assign({},t);case"date":return new t.constructor(Number(t));case"map":return new Map(t);case"set":return new Set(t);case"buffer":return function(t){const e=t.length,r=Buffer.allocUnsafe?Buffer.allocUnsafe(e):Buffer.from(e);return t.copy(r),r}(t);case"symbol":return function(t){return Et?Object(Et.call(t)):{}}(t);case"arraybuffer":return function(t){const e=new t.constructor(t.byteLength);return new Uint8Array(e).set(new Uint8Array(t)),e}(t);case"float32array":case"float64array":case"int16array":case"int32array":case"int8array":case"uint16array":case"uint32array":case"uint8clampedarray":case"uint8array":return function(t,e){return new t.constructor(t.buffer,t.byteOffset,t.length)}(t);case"regexp":return function(t){const e=void 0!==t.flags?t.flags:/\w+$/.exec(t)||void 0,r=new t.constructor(t.source,e);return r.lastIndex=t.lastIndex,r}(t);case"error":return Object.create(t);default:return t}},wt=function(t){return null!=t&&"object"==typeof t&&!1===Array.isArray(t)};
/*!
* isobject <https://github.com/jonschlinkert/isobject>
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/function St(t){return!0===wt(t)&&"[object Object]"===Object.prototype.toString.call(t)}const At=_t,Tt=vt,Bt=function(t){var e,r;return!1!==St(t)&&("function"==typeof(e=t.constructor)&&(!1!==St(r=e.prototype)&&!1!==r.hasOwnProperty("isPrototypeOf")))};function Ot(t,e){switch(Tt(t)){case"object":return function(t,e){if("function"==typeof e)return e(t);if(e||Bt(t)){const r=new t.constructor;for(let n in t)r[n]=Ot(t[n],e);return r}return t}(t,e);case"array":return function(t,e){const r=new t.constructor(t.length);for(let n=0;n<t.length;n++)r[n]=Ot(t[n],e);return r}(t,e);default:return At(t)}}for(var It=Ot,Dt={},xt={byteLength:function(t){var e=jt(t),r=e[0],n=e[1];return 3*(r+n)/4-n},toByteArray:function(t){var e,r,n=jt(t),o=n[0],i=n[1],s=new Pt(function(t,e,r){return 3*(e+r)/4-r}(0,o,i)),a=0,u=i>0?o-4:o;for(r=0;r<u;r+=4)e=Nt[t.charCodeAt(r)]<<18|Nt[t.charCodeAt(r+1)]<<12|Nt[t.charCodeAt(r+2)]<<6|Nt[t.charCodeAt(r+3)],s[a++]=e>>16&255,s[a++]=e>>8&255,s[a++]=255&e;2===i&&(e=Nt[t.charCodeAt(r)]<<2|Nt[t.charCodeAt(r+1)]>>4,s[a++]=255&e);1===i&&(e=Nt[t.charCodeAt(r)]<<10|Nt[t.charCodeAt(r+1)]<<4|Nt[t.charCodeAt(r+2)]>>2,s[a++]=e>>8&255,s[a++]=255&e);return s},fromByteArray:function(t){for(var e,r=t.length,n=r%3,o=[],i=16383,s=0,a=r-n;s<a;s+=i)o.push(Mt(t,s,s+i>a?a:s+i));1===n?(e=t[r-1],o.push(Lt[e>>2]+Lt[e<<4&63]+"==")):2===n&&(e=(t[r-2]<<8)+t[r-1],o.push(Lt[e>>10]+Lt[e>>4&63]+Lt[e<<2&63]+"="));return o.join("")}},Lt=[],Nt=[],Pt="undefined"!=typeof Uint8Array?Uint8Array:Array,Ut="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Rt=0;Rt<64;++Rt)Lt[Rt]=Ut[Rt],Nt[Ut.charCodeAt(Rt)]=Rt;function jt(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function Mt(t,e,r){for(var n,o,i=[],s=e;s<r;s+=3)n=(t[s]<<16&16711680)+(t[s+1]<<8&65280)+(255&t[s+2]),i.push(Lt[(o=n)>>18&63]+Lt[o>>12&63]+Lt[o>>6&63]+Lt[63&o]);return i.join("")}Nt["-".charCodeAt(0)]=62,Nt["_".charCodeAt(0)]=63;var Ht={};
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */Ht.read=function(t,e,r,n,o){var i,s,a=8*o-n-1,u=(1<<a)-1,c=u>>1,h=-7,l=r?o-1:0,p=r?-1:1,f=t[e+l];for(l+=p,i=f&(1<<-h)-1,f>>=-h,h+=a;h>0;i=256*i+t[e+l],l+=p,h-=8);for(s=i&(1<<-h)-1,i>>=-h,h+=n;h>0;s=256*s+t[e+l],l+=p,h-=8);if(0===i)i=1-c;else{if(i===u)return s?NaN:1/0*(f?-1:1);s+=Math.pow(2,n),i-=c}return(f?-1:1)*s*Math.pow(2,i-n)},Ht.write=function(t,e,r,n,o,i){var s,a,u,c=8*i-o-1,h=(1<<c)-1,l=h>>1,p=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,f=n?0:i-1,m=n?1:-1,d=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=h):(s=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-s))<1&&(s--,u*=2),(e+=s+l>=1?p/u:p*Math.pow(2,1-l))*u>=2&&(s++,u/=2),s+l>=h?(a=0,s=h):s+l>=1?(a=(e*u-1)*Math.pow(2,o),s+=l):(a=e*Math.pow(2,l-1)*Math.pow(2,o),s=0));o>=8;t[r+f]=255&a,f+=m,a/=256,o-=8);for(s=s<<o|a,c+=o;c>0;t[r+f]=255&s,f+=m,s/=256,c-=8);t[r+f-m]|=128*d},
/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/
function(t){var e=xt,r=Ht,n="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;t.Buffer=s,t.SlowBuffer=function(t){+t!=t&&(t=0);return s.alloc(+t)},t.INSPECT_MAX_BYTES=50;var o=2147483647;function i(t){if(t>o)throw new RangeError('The value "'+t+'" is invalid for option "size"');var e=new Uint8Array(t);return Object.setPrototypeOf(e,s.prototype),e}function s(t,e,r){if("number"==typeof t){if("string"==typeof e)throw new TypeError('The "string" argument must be of type string. Received type number');return c(t)}return a(t,e,r)}function a(t,e,r){if("string"==typeof t)return function(t,e){"string"==typeof e&&""!==e||(e="utf8");if(!s.isEncoding(e))throw new TypeError("Unknown encoding: "+e);var r=0|f(t,e),n=i(r),o=n.write(t,e);o!==r&&(n=n.slice(0,o));return n}(t,e);if(ArrayBuffer.isView(t))return function(t){if(M(t,Uint8Array)){var e=new Uint8Array(t);return l(e.buffer,e.byteOffset,e.byteLength)}return h(t)}(t);if(null==t)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(M(t,ArrayBuffer)||t&&M(t.buffer,ArrayBuffer))return l(t,e,r);if("undefined"!=typeof SharedArrayBuffer&&(M(t,SharedArrayBuffer)||t&&M(t.buffer,SharedArrayBuffer)))return l(t,e,r);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');var n=t.valueOf&&t.valueOf();if(null!=n&&n!==t)return s.from(n,e,r);var o=function(t){if(s.isBuffer(t)){var e=0|p(t.length),r=i(e);return 0===r.length||t.copy(r,0,0,e),r}if(void 0!==t.length)return"number"!=typeof t.length||H(t.length)?i(0):h(t);if("Buffer"===t.type&&Array.isArray(t.data))return h(t.data)}(t);if(o)return o;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return s.from(t[Symbol.toPrimitive]("string"),e,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function u(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function c(t){return u(t),i(t<0?0:0|p(t))}function h(t){for(var e=t.length<0?0:0|p(t.length),r=i(e),n=0;n<e;n+=1)r[n]=255&t[n];return r}function l(t,e,r){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(r||0))throw new RangeError('"length" is outside of buffer bounds');var n;return n=void 0===e&&void 0===r?new Uint8Array(t):void 0===r?new Uint8Array(t,e):new Uint8Array(t,e,r),Object.setPrototypeOf(n,s.prototype),n}function p(t){if(t>=o)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+o.toString(16)+" bytes");return 0|t}function f(t,e){if(s.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||M(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);var r=t.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;for(var o=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return U(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return R(t).length;default:if(o)return n?-1:U(t).length;e=(""+e).toLowerCase(),o=!0}}function m(t,e,r){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return B(this,e,r);case"utf8":case"utf-8":return w(this,e,r);case"ascii":return A(this,e,r);case"latin1":case"binary":return T(this,e,r);case"base64":return _(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return O(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function d(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function y(t,e,r,n,o){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),H(r=+r)&&(r=o?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(o)return-1;r=t.length-1}else if(r<0){if(!o)return-1;r=0}if("string"==typeof e&&(e=s.from(e,n)),s.isBuffer(e))return 0===e.length?-1:g(t,e,r,n,o);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):g(t,[e],r,n,o);throw new TypeError("val must be string, number or Buffer")}function g(t,e,r,n,o){var i,s=1,a=t.length,u=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;s=2,a/=2,u/=2,r/=2}function c(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}if(o){var h=-1;for(i=r;i<a;i++)if(c(t,i)===c(e,-1===h?0:i-h)){if(-1===h&&(h=i),i-h+1===u)return h*s}else-1!==h&&(i-=i-h),h=-1}else for(r+u>a&&(r=a-u),i=r;i>=0;i--){for(var l=!0,p=0;p<u;p++)if(c(t,i+p)!==c(e,p)){l=!1;break}if(l)return i}return-1}function b(t,e,r,n){r=Number(r)||0;var o=t.length-r;n?(n=Number(n))>o&&(n=o):n=o;var i=e.length;n>i/2&&(n=i/2);for(var s=0;s<n;++s){var a=parseInt(e.substr(2*s,2),16);if(H(a))return s;t[r+s]=a}return s}function v(t,e,r,n){return j(U(e,t.length-r),t,r,n)}function k(t,e,r,n){return j(function(t){for(var e=[],r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function E(t,e,r,n){return j(R(e),t,r,n)}function C(t,e,r,n){return j(function(t,e){for(var r,n,o,i=[],s=0;s<t.length&&!((e-=2)<0);++s)n=(r=t.charCodeAt(s))>>8,o=r%256,i.push(o),i.push(n);return i}(e,t.length-r),t,r,n)}function _(t,r,n){return 0===r&&n===t.length?e.fromByteArray(t):e.fromByteArray(t.slice(r,n))}function w(t,e,r){r=Math.min(t.length,r);for(var n=[],o=e;o<r;){var i,s,a,u,c=t[o],h=null,l=c>239?4:c>223?3:c>191?2:1;if(o+l<=r)switch(l){case 1:c<128&&(h=c);break;case 2:128==(192&(i=t[o+1]))&&(u=(31&c)<<6|63&i)>127&&(h=u);break;case 3:i=t[o+1],s=t[o+2],128==(192&i)&&128==(192&s)&&(u=(15&c)<<12|(63&i)<<6|63&s)>2047&&(u<55296||u>57343)&&(h=u);break;case 4:i=t[o+1],s=t[o+2],a=t[o+3],128==(192&i)&&128==(192&s)&&128==(192&a)&&(u=(15&c)<<18|(63&i)<<12|(63&s)<<6|63&a)>65535&&u<1114112&&(h=u)}null===h?(h=65533,l=1):h>65535&&(h-=65536,n.push(h>>>10&1023|55296),h=56320|1023&h),n.push(h),o+=l}return function(t){var e=t.length;if(e<=S)return String.fromCharCode.apply(String,t);var r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=S));return r}(n)}t.kMaxLength=o,s.TYPED_ARRAY_SUPPORT=function(){try{var t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),42===t.foo()}catch(t){return!1}}(),s.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(s.prototype,"parent",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.buffer}}),Object.defineProperty(s.prototype,"offset",{enumerable:!0,get:function(){if(s.isBuffer(this))return this.byteOffset}}),s.poolSize=8192,s.from=function(t,e,r){return a(t,e,r)},Object.setPrototypeOf(s.prototype,Uint8Array.prototype),Object.setPrototypeOf(s,Uint8Array),s.alloc=function(t,e,r){return function(t,e,r){return u(t),t<=0?i(t):void 0!==e?"string"==typeof r?i(t).fill(e,r):i(t).fill(e):i(t)}(t,e,r)},s.allocUnsafe=function(t){return c(t)},s.allocUnsafeSlow=function(t){return c(t)},s.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==s.prototype},s.compare=function(t,e){if(M(t,Uint8Array)&&(t=s.from(t,t.offset,t.byteLength)),M(e,Uint8Array)&&(e=s.from(e,e.offset,e.byteLength)),!s.isBuffer(t)||!s.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;for(var r=t.length,n=e.length,o=0,i=Math.min(r,n);o<i;++o)if(t[o]!==e[o]){r=t[o],n=e[o];break}return r<n?-1:n<r?1:0},s.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},s.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return s.alloc(0);var r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;var n=s.allocUnsafe(e),o=0;for(r=0;r<t.length;++r){var i=t[r];if(M(i,Uint8Array))o+i.length>n.length?s.from(i).copy(n,o):Uint8Array.prototype.set.call(n,i,o);else{if(!s.isBuffer(i))throw new TypeError('"list" argument must be an Array of Buffers');i.copy(n,o)}o+=i.length}return n},s.byteLength=f,s.prototype._isBuffer=!0,s.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)d(this,e,e+1);return this},s.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)d(this,e,e+3),d(this,e+1,e+2);return this},s.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)d(this,e,e+7),d(this,e+1,e+6),d(this,e+2,e+5),d(this,e+3,e+4);return this},s.prototype.toString=function(){var t=this.length;return 0===t?"":0===arguments.length?w(this,0,t):m.apply(this,arguments)},s.prototype.toLocaleString=s.prototype.toString,s.prototype.equals=function(t){if(!s.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===s.compare(this,t)},s.prototype.inspect=function(){var e="",r=t.INSPECT_MAX_BYTES;return e=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim(),this.length>r&&(e+=" ... "),"<Buffer "+e+">"},n&&(s.prototype[n]=s.prototype.inspect),s.prototype.compare=function(t,e,r,n,o){if(M(t,Uint8Array)&&(t=s.from(t,t.offset,t.byteLength)),!s.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),e<0||r>t.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&e>=r)return 0;if(n>=o)return-1;if(e>=r)return 1;if(this===t)return 0;for(var i=(o>>>=0)-(n>>>=0),a=(r>>>=0)-(e>>>=0),u=Math.min(i,a),c=this.slice(n,o),h=t.slice(e,r),l=0;l<u;++l)if(c[l]!==h[l]){i=c[l],a=h[l];break}return i<a?-1:a<i?1:0},s.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},s.prototype.indexOf=function(t,e,r){return y(this,t,e,r,!0)},s.prototype.lastIndexOf=function(t,e,r){return y(this,t,e,r,!1)},s.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var o=this.length-e;if((void 0===r||r>o)&&(r=o),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var i=!1;;)switch(n){case"hex":return b(this,t,e,r);case"utf8":case"utf-8":return v(this,t,e,r);case"ascii":case"latin1":case"binary":return k(this,t,e,r);case"base64":return E(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(this,t,e,r);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},s.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var S=4096;function A(t,e,r){var n="";r=Math.min(t.length,r);for(var o=e;o<r;++o)n+=String.fromCharCode(127&t[o]);return n}function T(t,e,r){var n="";r=Math.min(t.length,r);for(var o=e;o<r;++o)n+=String.fromCharCode(t[o]);return n}function B(t,e,r){var n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);for(var o="",i=e;i<r;++i)o+=G[t[i]];return o}function O(t,e,r){for(var n=t.slice(e,r),o="",i=0;i<n.length-1;i+=2)o+=String.fromCharCode(n[i]+256*n[i+1]);return o}function I(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function D(t,e,r,n,o,i){if(!s.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||e<i)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function x(t,e,r,n,o,i){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function L(t,e,n,o,i){return e=+e,n>>>=0,i||x(t,0,n,4),r.write(t,e,n,o,23,4),n+4}function N(t,e,n,o,i){return e=+e,n>>>=0,i||x(t,0,n,8),r.write(t,e,n,o,52,8),n+8}s.prototype.slice=function(t,e){var r=this.length;(t=~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),(e=void 0===e?r:~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),e<t&&(e=t);var n=this.subarray(t,e);return Object.setPrototypeOf(n,s.prototype),n},s.prototype.readUintLE=s.prototype.readUIntLE=function(t,e,r){t>>>=0,e>>>=0,r||I(t,e,this.length);for(var n=this[t],o=1,i=0;++i<e&&(o*=256);)n+=this[t+i]*o;return n},s.prototype.readUintBE=s.prototype.readUIntBE=function(t,e,r){t>>>=0,e>>>=0,r||I(t,e,this.length);for(var n=this[t+--e],o=1;e>0&&(o*=256);)n+=this[t+--e]*o;return n},s.prototype.readUint8=s.prototype.readUInt8=function(t,e){return t>>>=0,e||I(t,1,this.length),this[t]},s.prototype.readUint16LE=s.prototype.readUInt16LE=function(t,e){return t>>>=0,e||I(t,2,this.length),this[t]|this[t+1]<<8},s.prototype.readUint16BE=s.prototype.readUInt16BE=function(t,e){return t>>>=0,e||I(t,2,this.length),this[t]<<8|this[t+1]},s.prototype.readUint32LE=s.prototype.readUInt32LE=function(t,e){return t>>>=0,e||I(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},s.prototype.readUint32BE=s.prototype.readUInt32BE=function(t,e){return t>>>=0,e||I(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},s.prototype.readIntLE=function(t,e,r){t>>>=0,e>>>=0,r||I(t,e,this.length);for(var n=this[t],o=1,i=0;++i<e&&(o*=256);)n+=this[t+i]*o;return n>=(o*=128)&&(n-=Math.pow(2,8*e)),n},s.prototype.readIntBE=function(t,e,r){t>>>=0,e>>>=0,r||I(t,e,this.length);for(var n=e,o=1,i=this[t+--n];n>0&&(o*=256);)i+=this[t+--n]*o;return i>=(o*=128)&&(i-=Math.pow(2,8*e)),i},s.prototype.readInt8=function(t,e){return t>>>=0,e||I(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},s.prototype.readInt16LE=function(t,e){t>>>=0,e||I(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt16BE=function(t,e){t>>>=0,e||I(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt32LE=function(t,e){return t>>>=0,e||I(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},s.prototype.readInt32BE=function(t,e){return t>>>=0,e||I(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},s.prototype.readFloatLE=function(t,e){return t>>>=0,e||I(t,4,this.length),r.read(this,t,!0,23,4)},s.prototype.readFloatBE=function(t,e){return t>>>=0,e||I(t,4,this.length),r.read(this,t,!1,23,4)},s.prototype.readDoubleLE=function(t,e){return t>>>=0,e||I(t,8,this.length),r.read(this,t,!0,52,8)},s.prototype.readDoubleBE=function(t,e){return t>>>=0,e||I(t,8,this.length),r.read(this,t,!1,52,8)},s.prototype.writeUintLE=s.prototype.writeUIntLE=function(t,e,r,n){(t=+t,e>>>=0,r>>>=0,n)||D(this,t,e,r,Math.pow(2,8*r)-1,0);var o=1,i=0;for(this[e]=255&t;++i<r&&(o*=256);)this[e+i]=t/o&255;return e+r},s.prototype.writeUintBE=s.prototype.writeUIntBE=function(t,e,r,n){(t=+t,e>>>=0,r>>>=0,n)||D(this,t,e,r,Math.pow(2,8*r)-1,0);var o=r-1,i=1;for(this[e+o]=255&t;--o>=0&&(i*=256);)this[e+o]=t/i&255;return e+r},s.prototype.writeUint8=s.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||D(this,t,e,1,255,0),this[e]=255&t,e+1},s.prototype.writeUint16LE=s.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||D(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},s.prototype.writeUint16BE=s.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||D(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},s.prototype.writeUint32LE=s.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||D(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},s.prototype.writeUint32BE=s.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||D(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},s.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e>>>=0,!n){var o=Math.pow(2,8*r-1);D(this,t,e,r,o-1,-o)}var i=0,s=1,a=0;for(this[e]=255&t;++i<r&&(s*=256);)t<0&&0===a&&0!==this[e+i-1]&&(a=1),this[e+i]=(t/s>>0)-a&255;return e+r},s.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e>>>=0,!n){var o=Math.pow(2,8*r-1);D(this,t,e,r,o-1,-o)}var i=r-1,s=1,a=0;for(this[e+i]=255&t;--i>=0&&(s*=256);)t<0&&0===a&&0!==this[e+i+1]&&(a=1),this[e+i]=(t/s>>0)-a&255;return e+r},s.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||D(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},s.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||D(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},s.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||D(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},s.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||D(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},s.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||D(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},s.prototype.writeFloatLE=function(t,e,r){return L(this,t,e,!0,r)},s.prototype.writeFloatBE=function(t,e,r){return L(this,t,e,!1,r)},s.prototype.writeDoubleLE=function(t,e,r){return N(this,t,e,!0,r)},s.prototype.writeDoubleBE=function(t,e,r){return N(this,t,e,!1,r)},s.prototype.copy=function(t,e,r,n){if(!s.isBuffer(t))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);var o=n-r;return this===t&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(e,r,n):Uint8Array.prototype.set.call(t,this.subarray(r,n),e),o},s.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!s.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===t.length){var o=t.charCodeAt(0);("utf8"===n&&o<128||"latin1"===n)&&(t=o)}}else"number"==typeof t?t&=255:"boolean"==typeof t&&(t=Number(t));if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;var i;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(i=e;i<r;++i)this[i]=t;else{var a=s.isBuffer(t)?t:s.from(t,n),u=a.length;if(0===u)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(i=0;i<r-e;++i)this[i+e]=a[i%u]}return this};var P=/[^+/0-9A-Za-z-_]/g;function U(t,e){var r;e=e||1/0;for(var n=t.length,o=null,i=[],s=0;s<n;++s){if((r=t.charCodeAt(s))>55295&&r<57344){if(!o){if(r>56319){(e-=3)>-1&&i.push(239,191,189);continue}if(s+1===n){(e-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(e-=3)>-1&&i.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&(e-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((e-=1)<0)break;i.push(r)}else if(r<2048){if((e-=2)<0)break;i.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function R(t){return e.toByteArray(function(t){if((t=(t=t.split("=")[0]).trim().replace(P,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function j(t,e,r,n){for(var o=0;o<n&&!(o+r>=e.length||o>=t.length);++o)e[o+r]=t[o];return o}function M(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}function H(t){return t!=t}var G=function(){for(var t="0123456789abcdef",e=new Array(256),r=0;r<16;++r)for(var n=16*r,o=0;o<16;++o)e[n+o]=t[r]+t[o];return e}()}(Dt);const Gt=p,$t=d,Ft=b,zt=k,qt=E,Vt=at,Wt=ut,Kt=It,Yt=Dt.Buffer,Jt=function(t){return new Promise((e=>{setTimeout((()=>{e()}),t)}))},Xt=J,Zt=Xt.InvalidArgumentsError,Qt=Xt.InvalidMessageError,te=Xt.SocketProtocolError,ee=Xt.TimeoutError,re=Xt.BadConnectionError;function ne(t){$t.call(this);let e=Object.assign({path:"/socketcluster/",secure:!1,protocolScheme:null,socketPath:null,autoConnect:!0,autoReconnect:!0,autoSubscribeOnConnect:!0,connectTimeout:2e4,ackTimeout:1e4,timestampRequests:!1,timestampParam:"t",binaryType:"arraybuffer",batchOnHandshake:!1,batchOnHandshakeDuration:100,batchInterval:50,protocolVersion:2,wsOptions:{},cloneData:!1},t);null==e.authTokenName&&(e.authTokenName=this._generateAuthTokenNameFromURI(e)),this.id=null,this.version=e.version||null,this.protocolVersion=e.protocolVersion,this.state=this.CLOSED,this.authState=this.UNAUTHENTICATED,this.signedAuthToken=null,this.authToken=null,this.pendingReconnect=!1,this.pendingReconnectTimeout=null,this.preparingPendingSubscriptions=!1,this.clientId=e.clientId,this.wsOptions=e.wsOptions,this.connectTimeout=e.connectTimeout,this.ackTimeout=e.ackTimeout,this.channelPrefix=e.channelPrefix||null,this.authTokenName=e.authTokenName,e.pingTimeout=e.connectTimeout,this.pingTimeout=e.pingTimeout,this.pingTimeoutDisabled=!!e.pingTimeoutDisabled;let r=Math.pow(2,31)-1,n=t=>{if(this[t]>r)throw new Zt(`The ${t} value provided exceeded the maximum amount allowed`)};if(n("connectTimeout"),n("ackTimeout"),n("pingTimeout"),this.connectAttempts=0,this.isBatching=!1,this.batchOnHandshake=e.batchOnHandshake,this.batchOnHandshakeDuration=e.batchOnHandshakeDuration,this._batchingIntervalId=null,this._outboundBuffer=new Wt,this._channelMap={},this._channelEventDemux=new Gt,this._channelDataDemux=new Gt,this._receiverDemux=new Gt,this._procedureDemux=new Gt,this.options=e,this._cid=1,this.options.callIdGenerator=()=>this._cid++,this.options.autoReconnect){null==this.options.autoReconnectOptions&&(this.options.autoReconnectOptions={});let t=this.options.autoReconnectOptions;null==t.initialDelay&&(t.initialDelay=1e4),null==t.randomness&&(t.randomness=1e4),null==t.multiplier&&(t.multiplier=1.5),null==t.maxDelay&&(t.maxDelay=6e4)}if(null==this.options.subscriptionRetryOptions&&(this.options.subscriptionRetryOptions={}),this.options.authEngine?this.auth=this.options.authEngine:this.auth=new zt,this.options.codecEngine?this.codec=this.options.codecEngine:this.codec=qt,this.options.protocol){let t=new Zt("The protocol option does not affect socketcluster-client - If you want to utilize SSL/TLS, use the secure option instead");this._onError(t)}if(this.options.query=e.query||{},"string"==typeof this.options.query){let t=new URLSearchParams(this.options.query),e={};for(let[r,n]of t.entries()){let t=e[r];null==t?e[r]=n:(Array.isArray(t)||(e[r]=[t]),e[r].push(n))}this.options.query=e}this.options.autoConnect&&this.connect()}ne.prototype=Object.create($t.prototype),ne.CONNECTING=ne.prototype.CONNECTING=Vt.prototype.CONNECTING,ne.OPEN=ne.prototype.OPEN=Vt.prototype.OPEN,ne.CLOSED=ne.prototype.CLOSED=Vt.prototype.CLOSED,ne.AUTHENTICATED=ne.prototype.AUTHENTICATED="authenticated",ne.UNAUTHENTICATED=ne.prototype.UNAUTHENTICATED="unauthenticated",ne.SUBSCRIBED=ne.prototype.SUBSCRIBED=Ft.SUBSCRIBED,ne.PENDING=ne.prototype.PENDING=Ft.PENDING,ne.UNSUBSCRIBED=ne.prototype.UNSUBSCRIBED=Ft.UNSUBSCRIBED,ne.ignoreStatuses=Xt.socketProtocolIgnoreStatuses,ne.errorStatuses=Xt.socketProtocolErrorStatuses,Object.defineProperty(ne.prototype,"isBufferingBatch",{get:function(){return this.transport.isBufferingBatch}}),ne.prototype.uri=function(){return Vt.computeURI(this.options)},ne.prototype.getBackpressure=function(){return Math.max(this.getAllListenersBackpressure(),this.getAllReceiversBackpressure(),this.getAllProceduresBackpressure(),this.getAllChannelsBackpressure())},ne.prototype._generateAuthTokenNameFromURI=function(t){return`socketcluster.authToken${t.host?`.${t.host}`:`.${t.hostname||"localhost"}${t.port?`:${t.port}`:""}`}`},ne.prototype._setAuthToken=function(t){this._changeToAuthenticatedState(t.token),(async()=>{try{await this.auth.saveToken(this.authTokenName,t.token,{})}catch(t){this._onError(t)}})()},ne.prototype._removeAuthToken=function(t){(async()=>{let t;try{t=await this.auth.removeToken(this.authTokenName)}catch(t){return void this._onError(t)}this.emit("removeAuthToken",{oldAuthToken:t})})(),this._changeToUnauthenticatedStateAndClearTokens()},ne.prototype._privateDataHandlerMap={"#publish":function(t){if("string"!=typeof t.channel)return;let e=this._undecorateChannelName(t.channel);this.isSubscribed(e,!0)&&this._channelDataDemux.write(e,t.data)},"#kickOut":function(t){if("string"!=typeof t.channel)return;let e=this._undecorateChannelName(t.channel),r=this._channelMap[e];r&&(this.emit("kickOut",{channel:e,message:t.message}),this._channelEventDemux.write(`${e}/kickOut`,{message:t.message}),this._triggerChannelUnsubscribe(r))},"#setAuthToken":function(t){t&&this._setAuthToken(t)},"#removeAuthToken":function(t){this._removeAuthToken(t)}},ne.prototype._privateRPCHandlerMap={"#setAuthToken":function(t,e){if(t)this._setAuthToken(t),e.end();else{let t=new Qt("No token data provided by #setAuthToken event");delete t.stack,e.error(t)}},"#removeAuthToken":function(t,e){this._removeAuthToken(t),e.end()}},ne.prototype.getState=function(){return this.state},ne.prototype.getBytesReceived=function(){return this.transport.getBytesReceived()},ne.prototype.deauthenticate=async function(){(async()=>{let t;try{t=await this.auth.removeToken(this.authTokenName)}catch(t){return void this._onError(t)}this.emit("removeAuthToken",{oldAuthToken:t})})(),this.state!==this.CLOSED&&this.transmit("#removeAuthToken"),this._changeToUnauthenticatedStateAndClearTokens(),await Jt(0)},ne.prototype.connect=function(t){if(t&&(this.state!==this.CLOSED&&this.disconnect(1e3,"Socket was disconnected by the client to initiate a new connection"),this.options={...this.options,...t},null==this.options.authTokenName&&(this.options.authTokenName=this._generateAuthTokenNameFromURI(this.options))),this.state===this.CLOSED){this.pendingReconnect=!1,this.pendingReconnectTimeout=null,clearTimeout(this._reconnectTimeoutRef),this.state=this.CONNECTING,this.emit("connecting",{}),this.transport&&this.transport.clearAllListeners();let t={onOpen:t=>{this.state=this.OPEN,this._onOpen(t)},onOpenAbort:t=>{this.state!==this.CLOSED&&(this.state=this.CLOSED,this._destroy(t.code,t.reason,!0))},onClose:t=>{this.state!==this.CLOSED&&(this.state=this.CLOSED,this._destroy(t.code,t.reason))},onEvent:t=>{this.emit(t.event,t.data)},onError:t=>{this._onError(t.error)},onInboundInvoke:t=>{this._onInboundInvoke(t)},onInboundTransmit:t=>{this._onInboundTransmit(t.event,t.data)}};this.transport=new Vt(this.auth,this.codec,this.options,this.wsOptions,t)}},ne.prototype.reconnect=function(t,e){this.disconnect(t,e),this.connect()},ne.prototype.disconnect=function(t,e){if("number"!=typeof(t=t||1e3))throw new Zt("If specified, the code argument must be a number");let r=this.state===this.CONNECTING;r||this.state===this.OPEN?(this.state=this.CLOSED,this._destroy(t,e,r),this.transport.close(t,e)):(this.pendingReconnect=!1,this.pendingReconnectTimeout=null,clearTimeout(this._reconnectTimeoutRef))},ne.prototype._changeToUnauthenticatedStateAndClearTokens=function(){if(this.authState!==this.UNAUTHENTICATED){let t=this.authState,e=this.authToken,r=this.signedAuthToken;this.authState=this.UNAUTHENTICATED,this.signedAuthToken=null,this.authToken=null;let n={oldAuthState:t,newAuthState:this.authState};this.emit("authStateChange",n),this.emit("deauthenticate",{oldSignedAuthToken:r,oldAuthToken:e})}},ne.prototype._changeToAuthenticatedState=function(t){if(this.signedAuthToken=t,this.authToken=this._extractAuthTokenData(t),this.authState!==this.AUTHENTICATED){let e=this.authState;this.authState=this.AUTHENTICATED;let r={oldAuthState:e,newAuthState:this.authState,signedAuthToken:t,authToken:this.authToken};this.preparingPendingSubscriptions||this.processPendingSubscriptions(),this.emit("authStateChange",r)}this.emit("authenticate",{signedAuthToken:t,authToken:this.authToken})},ne.prototype.decodeBase64=function(t){return Yt.from(t,"base64").toString("utf8")},ne.prototype.encodeBase64=function(t){return Yt.from(t,"utf8").toString("base64")},ne.prototype._extractAuthTokenData=function(t){if("string"!=typeof t)return null;let e=t.split(".")[1];if(null!=e){let t=e;try{return t=this.decodeBase64(t),JSON.parse(t)}catch(e){return t}}return null},ne.prototype.getAuthToken=function(){return this.authToken},ne.prototype.getSignedAuthToken=function(){return this.signedAuthToken},ne.prototype.authenticate=async function(t){let e;try{e=await this.invoke("#authenticate",t)}catch(t){throw"BadConnectionError"!==t.name&&"TimeoutError"!==t.name&&this._changeToUnauthenticatedStateAndClearTokens(),await Jt(0),t}return e&&null!=e.isAuthenticated?e.authError&&(e.authError=Xt.hydrateError(e.authError)):e={isAuthenticated:this.authState,authError:null},e.isAuthenticated?this._changeToAuthenticatedState(t):this._changeToUnauthenticatedStateAndClearTokens(),(async()=>{try{await this.auth.saveToken(this.authTokenName,t,{})}catch(t){this._onError(t)}})(),await Jt(0),e},ne.prototype._tryReconnect=function(t){let e,r=this.connectAttempts++,n=this.options.autoReconnectOptions;if(null==t||r>0){let t=Math.round(n.initialDelay+(n.randomness||0)*Math.random());e=Math.round(t*Math.pow(n.multiplier,r))}else e=t;e>n.maxDelay&&(e=n.maxDelay),clearTimeout(this._reconnectTimeoutRef),this.pendingReconnect=!0,this.pendingReconnectTimeout=e,this._reconnectTimeoutRef=setTimeout((()=>{this.connect()}),e)},ne.prototype._onOpen=function(t){this.isBatching?this._startBatching():this.batchOnHandshake&&(this._startBatching(),setTimeout((()=>{this.isBatching||this._stopBatching()}),this.batchOnHandshakeDuration)),this.preparingPendingSubscriptions=!0,t?(this.id=t.id,this.pingTimeout=t.pingTimeout,t.isAuthenticated?this._changeToAuthenticatedState(t.authToken):this._changeToUnauthenticatedStateAndClearTokens()):this._changeToUnauthenticatedStateAndClearTokens(),this.connectAttempts=0,this.options.autoSubscribeOnConnect&&this.processPendingSubscriptions(),this.emit("connect",{...t,processPendingSubscriptions:()=>{this.processPendingSubscriptions()}}),this.state===this.OPEN&&this._flushOutboundBuffer()},ne.prototype._onError=function(t){this.emit("error",{error:t})},ne.prototype._suspendSubscriptions=function(){Object.keys(this._channelMap).forEach((t=>{let e=this._channelMap[t];this._triggerChannelUnsubscribe(e,!0)}))},ne.prototype._abortAllPendingEventsDueToBadConnection=function(t,e,r){let n,o=this._outboundBuffer.head;for(;o;){n=o.next;let i=o.data;clearTimeout(i.timeout),delete i.timeout,o.detach(),o=n;let s=i.callback;if(s){delete i.callback;let n=`Event ${i.event} was aborted due to a bad connection`,o=new re(n,t,e,r);s.call(i,o,i)}i.cid&&this.transport.cancelPendingResponse(i.cid)}},ne.prototype._destroy=function(t,e,r){if(this.id=null,this._cancelBatching(),this.transport&&this.transport.clearAllListeners(),this.pendingReconnect=!1,this.pendingReconnectTimeout=null,clearTimeout(this._reconnectTimeoutRef),this._suspendSubscriptions(),r?this.emit("connectAbort",{code:t,reason:e}):this.emit("disconnect",{code:t,reason:e}),this.emit("close",{code:t,reason:e}),!ne.ignoreStatuses[t]){let r;r="string"==typeof e?"Socket connection closed with status code "+t+" and reason: "+e:"Socket connection closed with status code "+t;let n=new te(ne.errorStatuses[t]||r,t);this._onError(n)}this._abortAllPendingEventsDueToBadConnection(r?"connectAbort":"disconnect",t,e),this.options.autoReconnect&&(4e3===t||4001===t||1005===t?this._tryReconnect(0):1e3!==t&&t<4500&&this._tryReconnect())},ne.prototype._onInboundTransmit=function(t,e){let r=this._privateDataHandlerMap[t];r?r.call(this,e||{}):this._receiverDemux.write(t,e)},ne.prototype._onInboundInvoke=function(t){let{procedure:e,data:r}=t,n=this._privateRPCHandlerMap[e];n?n.call(this,r,t):this._procedureDemux.write(e,t)},ne.prototype.decode=function(t){return this.transport.decode(t)},ne.prototype.encode=function(t){return this.transport.encode(t)},ne.prototype._flushOutboundBuffer=function(){let t,e=this._outboundBuffer.head;for(;e;){t=e.next;let r=e.data;e.detach(),this.transport.transmitObject(r),e=t}},ne.prototype._handleEventAckTimeout=function(t,e){e&&e.detach(),delete t.timeout;let r=t.callback;if(r){delete t.callback;let e=new ee(`Event response for ${t.event} event timed out`);r.call(t,e,t)}t.cid&&this.transport.cancelPendingResponse(t.cid)},ne.prototype._processOutboundEvent=function(t,e,r,n){r=r||{},this.state===this.CLOSED&&this.connect();let o,i={event:t};o=n?new Promise(((t,e)=>{i.callback=(r,n)=>{r?e(r):t(n)}})):Promise.resolve();let s=new Wt.Item;this.options.cloneData?i.data=Kt(e):i.data=e,s.data=i;let a=null==r.ackTimeout?this.ackTimeout:r.ackTimeout;return i.timeout=setTimeout((()=>{this._handleEventAckTimeout(i,s)}),a),this._outboundBuffer.append(s),this.state===this.OPEN&&this._flushOutboundBuffer(),o},ne.prototype.send=function(t){this.transport.send(t)},ne.prototype.transmit=function(t,e,r){return this._processOutboundEvent(t,e,r)},ne.prototype.invoke=function(t,e,r){return this._processOutboundEvent(t,e,r,!0)},ne.prototype.transmitPublish=function(t,e){let r={channel:this._decorateChannelName(t),data:e};return this.transmit("#publish",r)},ne.prototype.invokePublish=function(t,e){let r={channel:this._decorateChannelName(t),data:e};return this.invoke("#publish",r)},ne.prototype._triggerChannelSubscribe=function(t,e){let r=t.name;if(t.state!==Ft.SUBSCRIBED){let n=t.state;t.state=Ft.SUBSCRIBED;let o={oldChannelState:n,newChannelState:t.state,subscriptionOptions:e};this._channelEventDemux.write(`${r}/subscribeStateChange`,o),this._channelEventDemux.write(`${r}/subscribe`,{subscriptionOptions:e}),this.emit("subscribeStateChange",{channel:r,...o}),this.emit("subscribe",{channel:r,subscriptionOptions:e})}},ne.prototype._triggerChannelSubscribeFail=function(t,e,r){let n=e.name,o=!e.options.waitForAuth||this.authState===this.AUTHENTICATED;!!this._channelMap[n]&&o&&(delete this._channelMap[n],this._channelEventDemux.write(`${n}/subscribeFail`,{error:t,subscriptionOptions:r}),this.emit("subscribeFail",{error:t,channel:n,subscriptionOptions:r}))},ne.prototype._cancelPendingSubscribeCallback=function(t){null!=t._pendingSubscriptionCid&&(this.transport.cancelPendingResponse(t._pendingSubscriptionCid),delete t._pendingSubscriptionCid)},ne.prototype._decorateChannelName=function(t){return this.channelPrefix&&(t=this.channelPrefix+t),t},ne.prototype._undecorateChannelName=function(t){return this.channelPrefix&&0===t.indexOf(this.channelPrefix)?t.replace(this.channelPrefix,""):t},ne.prototype.startBatch=function(){this.transport.startBatch()},ne.prototype.flushBatch=function(){this.transport.flushBatch()},ne.prototype.cancelBatch=function(){this.transport.cancelBatch()},ne.prototype._startBatching=function(){null==this._batchingIntervalId&&(this.startBatch(),this._batchingIntervalId=setInterval((()=>{this.flushBatch(),this.startBatch()}),this.options.batchInterval))},ne.prototype.startBatching=function(){this.isBatching=!0,this._startBatching()},ne.prototype._stopBatching=function(){null!=this._batchingIntervalId&&clearInterval(this._batchingIntervalId),this._batchingIntervalId=null,this.flushBatch()},ne.prototype.stopBatching=function(){this.isBatching=!1,this._stopBatching()},ne.prototype._cancelBatching=function(){null!=this._batchingIntervalId&&clearInterval(this._batchingIntervalId),this._batchingIntervalId=null,this.cancelBatch()},ne.prototype.cancelBatching=function(){this.isBatching=!1,this._cancelBatching()},ne.prototype._trySubscribe=function(t){let e=!t.options.waitForAuth||this.authState===this.AUTHENTICATED;if(this.state===this.OPEN&&!this.preparingPendingSubscriptions&&null==t._pendingSubscriptionCid&&e){let e={noTimeout:!0},r={};t.options.waitForAuth&&(e.waitForAuth=!0,r.waitForAuth=e.waitForAuth),t.options.data&&(r.data=t.options.data),t._pendingSubscriptionCid=this.transport.invokeRaw("#subscribe",{channel:this._decorateChannelName(t.name),...r},e,(e=>{if(e){if("BadConnectionError"===e.name)return;delete t._pendingSubscriptionCid,this._triggerChannelSubscribeFail(e,t,r)}else delete t._pendingSubscriptionCid,this._triggerChannelSubscribe(t,r)})),this.emit("subscribeRequest",{channel:t.name,subscriptionOptions:r})}},ne.prototype.subscribe=function(t,e){e=e||{};let r=this._channelMap[t],n={waitForAuth:!!e.waitForAuth};return null!=e.priority&&(n.priority=e.priority),void 0!==e.data&&(n.data=e.data),r?e&&(r.options=n):(r={name:t,state:Ft.PENDING,options:n},this._channelMap[t]=r,this._trySubscribe(r)),new Ft(t,this,this._channelEventDemux,this._channelDataDemux)},ne.prototype._triggerChannelUnsubscribe=function(t,e){let r=t.name;if(this._cancelPendingSubscribeCallback(t),t.state===Ft.SUBSCRIBED){let n={oldChannelState:t.state,newChannelState:e?Ft.PENDING:Ft.UNSUBSCRIBED};this._channelEventDemux.write(`${r}/subscribeStateChange`,n),this._channelEventDemux.write(`${r}/unsubscribe`,{}),this.emit("subscribeStateChange",{channel:r,...n}),this.emit("unsubscribe",{channel:r})}e?t.state=Ft.PENDING:delete this._channelMap[r]},ne.prototype._tryUnsubscribe=function(t){if(this.state===this.OPEN){let e={noTimeout:!0};this._cancelPendingSubscribeCallback(t);let r=this._decorateChannelName(t.name);this.transport.transmit("#unsubscribe",r,e)}},ne.prototype.unsubscribe=function(t){let e=this._channelMap[t];e&&(this._triggerChannelUnsubscribe(e),this._tryUnsubscribe(e))},ne.prototype.receiver=function(t){return this._receiverDemux.stream(t)},ne.prototype.closeReceiver=function(t){this._receiverDemux.close(t)},ne.prototype.closeAllReceivers=function(){this._receiverDemux.closeAll()},ne.prototype.killReceiver=function(t){this._receiverDemux.kill(t)},ne.prototype.killAllReceivers=function(){this._receiverDemux.killAll()},ne.prototype.killReceiverConsumer=function(t){this._receiverDemux.killConsumer(t)},ne.prototype.getReceiverConsumerStats=function(t){return this._receiverDemux.getConsumerStats(t)},ne.prototype.getReceiverConsumerStatsList=function(t){return this._receiverDemux.getConsumerStatsList(t)},ne.prototype.getAllReceiversConsumerStatsList=function(){return this._receiverDemux.getConsumerStatsListAll()},ne.prototype.getReceiverBackpressure=function(t){return this._receiverDemux.getBackpressure(t)},ne.prototype.getAllReceiversBackpressure=function(){return this._receiverDemux.getBackpressureAll()},ne.prototype.getReceiverConsumerBackpressure=function(t){return this._receiverDemux.getConsumerBackpressure(t)},ne.prototype.hasReceiverConsumer=function(t,e){return this._receiverDemux.hasConsumer(t,e)},ne.prototype.hasAnyReceiverConsumer=function(t){return this._receiverDemux.hasConsumerAll(t)},ne.prototype.procedure=function(t){return this._procedureDemux.stream(t)},ne.prototype.closeProcedure=function(t){this._procedureDemux.close(t)},ne.prototype.closeAllProcedures=function(){this._procedureDemux.closeAll()},ne.prototype.killProcedure=function(t){this._procedureDemux.kill(t)},ne.prototype.killAllProcedures=function(){this._procedureDemux.killAll()},ne.prototype.killProcedureConsumer=function(t){this._procedureDemux.killConsumer(t)},ne.prototype.getProcedureConsumerStats=function(t){return this._procedureDemux.getConsumerStats(t)},ne.prototype.getProcedureConsumerStatsList=function(t){return this._procedureDemux.getConsumerStatsList(t)},ne.prototype.getAllProceduresConsumerStatsList=function(){return this._procedureDemux.getConsumerStatsListAll()},ne.prototype.getProcedureBackpressure=function(t){return this._procedureDemux.getBackpressure(t)},ne.prototype.getAllProceduresBackpressure=function(){return this._procedureDemux.getBackpressureAll()},ne.prototype.getProcedureConsumerBackpressure=function(t){return this._procedureDemux.getConsumerBackpressure(t)},ne.prototype.hasProcedureConsumer=function(t,e){return this._procedureDemux.hasConsumer(t,e)},ne.prototype.hasAnyProcedureConsumer=function(t){return this._procedureDemux.hasConsumerAll(t)},ne.prototype.channel=function(t){return this._channelMap[t],new Ft(t,this,this._channelEventDemux,this._channelDataDemux)},ne.prototype.closeChannel=function(t){this.channelCloseOutput(t),this.channelCloseAllListeners(t)},ne.prototype.closeAllChannelOutputs=function(){this._channelDataDemux.closeAll()},ne.prototype.closeAllChannelListeners=function(){this._channelEventDemux.closeAll()},ne.prototype.closeAllChannels=function(){this.closeAllChannelOutputs(),this.closeAllChannelListeners()},ne.prototype.killChannel=function(t){this.channelKillOutput(t),this.channelKillAllListeners(t)},ne.prototype.killAllChannelOutputs=function(){this._channelDataDemux.killAll()},ne.prototype.killAllChannelListeners=function(){this._channelEventDemux.killAll()},ne.prototype.killAllChannels=function(){this.killAllChannelOutputs(),this.killAllChannelListeners()},ne.prototype.killChannelOutputConsumer=function(t){this._channelDataDemux.killConsumer(t)},ne.prototype.killChannelListenerConsumer=function(t){this._channelEventDemux.killConsumer(t)},ne.prototype.getChannelOutputConsumerStats=function(t){return this._channelDataDemux.getConsumerStats(t)},ne.prototype.getChannelListenerConsumerStats=function(t){return this._channelEventDemux.getConsumerStats(t)},ne.prototype.getAllChannelOutputsConsumerStatsList=function(){return this._channelDataDemux.getConsumerStatsListAll()},ne.prototype.getAllChannelListenersConsumerStatsList=function(){return this._channelEventDemux.getConsumerStatsListAll()},ne.prototype.getChannelBackpressure=function(t){return Math.max(this.channelGetOutputBackpressure(t),this.channelGetAllListenersBackpressure(t))},ne.prototype.getAllChannelOutputsBackpressure=function(){return this._channelDataDemux.getBackpressureAll()},ne.prototype.getAllChannelListenersBackpressure=function(){return this._channelEventDemux.getBackpressureAll()},ne.prototype.getAllChannelsBackpressure=function(){return Math.max(this.getAllChannelOutputsBackpressure(),this.getAllChannelListenersBackpressure())},ne.prototype.getChannelListenerConsumerBackpressure=function(t){return this._channelEventDemux.getConsumerBackpressure(t)},ne.prototype.getChannelOutputConsumerBackpressure=function(t){return this._channelDataDemux.getConsumerBackpressure(t)},ne.prototype.hasAnyChannelOutputConsumer=function(t){return this._channelDataDemux.hasConsumerAll(t)},ne.prototype.hasAnyChannelListenerConsumer=function(t){return this._channelEventDemux.hasConsumerAll(t)},ne.prototype.getChannelState=function(t){let e=this._channelMap[t];return e?e.state:Ft.UNSUBSCRIBED},ne.prototype.getChannelOptions=function(t){let e=this._channelMap[t];return e?{...e.options}:{}},ne.prototype._getAllChannelStreamNames=function(t){let e=this._channelEventDemux.getConsumerStatsListAll().filter((e=>0===e.stream.indexOf(`${t}/`))).reduce(((t,e)=>(t[e.stream]=!0,t)),{});return Object.keys(e)},ne.prototype.channelCloseOutput=function(t){this._channelDataDemux.close(t)},ne.prototype.channelCloseListener=function(t,e){this._channelEventDemux.close(`${t}/${e}`)},ne.prototype.channelCloseAllListeners=function(t){this._getAllChannelStreamNames(t).forEach((t=>{this._channelEventDemux.close(t)}))},ne.prototype.channelKillOutput=function(t){this._channelDataDemux.kill(t)},ne.prototype.channelKillListener=function(t,e){this._channelEventDemux.kill(`${t}/${e}`)},ne.prototype.channelKillAllListeners=function(t){this._getAllChannelStreamNames(t).forEach((t=>{this._channelEventDemux.kill(t)}))},ne.prototype.channelGetOutputConsumerStatsList=function(t){return this._channelDataDemux.getConsumerStatsList(t)},ne.prototype.channelGetListenerConsumerStatsList=function(t,e){return this._channelEventDemux.getConsumerStatsList(`${t}/${e}`)},ne.prototype.channelGetAllListenersConsumerStatsList=function(t){return this._getAllChannelStreamNames(t).map((t=>this._channelEventDemux.getConsumerStatsList(t))).reduce(((t,e)=>(e.forEach((e=>{t.push(e)})),t)),[])},ne.prototype.channelGetOutputBackpressure=function(t){return this._channelDataDemux.getBackpressure(t)},ne.prototype.channelGetListenerBackpressure=function(t,e){return this._channelEventDemux.getBackpressure(`${t}/${e}`)},ne.prototype.channelGetAllListenersBackpressure=function(t){let e=this._getAllChannelStreamNames(t).map((t=>this._channelEventDemux.getBackpressure(t)));return Math.max(...e.concat(0))},ne.prototype.channelHasOutputConsumer=function(t,e){return this._channelDataDemux.hasConsumer(t,e)},ne.prototype.channelHasListenerConsumer=function(t,e,r){return this._channelEventDemux.hasConsumer(`${t}/${e}`,r)},ne.prototype.channelHasAnyListenerConsumer=function(t,e){return this._getAllChannelStreamNames(t).some((t=>this._channelEventDemux.hasConsumer(t,e)))},ne.prototype.subscriptions=function(t){let e=[];return Object.keys(this._channelMap).forEach((r=>{(t||this._channelMap[r].state===Ft.SUBSCRIBED)&&e.push(r)})),e},ne.prototype.isSubscribed=function(t,e){let r=this._channelMap[t];return e?!!r:!!r&&r.state===Ft.SUBSCRIBED},ne.prototype.processPendingSubscriptions=function(){this.preparingPendingSubscriptions=!1;let t=[];Object.keys(this._channelMap).forEach((e=>{let r=this._channelMap[e];r.state===Ft.PENDING&&t.push(r)})),t.sort(((t,e)=>{let r=t.options.priority||0,n=e.options.priority||0;return r>n?-1:r<n?1:0})),t.forEach((t=>{this._trySubscribe(t)}))};var oe,ie=ne,se=new Uint8Array(16);function ae(){if(!oe&&!(oe="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return oe(se)}var ue=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function ce(t){return"string"==typeof t&&ue.test(t)}for(var he,le,pe=[],fe=0;fe<256;++fe)pe.push((fe+256).toString(16).substr(1));function me(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=(pe[t[e+0]]+pe[t[e+1]]+pe[t[e+2]]+pe[t[e+3]]+"-"+pe[t[e+4]]+pe[t[e+5]]+"-"+pe[t[e+6]]+pe[t[e+7]]+"-"+pe[t[e+8]]+pe[t[e+9]]+"-"+pe[t[e+10]]+pe[t[e+11]]+pe[t[e+12]]+pe[t[e+13]]+pe[t[e+14]]+pe[t[e+15]]).toLowerCase();if(!ce(r))throw TypeError("Stringified UUID is invalid");return r}var de=0,ye=0;function ge(t){if(!ce(t))throw TypeError("Invalid UUID");var e,r=new Uint8Array(16);return r[0]=(e=parseInt(t.slice(0,8),16))>>>24,r[1]=e>>>16&255,r[2]=e>>>8&255,r[3]=255&e,r[4]=(e=parseInt(t.slice(9,13),16))>>>8,r[5]=255&e,r[6]=(e=parseInt(t.slice(14,18),16))>>>8,r[7]=255&e,r[8]=(e=parseInt(t.slice(19,23),16))>>>8,r[9]=255&e,r[10]=(e=parseInt(t.slice(24,36),16))/1099511627776&255,r[11]=e/4294967296&255,r[12]=e>>>24&255,r[13]=e>>>16&255,r[14]=e>>>8&255,r[15]=255&e,r}function be(t,e,r){function n(t,n,o,i){if("string"==typeof t&&(t=function(t){t=unescape(encodeURIComponent(t));for(var e=[],r=0;r<t.length;++r)e.push(t.charCodeAt(r));return e}(t)),"string"==typeof n&&(n=ge(n)),16!==n.length)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");var s=new Uint8Array(16+t.length);if(s.set(n),s.set(t,n.length),(s=r(s))[6]=15&s[6]|e,s[8]=63&s[8]|128,o){i=i||0;for(var a=0;a<16;++a)o[i+a]=s[a];return o}return me(s)}try{n.name=t}catch(t){}return n.DNS="6ba7b810-9dad-11d1-80b4-00c04fd430c8",n.URL="6ba7b811-9dad-11d1-80b4-00c04fd430c8",n}function ve(t){return 14+(t+64>>>9<<4)+1}function ke(t,e){var r=(65535&t)+(65535&e);return(t>>16)+(e>>16)+(r>>16)<<16|65535&r}function Ee(t,e,r,n,o,i){return ke((s=ke(ke(e,t),ke(n,i)))<<(a=o)|s>>>32-a,r);var s,a}function Ce(t,e,r,n,o,i,s){return Ee(e&r|~e&n,t,e,o,i,s)}function _e(t,e,r,n,o,i,s){return Ee(e&n|r&~n,t,e,o,i,s)}function we(t,e,r,n,o,i,s){return Ee(e^r^n,t,e,o,i,s)}function Se(t,e,r,n,o,i,s){return Ee(r^(e|~n),t,e,o,i,s)}var Ae=be("v3",48,(function(t){if("string"==typeof t){var e=unescape(encodeURIComponent(t));t=new Uint8Array(e.length);for(var r=0;r<e.length;++r)t[r]=e.charCodeAt(r)}return function(t){for(var e=[],r=32*t.length,n="0123456789abcdef",o=0;o<r;o+=8){var i=t[o>>5]>>>o%32&255,s=parseInt(n.charAt(i>>>4&15)+n.charAt(15&i),16);e.push(s)}return e}(function(t,e){t[e>>5]|=128<<e%32,t[ve(e)-1]=e;for(var r=1732584193,n=-271733879,o=-1732584194,i=271733878,s=0;s<t.length;s+=16){var a=r,u=n,c=o,h=i;r=Ce(r,n,o,i,t[s],7,-680876936),i=Ce(i,r,n,o,t[s+1],12,-389564586),o=Ce(o,i,r,n,t[s+2],17,606105819),n=Ce(n,o,i,r,t[s+3],22,-1044525330),r=Ce(r,n,o,i,t[s+4],7,-176418897),i=Ce(i,r,n,o,t[s+5],12,1200080426),o=Ce(o,i,r,n,t[s+6],17,-1473231341),n=Ce(n,o,i,r,t[s+7],22,-45705983),r=Ce(r,n,o,i,t[s+8],7,1770035416),i=Ce(i,r,n,o,t[s+9],12,-1958414417),o=Ce(o,i,r,n,t[s+10],17,-42063),n=Ce(n,o,i,r,t[s+11],22,-1990404162),r=Ce(r,n,o,i,t[s+12],7,1804603682),i=Ce(i,r,n,o,t[s+13],12,-40341101),o=Ce(o,i,r,n,t[s+14],17,-1502002290),r=_e(r,n=Ce(n,o,i,r,t[s+15],22,1236535329),o,i,t[s+1],5,-165796510),i=_e(i,r,n,o,t[s+6],9,-1069501632),o=_e(o,i,r,n,t[s+11],14,643717713),n=_e(n,o,i,r,t[s],20,-373897302),r=_e(r,n,o,i,t[s+5],5,-701558691),i=_e(i,r,n,o,t[s+10],9,38016083),o=_e(o,i,r,n,t[s+15],14,-660478335),n=_e(n,o,i,r,t[s+4],20,-405537848),r=_e(r,n,o,i,t[s+9],5,568446438),i=_e(i,r,n,o,t[s+14],9,-1019803690),o=_e(o,i,r,n,t[s+3],14,-187363961),n=_e(n,o,i,r,t[s+8],20,1163531501),r=_e(r,n,o,i,t[s+13],5,-1444681467),i=_e(i,r,n,o,t[s+2],9,-51403784),o=_e(o,i,r,n,t[s+7],14,1735328473),r=we(r,n=_e(n,o,i,r,t[s+12],20,-1926607734),o,i,t[s+5],4,-378558),i=we(i,r,n,o,t[s+8],11,-2022574463),o=we(o,i,r,n,t[s+11],16,1839030562),n=we(n,o,i,r,t[s+14],23,-35309556),r=we(r,n,o,i,t[s+1],4,-1530992060),i=we(i,r,n,o,t[s+4],11,1272893353),o=we(o,i,r,n,t[s+7],16,-155497632),n=we(n,o,i,r,t[s+10],23,-1094730640),r=we(r,n,o,i,t[s+13],4,681279174),i=we(i,r,n,o,t[s],11,-358537222),o=we(o,i,r,n,t[s+3],16,-722521979),n=we(n,o,i,r,t[s+6],23,76029189),r=we(r,n,o,i,t[s+9],4,-640364487),i=we(i,r,n,o,t[s+12],11,-421815835),o=we(o,i,r,n,t[s+15],16,530742520),r=Se(r,n=we(n,o,i,r,t[s+2],23,-995338651),o,i,t[s],6,-198630844),i=Se(i,r,n,o,t[s+7],10,1126891415),o=Se(o,i,r,n,t[s+14],15,-1416354905),n=Se(n,o,i,r,t[s+5],21,-57434055),r=Se(r,n,o,i,t[s+12],6,1700485571),i=Se(i,r,n,o,t[s+3],10,-1894986606),o=Se(o,i,r,n,t[s+10],15,-1051523),n=Se(n,o,i,r,t[s+1],21,-2054922799),r=Se(r,n,o,i,t[s+8],6,1873313359),i=Se(i,r,n,o,t[s+15],10,-30611744),o=Se(o,i,r,n,t[s+6],15,-1560198380),n=Se(n,o,i,r,t[s+13],21,1309151649),r=Se(r,n,o,i,t[s+4],6,-145523070),i=Se(i,r,n,o,t[s+11],10,-1120210379),o=Se(o,i,r,n,t[s+2],15,718787259),n=Se(n,o,i,r,t[s+9],21,-343485551),r=ke(r,a),n=ke(n,u),o=ke(o,c),i=ke(i,h)}return[r,n,o,i]}(function(t){if(0===t.length)return[];for(var e=8*t.length,r=new Uint32Array(ve(e)),n=0;n<e;n+=8)r[n>>5]|=(255&t[n/8])<<n%32;return r}(t),8*t.length))})),Te=Ae;function Be(t,e,r,n){switch(t){case 0:return e&r^~e&n;case 1:case 3:return e^r^n;case 2:return e&r^e&n^r&n}}function Oe(t,e){return t<<e|t>>>32-e}var Ie=be("v5",80,(function(t){var e=[1518500249,1859775393,2400959708,3395469782],r=[1732584193,4023233417,2562383102,271733878,3285377520];if("string"==typeof t){var n=unescape(encodeURIComponent(t));t=[];for(var o=0;o<n.length;++o)t.push(n.charCodeAt(o))}else Array.isArray(t)||(t=Array.prototype.slice.call(t));t.push(128);for(var i=t.length/4+2,s=Math.ceil(i/16),a=new Array(s),u=0;u<s;++u){for(var c=new Uint32Array(16),h=0;h<16;++h)c[h]=t[64*u+4*h]<<24|t[64*u+4*h+1]<<16|t[64*u+4*h+2]<<8|t[64*u+4*h+3];a[u]=c}a[s-1][14]=8*(t.length-1)/Math.pow(2,32),a[s-1][14]=Math.floor(a[s-1][14]),a[s-1][15]=8*(t.length-1)&4294967295;for(var l=0;l<s;++l){for(var p=new Uint32Array(80),f=0;f<16;++f)p[f]=a[l][f];for(var m=16;m<80;++m)p[m]=Oe(p[m-3]^p[m-8]^p[m-14]^p[m-16],1);for(var d=r[0],y=r[1],g=r[2],b=r[3],v=r[4],k=0;k<80;++k){var E=Math.floor(k/20),C=Oe(d,5)+Be(E,y,g,b)+v+e[E]+p[k]>>>0;v=b,b=g,g=Oe(y,30)>>>0,y=d,d=C}r[0]=r[0]+d>>>0,r[1]=r[1]+y>>>0,r[2]=r[2]+g>>>0,r[3]=r[3]+b>>>0,r[4]=r[4]+v>>>0}return[r[0]>>24&255,r[0]>>16&255,r[0]>>8&255,255&r[0],r[1]>>24&255,r[1]>>16&255,r[1]>>8&255,255&r[1],r[2]>>24&255,r[2]>>16&255,r[2]>>8&255,255&r[2],r[3]>>24&255,r[3]>>16&255,r[3]>>8&255,255&r[3],r[4]>>24&255,r[4]>>16&255,r[4]>>8&255,255&r[4]]})),De=Ie;var xe=Object.freeze({__proto__:null,NIL:"00000000-0000-0000-0000-000000000000",parse:ge,stringify:me,v1:function(t,e,r){var n=e&&r||0,o=e||new Array(16),i=(t=t||{}).node||he,s=void 0!==t.clockseq?t.clockseq:le;if(null==i||null==s){var a=t.random||(t.rng||ae)();null==i&&(i=he=[1|a[0],a[1],a[2],a[3],a[4],a[5]]),null==s&&(s=le=16383&(a[6]<<8|a[7]))}var u=void 0!==t.msecs?t.msecs:Date.now(),c=void 0!==t.nsecs?t.nsecs:ye+1,h=u-de+(c-ye)/1e4;if(h<0&&void 0===t.clockseq&&(s=s+1&16383),(h<0||u>de)&&void 0===t.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");de=u,ye=c,le=s;var l=(1e4*(268435455&(u+=122192928e5))+c)%4294967296;o[n++]=l>>>24&255,o[n++]=l>>>16&255,o[n++]=l>>>8&255,o[n++]=255&l;var p=u/4294967296*1e4&268435455;o[n++]=p>>>8&255,o[n++]=255&p,o[n++]=p>>>24&15|16,o[n++]=p>>>16&255,o[n++]=s>>>8|128,o[n++]=255&s;for(var f=0;f<6;++f)o[n+f]=i[f];return e||me(o)},v3:Te,v4:function(t,e,r){var n=(t=t||{}).random||(t.rng||ae)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,e){r=r||0;for(var o=0;o<16;++o)e[r+o]=n[o];return e}return me(n)},v5:De,validate:ce,version:function(t){if(!ce(t))throw TypeError("Invalid UUID");return parseInt(t.substr(14,1),16)}});const Le=ie,Ne=e(xe),Pe=J.InvalidArgumentsError;function Ue(t,e){let r=null==t.secure?e:t.secure;return t.port||("undefined"!=typeof location&&location.port?location.port:r?443:80)}const Re=ie,je={create:function(t){if((t=t||{}).host&&!t.host.match(/[^:]+:\d{2,5}/))throw new Pe("The host option should include both the hostname and the port number in the hostname:port format");if(t.host&&t.hostname)throw new Pe("The host option should already include the hostname and the port number in the hostname:port format - Because of this, you should never use host and hostname options together");if(t.host&&t.port)throw new Pe("The host option should already include the hostname and the port number in the hostname:port format - Because of this, you should never use host and port options together");let e="undefined"!=typeof location&&"https:"===location.protocol,r={clientId:Ne.v4(),port:Ue(t,e),hostname:"undefined"!=typeof location&&location.hostname||"localhost",secure:e};return Object.assign(r,t),new Le(r)}},Me="19.1.2";var He=r.factory=je,Ge=r.AGClientSocket=Re,$e=r.create=function(t){return je.create({...t,version:Me})},Fe=r.version=Me,ze=t({__proto__:null,AGClientSocket:Ge,create:$e,default:r,factory:He,version:Fe},[r]);const{factory:qe,AGClientSocket:Ve,create:We,version:Ke}=ze;export{Ve as AGClientSocket,We as create,qe as factory,Ke as version};