-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhyperion-stream-client.js
1 lines (1 loc) · 54.5 KB
/
hyperion-stream-client.js
1
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("fetch"));else if("function"==typeof define&&define.amd)define(["fetch"],e);else{var s="object"==typeof exports?e(require("fetch")):e(t.fetch);for(var n in s)("object"==typeof exports?exports:t)[n]=s[n]}}(self,(t=>(()=>{"use strict";var e={265:e=>{e.exports=t}},s={};function n(t){var r=s[t];if(void 0!==r)return r.exports;var i=s[t]={exports:{}};return e[t](i,i.exports,n),i.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var s in e)n.o(e,s)&&!n.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r={};return(()=>{n.r(r),n.d(r,{HyperionStreamClient:()=>ae,StreamClientEvents:()=>ne});var t={};n.r(t),n.d(t,{Decoder:()=>$t,Encoder:()=>zt,PacketType:()=>Qt,protocol:()=>Yt});var e="function"==typeof queueMicrotask&&queueMicrotask,s="function"==typeof setImmediate&&setImmediate,i="object"==typeof process&&"function"==typeof process.nextTick;function o(t){setTimeout(t,0)}function a(t){return(e,...s)=>t((()=>e(...s)))}var c=a(e?queueMicrotask:s?setImmediate:i?process.nextTick:o);function h(t,e){return t.then((t=>{u(e,null,t)}),(t=>{u(e,t&&t.message?t:new Error(t))}))}function u(t,e,s){try{t(e,s)}catch(t){c((t=>{throw t}),t)}}function l(t){return"AsyncFunction"===t[Symbol.toStringTag]}function p(t){if("function"!=typeof t)throw new Error("expected a function");return l(t)?l(e=t)?function(...t){const s=t.pop();return h(e.apply(this,t),s)}:(s=function(t,s){var n;try{n=e.apply(this,t)}catch(t){return s(t)}if(n&&"function"==typeof n.then)return h(n,s);s(null,n)},function(...t){var e=t.pop();return s.call(this,t,e)}):t;var e,s}function f(t,e=t.length){if(!e)throw new Error("arity is undefined");return function(...s){return"function"==typeof s[e-1]?t.apply(this,s):new Promise(((n,r)=>{s[e-1]=(t,...e)=>{if(t)return r(t);n(e.length>1?e:e[0])},t.apply(this,s)}))}}function d(t){return function(e,...s){return f((function(n){var r=this;return t(e,((t,e)=>{p(t).apply(r,s.concat(e))}),n)}))}}function y(t,e,s,n){e=e||[];var r=[],i=0,o=p(s);return t(e,((t,e,s)=>{var n=i++;o(t,((t,e)=>{r[n]=e,s(t)}))}),(t=>{n(t,r)}))}function m(t){return t&&"number"==typeof t.length&&t.length>=0&&t.length%1==0}const g={};function v(t){function e(...e){if(null!==t){var s=t;t=null,s.apply(this,e)}}return Object.assign(e,t),e}function b(t){return function(...e){if(null===t)throw new Error("Callback was already called.");var s=t;t=null,s.apply(this,e)}}function k(t,e,s,n){let r=!1,i=!1,o=!1,a=0,c=0;function h(){a>=e||o||r||(o=!0,t.next().then((({value:t,done:e})=>{if(!i&&!r){if(o=!1,e)return r=!0,void(a<=0&&n(null));a++,s(t,c,u),c++,h()}})).catch(l))}function u(t,e){if(a-=1,!i)return t?l(t):!1===t?(r=!0,void(i=!0)):e===g||r&&a<=0?(r=!0,n(null)):void h()}function l(t){i||(o=!1,r=!0,n(t))}h()}var w=t=>(e,s,n)=>{if(n=v(n),t<=0)throw new RangeError("concurrency limit cannot be less than 1");if(!e)return n(null);if("AsyncGenerator"===e[Symbol.toStringTag])return k(e,t,s,n);if(function(t){return"function"==typeof t[Symbol.asyncIterator]}(e))return k(e[Symbol.asyncIterator](),t,s,n);var r=function(t){if(m(t))return function(t){var e=-1,s=t.length;return function(){return++e<s?{value:t[e],key:e}:null}}(t);var e=function(t){return t[Symbol.iterator]&&t[Symbol.iterator]()}(t);return e?function(t){var e=-1;return function(){var s=t.next();return s.done?null:(e++,{value:s.value,key:e})}}(e):function(t){var e=t?Object.keys(t):[],s=-1,n=e.length;return function r(){var i=e[++s];return"__proto__"===i?r():s<n?{value:t[i],key:i}:null}}(t)}(e),i=!1,o=!1,a=0,c=!1;function h(t,e){if(!o)if(a-=1,t)i=!0,n(t);else if(!1===t)i=!0,o=!0;else{if(e===g||i&&a<=0)return i=!0,n(null);c||u()}}function u(){for(c=!0;a<t&&!i;){var e=r();if(null===e)return i=!0,void(a<=0&&n(null));a+=1,s(e.value,e.key,b(h))}c=!1}u()},_=f((function(t,e,s,n){return w(e)(t,p(s),n)}),4);function E(t,e,s){s=v(s);var n=0,r=0,{length:i}=t,o=!1;function a(t,e){!1===t&&(o=!0),!0!==o&&(t?s(t):++r!==i&&e!==g||s(null))}for(0===i&&s(null);n<i;n++)e(t[n],n,b(a))}function A(t,e,s){return _(t,1/0,e,s)}var R=f((function(t,e,s){return(m(t)?E:A)(t,p(e),s)}),3),L=f((function(t,e,s){return y(R,t,e,s)}),3);d(L);var O=f((function(t,e,s){return _(t,1,e,s)}),3);d(f((function(t,e,s){return y(O,t,e,s)}),3)),Symbol("promiseCallback");class T{constructor(){this.head=this.tail=null,this.length=0}removeLink(t){return t.prev?t.prev.next=t.next:this.head=t.next,t.next?t.next.prev=t.prev:this.tail=t.prev,t.prev=t.next=null,this.length-=1,t}empty(){for(;this.head;)this.shift();return this}insertAfter(t,e){e.prev=t,e.next=t.next,t.next?t.next.prev=e:this.tail=e,t.next=e,this.length+=1}insertBefore(t,e){e.prev=t.prev,e.next=t,t.prev?t.prev.next=e:this.head=e,t.prev=e,this.length+=1}unshift(t){this.head?this.insertBefore(this.head,t):B(this,t)}push(t){this.tail?this.insertAfter(this.tail,t):B(this,t)}shift(){return this.head&&this.removeLink(this.head)}pop(){return this.tail&&this.removeLink(this.tail)}toArray(){return[...this]}*[Symbol.iterator](){for(var t=this.head;t;)yield t.data,t=t.next}remove(t){for(var e=this.head;e;){var{next:s}=e;t(e)&&this.removeLink(e),e=s}return this}}function B(t,e){t.length=1,t.head=t.tail=e}function x(t,e,s){if(null==e)e=1;else if(0===e)throw new RangeError("Concurrency must not be zero");var n=p(t),r=0,i=[];const o={error:[],drain:[],saturated:[],unsaturated:[],empty:[]};function a(t,e){return t?e?void(o[t]=o[t].filter((t=>t!==e))):o[t]=[]:Object.keys(o).forEach((t=>o[t]=[]))}function h(t,...e){o[t].forEach((t=>t(...e)))}var u=!1;function l(t,e,s,n){if(null!=n&&"function"!=typeof n)throw new Error("task callback must be a function");var r,i;function o(t,...e){return t?s?i(t):r():e.length<=1?r(e[0]):void r(e)}g.started=!0;var a=g._createTaskItem(t,s?o:n||o);if(e?g._tasks.unshift(a):g._tasks.push(a),u||(u=!0,c((()=>{u=!1,g.process()}))),s||!n)return new Promise(((t,e)=>{r=t,i=e}))}function f(t){return function(e,...s){r-=1;for(var n=0,o=t.length;n<o;n++){var a=t[n],c=i.indexOf(a);0===c?i.shift():c>0&&i.splice(c,1),a.callback(e,...s),null!=e&&h("error",e,a.data)}r<=g.concurrency-g.buffer&&h("unsaturated"),g.idle()&&h("drain"),g.process()}}function d(t){return!(0!==t.length||!g.idle()||(c((()=>h("drain"))),0))}const y=t=>e=>{if(!e)return new Promise(((e,s)=>{!function(t,n){const r=(...n)=>{a(t,r),((t,n)=>{if(t)return s(t);e(n)})(...n)};o[t].push(r)}(t)}));a(t),function(t,e){o[t].push(e)}(t,e)};var m=!1,g={_tasks:new T,_createTaskItem:(t,e)=>({data:t,callback:e}),*[Symbol.iterator](){yield*g._tasks[Symbol.iterator]()},concurrency:e,payload:s,buffer:e/4,started:!1,paused:!1,push(t,e){if(Array.isArray(t)){if(d(t))return;return t.map((t=>l(t,!1,!1,e)))}return l(t,!1,!1,e)},pushAsync(t,e){if(Array.isArray(t)){if(d(t))return;return t.map((t=>l(t,!1,!0,e)))}return l(t,!1,!0,e)},kill(){a(),g._tasks.empty()},unshift(t,e){if(Array.isArray(t)){if(d(t))return;return t.map((t=>l(t,!0,!1,e)))}return l(t,!0,!1,e)},unshiftAsync(t,e){if(Array.isArray(t)){if(d(t))return;return t.map((t=>l(t,!0,!0,e)))}return l(t,!0,!0,e)},remove(t){g._tasks.remove(t)},process(){if(!m){for(m=!0;!g.paused&&r<g.concurrency&&g._tasks.length;){var t=[],e=[],s=g._tasks.length;g.payload&&(s=Math.min(s,g.payload));for(var o=0;o<s;o++){var a=g._tasks.shift();t.push(a),i.push(a),e.push(a.data)}r+=1,0===g._tasks.length&&h("empty"),r===g.concurrency&&h("saturated");var c=b(f(t));n(e,c)}m=!1}},length:()=>g._tasks.length,running:()=>r,workersList:()=>i,idle:()=>g._tasks.length+r===0,pause(){g.paused=!0},resume(){!1!==g.paused&&(g.paused=!1,c(g.process))}};return Object.defineProperties(g,{saturated:{writable:!1,value:y("saturated")},unsaturated:{writable:!1,value:y("unsaturated")},empty:{writable:!1,value:y("empty")},drain:{writable:!1,value:y("drain")},error:{writable:!1,value:y("error")}}),g}f((function(t,e,s,n){n=v(n);var r=p(s);return O(t,((t,s,n)=>{r(e,t,((t,s)=>{e=s,n(t)}))}),(t=>n(t,e)))}),4);var C=f((function(t,e,s,n){return y(w(e),t,s,n)}),4),S=f((function(t,e,s,n){var r=p(s);return C(t,e,((t,e)=>{r(t,((t,...s)=>t?e(t):e(t,s)))}),((t,e)=>{for(var s=[],r=0;r<e.length;r++)e[r]&&(s=s.concat(...e[r]));return n(t,s)}))}),4);function N(t,e){return(s,n,r,i)=>{var o,a=!1;const c=p(r);s(n,((s,n,r)=>{c(s,((n,i)=>n||!1===n?r(n):t(i)&&!o?(a=!0,o=e(!0,s),r(null,g)):void r()))}),(t=>{if(t)return i(t);i(null,a?o:e(!1))}))}}function q(t){return(e,...s)=>p(e)(...s,((e,...s)=>{"object"==typeof console&&(e?console.error&&console.error(e):console[t]&&s.forEach((e=>console[t](e))))}))}function D(t){return(e,s,n)=>t(e,n)}f((function(t,e,s){return S(t,1/0,e,s)}),3),f((function(t,e,s){return S(t,1,e,s)}),3),f((function(t,e,s){return N((t=>t),((t,e)=>e))(R,t,e,s)}),3),f((function(t,e,s,n){return N((t=>t),((t,e)=>e))(w(e),t,s,n)}),4),f((function(t,e,s){return N((t=>t),((t,e)=>e))(w(1),t,e,s)}),3),q("dir"),f((function(t,e,s){s=b(s);var n,r=p(t),i=p(e);function o(t,...e){if(t)return s(t);!1!==t&&(n=e,i(...e,a))}function a(t,e){return t?s(t):!1!==t?e?void r(o):s(null,...n):void 0}return a(null,!0)}),3),f((function(t,e,s){return R(t,D(p(e)),s)}),3);var P=f((function(t,e,s,n){return w(e)(t,D(p(s)),n)}),4),j=f((function(t,e,s){return P(t,1,e,s)}),3);function I(t,e,s,n){var r=new Array(e.length);t(e,((t,e,n)=>{s(t,((t,s)=>{r[e]=!!s,n(t)}))}),(t=>{if(t)return n(t);for(var s=[],i=0;i<e.length;i++)r[i]&&s.push(e[i]);n(null,s)}))}function M(t,e,s,n){var r=[];t(e,((t,e,n)=>{s(t,((s,i)=>{if(s)return n(s);i&&r.push({index:e,value:t}),n(s)}))}),(t=>{if(t)return n(t);n(null,r.sort(((t,e)=>t.index-e.index)).map((t=>t.value)))}))}function U(t,e,s,n){return(m(e)?I:M)(t,e,p(s),n)}function F(t,e){var s=p(t);return x(((t,e)=>{s(t[0],e)}),e,1)}f((function(t,e,s){return N((t=>!t),(t=>!t))(R,t,e,s)}),3),f((function(t,e,s,n){return N((t=>!t),(t=>!t))(w(e),t,s,n)}),4),f((function(t,e,s){return N((t=>!t),(t=>!t))(O,t,e,s)}),3),f((function(t,e,s){return U(R,t,e,s)}),3),f((function(t,e,s,n){return U(w(e),t,s,n)}),4),f((function(t,e,s){return U(O,t,e,s)}),3),f((function(t,e){var s=b(e),n=p(function(t){return l(t)?t:function(...e){var s=e.pop(),n=!0;e.push(((...t)=>{n?c((()=>s(...t))):s(...t)})),t.apply(this,e),n=!1}}(t));return function t(e){if(e)return s(e);!1!==e&&n(t)}()}),2),f((function(t,e,s,n){var r=p(s);return C(t,e,((t,e)=>{r(t,((s,n)=>s?e(s):e(s,{key:n,val:t})))}),((t,e)=>{for(var s={},{hasOwnProperty:r}=Object.prototype,i=0;i<e.length;i++)if(e[i]){var{key:o}=e[i],{val:a}=e[i];r.call(s,o)?s[o].push(a):s[o]=[a]}return n(t,s)}))}),4),q("log"),f((function(t,e,s,n){n=v(n);var r={},i=p(s);return w(e)(t,((t,e,s)=>{i(t,e,((t,n)=>{if(t)return s(t);r[e]=n,s(t)}))}),(t=>n(t,r)))}),4),a(i?process.nextTick:s?setImmediate:o),f(((t,e,s)=>{var n=m(e)?[]:{};t(e,((t,e,s)=>{p(t)(((t,...r)=>{r.length<2&&([r]=r),n[e]=r,s(t)}))}),(t=>s(t,n)))}),3);class H{constructor(){this.heap=[],this.pushCount=Number.MIN_SAFE_INTEGER}get length(){return this.heap.length}empty(){return this.heap=[],this}percUp(t){let e;for(;t>0&&smaller(this.heap[t],this.heap[async_parent(t)]);){let s=this.heap[t];this.heap[t]=this.heap[e],this.heap[e]=s}}percDown(t){let e;for(;leftChi(t)<this.heap.length&&(NaN<this.heap.length&&smaller(this.heap.NaN,this.heap[e]),!smaller(this.heap[t],this.heap[e]));){let s=this.heap[t];this.heap[t]=this.heap[e],this.heap[e]=s}}push(t){t.pushCount=++this.pushCount,this.heap.push(t),this.percUp(this.heap.length-1)}unshift(t){return this.heap.push(t)}shift(){let[t]=this.heap;return this.heap[0]=this.heap[this.heap.length-1],this.heap.pop(),this.percDown(0),t}toArray(){return[...this]}*[Symbol.iterator](){for(let t=0;t<this.heap.length;t++)yield this.heap[t].data}remove(t){for(let e=0;e<this.heap.length;e++)t(this.heap[e])||(this.heap[0]=this.heap[e]);this.heap.splice(0);for(let t=async_parent(this.heap.length-1);t>=0;t--)this.percDown(t);return this}}function V(t,e,s,n){const r=p(s);return U(t,e,((t,e)=>{r(t,((t,s)=>{e(t,!s)}))}),n)}f((function(t,e){if(e=v(e),!Array.isArray(t))return e(new TypeError("First argument to race must be an array of functions"));if(!t.length)return e();for(var s=0,n=t.length;s<n;s++)p(t[s])(e)}),2),f((function(t,e,s){return V(R,t,e,s)}),3),f((function(t,e,s,n){return V(w(e),t,s,n)}),4),f((function(t,e,s){return V(O,t,e,s)}),3),f((function(t,e,s){return N(Boolean,(t=>t))(R,t,e,s)}),3),f((function(t,e,s,n){return N(Boolean,(t=>t))(w(e),t,s,n)}),4),f((function(t,e,s){return N(Boolean,(t=>t))(O,t,e,s)}),3),f((function(t,e,s){var n=p(e);return L(t,((t,e)=>{n(t,((s,n)=>{if(s)return e(s);e(s,{value:t,criteria:n})}))}),((t,e)=>{if(t)return s(t);s(null,e.sort(r).map((t=>t.value)))}));function r(t,e){var s=t.criteria,n=e.criteria;return s<n?-1:s>n?1:0}}),3),f((function(t,e){var s,n=null;return j(t,((t,e)=>{p(t)(((t,...r)=>{if(!1===t)return e(t);r.length<2?[s]=r:s=r,n=t,e(t?null:{})}))}),(()=>e(n,s)))})),f((function(t,e,s){s=b(s);var n=p(e),r=p(t),i=[];function o(t,...e){if(t)return s(t);i=e,!1!==t&&r(a)}function a(t,e){return t?s(t):!1!==t?e?void n(o):s(null,...i):void 0}return r(a)}),3),f((function(t,e){if(e=v(e),!Array.isArray(t))return e(new Error("First argument to waterfall must be an array of functions"));if(!t.length)return e();var s=0;function n(e){p(t[s++])(...e,b(r))}function r(r,...i){if(!1!==r)return r||s===t.length?e(r,...i):void n(i)}n([])}));const K=Object.create(null);K.open="0",K.close="1",K.ping="2",K.pong="3",K.message="4",K.upgrade="5",K.noop="6";const Y=Object.create(null);Object.keys(K).forEach((t=>{Y[K[t]]=t}));const Q={type:"error",data:"parser error"},z="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Object.prototype.toString.call(Blob),$="function"==typeof ArrayBuffer,W=(t,e)=>{const s=new FileReader;return s.onload=function(){const t=s.result.split(",")[1];e("b"+t)},s.readAsDataURL(t)},J=({type:t,data:e},s,n)=>{return z&&e instanceof Blob?s?n(e):W(e,n):$&&(e instanceof ArrayBuffer||(r=e,"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(r):r&&r.buffer instanceof ArrayBuffer))?s?n(e):W(new Blob([e]),n):n(K[t]+(e||""));var r},X="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",G="undefined"==typeof Uint8Array?[]:new Uint8Array(256);for(let t=0;t<X.length;t++)G[X.charCodeAt(t)]=t;const Z="function"==typeof ArrayBuffer,tt=(t,e)=>{if(Z){const s=(t=>{let e,s,n,r,i,o=.75*t.length,a=t.length,c=0;"="===t[t.length-1]&&(o--,"="===t[t.length-2]&&o--);const h=new ArrayBuffer(o),u=new Uint8Array(h);for(e=0;e<a;e+=4)s=G[t.charCodeAt(e)],n=G[t.charCodeAt(e+1)],r=G[t.charCodeAt(e+2)],i=G[t.charCodeAt(e+3)],u[c++]=s<<2|n>>4,u[c++]=(15&n)<<4|r>>2,u[c++]=(3&r)<<6|63&i;return h})(t);return et(s,e)}return{base64:!0,data:t}},et=(t,e)=>"blob"===e&&t instanceof ArrayBuffer?new Blob([t]):t,st=(t,e)=>{if("string"!=typeof t)return{type:"message",data:et(t,e)};const s=t.charAt(0);return"b"===s?{type:"message",data:tt(t.substring(1),e)}:Y[s]?t.length>1?{type:Y[s],data:t.substring(1)}:{type:Y[s]}:Q},nt=String.fromCharCode(30);function rt(t){if(t)return function(t){for(var e in rt.prototype)t[e]=rt.prototype[e];return t}(t)}rt.prototype.on=rt.prototype.addEventListener=function(t,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(e),this},rt.prototype.once=function(t,e){function s(){this.off(t,s),e.apply(this,arguments)}return s.fn=e,this.on(t,s),this},rt.prototype.off=rt.prototype.removeListener=rt.prototype.removeAllListeners=rt.prototype.removeEventListener=function(t,e){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var s,n=this._callbacks["$"+t];if(!n)return this;if(1==arguments.length)return delete this._callbacks["$"+t],this;for(var r=0;r<n.length;r++)if((s=n[r])===e||s.fn===e){n.splice(r,1);break}return 0===n.length&&delete this._callbacks["$"+t],this},rt.prototype.emit=function(t){this._callbacks=this._callbacks||{};for(var e=new Array(arguments.length-1),s=this._callbacks["$"+t],n=1;n<arguments.length;n++)e[n-1]=arguments[n];if(s){n=0;for(var r=(s=s.slice(0)).length;n<r;++n)s[n].apply(this,e)}return this},rt.prototype.emitReserved=rt.prototype.emit,rt.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks["$"+t]||[]},rt.prototype.hasListeners=function(t){return!!this.listeners(t).length};const it="undefined"!=typeof self?self:"undefined"!=typeof window?window:Function("return this")();function ot(t,...e){return e.reduce(((e,s)=>(t.hasOwnProperty(s)&&(e[s]=t[s]),e)),{})}const at=setTimeout,ct=clearTimeout;function ht(t,e){e.useNativeTimers?(t.setTimeoutFn=at.bind(it),t.clearTimeoutFn=ct.bind(it)):(t.setTimeoutFn=setTimeout.bind(it),t.clearTimeoutFn=clearTimeout.bind(it))}class ut extends Error{constructor(t,e,s){super(t),this.description=e,this.context=s,this.type="TransportError"}}class lt extends rt{constructor(t){super(),this.writable=!1,ht(this,t),this.opts=t,this.query=t.query,this.readyState="",this.socket=t.socket}onError(t,e,s){return super.emitReserved("error",new ut(t,e,s)),this}open(){return"closed"!==this.readyState&&""!==this.readyState||(this.readyState="opening",this.doOpen()),this}close(){return"opening"!==this.readyState&&"open"!==this.readyState||(this.doClose(),this.onClose()),this}send(t){"open"===this.readyState&&this.write(t)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(t){const e=st(t,this.socket.binaryType);this.onPacket(e)}onPacket(t){super.emitReserved("packet",t)}onClose(t){this.readyState="closed",super.emitReserved("close",t)}}const pt="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),ft={};let dt,yt=0,mt=0;function gt(t){let e="";do{e=pt[t%64]+e,t=Math.floor(t/64)}while(t>0);return e}function vt(){const t=gt(+new Date);return t!==dt?(yt=0,dt=t):t+"."+gt(yt++)}for(;mt<64;mt++)ft[pt[mt]]=mt;function bt(t){let e="";for(let s in t)t.hasOwnProperty(s)&&(e.length&&(e+="&"),e+=encodeURIComponent(s)+"="+encodeURIComponent(t[s]));return e}let kt=!1;try{kt="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(t){}const wt=kt;function _t(t){const e=t.xdomain;try{if("undefined"!=typeof XMLHttpRequest&&(!e||wt))return new XMLHttpRequest}catch(t){}if(!e)try{return new(it[["Active"].concat("Object").join("X")])("Microsoft.XMLHTTP")}catch(t){}}function Et(){}const At=null!=new _t({xdomain:!1}).responseType;class Rt extends rt{constructor(t,e){super(),ht(this,e),this.opts=e,this.method=e.method||"GET",this.uri=t,this.async=!1!==e.async,this.data=void 0!==e.data?e.data:null,this.create()}create(){const t=ot(this.opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");t.xdomain=!!this.opts.xd,t.xscheme=!!this.opts.xs;const e=this.xhr=new _t(t);try{e.open(this.method,this.uri,this.async);try{if(this.opts.extraHeaders){e.setDisableHeaderCheck&&e.setDisableHeaderCheck(!0);for(let t in this.opts.extraHeaders)this.opts.extraHeaders.hasOwnProperty(t)&&e.setRequestHeader(t,this.opts.extraHeaders[t])}}catch(t){}if("POST"===this.method)try{e.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(t){}try{e.setRequestHeader("Accept","*/*")}catch(t){}"withCredentials"in e&&(e.withCredentials=this.opts.withCredentials),this.opts.requestTimeout&&(e.timeout=this.opts.requestTimeout),e.onreadystatechange=()=>{4===e.readyState&&(200===e.status||1223===e.status?this.onLoad():this.setTimeoutFn((()=>{this.onError("number"==typeof e.status?e.status:0)}),0))},e.send(this.data)}catch(t){return void this.setTimeoutFn((()=>{this.onError(t)}),0)}"undefined"!=typeof document&&(this.index=Rt.requestsCount++,Rt.requests[this.index]=this)}onError(t){this.emitReserved("error",t,this.xhr),this.cleanup(!0)}cleanup(t){if(void 0!==this.xhr&&null!==this.xhr){if(this.xhr.onreadystatechange=Et,t)try{this.xhr.abort()}catch(t){}"undefined"!=typeof document&&delete Rt.requests[this.index],this.xhr=null}}onLoad(){const t=this.xhr.responseText;null!==t&&(this.emitReserved("data",t),this.emitReserved("success"),this.cleanup())}abort(){this.cleanup()}}function Lt(){for(let t in Rt.requests)Rt.requests.hasOwnProperty(t)&&Rt.requests[t].abort()}Rt.requestsCount=0,Rt.requests={},"undefined"!=typeof document&&("function"==typeof attachEvent?attachEvent("onunload",Lt):"function"==typeof addEventListener&&addEventListener("onpagehide"in it?"pagehide":"unload",Lt,!1));const Ot="function"==typeof Promise&&"function"==typeof Promise.resolve?t=>Promise.resolve().then(t):(t,e)=>e(t,0),Tt=it.WebSocket||it.MozWebSocket,Bt="undefined"!=typeof navigator&&"string"==typeof navigator.product&&"reactnative"===navigator.product.toLowerCase(),xt={websocket:class extends lt{constructor(t){super(t),this.supportsBinary=!t.forceBase64}get name(){return"websocket"}doOpen(){if(!this.check())return;const t=this.uri(),e=this.opts.protocols,s=Bt?{}:ot(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(s.headers=this.opts.extraHeaders);try{this.ws=Bt?new Tt(t,e,s):e?new Tt(t,e):new Tt(t)}catch(t){return this.emitReserved("error",t)}this.ws.binaryType=this.socket.binaryType||"arraybuffer",this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=t=>this.onClose({description:"websocket connection closed",context:t}),this.ws.onmessage=t=>this.onData(t.data),this.ws.onerror=t=>this.onError("websocket error",t)}write(t){this.writable=!1;for(let e=0;e<t.length;e++){const s=t[e],n=e===t.length-1;J(s,this.supportsBinary,(t=>{try{this.ws.send(t)}catch(t){}n&&Ot((()=>{this.writable=!0,this.emitReserved("drain")}),this.setTimeoutFn)}))}}doClose(){void 0!==this.ws&&(this.ws.close(),this.ws=null)}uri(){let t=this.query||{};const e=this.opts.secure?"wss":"ws";let s="";this.opts.port&&("wss"===e&&443!==Number(this.opts.port)||"ws"===e&&80!==Number(this.opts.port))&&(s=":"+this.opts.port),this.opts.timestampRequests&&(t[this.opts.timestampParam]=vt()),this.supportsBinary||(t.b64=1);const n=bt(t);return e+"://"+(-1!==this.opts.hostname.indexOf(":")?"["+this.opts.hostname+"]":this.opts.hostname)+s+this.opts.path+(n.length?"?"+n:"")}check(){return!!Tt}},polling:class extends lt{constructor(t){if(super(t),this.polling=!1,"undefined"!=typeof location){const e="https:"===location.protocol;let s=location.port;s||(s=e?"443":"80"),this.xd="undefined"!=typeof location&&t.hostname!==location.hostname||s!==t.port,this.xs=t.secure!==e}const e=t&&t.forceBase64;this.supportsBinary=At&&!e}get name(){return"polling"}doOpen(){this.poll()}pause(t){this.readyState="pausing";const e=()=>{this.readyState="paused",t()};if(this.polling||!this.writable){let t=0;this.polling&&(t++,this.once("pollComplete",(function(){--t||e()}))),this.writable||(t++,this.once("drain",(function(){--t||e()})))}else e()}poll(){this.polling=!0,this.doPoll(),this.emitReserved("poll")}onData(t){((t,e)=>{const s=t.split(nt),n=[];for(let t=0;t<s.length;t++){const r=st(s[t],e);if(n.push(r),"error"===r.type)break}return n})(t,this.socket.binaryType).forEach((t=>{if("opening"===this.readyState&&"open"===t.type&&this.onOpen(),"close"===t.type)return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(t)})),"closed"!==this.readyState&&(this.polling=!1,this.emitReserved("pollComplete"),"open"===this.readyState&&this.poll())}doClose(){const t=()=>{this.write([{type:"close"}])};"open"===this.readyState?t():this.once("open",t)}write(t){this.writable=!1,((t,e)=>{const s=t.length,n=new Array(s);let r=0;t.forEach(((t,i)=>{J(t,!1,(t=>{n[i]=t,++r===s&&e(n.join(nt))}))}))})(t,(t=>{this.doWrite(t,(()=>{this.writable=!0,this.emitReserved("drain")}))}))}uri(){let t=this.query||{};const e=this.opts.secure?"https":"http";let s="";!1!==this.opts.timestampRequests&&(t[this.opts.timestampParam]=vt()),this.supportsBinary||t.sid||(t.b64=1),this.opts.port&&("https"===e&&443!==Number(this.opts.port)||"http"===e&&80!==Number(this.opts.port))&&(s=":"+this.opts.port);const n=bt(t);return e+"://"+(-1!==this.opts.hostname.indexOf(":")?"["+this.opts.hostname+"]":this.opts.hostname)+s+this.opts.path+(n.length?"?"+n:"")}request(t={}){return Object.assign(t,{xd:this.xd,xs:this.xs},this.opts),new Rt(this.uri(),t)}doWrite(t,e){const s=this.request({method:"POST",data:t});s.on("success",e),s.on("error",((t,e)=>{this.onError("xhr post error",t,e)}))}doPoll(){const t=this.request();t.on("data",this.onData.bind(this)),t.on("error",((t,e)=>{this.onError("xhr poll error",t,e)})),this.pollXhr=t}}},Ct=/^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,St=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function Nt(t){const e=t,s=t.indexOf("["),n=t.indexOf("]");-1!=s&&-1!=n&&(t=t.substring(0,s)+t.substring(s,n).replace(/:/g,";")+t.substring(n,t.length));let r=Ct.exec(t||""),i={},o=14;for(;o--;)i[St[o]]=r[o]||"";return-1!=s&&-1!=n&&(i.source=e,i.host=i.host.substring(1,i.host.length-1).replace(/;/g,":"),i.authority=i.authority.replace("[","").replace("]","").replace(/;/g,":"),i.ipv6uri=!0),i.pathNames=function(t,e){const s=e.replace(/\/{2,9}/g,"/").split("/");return"/"!=e.slice(0,1)&&0!==e.length||s.splice(0,1),"/"==e.slice(-1)&&s.splice(s.length-1,1),s}(0,i.path),i.queryKey=function(t,e){const s={};return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,(function(t,e,n){e&&(s[e]=n)})),s}(0,i.query),i}class qt extends rt{constructor(t,e={}){super(),t&&"object"==typeof t&&(e=t,t=null),t?(t=Nt(t),e.hostname=t.host,e.secure="https"===t.protocol||"wss"===t.protocol,e.port=t.port,t.query&&(e.query=t.query)):e.host&&(e.hostname=Nt(e.host).host),ht(this,e),this.secure=null!=e.secure?e.secure:"undefined"!=typeof location&&"https:"===location.protocol,e.hostname&&!e.port&&(e.port=this.secure?"443":"80"),this.hostname=e.hostname||("undefined"!=typeof location?location.hostname:"localhost"),this.port=e.port||("undefined"!=typeof location&&location.port?location.port:this.secure?"443":"80"),this.transports=e.transports||["polling","websocket"],this.readyState="",this.writeBuffer=[],this.prevBufferLen=0,this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!0},e),this.opts.path=this.opts.path.replace(/\/$/,"")+"/","string"==typeof this.opts.query&&(this.opts.query=function(t){let e={},s=t.split("&");for(let t=0,n=s.length;t<n;t++){let n=s[t].split("=");e[decodeURIComponent(n[0])]=decodeURIComponent(n[1])}return e}(this.opts.query)),this.id=null,this.upgrades=null,this.pingInterval=null,this.pingTimeout=null,this.pingTimeoutTimer=null,"function"==typeof addEventListener&&(this.opts.closeOnBeforeunload&&(this.beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this.beforeunloadEventListener,!1)),"localhost"!==this.hostname&&(this.offlineEventListener=()=>{this.onClose("transport close",{description:"network connection lost"})},addEventListener("offline",this.offlineEventListener,!1))),this.open()}createTransport(t){const e=Object.assign({},this.opts.query);e.EIO=4,e.transport=t,this.id&&(e.sid=this.id);const s=Object.assign({},this.opts.transportOptions[t],this.opts,{query:e,socket:this,hostname:this.hostname,secure:this.secure,port:this.port});return new xt[t](s)}open(){let t;if(this.opts.rememberUpgrade&&qt.priorWebsocketSuccess&&-1!==this.transports.indexOf("websocket"))t="websocket";else{if(0===this.transports.length)return void this.setTimeoutFn((()=>{this.emitReserved("error","No transports available")}),0);t=this.transports[0]}this.readyState="opening";try{t=this.createTransport(t)}catch(t){return this.transports.shift(),void this.open()}t.open(),this.setTransport(t)}setTransport(t){this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",this.onDrain.bind(this)).on("packet",this.onPacket.bind(this)).on("error",this.onError.bind(this)).on("close",(t=>this.onClose("transport close",t)))}probe(t){let e=this.createTransport(t),s=!1;qt.priorWebsocketSuccess=!1;const n=()=>{s||(e.send([{type:"ping",data:"probe"}]),e.once("packet",(t=>{if(!s)if("pong"===t.type&&"probe"===t.data){if(this.upgrading=!0,this.emitReserved("upgrading",e),!e)return;qt.priorWebsocketSuccess="websocket"===e.name,this.transport.pause((()=>{s||"closed"!==this.readyState&&(h(),this.setTransport(e),e.send([{type:"upgrade"}]),this.emitReserved("upgrade",e),e=null,this.upgrading=!1,this.flush())}))}else{const t=new Error("probe error");t.transport=e.name,this.emitReserved("upgradeError",t)}})))};function r(){s||(s=!0,h(),e.close(),e=null)}const i=t=>{const s=new Error("probe error: "+t);s.transport=e.name,r(),this.emitReserved("upgradeError",s)};function o(){i("transport closed")}function a(){i("socket closed")}function c(t){e&&t.name!==e.name&&r()}const h=()=>{e.removeListener("open",n),e.removeListener("error",i),e.removeListener("close",o),this.off("close",a),this.off("upgrading",c)};e.once("open",n),e.once("error",i),e.once("close",o),this.once("close",a),this.once("upgrading",c),e.open()}onOpen(){if(this.readyState="open",qt.priorWebsocketSuccess="websocket"===this.transport.name,this.emitReserved("open"),this.flush(),"open"===this.readyState&&this.opts.upgrade&&this.transport.pause){let t=0;const e=this.upgrades.length;for(;t<e;t++)this.probe(this.upgrades[t])}}onPacket(t){if("opening"===this.readyState||"open"===this.readyState||"closing"===this.readyState)switch(this.emitReserved("packet",t),this.emitReserved("heartbeat"),t.type){case"open":this.onHandshake(JSON.parse(t.data));break;case"ping":this.resetPingTimeout(),this.sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong");break;case"error":const e=new Error("server error");e.code=t.data,this.onError(e);break;case"message":this.emitReserved("data",t.data),this.emitReserved("message",t.data)}}onHandshake(t){this.emitReserved("handshake",t),this.id=t.sid,this.transport.query.sid=t.sid,this.upgrades=this.filterUpgrades(t.upgrades),this.pingInterval=t.pingInterval,this.pingTimeout=t.pingTimeout,this.maxPayload=t.maxPayload,this.onOpen(),"closed"!==this.readyState&&this.resetPingTimeout()}resetPingTimeout(){this.clearTimeoutFn(this.pingTimeoutTimer),this.pingTimeoutTimer=this.setTimeoutFn((()=>{this.onClose("ping timeout")}),this.pingInterval+this.pingTimeout),this.opts.autoUnref&&this.pingTimeoutTimer.unref()}onDrain(){this.writeBuffer.splice(0,this.prevBufferLen),this.prevBufferLen=0,0===this.writeBuffer.length?this.emitReserved("drain"):this.flush()}flush(){if("closed"!==this.readyState&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const t=this.getWritablePackets();this.transport.send(t),this.prevBufferLen=t.length,this.emitReserved("flush")}}getWritablePackets(){if(!(this.maxPayload&&"polling"===this.transport.name&&this.writeBuffer.length>1))return this.writeBuffer;let t=1;for(let s=0;s<this.writeBuffer.length;s++){const n=this.writeBuffer[s].data;if(n&&(t+="string"==typeof(e=n)?function(t){let e=0,s=0;for(let n=0,r=t.length;n<r;n++)e=t.charCodeAt(n),e<128?s+=1:e<2048?s+=2:e<55296||e>=57344?s+=3:(n++,s+=4);return s}(e):Math.ceil(1.33*(e.byteLength||e.size))),s>0&&t>this.maxPayload)return this.writeBuffer.slice(0,s);t+=2}var e;return this.writeBuffer}write(t,e,s){return this.sendPacket("message",t,e,s),this}send(t,e,s){return this.sendPacket("message",t,e,s),this}sendPacket(t,e,s,n){if("function"==typeof e&&(n=e,e=void 0),"function"==typeof s&&(n=s,s=null),"closing"===this.readyState||"closed"===this.readyState)return;(s=s||{}).compress=!1!==s.compress;const r={type:t,data:e,options:s};this.emitReserved("packetCreate",r),this.writeBuffer.push(r),n&&this.once("flush",n),this.flush()}close(){const t=()=>{this.onClose("forced close"),this.transport.close()},e=()=>{this.off("upgrade",e),this.off("upgradeError",e),t()},s=()=>{this.once("upgrade",e),this.once("upgradeError",e)};return"opening"!==this.readyState&&"open"!==this.readyState||(this.readyState="closing",this.writeBuffer.length?this.once("drain",(()=>{this.upgrading?s():t()})):this.upgrading?s():t()),this}onError(t){qt.priorWebsocketSuccess=!1,this.emitReserved("error",t),this.onClose("transport error",t)}onClose(t,e){"opening"!==this.readyState&&"open"!==this.readyState&&"closing"!==this.readyState||(this.clearTimeoutFn(this.pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),"function"==typeof removeEventListener&&(removeEventListener("beforeunload",this.beforeunloadEventListener,!1),removeEventListener("offline",this.offlineEventListener,!1)),this.readyState="closed",this.id=null,this.emitReserved("close",t,e),this.writeBuffer=[],this.prevBufferLen=0)}filterUpgrades(t){const e=[];let s=0;const n=t.length;for(;s<n;s++)~this.transports.indexOf(t[s])&&e.push(t[s]);return e}}qt.protocol=4,qt.protocol;const Dt="function"==typeof ArrayBuffer,Pt=Object.prototype.toString,jt="function"==typeof Blob||"undefined"!=typeof Blob&&"[object BlobConstructor]"===Pt.call(Blob),It="function"==typeof File||"undefined"!=typeof File&&"[object FileConstructor]"===Pt.call(File);function Mt(t){return Dt&&(t instanceof ArrayBuffer||(t=>"function"==typeof ArrayBuffer.isView?ArrayBuffer.isView(t):t.buffer instanceof ArrayBuffer)(t))||jt&&t instanceof Blob||It&&t instanceof File}function Ut(t,e){if(!t||"object"!=typeof t)return!1;if(Array.isArray(t)){for(let e=0,s=t.length;e<s;e++)if(Ut(t[e]))return!0;return!1}if(Mt(t))return!0;if(t.toJSON&&"function"==typeof t.toJSON&&1===arguments.length)return Ut(t.toJSON(),!0);for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e)&&Ut(t[e]))return!0;return!1}function Ft(t){const e=[],s=t.data,n=t;return n.data=Ht(s,e),n.attachments=e.length,{packet:n,buffers:e}}function Ht(t,e){if(!t)return t;if(Mt(t)){const s={_placeholder:!0,num:e.length};return e.push(t),s}if(Array.isArray(t)){const s=new Array(t.length);for(let n=0;n<t.length;n++)s[n]=Ht(t[n],e);return s}if("object"==typeof t&&!(t instanceof Date)){const s={};for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&(s[n]=Ht(t[n],e));return s}return t}function Vt(t,e){return t.data=Kt(t.data,e),t.attachments=void 0,t}function Kt(t,e){if(!t)return t;if(t&&!0===t._placeholder){if("number"==typeof t.num&&t.num>=0&&t.num<e.length)return e[t.num];throw new Error("illegal attachments")}if(Array.isArray(t))for(let s=0;s<t.length;s++)t[s]=Kt(t[s],e);else if("object"==typeof t)for(const s in t)Object.prototype.hasOwnProperty.call(t,s)&&(t[s]=Kt(t[s],e));return t}const Yt=5;var Qt;!function(t){t[t.CONNECT=0]="CONNECT",t[t.DISCONNECT=1]="DISCONNECT",t[t.EVENT=2]="EVENT",t[t.ACK=3]="ACK",t[t.CONNECT_ERROR=4]="CONNECT_ERROR",t[t.BINARY_EVENT=5]="BINARY_EVENT",t[t.BINARY_ACK=6]="BINARY_ACK"}(Qt||(Qt={}));class zt{constructor(t){this.replacer=t}encode(t){return t.type!==Qt.EVENT&&t.type!==Qt.ACK||!Ut(t)?[this.encodeAsString(t)]:(t.type=t.type===Qt.EVENT?Qt.BINARY_EVENT:Qt.BINARY_ACK,this.encodeAsBinary(t))}encodeAsString(t){let e=""+t.type;return t.type!==Qt.BINARY_EVENT&&t.type!==Qt.BINARY_ACK||(e+=t.attachments+"-"),t.nsp&&"/"!==t.nsp&&(e+=t.nsp+","),null!=t.id&&(e+=t.id),null!=t.data&&(e+=JSON.stringify(t.data,this.replacer)),e}encodeAsBinary(t){const e=Ft(t),s=this.encodeAsString(e.packet),n=e.buffers;return n.unshift(s),n}}class $t extends rt{constructor(t){super(),this.reviver=t}add(t){let e;if("string"==typeof t){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");e=this.decodeString(t),e.type===Qt.BINARY_EVENT||e.type===Qt.BINARY_ACK?(this.reconstructor=new Wt(e),0===e.attachments&&super.emitReserved("decoded",e)):super.emitReserved("decoded",e)}else{if(!Mt(t)&&!t.base64)throw new Error("Unknown type: "+t);if(!this.reconstructor)throw new Error("got binary data when not reconstructing a packet");e=this.reconstructor.takeBinaryData(t),e&&(this.reconstructor=null,super.emitReserved("decoded",e))}}decodeString(t){let e=0;const s={type:Number(t.charAt(0))};if(void 0===Qt[s.type])throw new Error("unknown packet type "+s.type);if(s.type===Qt.BINARY_EVENT||s.type===Qt.BINARY_ACK){const n=e+1;for(;"-"!==t.charAt(++e)&&e!=t.length;);const r=t.substring(n,e);if(r!=Number(r)||"-"!==t.charAt(e))throw new Error("Illegal attachments");s.attachments=Number(r)}if("/"===t.charAt(e+1)){const n=e+1;for(;++e&&","!==t.charAt(e)&&e!==t.length;);s.nsp=t.substring(n,e)}else s.nsp="/";const n=t.charAt(e+1);if(""!==n&&Number(n)==n){const n=e+1;for(;++e;){const s=t.charAt(e);if(null==s||Number(s)!=s){--e;break}if(e===t.length)break}s.id=Number(t.substring(n,e+1))}if(t.charAt(++e)){const n=this.tryParse(t.substr(e));if(!$t.isPayloadValid(s.type,n))throw new Error("invalid payload");s.data=n}return s}tryParse(t){try{return JSON.parse(t,this.reviver)}catch(t){return!1}}static isPayloadValid(t,e){switch(t){case Qt.CONNECT:return"object"==typeof e;case Qt.DISCONNECT:return void 0===e;case Qt.CONNECT_ERROR:return"string"==typeof e||"object"==typeof e;case Qt.EVENT:case Qt.BINARY_EVENT:return Array.isArray(e)&&e.length>0;case Qt.ACK:case Qt.BINARY_ACK:return Array.isArray(e)}}destroy(){this.reconstructor&&this.reconstructor.finishedReconstruction()}}class Wt{constructor(t){this.packet=t,this.buffers=[],this.reconPack=t}takeBinaryData(t){if(this.buffers.push(t),this.buffers.length===this.reconPack.attachments){const t=Vt(this.reconPack,this.buffers);return this.finishedReconstruction(),t}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}}function Jt(t,e,s){return t.on(e,s),function(){t.off(e,s)}}const Xt=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1});class Gt extends rt{constructor(t,e,s){super(),this.connected=!1,this.receiveBuffer=[],this.sendBuffer=[],this.ids=0,this.acks={},this.flags={},this.io=t,this.nsp=e,s&&s.auth&&(this.auth=s.auth),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;const t=this.io;this.subs=[Jt(t,"open",this.onopen.bind(this)),Jt(t,"packet",this.onpacket.bind(this)),Jt(t,"error",this.onerror.bind(this)),Jt(t,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected||(this.subEvents(),this.io._reconnecting||this.io.open(),"open"===this.io._readyState&&this.onopen()),this}open(){return this.connect()}send(...t){return t.unshift("message"),this.emit.apply(this,t),this}emit(t,...e){if(Xt.hasOwnProperty(t))throw new Error('"'+t.toString()+'" is a reserved event name');e.unshift(t);const s={type:Qt.EVENT,data:e,options:{}};if(s.options.compress=!1!==this.flags.compress,"function"==typeof e[e.length-1]){const t=this.ids++,n=e.pop();this._registerAckCallback(t,n),s.id=t}const n=this.io.engine&&this.io.engine.transport&&this.io.engine.transport.writable;return this.flags.volatile&&(!n||!this.connected)||(this.connected?(this.notifyOutgoingListeners(s),this.packet(s)):this.sendBuffer.push(s)),this.flags={},this}_registerAckCallback(t,e){const s=this.flags.timeout;if(void 0===s)return void(this.acks[t]=e);const n=this.io.setTimeoutFn((()=>{delete this.acks[t];for(let e=0;e<this.sendBuffer.length;e++)this.sendBuffer[e].id===t&&this.sendBuffer.splice(e,1);e.call(this,new Error("operation has timed out"))}),s);this.acks[t]=(...t)=>{this.io.clearTimeoutFn(n),e.apply(this,[null,...t])}}packet(t){t.nsp=this.nsp,this.io._packet(t)}onopen(){"function"==typeof this.auth?this.auth((t=>{this.packet({type:Qt.CONNECT,data:t})})):this.packet({type:Qt.CONNECT,data:this.auth})}onerror(t){this.connected||this.emitReserved("connect_error",t)}onclose(t,e){this.connected=!1,delete this.id,this.emitReserved("disconnect",t,e)}onpacket(t){if(t.nsp===this.nsp)switch(t.type){case Qt.CONNECT:if(t.data&&t.data.sid){const e=t.data.sid;this.onconnect(e)}else this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case Qt.EVENT:case Qt.BINARY_EVENT:this.onevent(t);break;case Qt.ACK:case Qt.BINARY_ACK:this.onack(t);break;case Qt.DISCONNECT:this.ondisconnect();break;case Qt.CONNECT_ERROR:this.destroy();const e=new Error(t.data.message);e.data=t.data.data,this.emitReserved("connect_error",e)}}onevent(t){const e=t.data||[];null!=t.id&&e.push(this.ack(t.id)),this.connected?this.emitEvent(e):this.receiveBuffer.push(Object.freeze(e))}emitEvent(t){if(this._anyListeners&&this._anyListeners.length){const e=this._anyListeners.slice();for(const s of e)s.apply(this,t)}super.emit.apply(this,t)}ack(t){const e=this;let s=!1;return function(...n){s||(s=!0,e.packet({type:Qt.ACK,id:t,data:n}))}}onack(t){const e=this.acks[t.id];"function"==typeof e&&(e.apply(this,t.data),delete this.acks[t.id])}onconnect(t){this.id=t,this.connected=!0,this.emitBuffered(),this.emitReserved("connect")}emitBuffered(){this.receiveBuffer.forEach((t=>this.emitEvent(t))),this.receiveBuffer=[],this.sendBuffer.forEach((t=>{this.notifyOutgoingListeners(t),this.packet(t)})),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach((t=>t())),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:Qt.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(t){return this.flags.compress=t,this}get volatile(){return this.flags.volatile=!0,this}timeout(t){return this.flags.timeout=t,this}onAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(t),this}prependAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(t),this}offAny(t){if(!this._anyListeners)return this;if(t){const e=this._anyListeners;for(let s=0;s<e.length;s++)if(t===e[s])return e.splice(s,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(t),this}prependAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(t),this}offAnyOutgoing(t){if(!this._anyOutgoingListeners)return this;if(t){const e=this._anyOutgoingListeners;for(let s=0;s<e.length;s++)if(t===e[s])return e.splice(s,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(t){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){const e=this._anyOutgoingListeners.slice();for(const s of e)s.apply(this,t.data)}}}function Zt(t){t=t||{},this.ms=t.min||100,this.max=t.max||1e4,this.factor=t.factor||2,this.jitter=t.jitter>0&&t.jitter<=1?t.jitter:0,this.attempts=0}Zt.prototype.duration=function(){var t=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var e=Math.random(),s=Math.floor(e*this.jitter*t);t=0==(1&Math.floor(10*e))?t-s:t+s}return 0|Math.min(t,this.max)},Zt.prototype.reset=function(){this.attempts=0},Zt.prototype.setMin=function(t){this.ms=t},Zt.prototype.setMax=function(t){this.max=t},Zt.prototype.setJitter=function(t){this.jitter=t};class te extends rt{constructor(e,s){var n;super(),this.nsps={},this.subs=[],e&&"object"==typeof e&&(s=e,e=void 0),(s=s||{}).path=s.path||"/socket.io",this.opts=s,ht(this,s),this.reconnection(!1!==s.reconnection),this.reconnectionAttempts(s.reconnectionAttempts||1/0),this.reconnectionDelay(s.reconnectionDelay||1e3),this.reconnectionDelayMax(s.reconnectionDelayMax||5e3),this.randomizationFactor(null!==(n=s.randomizationFactor)&&void 0!==n?n:.5),this.backoff=new Zt({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(null==s.timeout?2e4:s.timeout),this._readyState="closed",this.uri=e;const r=s.parser||t;this.encoder=new r.Encoder,this.decoder=new r.Decoder,this._autoConnect=!1!==s.autoConnect,this._autoConnect&&this.open()}reconnection(t){return arguments.length?(this._reconnection=!!t,this):this._reconnection}reconnectionAttempts(t){return void 0===t?this._reconnectionAttempts:(this._reconnectionAttempts=t,this)}reconnectionDelay(t){var e;return void 0===t?this._reconnectionDelay:(this._reconnectionDelay=t,null===(e=this.backoff)||void 0===e||e.setMin(t),this)}randomizationFactor(t){var e;return void 0===t?this._randomizationFactor:(this._randomizationFactor=t,null===(e=this.backoff)||void 0===e||e.setJitter(t),this)}reconnectionDelayMax(t){var e;return void 0===t?this._reconnectionDelayMax:(this._reconnectionDelayMax=t,null===(e=this.backoff)||void 0===e||e.setMax(t),this)}timeout(t){return arguments.length?(this._timeout=t,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&0===this.backoff.attempts&&this.reconnect()}open(t){if(~this._readyState.indexOf("open"))return this;this.engine=new qt(this.uri,this.opts);const e=this.engine,s=this;this._readyState="opening",this.skipReconnect=!1;const n=Jt(e,"open",(function(){s.onopen(),t&&t()})),r=Jt(e,"error",(e=>{s.cleanup(),s._readyState="closed",this.emitReserved("error",e),t?t(e):s.maybeReconnectOnOpen()}));if(!1!==this._timeout){const t=this._timeout;0===t&&n();const s=this.setTimeoutFn((()=>{n(),e.close(),e.emit("error",new Error("timeout"))}),t);this.opts.autoUnref&&s.unref(),this.subs.push((function(){clearTimeout(s)}))}return this.subs.push(n),this.subs.push(r),this}connect(t){return this.open(t)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");const t=this.engine;this.subs.push(Jt(t,"ping",this.onping.bind(this)),Jt(t,"data",this.ondata.bind(this)),Jt(t,"error",this.onerror.bind(this)),Jt(t,"close",this.onclose.bind(this)),Jt(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(t){try{this.decoder.add(t)}catch(t){this.onclose("parse error",t)}}ondecoded(t){Ot((()=>{this.emitReserved("packet",t)}),this.setTimeoutFn)}onerror(t){this.emitReserved("error",t)}socket(t,e){let s=this.nsps[t];return s||(s=new Gt(this,t,e),this.nsps[t]=s),s}_destroy(t){const e=Object.keys(this.nsps);for(const t of e)if(this.nsps[t].active)return;this._close()}_packet(t){const e=this.encoder.encode(t);for(let s=0;s<e.length;s++)this.engine.write(e[s],t.options)}cleanup(){this.subs.forEach((t=>t())),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close"),this.engine&&this.engine.close()}disconnect(){return this._close()}onclose(t,e){this.cleanup(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",t,e),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;const t=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{const e=this.backoff.duration();this._reconnecting=!0;const s=this.setTimeoutFn((()=>{t.skipReconnect||(this.emitReserved("reconnect_attempt",t.backoff.attempts),t.skipReconnect||t.open((e=>{e?(t._reconnecting=!1,t.reconnect(),this.emitReserved("reconnect_error",e)):t.onreconnect()})))}),e);this.opts.autoUnref&&s.unref(),this.subs.push((function(){clearTimeout(s)}))}}onreconnect(){const t=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",t)}}const ee={};function se(t,e){"object"==typeof t&&(e=t,t=void 0);const s=function(t,e="",s){let n=t;s=s||"undefined"!=typeof location&&location,null==t&&(t=s.protocol+"//"+s.host),"string"==typeof t&&("/"===t.charAt(0)&&(t="/"===t.charAt(1)?s.protocol+t:s.host+t),/^(https?|wss?):\/\//.test(t)||(t=void 0!==s?s.protocol+"//"+t:"https://"+t),n=Nt(t)),n.port||(/^(http|ws)$/.test(n.protocol)?n.port="80":/^(http|ws)s$/.test(n.protocol)&&(n.port="443")),n.path=n.path||"/";const r=-1!==n.host.indexOf(":")?"["+n.host+"]":n.host;return n.id=n.protocol+"://"+r+":"+n.port+e,n.href=n.protocol+"://"+r+(s&&s.port===n.port?"":":"+n.port),n}(t,(e=e||{}).path||"/socket.io"),n=s.source,r=s.id,i=s.path,o=ee[r]&&i in ee[r].nsps;let a;return e.forceNew||e["force new connection"]||!1===e.multiplex||o?a=new te(n,e):(ee[r]||(ee[r]=new te(n,e)),a=ee[r]),s.query&&!e.query&&(e.query=s.queryKey),a.socket(s.path,e)}Object.assign(se,{Manager:te,Socket:Gt,io:se,connect:se});var ne,re=n(265),ie=n.n(re);function oe(t){return t.endsWith("/")?t.slice(0,t.length-1):t}!function(t){t.DATA="data",t.LIBUPDATE="libUpdate",t.FORK="fork",t.EMPTY="empty",t.CONNECT="connect",t.DRAIN="drain",t.LIBDATA="libData"}(ne||(ne={}));class ae{socket;socketURL;lastReceivedBlock=0;dataQueue=null;options={async:!0,libStream:!1,endpoint:""};libDataQueue=null;reversibleBuffer=[];onDataAsync;onLibDataAsync;online=!1;savedRequests=[];eventListeners=new Map;tempEventListeners=new Map;constructor(t){if(!t||"object"!=typeof t)throw new Error("Invalid options");for(let e in t)if(void 0!==t[e]){const s=t[e];switch(e){case"endpoint":this.options[e]=s,this.setEndpoint(s);break;case"chainApi":this.options.chainApi=oe(s);break;default:this.options[e]=t[e]}}}disconnect(){this.socket?(this.lastReceivedBlock=0,this.socket.disconnect(),this.savedRequests=[]):console.log("Nothing to disconnect!")}get lastBlockNum(){return this.lastReceivedBlock}setEndpoint(t){t?this.socketURL=oe(t):console.error("URL not informed")}pushToBuffer(t){this.options.libStream&&this.reversibleBuffer.push(t)}setupIncomingQueue(){this.dataQueue=F(((t,e)=>{t.irreversible=!1,this.emit(ne.DATA,t),this.pushToBuffer(t),this.onDataAsync?this.onDataAsync(t).then((()=>{e()})):e()}),1),this.dataQueue.error((t=>{t&&console.error("task experienced an error")})),this.dataQueue.drain((()=>{this.emit(ne.DRAIN)})),this.dataQueue.empty((()=>{this.emit(ne.EMPTY)}))}setupIrreversibleQueue(){this.options.libStream&&(this.libDataQueue=F(((t,e)=>{t.irreversible=!0,this.emit(ne.LIBDATA,t),this.onLibDataAsync?this.onLibDataAsync(t).then((()=>{e()})):e()}),1))}handleLibUpdate(t){if(this.options.libStream)for(;this.reversibleBuffer.length>0&&this.reversibleBuffer[0]&&this.reversibleBuffer[0].content.block_num<=t.block_num&&this.libDataQueue;){const t=this.reversibleBuffer.shift();if(!t)break;this.libDataQueue.push(t).catch(console.log)}this.emit(ne.LIBUPDATE,t);for(const e of this.savedRequests)e.req.read_until&&0!==e.req.read_until&&e.req.read_until<t.block_num&&this.disconnect()}async setupSocket(){return new Promise(((t,e)=>{this.socketURL?(this.socket=se(this.socketURL,{transports:["websocket"],path:"/stream"}),this.socket.on("connect",(()=>{this.debugLog("connected"),this.online=!0,this.emit(ne.CONNECT),this.resendRequests().catch(console.log),t()})),this.socket.on("error",(t=>{console.log(t)})),this.socket.on("lib_update",this.handleLibUpdate.bind(this)),this.socket.on("fork_event",(t=>{this.emit(ne.FORK,t)})),this.socket.on("message",(t=>{if((this.onDataAsync||this.onLibDataAsync)&&(t.message||t.messages))switch(t.type){case"delta_trace":t.messages?t.messages.forEach((e=>{this.processDeltaTrace(e,t.mode)})):this.processDeltaTrace(JSON.parse(t.message),t.mode);break;case"action_trace":t.messages?t.messages.forEach((e=>{this.processActionTrace(e,t.mode)})):this.processActionTrace(JSON.parse(t.message),t.mode)}})),this.socket.on("status",(t=>{switch(t){case"relay_restored":this.online||(this.online=!0,this.resendRequests().catch(console.log));break;case"relay_down":this.online=!1;break;default:console.log(t)}})),this.socket.on("disconnect",(()=>{this.online=!1,console.log("disconnected!")}))):e()}))}async connect(){if(this.setupIncomingQueue(),this.setupIrreversibleQueue(),!this.socketURL)throw new Error("endpoint was not defined!");this.debugLog(`Connecting to ${this.socketURL}...`),await this.setupSocket()}processActionTrace(t,e){const s="@"+t.act.name;if(t[s]){const e=t[s];Object.keys(e).forEach((s=>{t.act.data||(t.act.data={}),t.act.data[s]=e[s]})),delete t[s]}this.dataQueue&&(this.dataQueue.push({type:"action",mode:e,content:t,irreversible:!1}).catch(console.log),this.lastReceivedBlock=t.block_num)}processDeltaTrace(t,e){let s="@"+t.table;if(t[s+".data"]&&(s+=".data"),t[s]){const e=t[s];Object.keys(e).forEach((s=>{t.data||(t.data={}),t.data[s]=e[s]})),delete t[s]}this.dataQueue&&(this.dataQueue.push({type:"delta",mode:e,content:t,irreversible:!1}).catch(console.log),this.lastReceivedBlock=t.block_num)}async resendRequests(){if(0===this.savedRequests.length)return;this.debugLog(`Sending ${this.savedRequests.length} saved requests`);const t=[...this.savedRequests];this.savedRequests=[];for(const e of t)switch(e.type){case"action":await this.streamActions(e.req);break;case"delta":await this.streamDeltas(e.req)}}async streamActions(t){if(this.socket&&this.socket.connected){try{await this.checkLastBlock(t)}catch(t){return{status:"ERROR",error:t.message}}return new Promise(((e,s)=>{this.socket?this.socket.emit("action_stream_request",t,(n=>{this.debugLog(n),"OK"===n.status?(this.savedRequests.push({type:"action",req:t}),n.startingBlock=t.start_from,e(n)):s(n)})):s({status:!1,error:"socket was not created"})}))}throw new Error("Client is not connected! Please call connect before sending requests")}async streamDeltas(t){if(this.socket&&this.socket.connected){try{await this.checkLastBlock(t)}catch(t){return{status:"ERROR",error:t.message}}return new Promise(((e,s)=>{this.socket?this.socket.emit("delta_stream_request",t,(n=>{this.debugLog(n),"OK"===n.status?(this.savedRequests.push({type:"delta",req:t}),n.startingBlock=t.start_from,e(n)):s(n)})):s({status:!1,error:"socket was not created"})}))}throw new Error("Client is not connected! Please call connect before sending requests")}async checkLastBlock(t){if("LIB"===String(t.start_from).toUpperCase()){let e;if(e=this.options.chainApi?this.options.chainApi:this.socketURL,e+="/v1/chain/get_info",e)try{const s=await ie()(e),n=await s.json();n&&n.last_irreversible_block_num&&(t.start_from=n.last_irreversible_block_num,this.debugLog(`Stream starting at lib (block ${t.start_from})`))}catch(t){throw new Error(`get_info failed on: ${e} | error: ${t.message}`)}}else 0!==t.start_from&&this.lastReceivedBlock&&t.start_from<this.lastReceivedBlock&&(t.start_from=this.lastReceivedBlock)}debugLog(...t){this.options.debug&&console.log("[hyperion:debug]",...t)}setAsyncDataHandler(t){this.onDataAsync=t}setAsyncLibDataHandler(t){this.onLibDataAsync=t}emit(t,e){const s=this.eventListeners.get(t);s&&s.forEach((t=>t(e)));const n=this.tempEventListeners.get(t);if(n&&n.length>0){const t=n.shift();t&&t(e)}}once(t,e){if("function"!=typeof e)throw new Error("Event listener must be a function");this.tempEventListeners.has(t)?this.tempEventListeners.get(t)?.push(e):this.tempEventListeners.set(t,[e])}on(t,e){if("function"!=typeof e)throw new Error("Event listener must be a function");this.eventListeners.has(t)?this.eventListeners.get(t)?.push(e):this.eventListeners.set(t,[e])}off(t,e){const s=this.eventListeners.get(t);if(s&&s.length>0){const t=s.findIndex((t=>t===e));s.splice(t,1)}const n=this.tempEventListeners.get(t);if(n&&n.length>0){const t=n.findIndex((t=>t===e));n.splice(t,1)}}}"undefined"!=typeof window&&(window.HyperionStreamClient=ae)})(),r})()));