diff --git a/.gitignore b/.gitignore index 17d0b82..e67fc88 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,9 @@ node_modules -*/**/*.js -*/**/*.d.ts +src/**/*.js +src/**/*.d.ts -!lib/Backend.js -!lib/Frontend.js \ No newline at end of file +test/**/*.js +test/**/*.d.ts + +lib \ No newline at end of file diff --git a/lib/Backend.js b/lib/Backend.js deleted file mode 100644 index c3c0260..0000000 --- a/lib/Backend.js +++ /dev/null @@ -1,167 +0,0 @@ -!function(e,t){for(var s in t)e[s]=t[s]}(exports,function(e){var t={};function s(r){if(t[r])return t[r].exports;var n=t[r]={i:r,l:!1,exports:{}};return e[r].call(n.exports,n,n.exports,s),n.l=!0,n.exports}return s.m=e,s.c=t,s.d=function(e,t,r){s.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},s.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.t=function(e,t){if(1&t&&(e=s(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(s.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)s.d(r,n,function(t){return e[t]}.bind(null,n));return r},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,"a",t),t},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s.p="",s(s.s=10)}([function(e,t){e.exports=require("util")},function(e,t,s){"use strict"; -/*! - * assert.js - assertions for javascript - * Copyright (c) 2018, Christopher Jeffrey (MIT License). - * https://github.com/chjj/bsert - */class r extends Error{constructor(e){"string"==typeof e&&(e={message:e}),null!==e&&"object"==typeof e||(e={});let t=null,s="fail",r=Boolean(e.generatedMessage);var n;if(null!=e.message&&(t="string"==typeof(n=e.message)?n:b(n)?d(n):p(n)),"string"==typeof e.operator&&(s=e.operator),null==t){if("fail"===s)t="Assertion failed.";else{t=`${p(e.actual)} ${s} ${p(e.expected)}`}r=!0}super(t);let i=this.constructor;"function"==typeof e.stackStartFunction?i=e.stackStartFunction:"function"==typeof e.stackStartFn&&(i=e.stackStartFn),this.type="AssertionError",this.name="AssertionError [ERR_ASSERTION]",this.code="ERR_ASSERTION",this.generatedMessage=r,this.actual=e.actual,this.expected=e.expected,this.operator=s,Error.captureStackTrace&&Error.captureStackTrace(this,i)}}function n(e,t){if(!e){let s=!1;if(0===arguments.length)t="No value argument passed to `assert()`.",s=!0;else if(null==t)t="Assertion failed.",s=!0;else if(b(t))throw t;throw new r({message:t,actual:e,expected:!0,operator:"==",generatedMessage:s,stackStartFn:n})}}function i(e,t,s){if(!Object.is(e,t)){if(b(s))throw s;throw new r({message:s,actual:e,expected:t,operator:"strictEqual",stackStartFn:i})}}function o(e,t,s){if(Object.is(e,t)){if(b(s))throw s;throw new r({message:s,actual:e,expected:t,operator:"notStrictEqual",stackStartFn:o})}}function a(e,t,s){"string"==typeof t&&(s=t,t=void 0);let n=!1,i=null;l("function"==typeof e,"func","function");try{e()}catch(e){n=!0,i=e}if(n){if(_(i,t,s,a)){let e=!1;throw null==s&&(s="Got unwanted exception.",e=!0),new r({message:s,actual:i,expected:t,operator:"doesNotThrow",generatedMessage:e,stackStartFn:a})}throw i}}async function h(e,t,s){"string"==typeof t&&(s=t,t=void 0);let n=!1,i=null;"function"!=typeof e&&l(S(e),"func","promise");try{S(e)?await e:await e()}catch(e){n=!0,i=e}if(!n){let e=!1;throw null==s&&(s="Missing expected rejection.",e=!0),new r({message:s,actual:void 0,expected:t,operator:"rejects",generatedMessage:e,stackStartFn:h})}if(!_(i,t,s,h))throw i}async function c(e,t,s){"string"==typeof t&&(s=t,t=void 0);let n=!1,i=null;"function"!=typeof e&&l(S(e),"func","promise");try{S(e)?await e:await e()}catch(e){n=!0,i=e}if(n){if(_(i,t,s,c)){let e=!1;throw null==s&&(s="Got unwanted rejection.",e=!0),new r({message:s,actual:void 0,expected:t,operator:"doesNotReject",generatedMessage:e,stackStartFn:c})}throw i}}function u(e,t,s){if(!g(e,t,!1)){if(b(s))throw s;throw new r({message:s,actual:e,expected:t,operator:"deepStrictEqual",stackStartFn:u})}}function f(e,t,s){if(g(e,t,!0)){if(b(s))throw s;throw new r({message:s,actual:e,expected:t,operator:"notDeepStrictEqual",stackStartFn:f})}}function l(e,t,s){if(!e){let e;e=null==t?"Invalid type for parameter.":null==s?`Invalid type for "${t}".`:`"${t}" must be a(n) ${s}.`;const r=new TypeError(e);throw Error.captureStackTrace&&Error.captureStackTrace(r,l),r}}function p(e){switch(typeof e){case"undefined":return"undefined";case"object":return null===e?"null":`[${function(e){const t=function(e){return m(e).slice(8,-1)}(e);if(null==e)return t;if("Object"!==t&&"Error"!==t)return t;let s,r;try{s=e.constructor}catch(e){}if(null==s)return t;try{r=s.name}catch(e){return t}return"string"!=typeof r||0===r.length?t:r}(e)}]`;case"boolean":case"number":return`${e}`;case"string":return e.length>80&&(e=`${e.substring(0,77)}...`),JSON.stringify(e);case"symbol":return d(e);case"function":return`[${function(e){let t;try{t=e.name}catch(e){}return"string"!=typeof t||0===t.length?"Function":`Function: ${t}`}(e)}]`;case"bigint":return`${e}n`;default:return`[${typeof e}]`}}function d(e){try{return String(e)}catch(e){return"Object"}}function _(e,t,s,n){if(null==t)return!0;if(k(t))return t.test(e);if("function"!=typeof t){if(n===a||n===c)throw new TypeError('"expected" must not be an object.');if("object"!=typeof t)throw new TypeError('"expected" must be an object.');let i=!1;if(null==s){s=`Missing expected ${n===h?"rejection":"exception"}.`,i=!0}if(null==e||"object"!=typeof e)throw new r({actual:e,expected:t,message:s,operator:n.name,generatedMessage:i,stackStartFn:n});const o=Object.keys(t);if(b(t)&&o.push("name","message"),0===o.length)throw new TypeError('"expected" may not be an empty object.');for(const a of o){const o=t[a],h=e[a];if(("string"!=typeof h||!k(o)||!o.test(h))&&!(a in e&&g(h,o,!1)))throw new r({actual:e,expected:t,message:s,operator:n.name,generatedMessage:i,stackStartFn:n})}return!0}return void 0!==t.prototype&&e instanceof t||!Error.isPrototypeOf(t)&&!0===t.call({},e)}function g(e,t,s){try{return y(e,t,null)}catch(e){return s}}function y(e,t,s){if(Object.is(e,t))return!0;if(!w(e)||!w(t))return!1;if(m(e)!==m(t))return!1;if(Object.getPrototypeOf(e)!==Object.getPrototypeOf(t))return!1;if(E(e)&&E(t))return e.equals(t);if(e instanceof Date)return Object.is(e.getTime(),t.getTime());if(k(e))return e.source===t.source&&e.global===t.global&&e.multiline===t.multiline&&e.lastIndex===t.lastIndex&&e.ignoreCase===t.ignoreCase;if(b(e)&&e.message!==t.message)return!1;if(function(e){return e instanceof ArrayBuffer}(e)&&(e=new Uint8Array(e),t=new Uint8Array(t)),function(e){return ArrayBuffer.isView(e)}(e)&&!E(e)){if(E(t))return!1;const s=new Uint8Array(e.buffer),r=new Uint8Array(t.buffer);if(s.length!==r.length)return!1;for(let e=0;e>>1?null:n}return t}n.AssertionError=r,n.assert=n,n.strict=n,n.ok=n,n.equal=i,n.notEqual=o,n.strictEqual=i,n.notStrictEqual=o,n.fail=function e(t){let s=!1;if(b(t))throw t;throw null==t&&(t="Assertion failed.",s=!0),new r({message:t,actual:!1,expected:!0,operator:"fail",generatedMessage:s,stackStartFn:e})},n.throws=function e(t,s,n){"string"==typeof s&&(n=s,s=void 0);let i=!1,o=null;l("function"==typeof t,"func","function");try{t()}catch(e){i=!0,o=e}if(!i){let t=!1;throw null==n&&(n="Missing expected exception.",t=!0),new r({message:n,actual:void 0,expected:s,operator:"throws",generatedMessage:t,stackStartFn:e})}if(!_(o,s,n,e))throw o},n.doesNotThrow=a,n.rejects=h,n.doesNotReject=c,n.ifError=function e(t){if(null!=t){let s="ifError got unwanted exception: ";throw"object"==typeof t&&"string"==typeof t.message?0===t.message.length&&t.constructor?s+=t.constructor.name:s+=t.message:s+=p(t),new r({message:s,actual:t,expected:null,operator:"ifError",generatedMessage:!0,stackStartFn:e})}},n.deepEqual=u,n.notDeepEqual=f,n.deepStrictEqual=u,n.notDeepStrictEqual=f,n.bufferEqual=function e(t,s,n,i){if(O(n)||(i=n,n=null),null==n&&(n="hex"),s=x(t,s,n),l(E(t),"actual","buffer"),l(E(s),"expected","buffer"),t!==s&&!t.equals(s)){if(b(i))throw i;throw new r({message:i,actual:t.toString(n),expected:s.toString(n),operator:"bufferEqual",stackStartFn:e})}},n.notBufferEqual=function e(t,s,n,i){if(O(n)||(i=n,n=null),null==n&&(n="hex"),s=x(t,s,n),l(E(t),"actual","buffer"),l(E(s),"expected","buffer"),t===s||t.equals(s)){if(b(i))throw i;throw new r({message:i,actual:t.toString(n),expected:s.toString(n),operator:"notBufferEqual",stackStartFn:e})}},n.enforce=l,n.range=function e(t,s){if(!t){const t=new RangeError(null!=s?`"${s}" is out of range.`:"Parameter is out of range.");throw Error.captureStackTrace&&Error.captureStackTrace(t,e),t}},e.exports=n},function(e,t){e.exports=require("events")},function(e,t){e.exports=require("stream")},function(e,t){e.exports=require("crypto")},function(e,t){e.exports=require("url")},function(e,t,s){"use strict";e.exports=s(13)},function(e,t,s){"use strict";const r=s(1),n={CONNECT:0,DISCONNECT:1,EVENT:2,ACK:3,ERROR:4,BINARY_EVENT:5,BINARY_ACK:6};class i{constructor(e){this.type=e||0,this.attachments=0,this.nsp="/",this.id=-1,this.data="",this.buffers=[]}setData(e){r(void 0!==e),r("number"!=typeof e),r("function"!=typeof e);const[t,s]=function(e){const t=[],s=function e(t,s,r,n){if(null===s||"object"!=typeof s)return s;if(Buffer.isBuffer(s)){const e=n.get(s);if(null!=e)return e;const t={_placeholder:!0,num:r.length};return n.set(s,t),r.push(s),t}if(n.has(s))throw new TypeError("Converting circular structure to JSON.");if(Array.isArray(s)){const t=[];n.set(s,null);for(let i=0;i0)switch(this.type){case n.EVENT:this.type=n.BINARY_EVENT;break;case n.ACK:this.type=n.BINARY_ACK}return this}getData(){return 0===this.data.length?null:(e=this.data,t=this.buffers,JSON.parse(e,(e,s)=>(function(e){return null!==e&&"object"==typeof e&&!0===e._placeholder&&e.num>>>0===e.num})(s)&&s.num0);let t=0,s=0,i=0,a="/",h=-1,c="";switch([t,s]=function(e,t){const s=e.charCodeAt(t)-48;return s<0||s>9?-1:[t+1,s]}(e,t),r(-1!==s),r(s<=n.BINARY_ACK),s){case n.BINARY_EVENT:case n.BINARY_ACK:[t,i]=o(e,t),r(-1!==i),r(t9)break;n*=10,n+=i,r((s+=1)<=10)}return r(n<=4294967295),0===s&&(n=-1),[t,n]}i.types=n,e.exports=i},function(e,t,s){"use strict";const r=s(1),n=s(2),i=s(6).Client,o=s(7),a=s(9),h=s(19),c=s(20),u=s(21),f=s(22);class l{constructor(e,t,s){this.resolve=e,this.reject=t,this.time=s}}function p(e){return null!==e&&"number"!=typeof e&&"string"!=typeof e?null:e}function d(e){return"string"!=typeof e?"No message.":e}function _(e){return"string"!=typeof e?null:e}function g(e,t,s){if(!e){const e=new TypeError(`'${t}' must be a(n) ${s}.`);throw Error.captureStackTrace&&Error.captureStackTrace(e,g),e}}e.exports=class extends n{constructor(){super(),this.server=null,this.ws=null,this.protocol="",this.url="ws://127.0.0.1:80/socket.io/?transport=websocket",this.ssl=!1,this.host="127.0.0.1",this.port=80,this.inbound=!1,this.handshake=!1,this.opened=!1,this.connected=!1,this.challenge=!1,this.destroyed=!1,this.reconnection=!0,this.time=0,this.sequence=0,this.pingInterval=25e3,this.pingTimeout=6e4,this.lastPing=0,this.parser=new c,this.binary=!1,this.packet=null,this.timer=null,this.jobs=new Map,this.hooks=new Map,this.channels=new Set,this.events=new n,this.buffer=[],this.admin=!1,this.auth=!1}accept(e,t,s,n){r(!this.ws,"Cannot accept twice."),r(e),r(t),r(s),r(s.remoteAddress),r(null!=s.remotePort),r(n);let i="ws",o=s.remoteAddress,a=s.remotePort;return s.encrypted&&(i="wss"),-1!==o.indexOf(":")&&(o=`[${o}]`),a||(a=0),this.server=e,this.binary=-1===t.url.indexOf("b64=1"),this.url=`${i}://${o}:${a}/socket.io/?transport=websocket`,this.ssl="wss"===i,this.host=s.remoteAddress,this.port=s.remotePort,this.inbound=!0,this.ws=n,this.init(),this}connect(e,t,s,n){r(!this.ws,"Cannot connect twice."),"string"==typeof e&&(n=t,[e,t,s]=h.parseURL(e));let o="ws";s&&(o="wss"),t||(t="127.0.0.1"),r("string"==typeof t),r((65535&e)===e,"Must pass a port."),r(!s||"boolean"==typeof s),r(!n||Array.isArray(n));let a=t;-1!==t.indexOf(":")&&"["!==t[0]&&(a=`[${t}]`);const c=`${o}://${a}:${e}/socket.io/?transport=websocket`;return this.binary=!0,this.url=c,this.ssl=s,this.host=t,this.port=e,this.inbound=!1,this.ws=new i(c,n),this.init(),this}init(){this.protocol=this.ws.protocol,this.time=Date.now(),this.observe(),this.parser.on("error",e=>{this.emit("error",e)}),this.parser.on("frame",async e=>{try{await this.handleFrame(e)}catch(e){this.emit("error",e)}}),this.start()}observe(){const e=this.ws;r(e),e.binaryType="arraybuffer",e.onopen=async()=>{await this.onOpen()},e.onmessage=async e=>{await this.onMessage(e)},e.onerror=async e=>{await this.onError(e)},e.onclose=async e=>{await this.onClose(e)}}async onOpen(){this.destroyed||this.inbound&&(r(!this.opened),r(!this.connected),r(!this.handshake),this.opened=!0,this.handshake=!0,await this.emitAsync("open"),this.sendHandshake(),this.connected=!0,await this.emitAsync("connect"),this.sendConnect())}async emitAsync(e,...t){const s=this.listeners(e);for(const e of s)try{await e(...t)}catch(e){this.emit("error",e)}}async onMessage(e){if(this.destroyed)return;let t;try{t=await function(e){return new Promise((t,s)=>{if("string"!=typeof e)if(e&&"object"==typeof e)if(Buffer.isBuffer(e))t(e);else if(e instanceof ArrayBuffer){const s=Buffer.from(e);t(s)}else if(e.buffer instanceof ArrayBuffer){const s=Buffer.from(e.buffer,e.byteOffset,e.byteLength);t(s)}else{if("undefined"!=typeof Blob&&Blob&&e instanceof Blob){const s=new FileReader;return s.onloadend=()=>{const e=Buffer.from(s.result);t(e)},void s.readAsArrayBuffer(e)}s(new Error("Bad data object."))}else s(new Error("Bad data object."));else t(e)})}(e.data)}catch(e){return void this.emit("error",e)}"string"!=typeof t?this.parser.feedBinary(t):this.parser.feedString(t)}async onError(e){this.destroyed||(this.emit("error",new Error(e.message)),this.inbound?this.destroy():this.close())}async onClose(e){if(this.destroyed)return;if(1e3===e.code||1001===e.code)return this.connected||this.emit("error",new Error("Could not connect.")),this.inbound?void this.destroy():void this.close();const t=u[e.code]||"UNKNOWN_CODE",s=e.reason||"Unknown reason",r=new Error(`Websocket Closed: ${s} (code=${t}).`);r.reason=e.reason||"",r.code=e.code||0,this.emit("error",r),this.inbound?this.destroy():this.reconnection?this.close():this.destroy()}close(){if(!this.destroyed){this.time=Date.now(),this.packet=null,this.handshake=!1,this.connected=!1,this.challenge=!1,this.sequence=0,this.lastPing=0;for(const[e,t]of this.jobs)this.jobs.delete(e),t.reject(new Error("Job timed out."));r(this.ws),this.ws.onopen=()=>{},this.ws.onmessage=()=>{},this.ws.onerror=()=>{},this.ws.onclose=()=>{},this.ws.close(),this.emitAsync("disconnect")}}error(e){this.destroyed||this.emit("error",new Error(e))}destroy(){this.destroyed||(this.close(),this.stop(),this.opened=!1,this.destroyed=!0,this.buffer.length=0,this.emitAsync("close"),this.removeAllListeners(),this.on("error",()=>{}))}send(e){this.destroyed||(r(this.ws),e.binary&&this.binary?this.ws.send(e.toRaw()):this.ws.send(e.toString()))}reconnect(){r(!this.inbound),this.close(),this.ws=new i(this.url),this.time=Date.now(),this.observe()}start(){r(this.ws),r(null==this.timer),this.timer=setInterval(()=>this.stall(),5e3)}stop(){null!=this.timer&&(clearInterval(this.timer),this.timer=null)}stall(){const e=Date.now();if(r(this.ws),!this.connected)return e-this.time>1e4?this.inbound||!this.reconnection?(this.error("Timed out waiting for connection."),void this.destroy()):(this.error("Timed out waiting for connection. Reconnecting..."),void this.reconnect()):void 0;for(const[t,s]of this.jobs)e-s.time>6e5&&(this.jobs.delete(t),s.reject(new Error("Job timed out.")));return this.inbound||this.challenge?!this.inbound&&e-this.lastPing>this.pingTimeout?(this.error("Connection is stalling (ping)."),this.inbound?void this.destroy():void this.close()):void 0:(this.challenge=!0,this.lastPing=e,void this.sendPing())}async handleFrame(e){if(!this.destroyed)switch(e.type){case a.types.OPEN:return this.handleOpen(e);case a.types.CLOSE:return this.handleClose(e);case a.types.PING:return this.handlePing(e);case a.types.PONG:return this.handlePong(e);case a.types.MESSAGE:return this.handleMessage(e);case a.types.UPGRADE:return this.handleUpgrade(e);case a.types.NOOP:return this.handleNoop(e);default:throw new Error("Unknown frame.")}}async handleOpen(e){if(this.inbound)throw new Error("Inbound socket sent an open frame.");if(e.binary)throw new Error("Received a binary open frame.");if(this.handshake)throw new Error("Duplicate open frame.");const t=JSON.parse(e.data);g(t&&"object"==typeof t,"open","object");const{pingInterval:s,pingTimeout:r}=t;g(s>>>0===s,"interval","uint32"),g(r>>>0===r,"timeout","uint32"),this.pingInterval=s,this.pingTimeout=r,this.handshake=!0,this.opened||(this.opened=!0,await this.emitAsync("open"))}async handleClose(e){if(this.inbound)throw new Error("Inbound socket sent a close frame.");this.close()}async handlePing(){if(!this.inbound)throw new Error("Outbound socket sent a ping frame.");this.sendPong()}async handlePong(){if(this.inbound)throw new Error("Inbound socket sent a pong frame.");if(!this.challenge)return this.error("Remote node sent bad pong."),void this.destroy();this.challenge=!1}async handleMessage(e){if(this.packet){const t=this.packet;if(!e.binary)throw new Error("Received non-binary frame as attachment.");return t.buffers.push(e.data),t.buffers.length===t.attachments?(this.packet=null,this.handlePacket(t)):void 0}if(e.binary)throw new Error("Received binary frame as a message.");const t=o.fromString(e.data);if(!(t.attachments>0))return this.handlePacket(t);this.packet=t}async handleUpgrade(e){if(!this.inbound)throw new Error("Outbound socket sent an upgrade frame.");throw new Error("Cannot upgrade from websocket.")}async handleNoop(e){}sendFrame(e,t,s){this.send(new a(e,t,s))}sendOpen(e){this.sendFrame(a.types.OPEN,e,!1)}sendClose(e){this.sendFrame(a.types.CLOSE,e,!1)}sendPing(e){this.sendFrame(a.types.PING,e,!1)}sendPong(e){this.sendFrame(a.types.PONG,e,!1)}sendMessage(e){this.sendFrame(a.types.MESSAGE,e,!1)}sendBinary(e){this.sendFrame(a.types.MESSAGE,e,!0)}sendHandshake(){const e=JSON.stringify({sid:"00000000000000000000",upgrades:[],pingInterval:this.pingInterval,pingTimeout:this.pingTimeout});this.sendOpen(e)}async handlePacket(e){if(!this.destroyed)switch(e.type){case o.types.CONNECT:return this.handleConnect();case o.types.DISCONNECT:return this.handleDisconnect();case o.types.EVENT:case o.types.BINARY_EVENT:{const t=e.getData();return g(Array.isArray(t),"args","array"),g(t.length>0,"args","array"),g("string"==typeof t[0],"event","string"),-1!==e.id?this.handleCall(e.id,t):this.handleEvent(t)}case o.types.ACK:case o.types.BINARY_ACK:{g(-1!==e.id,"id","uint32");const t=e.getData();g(null==t||Array.isArray(t),"args","array");let s=null,r=null;return t&&t.length>0&&(s=t[0]),t&&t.length>1&&(r=t[1]),null==r&&(r=null),s?(g("object"==typeof s,"error","object"),this.handleError(e.id,s)):this.handleAck(e.id,r)}case o.types.ERROR:{const t=e.getData();return g(t&&"object"==typeof t,"error","object"),this.handleError(-1,t)}default:throw new Error("Unknown packet.")}}async handleConnect(){if(this.inbound)throw new Error("Inbound socket sent connect packet.");this.connected=!0,await this.emitAsync("connect");for(const e of this.buffer)this.sendPacket(e);this.buffer.length=0}async handleDisconnect(){this.close()}async handleEvent(e){try{const t=e[0];if(f.hasOwnProperty(t))throw new Error(`Cannot emit blacklisted event: ${t}.`);this.events.emit(...e)}catch(e){this.emit("error",e),this.sendError(-1,e)}}async handleCall(e,t){let s;try{const e=t.shift();if(f.hasOwnProperty(e))throw new Error(`Cannot emit blacklisted event: ${e}.`);const r=this.hooks.get(e);if(!r)throw new Error(`Call not found: ${e}.`);s=await r(...t)}catch(t){return this.emit("error",t),void this.sendError(e,t)}null==s&&(s=null),this.sendAck(e,s)}async handleAck(e,t){const s=this.jobs.get(e);if(!s)throw new Error(`Job not found for ${e}.`);this.jobs.delete(e),s.resolve(t)}async handleError(e,t){const s=d(t.message),r=_(t.name),n=_(t.type),i=p(t.code);if(-1===e){const e=new Error(s);return e.name=r,e.type=n,e.code=i,void this.emit("error",e)}const o=this.jobs.get(e);if(!o)throw new Error(`Job not found for ${e}.`);this.jobs.delete(e);const a=new Error(s);a.name=r,a.type=n,a.code=i,o.reject(a)}sendPacket(e){this.sendMessage(e.toString());for(const t of e.buffers)this.sendBinary(t)}sendConnect(){this.sendPacket(new o(o.types.CONNECT))}sendDisconnect(){this.sendPacket(new o(o.types.DISCONNECT))}sendEvent(e){const t=new o;t.type=o.types.EVENT,t.setData(e),this.connected?this.sendPacket(t):this.buffer.push(t)}sendCall(e,t){const s=new o;s.type=o.types.EVENT,s.id=e,s.setData(t),this.connected?this.sendPacket(s):this.buffer.push(s)}sendAck(e,t){const s=new o;s.type=o.types.ACK,s.id=e,s.setData([null,t]),this.sendPacket(s)}sendError(e,t){const s=d(t.message),r=_(t.name),n=_(t.type),i=p(t.code);if(-1===e){const e=new o;return e.type=o.types.ERROR,e.setData({message:s,name:r,type:n,code:i}),void this.sendPacket(e)}const a=new o;a.type=o.types.ACK,a.id=e,a.setData([{message:s,name:r,type:n,code:i}]),this.sendPacket(a)}bind(e,t){g("string"==typeof e,"event","string"),g("function"==typeof t,"handler","function"),r(!f.hasOwnProperty(e),"Blacklisted event."),this.events.on(e,t)}unbind(e,t){g("string"==typeof e,"event","string"),g("function"==typeof t,"handler","function"),r(!f.hasOwnProperty(e),"Blacklisted event."),this.events.removeListener(e,t)}fire(...e){g(e.length>0,"event","string"),g("string"==typeof e[0],"event","string"),this.sendEvent(e)}hook(e,t){g("string"==typeof e,"event","string"),g("function"==typeof t,"handler","function"),r(!this.hooks.has(e),"Hook already bound."),r(!f.hasOwnProperty(e),"Blacklisted event."),this.hooks.set(e,t)}unhook(e){g("string"==typeof e,"event","string"),r(!f.hasOwnProperty(e),"Blacklisted event."),this.hooks.delete(e)}call(...e){g(e.length>0,"event","string"),g("string"==typeof e[0],"event","string");const t=this.sequence;return this.sequence+=1,this.sequence>>>=0,r(!this.jobs.has(t),"ID collision."),this.sendCall(t,e),new Promise((e,s)=>{this.jobs.set(t,new l(e,s,Date.now()))})}channel(e){return this.channels.has(e)}join(e){return!!this.server&&this.server.join(this,e)}leave(e){return!!this.server&&this.server.leave(this,e)}static accept(e,t,s,r){return(new this).accept(e,t,s,r)}static connect(e,t,s,r){return(new this).connect(e,t,s,r)}}},function(e,t,s){"use strict";const r=s(1),n=Buffer.alloc(0),i={OPEN:0,CLOSE:1,PING:2,PONG:3,MESSAGE:4,UPGRADE:5,NOOP:6};class o{constructor(e,t,s){r("number"==typeof e),r(e>>>0===e),r(e<=i.NOOP),r("boolean"==typeof s),s?(null==t&&(t=n),r(Buffer.isBuffer(t))):(null==t&&(t=""),r("string"==typeof t)),this.type=e,this.data=t,this.binary=s}toString(){let e="";return this.binary?(e+="b",e+=this.type.toString(10),e+=this.data.toString("base64")):(e+=this.type.toString(10),e+=this.data),e}static fromString(e){r("string"==typeof e);let t,s=e.charCodeAt(0),n=!1;return 98===s?(r(e.length>1),s=e.charCodeAt(1),t=Buffer.from(e.substring(2),"base64"),n=!0):t=e.substring(1),r((s-=48)>=0&&s<=9),r(s<=i.NOOP),new this(s,t,n)}size(){let e=1;return this.binary?e+=this.data.length:e+=Buffer.byteLength(this.data,"utf8"),e}toRaw(){const e=Buffer.allocUnsafe(this.size());return e[0]=this.type,this.binary?this.data.copy(e,1):this.data.length>0&&e.write(this.data,1,"utf8"),e}static fromRaw(e){r(Buffer.isBuffer(e)),r(e.length>0);const t=e[0];return r(t<=i.NOOP),new this(t,e.slice(1),!0)}}o.types=i,o.table=["open","close","ping","pong","message","upgrade","noop"],e.exports=o},function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const r=s(11),n=s(12),i=s(23);t.Server=class{constructor(e,t=[],s={errorHandler:e=>t=>{e.destroy(),console.error(t)},closeHandler:e=>()=>{console.log("Socket closing")},connectionHandler:e=>{console.log("New websocket connection in port "+e.port)},visibility:"127.0.0.1"}){this.port=e,this.exporters=t,this.conf=s,this.ws=r.createServer(),this.io=n.createServer(),this.startWebsocket()}startWebsocket(){try{this.io.attach(this.ws),this.io.on("socket",e=>{e.on("error",this.conf.errorHandler(e)),e.on("close",this.conf.closeHandler(e)),"127.0.0.1"===this.conf.visibility?this.initRPCs(e):this.initPublicRPCs(e)}),this.ws.listen(this.port,this.conf.visibility)}catch(e){this.errorHandler(void 0)("Unable to connect to socket")}}initRPCs(e){e.hook("info",()=>t);const t=[...this.exporters.flatMap(t=>i.rpcHooker(e,t))]}initPublicRPCs(e){e.hook("info",()=>t);const t=[...this.exporters.flatMap(t=>i.rpcHooker(e,t))]}}},function(e,t){e.exports=require("http")},function(e,t,s){"use strict";const r=s(6),n=s(18),i=s(8);t.WebSocket=r,t.Server=n,t.server=()=>new n,t.createServer=n.createServer.bind(n),t.attach=n.attach.bind(n),t.Socket=i,t.socket=()=>new i,t.connect=i.connect.bind(i)},function(e,t,s){(function(e,r,n){ -/*! - * faye-websocket@0.11.1 - Standards-compliant WebSocket server and client - * Copyright (c) 2019, James Coglan (MIT) - * https://github.com/faye/faye-websocket-node - * - * License for websocket-driver@0.7.0: - * - * # The MIT License - * - * Copyright (c) 2010-2017 James Coglan - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the 'Software'), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * License for http-parser-js@0.5.0: - * - * Copyright (c) 2015 Tim Caswell (https://github.com/creationix) and other - * contributors. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Some files from the tests folder are from joyent/node and mscedex/io.js, a - * fork of nodejs/io.js: - * - * - tests/iojs/test-http-parser-durability.js - * - * This file is from - * https://github.com/mscdex/io.js/blob/js-http-parser/test/pummel/test-http-parser-durability.js - * with modifications by Jan Schär (jscissr). - * - * """ Copyright io.js contributors. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. """ - * - * - tests/fixtures/* tests/parallel/* tests/testpy/* tests/common.js - * tests/test.py tests/utils.py - * - * These files are from https://github.com/nodejs/node with changes by Jan Schär - * (jscissr). - * - * Node.js is licensed for use as follows: - * - * """ Copyright Node.js contributors. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. """ - * - * This license applies to parts of Node.js originating from the - * https://github.com/joyent/node repository: - * - * """ Copyright Joyent, Inc. and other Node contributors. All rights reserved. - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. """ - * - * License for websocket-extensions@0.1.3: - * - * # The MIT License - * - * Copyright (c) 2014-2017 James Coglan - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the 'Software'), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -var i=[["faye-websocket","/lib/faye/websocket.js",function(e,t,r,n,i){var o=s(0),h=a(1),c=a(23),u=function(e,t,s,r,n){n=n||{},this._stream=t,this._driver=h.http(e,{maxLength:n.maxLength,protocols:r});var i=this;if(this._stream&&this._stream.writable){if(!this._stream.readable)return this._stream.end();var o=function(){i._stream.removeListener("data",o)};this._stream.on("data",o),c.call(this,n),process.nextTick((function(){i._driver.start(),i._driver.io.write(s)}))}};o.inherits(u,c),u.isWebSocket=function(e){return h.isWebSocket(e)},u.validateOptions=function(e,t){h.validateOptions(e,t)},u.WebSocket=u,u.Client=a(26),u.EventSource=a(27),t.exports=u}],["websocket-driver","/lib/websocket/driver.js",function(e,t,s,r,n){"use strict";var i=a(2),o=a(6),h=a(20),c={client:function(e,t){return void 0===(t=t||{}).masking&&(t.masking=!0),new o(e,t)},server:function(e){return void 0===(e=e||{}).requireMasking&&(e.requireMasking=!0),new h(e)},http:function(){return h.http.apply(h,arguments)},isSecureRequest:function(e){return h.isSecureRequest(e)},isWebSocket:function(e){if("GET"!==e.method)return!1;var t=e.headers.connection||"",s=e.headers.upgrade||"";return"GET"===e.method&&t.toLowerCase().split(/ *, */).indexOf("upgrade")>=0&&"websocket"===s.toLowerCase()},validateOptions:function(e,t){i.validateOptions(e,t)}};t.exports=c}],["websocket-driver","/lib/websocket/driver/base.js",function(e,t,r,n,i){"use strict";var o=s(2).EventEmitter,h=s(0),c=a(3),u=a(4),f=a(5),l=function(e,t,s){o.call(this),l.validateOptions(s||{},["maxLength","masking","requireMasking","protocols"]),this._request=e,this._reader=new f,this._options=s||{},this._maxLength=this._options.maxLength||this.MAX_LENGTH,this._headers=new u,this.__queue=[],this.readyState=0,this.url=t,this.io=new c.IO(this),this.messages=new c.Messages(this),this._bindEventListeners()};h.inherits(l,o),l.validateOptions=function(e,t){for(var s in e)if(t.indexOf(s)<0)throw new Error("Unrecognized option: "+s)};var p={MAX_LENGTH:67108863,STATES:["connecting","open","closing","closed"],_bindEventListeners:function(){var e=this;this.messages.on("error",(function(){})),this.on("message",(function(t){var s=e.messages;s.readable&&s.emit("data",t.data)})),this.on("error",(function(t){var s=e.messages;s.readable&&s.emit("error",t)})),this.on("close",(function(){var t=e.messages;t.readable&&(t.readable=t.writable=!1,t.emit("end"))}))},getState:function(){return this.STATES[this.readyState]||null},addExtension:function(e){return!1},setHeader:function(e,t){return!(this.readyState>0)&&(this._headers.set(e,t),!0)},start:function(){if(0!==this.readyState)return!1;var e=this._handshakeResponse();return!!e&&(this._write(e),-1!==this._stage&&this._open(),!0)},text:function(e){return this.frame(e)},binary:function(e){return!1},ping:function(){return!1},pong:function(){return!1},close:function(e,t){return 1===this.readyState&&(this.readyState=3,this.emit("close",new l.CloseEvent(null,null)),!0)},_open:function(){this.readyState=1,this.__queue.forEach((function(e){this.frame.apply(this,e)}),this),this.__queue=[],this.emit("open",new l.OpenEvent)},_queue:function(e){return this.__queue.push(e),!0},_write:function(e){var t=this.io;t.readable&&t.emit("data",e)}};for(var d in p)l.prototype[d]=p[d];l.ConnectEvent=function(){},l.OpenEvent=function(){},l.CloseEvent=function(e,t){this.code=e,this.reason=t},l.MessageEvent=function(e){this.data=e},l.PingEvent=function(e){this.data=e},l.PongEvent=function(e){this.data=e},t.exports=l}],["websocket-driver","/lib/websocket/streams.js",function(e,t,r,n,i){"use strict";var o=s(3).Stream,a=s(0),h=function(e){this.readable=this.writable=!0,this._paused=!1,this._driver=e};a.inherits(h,o),h.prototype.pause=function(){this._paused=!0,this._driver.messages._paused=!0},h.prototype.resume=function(){this._paused=!1,this.emit("drain");var e=this._driver.messages;e._paused=!1,e.emit("drain")},h.prototype.write=function(e){return!!this.writable&&(this._driver.parse(e),!this._paused)},h.prototype.end=function(e){if(this.writable){void 0!==e&&this.write(e),this.writable=!1;var t=this._driver.messages;t.readable&&(t.readable=t.writable=!1,t.emit("end"))}},h.prototype.destroy=function(){this.end()};var c=function(e){this.readable=this.writable=!0,this._paused=!1,this._driver=e};a.inherits(c,o),c.prototype.pause=function(){this._driver.io._paused=!0},c.prototype.resume=function(){this._driver.io._paused=!1,this._driver.io.emit("drain")},c.prototype.write=function(e){return!!this.writable&&("string"==typeof e?this._driver.text(e):this._driver.binary(e),!this._paused)},c.prototype.end=function(e){void 0!==e&&this.write(e)},c.prototype.destroy=function(){},e.IO=h,e.Messages=c}],["websocket-driver","/lib/websocket/driver/headers.js",function(e,t,s,r,n){"use strict";var i=function(){this.clear()};i.prototype.ALLOWED_DUPLICATES=["set-cookie","set-cookie2","warning","www-authenticate"],i.prototype.clear=function(){this._sent={},this._lines=[]},i.prototype.set=function(e,t){if(void 0!==t){e=this._strip(e),t=this._strip(t);var s=e.toLowerCase();(!this._sent.hasOwnProperty(s)||this.ALLOWED_DUPLICATES.indexOf(s)>=0)&&(this._sent[s]=!0,this._lines.push(e+": "+t+"\r\n"))}},i.prototype.toString=function(){return this._lines.join("")},i.prototype._strip=function(e){return e.toString().replace(/^ */,"").replace(/ *$/,"")},t.exports=i}],["websocket-driver","/lib/websocket/driver/stream_reader.js",function(e,t,s,r,n){"use strict";var i=function(){this._queue=[],this._queueSize=0,this._offset=0};i.prototype.put=function(e){e&&0!==e.length&&(e.copy||(e=new Buffer(e)),this._queue.push(e),this._queueSize+=e.length)},i.prototype.read=function(e){if(e>this._queueSize)return null;if(0===e)return new Buffer(0);this._queueSize-=e;var t,s,r=this._queue,n=e,i=r[0];if(i.length>=e)return i.length===e?r.shift():(s=i.slice(0,e),r[0]=i.slice(e),s);for(var o=0,a=r.length;o0&&r.length>0&&(t.push(r[0].slice(0,n)),r[0]=r[0].slice(n)),this._concat(t,e)},i.prototype.eachByte=function(e,t){for(var s,r,n;this._queue.length>0;){for(r=(s=this._queue[0]).length;this._offset0&&this._headers.set("Sec-WebSocket-Protocol",this._protocols.join(", ")),r&&this._headers.set("Authorization","Basic "+r)};c.inherits(d,l),d.generateKey=function(){return o.randomBytes(16).toString("base64")};var _={VALID_PROTOCOLS:["ws:","wss:"],proxy:function(e,t){return new p(this,e,t)},start:function(){return-1===this.readyState&&(this._write(this._handshakeRequest()),this.readyState=0,!0)},parse:function(e){if(3!==this.readyState){if(this.readyState>0)return l.prototype.parse.call(this,e);this._http.parse(e),this._http.isComplete()&&(this._validateHandshake(),3!==this.readyState&&(this._open(),this.parse(this._http.body)))}},_handshakeRequest:function(){var e=this._extensions.generateOffer();e&&this._headers.set("Sec-WebSocket-Extensions",e);var t=["GET "+this._pathname+" HTTP/1.1",this._headers.toString(),""];return new Buffer(t.join("\r\n"),"utf8")},_failHandshake:function(e){e="Error during WebSocket handshake: "+e,this.readyState=3,this.emit("error",new Error(e)),this.emit("close",new f.CloseEvent(this.ERRORS.protocol_error,e))},_validateHandshake:function(){if(this.statusCode=this._http.statusCode,this.headers=this._http.headers,this._http.error)return this._failHandshake(this._http.error.message);if(101!==this._http.statusCode)return this._failHandshake("Unexpected response code: "+this._http.statusCode);var e=this._http.headers,t=e.upgrade||"",s=e.connection||"",r=e["sec-websocket-accept"]||"",n=e["sec-websocket-protocol"]||"";if(""===t)return this._failHandshake("'Upgrade' header is missing");if("websocket"!==t.toLowerCase())return this._failHandshake("'Upgrade' header value is not 'WebSocket'");if(""===s)return this._failHandshake("'Connection' header is missing");if("upgrade"!==s.toLowerCase())return this._failHandshake("'Connection' header value is not 'Upgrade'");if(r!==this._accept)return this._failHandshake("Sec-WebSocket-Accept mismatch");if(this.protocol=null,""!==n){if(this._protocols.indexOf(n)<0)return this._failHandshake("Sec-WebSocket-Protocol mismatch");this.protocol=n}try{this._extensions.activate(this.headers["sec-websocket-extensions"])}catch(e){return this._failHandshake(e.message)}}};for(var g in _)d.prototype[g]=_[g];t.exports=d}],["websocket-driver","/lib/websocket/http_parser.js",function(e,t,s,r,n){"use strict";var i=a(8).HTTPParser,o=process.version.match(/[0-9]+/g).map((function(e){return parseInt(e,10)})),h={request:i.REQUEST||"request",response:i.RESPONSE||"response"},c=function(e){this._type=e,this._parser=new i(h[e]),this._complete=!1,this.headers={};var t=null,s=this;this._parser.onHeaderField=function(e,s,r){t=e.toString("utf8",s,s+r).toLowerCase()},this._parser.onHeaderValue=function(e,r,n){var i=e.toString("utf8",r,r+n);s.headers.hasOwnProperty(t)?s.headers[t]+=", "+i:s.headers[t]=i},this._parser.onHeadersComplete=this._parser[i.kOnHeadersComplete]=function(e,t,r,n,i,o){var a=arguments[0];if("object"==typeof a&&(n=a.method,i=a.url,o=a.statusCode,r=a.headers),s.method="number"==typeof n?c.METHODS[n]:n,s.statusCode=o,s.url=i,r){for(var h,u,f=0,l=r.length;fa.maxHeaderSize)?new Error("max header size exceeded"):s};var g={REQUEST_LINE:!0,RESPONSE_LINE:!0,BODY_RAW:!0};a.prototype.finish=function(){if(!this.hadError)return g[this.state]?void("BODY_RAW"===this.state&&this.userCall()(this[f]())):new Error("invalid state for EOF")},a.prototype.consume=a.prototype.unconsume=a.prototype.getCurrentBuffer=function(){},a.prototype.userCall=function(){this.isUserCall=!0;var e=this;return function(t){return e.isUserCall=!1,t}},a.prototype.nextRequest=function(){this.userCall()(this[f]()),this.reinitialize(this.type)},a.prototype.consumeLine=function(){for(var e=this.end,t=this.chunk,s=this.offset;s0&&this.info.versionMinor>0){if(-1!==this.connection.indexOf("close"))return!1}else if(-1===this.connection.indexOf("keep-alive"))return!1;return!(null===this.body_bytes&&!this.isChunked)},a.prototype.HEADER=function(){var e=this.consumeLine();if(void 0!==e){var t=this.info;if(e)this.parseHeader(e,t.headers);else{for(var s,r,n=t.headers,i=!1,o=!1,h=0;h=0}))[0],this.protocol&&this._headers.set("Sec-WebSocket-Protocol",this.protocol)),this.version="hybi-"+i}};h.inherits(p,u),p.mask=function(e,t,s){if(!t||0===t.length)return e;s=s||0;for(var r=0,n=e.length-s;r1)&&this.frame(e,"text")},binary:function(e){return!(this.readyState>1)&&this.frame(e,"binary")},ping:function(e,t){return!(this.readyState>1)&&(e=e||"",t&&(this._pingCallbacks[e]=t),this.frame(e,"ping"))},pong:function(e){return!(this.readyState>1)&&(e=e||"",this.frame(e,"pong"))},close:function(e,t){return e=e||"",t=t||this.ERRORS.normal_closure,this.readyState<=0?(this.readyState=3,this.emit("close",new u.CloseEvent(t,e)),!0):1===this.readyState&&(this.readyState=2,this._extensions.close((function(){this.frame(e,"close",t)}),this),!0)},frame:function(e,t,s){if(this.readyState<=0)return this._queue([e,t,s]);if(this.readyState>2)return!1;e instanceof Array&&(e=new Buffer(e)),"number"==typeof e&&(e=e.toString());var r,n,i=new l,a="string"==typeof e;i.rsv1=i.rsv2=i.rsv3=!1,i.opcode=this.OPCODES[t||(a?"text":"binary")],r=a?new Buffer(e,"utf8"):e,s&&(n=r,(r=new Buffer(2+n.length)).writeUInt16BE(s,0),n.copy(r,2)),i.data=r;var h=function(e){var t=new f;t.final=!0,t.rsv1=e.rsv1,t.rsv2=e.rsv2,t.rsv3=e.rsv3,t.opcode=e.opcode,t.masked=!!this._masking,t.length=e.data.length,t.payload=e.data,t.masked&&(t.maskingKey=o.randomBytes(4)),this._sendFrame(t)};return this.MESSAGE_OPCODES.indexOf(i.opcode)>=0?this._extensions.processOutgoingMessage(i,(function(e,t){if(e)return this._fail("extension_error",e.message);h.call(this,t)}),this):h.call(this,i),!0},_sendFrame:function(e){var t=e.length,s=t<=125?2:t<=65535?4:10,r=s+(e.masked?4:0),n=new Buffer(r+t),i=e.masked?this.MASK:0;n[0]=(e.final?this.FIN:0)|(e.rsv1?this.RSV1:0)|(e.rsv2?this.RSV2:0)|(e.rsv3?this.RSV3:0)|e.opcode,t<=125?n[1]=i|t:t<=65535?(n[1]=126|i,n.writeUInt16BE(t,2)):(n[1]=127|i,n.writeUInt32BE(Math.floor(t/4294967296),2),n.writeUInt32BE(t%4294967296,6)),e.payload.copy(n,r),e.masked&&(e.maskingKey.copy(n,s),p.mask(n,e.maskingKey,r)),this._write(n)},_handshakeResponse:function(){try{var e=this._extensions.generateResponse(this._request.headers["sec-websocket-extensions"])}catch(e){return this._fail("protocol_error",e.message)}e&&this._headers.set("Sec-WebSocket-Extensions",e);var t=["HTTP/1.1 101 Switching Protocols",this._headers.toString(),""];return new Buffer(t.join("\r\n"),"utf8")},_shutdown:function(e,t,s){delete this._frame,delete this._message,this._stage=5;var r=1===this.readyState;this.readyState=2,this._extensions.close((function(){r&&this.frame(t,"close",e),this.readyState=3,s&&this.emit("error",new Error(t)),this.emit("close",new u.CloseEvent(e,t))}),this)},_fail:function(e,t){this.readyState>1||this._shutdown(this.ERRORS[e],t,!0)},_parseOpcode:function(e){var t=[this.RSV1,this.RSV2,this.RSV3].map((function(t){return(e&t)===t})),s=this._frame=new f;return s.final=(e&this.FIN)===this.FIN,s.rsv1=t[0],s.rsv2=t[1],s.rsv3=t[2],s.opcode=e&this.OPCODE,this._stage=1,this._extensions.validFrameRsv(s)?this.OPCODE_CODES.indexOf(s.opcode)<0?this._fail("protocol_error","Unrecognized frame opcode: "+s.opcode):this.MESSAGE_OPCODES.indexOf(s.opcode)<0&&!s.final?this._fail("protocol_error","Received fragmented control frame: opcode = "+s.opcode):this._message&&this.OPENING_OPCODES.indexOf(s.opcode)>=0?this._fail("protocol_error","Received new data frame but previous continuous frame is unfinished"):void 0:this._fail("protocol_error","One or more reserved bits are on: reserved1 = "+(s.rsv1?1:0)+", reserved2 = "+(s.rsv2?1:0)+", reserved3 = "+(s.rsv3?1:0))},_parseLength:function(e){var t=this._frame;if(t.masked=(e&this.MASK)===this.MASK,t.length=e&this.LENGTH,t.length>=0&&t.length<=125){if(this._stage=t.masked?3:4,!this._checkFrameLength())return}else this._stage=2,t.lengthBytes=126===t.length?2:8;if(this._requireMasking&&!t.masked)return this._fail("unacceptable","Received unmasked frame but masking is required")},_parseExtendedLength:function(e){var t=this._frame;if(t.length=this._readUInt(e),this._stage=t.masked?3:4,this.MESSAGE_OPCODES.indexOf(t.opcode)<0&&t.length>125)return this._fail("protocol_error","Received control frame having too long payload: "+t.length);this._checkFrameLength()},_checkFrameLength:function(){return!((this._message?this._message.length:0)+this._frame.length>this._maxLength)||(this._fail("too_large","WebSocket frame length too large"),!1)},_emitFrame:function(e){var t,s,r,n,i,o=this._frame,a=o.payload=p.mask(e,o.maskingKey),h=o.opcode;if(delete this._frame,h===this.OPCODES.continuation){if(!this._message)return this._fail("protocol_error","Received unexpected continuation frame");this._message.pushFrame(o)}if(h!==this.OPCODES.text&&h!==this.OPCODES.binary||(this._message=new l,this._message.pushFrame(o)),o.final&&this.MESSAGE_OPCODES.indexOf(h)>=0)return this._emitMessage(this._message);h===this.OPCODES.close&&(s=a.length>=2?a.readUInt16BE(0):null,r=a.length>2?this._encode(a.slice(2)):null,0!==a.length&&!(null!==s&&s>=this.MIN_RESERVED_ERROR&&s<=this.MAX_RESERVED_ERROR)&&this.ERROR_CODES.indexOf(s)<0&&(s=this.ERRORS.protocol_error),(a.length>125||a.length>2&&!r)&&(s=this.ERRORS.protocol_error),this._shutdown(s||this.DEFAULT_ERROR_CODE,r||"")),h===this.OPCODES.ping&&(this.frame(a,"pong"),this.emit("ping",new u.PingEvent(a.toString()))),h===this.OPCODES.pong&&(i=(n=this._pingCallbacks)[t=this._encode(a)],delete n[t],i&&i(),this.emit("pong",new u.PongEvent(a.toString())))},_emitMessage:function(e){(e=this._message).read(),delete this._message,this._extensions.processIncomingMessage(e,(function(e,t){if(e)return this._fail("extension_error",e.message);var s=t.data;if(t.opcode===this.OPCODES.text&&(s=this._encode(s)),null===s)return this._fail("encoding_error","Could not decode a text frame as UTF-8");this.emit("message",new u.MessageEvent(s))}),this)},_encode:function(e){try{var t=e.toString("binary",0,e.length);if(!this.UTF8_MATCH.test(t))return null}catch(e){}return e.toString("utf8",0,e.length)},_readUInt:function(e){return 2===e.length?e.readUInt16BE(0):4294967296*e.readUInt32BE(0)+e.readUInt32BE(4)}};for(var _ in d)p.prototype[_]=d[_];t.exports=p}],["websocket-extensions","/lib/websocket_extensions.js",function(e,t,s,r,n){"use strict";var i=a(11),o=a(12),h=function(){this._rsv1=this._rsv2=this._rsv3=null,this._byName={},this._inOrder=[],this._sessions=[],this._index={}};h.MESSAGE_OPCODES=[1,2];var c={add:function(e){if("string"!=typeof e.name)throw new TypeError("extension.name must be a string");if("permessage"!==e.type)throw new TypeError('extension.type must be "permessage"');if("boolean"!=typeof e.rsv1)throw new TypeError("extension.rsv1 must be true or false");if("boolean"!=typeof e.rsv2)throw new TypeError("extension.rsv2 must be true or false");if("boolean"!=typeof e.rsv3)throw new TypeError("extension.rsv3 must be true or false");if(this._byName.hasOwnProperty(e.name))throw new TypeError('An extension with name "'+e.name+'" is already registered');this._byName[e.name]=e,this._inOrder.push(e)},generateOffer:function(){var e=[],t=[],s={};return this._inOrder.forEach((function(r){var n=r.createClientSession();if(n){var o=[r,n];e.push(o),s[r.name]=o;var a=n.generateOffer();(a=a?[].concat(a):[]).forEach((function(e){t.push(i.serializeParams(r.name,e))}),this)}}),this),this._sessions=e,this._index=s,t.length>0?t.join(", "):null},activate:function(e){var t=i.parseHeader(e),s=[];t.eachOffer((function(e,t){var r=this._index[e];if(!r)throw new Error('Server sent an extension response for unknown extension "'+e+'"');var n=r[0],o=r[1],a=this._reserved(n);if(a)throw new Error("Server sent two extension responses that use the RSV"+a[0]+' bit: "'+a[1]+'" and "'+n.name+'"');if(!0!==o.activate(t))throw new Error("Server sent unacceptable extension parameters: "+i.serializeParams(e,t));this._reserve(n),s.push(r)}),this),this._sessions=s,this._pipeline=new o(s)},generateResponse:function(e){var t=[],s=[],r=i.parseHeader(e);return this._inOrder.forEach((function(e){var n=r.byName(e.name);if(0!==n.length&&!this._reserved(e)){var o=e.createServerSession(n);o&&(this._reserve(e),t.push([e,o]),s.push(i.serializeParams(e.name,o.generateResponse())))}}),this),this._sessions=t,this._pipeline=new o(t),s.length>0?s.join(", "):null},validFrameRsv:function(e){var t,s={rsv1:!1,rsv2:!1,rsv3:!1};if(h.MESSAGE_OPCODES.indexOf(e.opcode)>=0)for(var r=0,n=this._sessions.length;r0&&t.peek().done;)(e=t.shift()).error?(this.pending=0,t.clear()):this.pending-=1,e.callback.call(e.context,e.error,e.message)},t.exports=o}],["websocket-extensions","/lib/pipeline/ring_buffer.js",function(e,t,s,r,n){"use strict";var i=function(e){this._bufferSize=e,this.clear()};i.prototype.clear=function(){this._buffer=new Array(this._bufferSize),this._ringOffset=0,this._ringSize=this._bufferSize,this._head=0,this._tail=0,this.length=0},i.prototype.push=function(e){var t=!1,s=!1;this._ringSize0?(this._head=this._ringSize,this._ringOffset=this.length,this._ringSize=this._bufferSize):this._head=(this._head+1)%this._ringSize,e}},t.exports=i}],["websocket-extensions","/lib/pipeline/pledge.js",function(e,t,s,r,n){"use strict";var i=a(15),o=function(){this._complete=!1,this._callbacks=new i(o.QUEUE_SIZE)};o.QUEUE_SIZE=4,o.all=function(e){var t=new o,s=e.length,r=s;for(0===s&&t.done();r--;)e[r].then((function(){0===(s-=1)&&t.done()}));return t},o.prototype.then=function(e){this._complete?e():this._callbacks.push(e)},o.prototype.done=function(){this._complete=!0;for(var e,t=this._callbacks;e=t.shift();)e()},t.exports=o}],["websocket-driver","/lib/websocket/driver/hybi/frame.js",function(e,t,s,r,n){"use strict";var i=function(){},o={final:!1,rsv1:!1,rsv2:!1,rsv3:!1,opcode:null,masked:!1,maskingKey:null,lengthBytes:1,length:0,payload:null};for(var a in o)i.prototype[a]=o[a];t.exports=i}],["websocket-driver","/lib/websocket/driver/hybi/message.js",function(e,t,s,r,n){"use strict";var i=function(){this.rsv1=!1,this.rsv2=!1,this.rsv3=!1,this.opcode=null,this.length=0,this._chunks=[]},o={read:function(){if(this.data)return this.data;this.data=new Buffer(this.length);for(var e=0,t=0,s=this._chunks.length;t1||(this._reader.put(e),this._reader.eachByte((function(e){var t;switch(this._stage){case-1:this._body.push(e),this._sendHandshakeBody();break;case 0:this._parseLeadingByte(e);break;case 1:if(this._length=(127&e)+128*this._length,this._closing&&0===this._length)return this.close();128!=(128&e)&&(0===this._length?this._stage=0:(this._skipped=0,this._stage=2));break;case 2:if(255===e)this._stage=0,t=new Buffer(this._buffer).toString("utf8",0,this._buffer.length),this.emit("message",new o.MessageEvent(t));else if(this._length)this._skipped+=1,this._skipped===this._length&&(this._stage=0);else if(this._buffer.push(e),this._buffer.length>this._maxLength)return this.close()}}),this))},frame:function(e){if(0===this.readyState)return this._queue([e]);if(this.readyState>1)return!1;"string"!=typeof e&&(e=e.toString());var t=new Buffer(e,"utf8"),s=new Buffer(t.length+2);return s[0]=0,s[t.length+1]=255,t.copy(s,1),this._write(s),!0},_handshakeResponse:function(){var e=["HTTP/1.1 101 Web Socket Protocol Handshake",this._headers.toString(),""];return new Buffer(e.join("\r\n"),"utf8")},_parseLeadingByte:function(e){128==(128&e)?(this._length=0,this._stage=1):(delete this._length,delete this._skipped,this._buffer=[],this._stage=2)}};for(var u in c)h.prototype[u]=c[u];t.exports=h}],["websocket-driver","/lib/websocket/driver/draft76.js",function(e,t,r,n,i){"use strict";var o=a(2),h=a(21),c=s(4),u=s(0),f=function(e){return parseInt(e.match(/[0-9]/g).join(""),10)},l=function(e){return e.match(/ /g).length},p=function(e,t,s){h.apply(this,arguments),this._stage=-1,this._body=[],this.version="hixie-76",this._headers.clear(),this._headers.set("Upgrade","WebSocket"),this._headers.set("Connection","Upgrade"),this._headers.set("Sec-WebSocket-Origin",this._request.headers.origin),this._headers.set("Sec-WebSocket-Location",this.url)};u.inherits(p,h);var d={BODY_SIZE:8,start:function(){return!!h.prototype.start.call(this)&&(this._started=!0,this._sendHandshakeBody(),!0)},close:function(){return 3!==this.readyState&&(this._write(new Buffer([255,0])),this.readyState=3,this.emit("close",new o.CloseEvent(null,null)),!0)},_handshakeResponse:function(){var e=(o=this._request.headers)["sec-websocket-key1"],t=f(e),s=l(e),r=o["sec-websocket-key2"],n=f(r),i=l(r);if(t%s!=0||n%i!=0)return this.emit("error",new Error("Client sent invalid Sec-WebSocket-Key headers")),this.close(),null;this._keyValues=[t/s,n/i];var o=["HTTP/1.1 101 WebSocket Protocol Handshake",this._headers.toString(),""];return new Buffer(o.join("\r\n"),"binary")},_handshakeSignature:function(){if(this._body.lengththis.BODY_SIZE&&this.parse(this._body.slice(this.BODY_SIZE)))}},_parseLeadingByte:function(e){if(255!==e)return h.prototype._parseLeadingByte.call(this,e);this._closing=!0,this._length=0,this._stage=1}};for(var _ in d)p.prototype[_]=d[_];t.exports=p}],["faye-websocket","/lib/faye/websocket/api.js",function(e,t,r,n,i){var o=s(3).Stream,h=s(0),c=a(1),u=a(24),f=a(25),l=function(e){e=e||{},c.validateOptions(e,["headers","extensions","maxLength","ping","proxy","tls","ca"]),this.readable=this.writable=!0;var t=e.headers;if(t)for(var s in t)this._driver.setHeader(s,t[s]);var r=e.extensions;r&&[].concat(r).forEach(this._driver.addExtension,this._driver),this._ping=e.ping,this._pingId=0,this.readyState=l.CONNECTING,this.bufferedAmount=0,this.protocol="",this.url=this._driver.url,this.version=this._driver.version;var n=this;this._driver.on("open",(function(e){n._open()})),this._driver.on("message",(function(e){n._receiveMessage(e.data)})),this._driver.on("close",(function(e){n._beginClose(e.reason,e.code)})),this._driver.on("error",(function(e){n._emitError(e.message)})),this.on("error",(function(){})),this._driver.messages.on("drain",(function(){n.emit("drain")})),this._ping&&(this._pingTimer=setInterval((function(){n._pingId+=1,n.ping(n._pingId.toString())}),1e3*this._ping)),this._configureStream(),this._proxy||(this._stream.pipe(this._driver.io),this._driver.io.pipe(this._stream))};h.inherits(l,o),l.CONNECTING=0,l.OPEN=1,l.CLOSING=2,l.CLOSED=3,l.CLOSE_TIMEOUT=3e4;var p={write:function(e){return this.send(e)},end:function(e){void 0!==e&&this.send(e),this.close()},pause:function(){return this._driver.messages.pause()},resume:function(){return this._driver.messages.resume()},send:function(e){return!(this.readyState>l.OPEN)&&(e instanceof Buffer||(e=String(e)),this._driver.messages.write(e))},ping:function(e,t){return!(this.readyState>l.OPEN)&&this._driver.ping(e,t)},close:function(e,t){if(void 0===e&&(e=1e3),void 0===t&&(t=""),1e3!==e&&(e<3e3||e>4999))throw new Error("Failed to execute 'close' on WebSocket: The code must be either 1000, or between 3000 and 4999. "+e+" is neither.");this.readyState!==l.CLOSED&&(this.readyState=l.CLOSING);var s=this;this._closeTimer=setTimeout((function(){s._beginClose("",1006)}),l.CLOSE_TIMEOUT),this._driver.close(t,e)},_configureStream:function(){var e=this;this._stream.setTimeout(0),this._stream.setNoDelay(!0),["close","end"].forEach((function(t){this._stream.on(t,(function(){e._finalizeClose()}))}),this),this._stream.on("error",(function(t){e._emitError("Network error: "+e.url+": "+t.message),e._finalizeClose()}))},_open:function(){if(this.readyState===l.CONNECTING){this.readyState=l.OPEN,this.protocol=this._driver.protocol||"";var e=new f("open");e.initEvent("open",!1,!1),this.dispatchEvent(e)}},_receiveMessage:function(e){if(this.readyState>l.OPEN)return!1;this.readable&&this.emit("data",e);var t=new f("message",{data:e});t.initEvent("message",!1,!1),this.dispatchEvent(t)},_emitError:function(e){if(!(this.readyState>=l.CLOSING)){var t=new f("error",{message:e});t.initEvent("error",!1,!1),this.dispatchEvent(t)}},_beginClose:function(e,t){this.readyState!==l.CLOSED&&(this.readyState=l.CLOSING,this._closeParams=[e,t],this._stream&&(this._stream.destroy(),this._stream.readable||this._finalizeClose()))},_finalizeClose:function(){if(this._closeTimer&&clearTimeout(this._closeTimer),this.readyState!==l.CLOSED){this.readyState=l.CLOSED,this._pingTimer&&clearInterval(this._pingTimer),this._stream&&this._stream.end(),this.readable&&this.emit("end"),this.readable=this.writable=!1;var e=this._closeParams?this._closeParams[0]:"",t=this._closeParams?this._closeParams[1]:1006,s=new f("close",{code:t,reason:e});s.initEvent("close",!1,!1),this.dispatchEvent(s)}}};for(var d in p)l.prototype[d]=p[d];for(var _ in u)l.prototype[_]=u[_];t.exports=l}],["faye-websocket","/lib/faye/websocket/api/event_target.js",function(e,t,s,r,n){var i=a(25),o={onopen:null,onmessage:null,onerror:null,onclose:null,addEventListener:function(e,t,s){this.on(e,t)},removeEventListener:function(e,t,s){this.removeListener(e,t)},dispatchEvent:function(e){e.target=e.currentTarget=this,e.eventPhase=i.AT_TARGET,this["on"+e.type]&&this["on"+e.type](e),this.emit(e.type,e)}};t.exports=o}],["faye-websocket","/lib/faye/websocket/api/event.js",function(e,t,s,r,n){var i=function(e,t){for(var s in this.type=e,t)this[s]=t[s]};i.prototype.initEvent=function(e,t,s){this.type=e,this.bubbles=t,this.cancelable=s},i.prototype.stopPropagation=function(){},i.prototype.preventDefault=function(){},i.CAPTURING_PHASE=1,i.AT_TARGET=2,i.BUBBLING_PHASE=3,t.exports=i}],["faye-websocket","/lib/faye/websocket/client.js",function(e,t,r,n,i){var o=s(0),h=s(16),c=s(17),u=s(5),f=a(1),l=a(23),p=(a(25),{"http:":80,"https:":443,"ws:":80,"wss:":443}),d=["https:","wss:"],_=function(e,t,s){s=s||{},this.url=e,this._driver=f.client(this.url,{maxLength:s.maxLength,protocols:t}),["open","error"].forEach((function(e){this._driver.on(e,(function(){v.headers=v._driver.headers,v.statusCode=v._driver.statusCode}))}),this);var r=s.proxy||{},n=u.parse(r.origin||this.url),i=n.port||p[n.protocol],o=d.indexOf(n.protocol)>=0,a=function(){v._onConnect()},_=s.net||{},g=s.tls||{},y=r.origin?r.tls||{}:g,v=this;_.host=y.host=n.hostname,_.port=y.port=i,g.ca=g.ca||s.ca,y.servername=y.servername||n.hostname,this._stream=o?c.connect(y,a):h.connect(_,a),r.origin&&this._configureProxy(r,g),l.call(this,s)};o.inherits(_,l),_.prototype._onConnect=function(){(this._proxy||this._driver).start()},_.prototype._configureProxy=function(e,t){var s,r=u.parse(this.url),n=d.indexOf(r.protocol)>=0,i=this;if(this._proxy=this._driver.proxy(e.origin),e.headers)for(s in e.headers)this._proxy.setHeader(s,e.headers[s]);this._proxy.pipe(this._stream,{end:!1}),this._stream.pipe(this._proxy),this._proxy.on("connect",(function(){if(n){var e={socket:i._stream,servername:r.hostname};for(s in t)e[s]=t[s];i._stream=c.connect(e),i._configureStream()}i._driver.io.pipe(i._stream),i._stream.pipe(i._driver.io),i._driver.start()})),this._proxy.on("error",(function(e){i._driver.emit("error",e)}))},t.exports=_}],["faye-websocket","/lib/faye/eventsource.js",function(e,t,r,n,i){var o=s(3).Stream,h=s(0),c=a(1),u=a(4),f=a(23),l=a(24),p=a(25),d=function(e,t,s){this.writable=!0,s=s||{},this._stream=t.socket,this._ping=s.ping||this.DEFAULT_PING,this._retry=s.retry||this.DEFAULT_RETRY;var r=c.isSecureRequest(e)?"https:":"http:";this.url=r+"//"+e.headers.host+e.url,this.lastEventId=e.headers["last-event-id"]||"",this.readyState=f.CONNECTING;var n=new u,i=this;if(s.headers)for(var o in s.headers)n.set(o,s.headers[o]);if(this._stream&&this._stream.writable){process.nextTick((function(){i._open()})),this._stream.setTimeout(0),this._stream.setNoDelay(!0);var a="HTTP/1.1 200 OK\r\nContent-Type: text/event-stream\r\nCache-Control: no-cache, no-store\r\nConnection: close\r\n"+n.toString()+"\r\nretry: "+Math.floor(1e3*this._retry)+"\r\n\r\n";this._write(a),this._stream.on("drain",(function(){i.emit("drain")})),this._ping&&(this._pingTimer=setInterval((function(){i.ping()}),1e3*this._ping)),["error","end"].forEach((function(e){i._stream.on(e,(function(){i.close()}))}))}};h.inherits(d,o),d.isEventSource=function(e){return"GET"===e.method&&(e.headers.accept||"").split(/\s*,\s*/).indexOf("text/event-stream")>=0};var _={DEFAULT_PING:10,DEFAULT_RETRY:5,_write:function(e){if(!this.writable)return!1;try{return this._stream.write(e,"utf8")}catch(e){return!1}},_open:function(){if(this.readyState===f.CONNECTING){this.readyState=f.OPEN;var e=new p("open");e.initEvent("open",!1,!1),this.dispatchEvent(e)}},write:function(e){return this.send(e)},end:function(e){void 0!==e&&this.write(e),this.close()},send:function(e,t){if(this.readyState>f.OPEN)return!1;e=String(e).replace(/(\r\n|\r|\n)/g,"$1data: ");var s="";return(t=t||{}).event&&(s+="event: "+t.event+"\r\n"),t.id&&(s+="id: "+t.id+"\r\n"),s+="data: "+e+"\r\n\r\n",this._write(s)},ping:function(){return this._write(":\r\n\r\n")},close:function(){if(this.readyState>f.OPEN)return!1;this.readyState=f.CLOSED,this.writable=!1,this._pingTimer&&clearInterval(this._pingTimer),this._stream&&this._stream.end();var e=new p("close");return e.initEvent("close",!1,!1),this.dispatchEvent(e),!0}};for(var g in _)d.prototype[g]=_[g];for(var y in l)d.prototype[y]=l[y];t.exports=d}]],o=[];function a(s){if(s>>>0!==s||s>i.length)return function(e){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}(s);for(;o.length<=s;)o.push(null);var a=o[s];if(a)return a.exports;var h=i[s],c=h[0],u=h[1],f=h[2],l=t,p=e;0!==s&&(p={id:"/"+c+u,exports:l={},parent:e.parent,filename:e.filename,loaded:!1,children:e.children,paths:e.paths}),o[s]=p;try{f.call(l,l,p,r,n,void 0)}catch(e){throw o[s]=null,e}return i[s]=null,0!==s&&(p.loaded=!0),p.exports}a(0)}).call(this,s(14)(e),"/index.js","/")},function(e,t){e.exports=function(e){return e.webpackPolyfill||(e.deprecate=function(){},e.paths=[],e.children||(e.children=[]),Object.defineProperty(e,"loaded",{enumerable:!0,get:function(){return e.l}}),Object.defineProperty(e,"id",{enumerable:!0,get:function(){return e.i}}),e.webpackPolyfill=1),e}},function(e,t){e.exports=require("assert")},function(e,t){e.exports=require("net")},function(e,t){e.exports=require("tls")},function(e,t,s){"use strict";const r=s(1),n=s(2),i=s(7),o=s(6),a=s(8);e.exports=class extends n{constructor(e={}){super(),r(!e.protocols||Array.isArray(e.protocols)),this.protocols=e.protocols||void 0,this.sockets=new Set,this.channels=new Map,this.mounts=[],this.mounted=!1}handleSocket(e){this.add(e),e.on("close",()=>{this.remove(e)}),this.emit("socket",e);for(const t of this.mounts)t.emit("socket",e)}mount(e){r(!e.mounted),e.mounted=!0,e.sockets=this.sockets,e.channels=this.channels,this.mounts.push(e)}async open(){}async close(){if(!this.mounted)for(const e of this.sockets)e.destroy()}attach(e){const t=(e,t,s)=>{if(!t.remoteAddress)return void t.destroy();if(!o.isWebSocket(e))return void t.destroy();const r=new o(e,t,s,this.protocols),n=a.accept(this,e,t,r);this.handleSocket(n)};return e.on("upgrade",(e,s,r)=>{try{t(e,s,r)}catch(e){this.emit("error",e)}}),this}add(e){this.sockets.add(e)}remove(e){for(const t of e.channels)this.leave(e,t);r(this.sockets.delete(e))}join(e,t){if(e.channels.has(t))return!1;return this.channels.has(t)||this.channels.set(t,new Set),this.channels.get(t).add(e),e.channels.add(t),!0}leave(e,t){if(!e.channels.has(t))return!1;const s=this.channels.get(t);return r(s),r(s.delete(e)),0===s.size&&this.channels.delete(t),e.channels.delete(t),!0}channel(e){const t=this.channels.get(e);return t?(r(t.size>0),t):null}event(e){r(e.length>0,"Event must be present."),r("string"==typeof e[0],"Event must be a string.");const t=new i;return t.type=i.types.EVENT,t.setData(e),t}to(e,...t){const s=this.channels.get(e);if(!s)return;r(s.size>0);const n=this.event(t);for(const e of s)e.sendPacket(n)}all(...e){const t=this.event(e);for(const e of this.sockets)e.sendPacket(t)}static attach(e,t){return new this(t).attach(e)}static createServer(e){return new this(e)}}},function(e,t,s){"use strict";const r=s(1),n=s(5);t.parseURL=function(e){-1===e.indexOf("://")&&(e=`ws://${e}`);const t=n.parse(e);if("http:"!==t.protocol&&"https:"!==t.protocol&&"ws:"!==t.protocol&&"wss:"!==t.protocol)throw new Error("Invalid protocol for websocket URL.");if(!t.hostname)throw new Error("Malformed URL.");const s=t.hostname;let i=80,o=!1;return"https:"!==t.protocol&&"wss:"!==t.protocol||(i=443,o=!0),t.port&&(i=parseInt(t.port,10),r((65535&i)===i),r(0!==i)),[i,s,o]}},function(e,t,s){"use strict"; -/*! - * parser.js - packet parser - * Copyright (c) 2017, Christopher Jeffrey (MIT License). - * https://github.com/chjj - */const r=s(1),n=s(2),i=s(9),o=1e8;e.exports=class extends n{constructor(){super()}error(e){this.emit("error",new Error(e))}feedBinary(e){if(r(Buffer.isBuffer(e)),e.length>o)return void this.error("Frame too large.");let t;try{t=i.fromRaw(e)}catch(e){return void this.emit("error",e)}this.emit("frame",t)}feedString(e){if(r("string"==typeof e),Buffer.byteLength(e,"utf8")>o)return void this.error("Frame too large.");let t;try{t=i.fromString(e)}catch(e){return void this.emit("error",e)}this.emit("frame",t)}}},function(e,t,s){"use strict";e.exports={1e3:"NORMAL_CLOSURE",1001:"GOING_AWAY",1002:"PROTOCOL_ERROR",1003:"UNSUPPORTED_DATA",1004:"RESERVED",1005:"NO_STATUS_RECVD",1006:"ABNORMAL_CLOSURE",1007:"INVALID_FRAME_PAYLOAD_DATA",1008:"POLICY_VIOLATION",1009:"MESSAGE_TOO_BIG",1010:"MISSING_EXTENSION",1011:"INTERNAL_ERROR",1012:"SERVICE_RESTART",1013:"TRY_AGAIN_LATER",1014:"BAD_GATEWAY",1015:"TLS_HANDSHAKE"}},function(e,t,s){"use strict";e.exports={connect:!0,connect_error:!0,connect_timeout:!0,connecting:!0,disconnect:!0,error:!0,reconnect:!0,reconnect_attempt:!0,reconnect_failed:!0,reconnect_error:!0,reconnecting:!0,ping:!0,pong:!0}},function(module,exports,__webpack_require__){"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const uuid=__webpack_require__(24);function rpcHooker(e,t,s=!0){const r=t.name,n=[...t.publicRPCs(),...t.localRPCs()],i=s?"-"+uuid().substr(0,4):"";return n.map(e=>exports.rpcToRpcinfo(e,r)).map(t=>{const s=t;switch(s.uniqueName=t.name+i,t.type){case"Hook":e.hook(s.uniqueName,t.generator(e));break;case"Unhook":e.hook(s.uniqueName,t.unhook);break;case"Call":e.hook(s.uniqueName,t.call)}return e.on("close",()=>e.unhook(t.name)),s})}exports.rpcToRpcinfo=(e,t)=>{switch(e.type){case"Call":return{owner:t,argNames:extractArgs(e.call),type:e.type,name:e.name,call:e.call};case"Unhook":return{owner:t,argNames:extractArgs(e.unhook),type:e.type,name:e.name,unhook:e.unhook};case"Hook":const s=hookGenerator(e);return{owner:t,argNames:extractArgs(s(void 0)),type:e.type,name:e.name,unhook:e.unhook,generator:s}}},exports.rpcHooker=rpcHooker;const hookGenerator=rpc=>{const argsArr=extractArgs(rpc.clbk);argsArr.pop();const args=argsArr.join(",");return eval("(socket) => async ("+args+") => { \n const res = await rpc.clbk("+args+(0!==args.length?",":"")+" (x) => {\n socket.call(res.uid, x)\n })\n if(res.result == 'Success'){\n socket.on('close', async () => {\n const unhookRes = await rpc.unhook(res.uid)\n console.log(\"Specific close handler for\", rpc.name, res.uid, unhookRes)\n })\n\n }\n return res\n }")},extractArgs=e=>{let t=String(e),s=t.substr(0,t.indexOf(")"));return(s=s.substr(t.indexOf("(")+1)).split(",")}},function(e,t,s){var r=s(25),n=s(26);e.exports=function(e,t,s){var i=t&&s||0;"string"==typeof e&&(t="binary"===e?new Array(16):null,e=null);var o=(e=e||{}).random||(e.rng||r)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,t)for(var a=0;a<16;++a)t[i+a]=o[a];return t||n(o)}},function(e,t,s){var r=s(4);e.exports=function(){return r.randomBytes(16)}},function(e,t){for(var s=[],r=0;r<256;++r)s[r]=(r+256).toString(16).substr(1);e.exports=function(e,t){var r=t||0,n=s;return[n[e[r++]],n[e[r++]],n[e[r++]],n[e[r++]],"-",n[e[r++]],n[e[r++]],"-",n[e[r++]],n[e[r++]],"-",n[e[r++]],n[e[r++]],"-",n[e[r++]],n[e[r++]],n[e[r++]],n[e[r++]],n[e[r++]],n[e[r++]]].join("")}}])); \ No newline at end of file diff --git a/lib/Frontend.js b/lib/Frontend.js deleted file mode 100644 index d1da19b..0000000 --- a/lib/Frontend.js +++ /dev/null @@ -1,19 +0,0 @@ -!function(t,e){for(var r in e)t[r]=e[r]}(exports,function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=6)}([function(t,e,r){"use strict"; -/*! - * assert.js - assertions for javascript - * Copyright (c) 2018, Christopher Jeffrey (MIT License). - * https://github.com/chjj/bsert - */class n extends Error{constructor(t){"string"==typeof t&&(t={message:t}),null!==t&&"object"==typeof t||(t={});let e=null,r="fail",n=Boolean(t.generatedMessage);var o;if(null!=t.message&&(e="string"==typeof(o=t.message)?o:E(o)?d(o):p(o)),"string"==typeof t.operator&&(r=t.operator),null==e){if("fail"===r)e="Assertion failed.";else{e=`${p(t.actual)} ${r} ${p(t.expected)}`}n=!0}super(e);let s=this.constructor;"function"==typeof t.stackStartFunction?s=t.stackStartFunction:"function"==typeof t.stackStartFn&&(s=t.stackStartFn),this.type="AssertionError",this.name="AssertionError [ERR_ASSERTION]",this.code="ERR_ASSERTION",this.generatedMessage=n,this.actual=t.actual,this.expected=t.expected,this.operator=r,Error.captureStackTrace&&Error.captureStackTrace(this,s)}}function o(t,e){if(!t){let r=!1;if(0===arguments.length)e="No value argument passed to `assert()`.",r=!0;else if(null==e)e="Assertion failed.",r=!0;else if(E(e))throw e;throw new n({message:e,actual:t,expected:!0,operator:"==",generatedMessage:r,stackStartFn:o})}}function s(t,e,r){if(!Object.is(t,e)){if(E(r))throw r;throw new n({message:r,actual:t,expected:e,operator:"strictEqual",stackStartFn:s})}}function i(t,e,r){if(Object.is(t,e)){if(E(r))throw r;throw new n({message:r,actual:t,expected:e,operator:"notStrictEqual",stackStartFn:i})}}function a(t,e,r){"string"==typeof e&&(r=e,e=void 0);let o=!1,s=null;l("function"==typeof t,"func","function");try{t()}catch(t){o=!0,s=t}if(o){if(g(s,e,r,a)){let t=!1;throw null==r&&(r="Got unwanted exception.",t=!0),new n({message:r,actual:s,expected:e,operator:"doesNotThrow",generatedMessage:t,stackStartFn:a})}throw s}}async function h(t,e,r){"string"==typeof e&&(r=e,e=void 0);let o=!1,s=null;"function"!=typeof t&&l(O(t),"func","promise");try{O(t)?await t:await t()}catch(t){o=!0,s=t}if(!o){let t=!1;throw null==r&&(r="Missing expected rejection.",t=!0),new n({message:r,actual:void 0,expected:e,operator:"rejects",generatedMessage:t,stackStartFn:h})}if(!g(s,e,r,h))throw s}async function u(t,e,r){"string"==typeof e&&(r=e,e=void 0);let o=!1,s=null;"function"!=typeof t&&l(O(t),"func","promise");try{O(t)?await t:await t()}catch(t){o=!0,s=t}if(o){if(g(s,e,r,u)){let t=!1;throw null==r&&(r="Got unwanted rejection.",t=!0),new n({message:r,actual:void 0,expected:e,operator:"doesNotReject",generatedMessage:t,stackStartFn:u})}throw s}}function c(t,e,r){if(!y(t,e,!1)){if(E(r))throw r;throw new n({message:r,actual:t,expected:e,operator:"deepStrictEqual",stackStartFn:c})}}function f(t,e,r){if(y(t,e,!0)){if(E(r))throw r;throw new n({message:r,actual:t,expected:e,operator:"notDeepStrictEqual",stackStartFn:f})}}function l(t,e,r){if(!t){let t;t=null==e?"Invalid type for parameter.":null==r?`Invalid type for "${e}".`:`"${e}" must be a(n) ${r}.`;const n=new TypeError(t);throw Error.captureStackTrace&&Error.captureStackTrace(n,l),n}}function p(t){switch(typeof t){case"undefined":return"undefined";case"object":return null===t?"null":`[${function(t){const e=function(t){return v(t).slice(8,-1)}(t);if(null==t)return e;if("Object"!==e&&"Error"!==e)return e;let r,n;try{r=t.constructor}catch(t){}if(null==r)return e;try{n=r.name}catch(t){return e}return"string"!=typeof n||0===n.length?e:n}(t)}]`;case"boolean":case"number":return`${t}`;case"string":return t.length>80&&(t=`${t.substring(0,77)}...`),JSON.stringify(t);case"symbol":return d(t);case"function":return`[${function(t){let e;try{e=t.name}catch(t){}return"string"!=typeof e||0===e.length?"Function":`Function: ${e}`}(t)}]`;case"bigint":return`${t}n`;default:return`[${typeof t}]`}}function d(t){try{return String(t)}catch(t){return"Object"}}function g(t,e,r,o){if(null==e)return!0;if(S(e))return e.test(t);if("function"!=typeof e){if(o===a||o===u)throw new TypeError('"expected" must not be an object.');if("object"!=typeof e)throw new TypeError('"expected" must be an object.');let s=!1;if(null==r){r=`Missing expected ${o===h?"rejection":"exception"}.`,s=!0}if(null==t||"object"!=typeof t)throw new n({actual:t,expected:e,message:r,operator:o.name,generatedMessage:s,stackStartFn:o});const i=Object.keys(e);if(E(e)&&i.push("name","message"),0===i.length)throw new TypeError('"expected" may not be an empty object.');for(const a of i){const i=e[a],h=t[a];if(("string"!=typeof h||!S(i)||!i.test(h))&&!(a in t&&y(h,i,!1)))throw new n({actual:t,expected:e,message:r,operator:o.name,generatedMessage:s,stackStartFn:o})}return!0}return void 0!==e.prototype&&t instanceof e||!Error.isPrototypeOf(e)&&!0===e.call({},t)}function y(t,e,r){try{return m(t,e,null)}catch(t){return r}}function m(t,e,r){if(Object.is(t,e))return!0;if(!A(t)||!A(e))return!1;if(v(t)!==v(e))return!1;if(Object.getPrototypeOf(t)!==Object.getPrototypeOf(e))return!1;if(b(t)&&b(e))return t.equals(e);if(t instanceof Date)return Object.is(t.getTime(),e.getTime());if(S(t))return t.source===e.source&&t.global===e.global&&t.multiline===e.multiline&&t.lastIndex===e.lastIndex&&t.ignoreCase===e.ignoreCase;if(E(t)&&t.message!==e.message)return!1;if(function(t){return t instanceof ArrayBuffer}(t)&&(t=new Uint8Array(t),e=new Uint8Array(e)),function(t){return ArrayBuffer.isView(t)}(t)&&!b(t)){if(b(e))return!1;const r=new Uint8Array(t.buffer),n=new Uint8Array(e.buffer);if(r.length!==n.length)return!1;for(let t=0;t>>1?null:o}return e}o.AssertionError=n,o.assert=o,o.strict=o,o.ok=o,o.equal=s,o.notEqual=i,o.strictEqual=s,o.notStrictEqual=i,o.fail=function t(e){let r=!1;if(E(e))throw e;throw null==e&&(e="Assertion failed.",r=!0),new n({message:e,actual:!1,expected:!0,operator:"fail",generatedMessage:r,stackStartFn:t})},o.throws=function t(e,r,o){"string"==typeof r&&(o=r,r=void 0);let s=!1,i=null;l("function"==typeof e,"func","function");try{e()}catch(t){s=!0,i=t}if(!s){let e=!1;throw null==o&&(o="Missing expected exception.",e=!0),new n({message:o,actual:void 0,expected:r,operator:"throws",generatedMessage:e,stackStartFn:t})}if(!g(i,r,o,t))throw i},o.doesNotThrow=a,o.rejects=h,o.doesNotReject=u,o.ifError=function t(e){if(null!=e){let r="ifError got unwanted exception: ";throw"object"==typeof e&&"string"==typeof e.message?0===e.message.length&&e.constructor?r+=e.constructor.name:r+=e.message:r+=p(e),new n({message:r,actual:e,expected:null,operator:"ifError",generatedMessage:!0,stackStartFn:t})}},o.deepEqual=c,o.notDeepEqual=f,o.deepStrictEqual=c,o.notDeepStrictEqual=f,o.bufferEqual=function t(e,r,o,s){if(_(o)||(s=o,o=null),null==o&&(o="hex"),r=R(e,r,o),l(b(e),"actual","buffer"),l(b(r),"expected","buffer"),e!==r&&!e.equals(r)){if(E(s))throw s;throw new n({message:s,actual:e.toString(o),expected:r.toString(o),operator:"bufferEqual",stackStartFn:t})}},o.notBufferEqual=function t(e,r,o,s){if(_(o)||(s=o,o=null),null==o&&(o="hex"),r=R(e,r,o),l(b(e),"actual","buffer"),l(b(r),"expected","buffer"),e===r||e.equals(r)){if(E(s))throw s;throw new n({message:s,actual:e.toString(o),expected:r.toString(o),operator:"notBufferEqual",stackStartFn:t})}},o.enforce=l,o.range=function t(e,r){if(!e){const e=new RangeError(null!=r?`"${r}" is out of range.`:"Parameter is out of range.");throw Error.captureStackTrace&&Error.captureStackTrace(e,t),e}},t.exports=o},function(t,e,r){"use strict";(function(t){ -/*! - * The buffer module from node.js, for the browser. - * - * @author Feross Aboukhadijeh - * @license MIT - */ -var n=r(10),o=r(11),s=r(12);function i(){return h.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function a(t,e){if(i()=i())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+i().toString(16)+" bytes");return 0|t}function d(t,e){if(h.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return F(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return q(t).length;default:if(n)return F(t).length;e=(""+e).toLowerCase(),n=!0}}function g(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 j(this,e,r);case"utf8":case"utf-8":return R(this,e,r);case"ascii":return P(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 C(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function y(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function m(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),r=+r,isNaN(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=h.from(e,n)),h.isBuffer(e))return 0===e.length?-1:w(t,e,r,n,o);if("number"==typeof e)return e&=255,h.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):w(t,[e],r,n,o);throw new TypeError("val must be string, number or Buffer")}function w(t,e,r,n,o){var s,i=1,a=t.length,h=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;i=2,a/=2,h/=2,r/=2}function u(t,e){return 1===i?t[e]:t.readUInt16BE(e*i)}if(o){var c=-1;for(s=r;sa&&(r=a-h),s=r;s>=0;s--){for(var f=!0,l=0;lo&&(n=o):n=o;var s=e.length;if(s%2!=0)throw new TypeError("Invalid hex string");n>s/2&&(n=s/2);for(var i=0;i>8,o=r%256,s.push(o),s.push(n);return s}(e,t.length-r),t,r,n)}function _(t,e,r){return 0===e&&r===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,r))}function R(t,e,r){r=Math.min(t.length,r);for(var n=[],o=e;o239?4:u>223?3:u>191?2:1;if(o+f<=r)switch(f){case 1:u<128&&(c=u);break;case 2:128==(192&(s=t[o+1]))&&(h=(31&u)<<6|63&s)>127&&(c=h);break;case 3:s=t[o+1],i=t[o+2],128==(192&s)&&128==(192&i)&&(h=(15&u)<<12|(63&s)<<6|63&i)>2047&&(h<55296||h>57343)&&(c=h);break;case 4:s=t[o+1],i=t[o+2],a=t[o+3],128==(192&s)&&128==(192&i)&&128==(192&a)&&(h=(15&u)<<18|(63&s)<<12|(63&i)<<6|63&a)>65535&&h<1114112&&(c=h)}null===c?(c=65533,f=1):c>65535&&(c-=65536,n.push(c>>>10&1023|55296),c=56320|1023&c),n.push(c),o+=f}return function(t){var e=t.length;if(e<=k)return String.fromCharCode.apply(String,t);var r="",n=0;for(;n0&&(t=this.toString("hex",0,r).match(/.{2}/g).join(" "),this.length>r&&(t+=" ... ")),""},h.prototype.compare=function(t,e,r,n,o){if(!h.isBuffer(t))throw new TypeError("Argument must be a Buffer");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 s=(o>>>=0)-(n>>>=0),i=(r>>>=0)-(e>>>=0),a=Math.min(s,i),u=this.slice(n,o),c=t.slice(e,r),f=0;fo)&&(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 s=!1;;)switch(n){case"hex":return v(this,t,e,r);case"utf8":case"utf-8":return b(this,t,e,r);case"ascii":return E(this,t,e,r);case"latin1":case"binary":return A(this,t,e,r);case"base64":return O(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return S(this,t,e,r);default:if(s)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),s=!0}},h.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var k=4096;function P(t,e,r){var n="";r=Math.min(t.length,r);for(var o=e;on)&&(r=n);for(var o="",s=e;sr)throw new RangeError("Trying to access beyond buffer length")}function N(t,e,r,n,o,s){if(!h.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||et.length)throw new RangeError("Index out of range")}function I(t,e,r,n){e<0&&(e=65535+e+1);for(var o=0,s=Math.min(t.length-r,2);o>>8*(n?o:1-o)}function B(t,e,r,n){e<0&&(e=4294967295+e+1);for(var o=0,s=Math.min(t.length-r,4);o>>8*(n?o:3-o)&255}function U(t,e,r,n,o,s){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,r,n,s){return s||U(t,0,r,4),o.write(t,e,r,n,23,4),r+4}function M(t,e,r,n,s){return s||U(t,0,r,8),o.write(t,e,r,n,52,8),r+8}h.prototype.slice=function(t,e){var r,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e0&&(o*=256);)n+=this[t+--e]*o;return n},h.prototype.readUInt8=function(t,e){return e||x(t,1,this.length),this[t]},h.prototype.readUInt16LE=function(t,e){return e||x(t,2,this.length),this[t]|this[t+1]<<8},h.prototype.readUInt16BE=function(t,e){return e||x(t,2,this.length),this[t]<<8|this[t+1]},h.prototype.readUInt32LE=function(t,e){return e||x(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},h.prototype.readUInt32BE=function(t,e){return e||x(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},h.prototype.readIntLE=function(t,e,r){t|=0,e|=0,r||x(t,e,this.length);for(var n=this[t],o=1,s=0;++s=(o*=128)&&(n-=Math.pow(2,8*e)),n},h.prototype.readIntBE=function(t,e,r){t|=0,e|=0,r||x(t,e,this.length);for(var n=e,o=1,s=this[t+--n];n>0&&(o*=256);)s+=this[t+--n]*o;return s>=(o*=128)&&(s-=Math.pow(2,8*e)),s},h.prototype.readInt8=function(t,e){return e||x(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},h.prototype.readInt16LE=function(t,e){e||x(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},h.prototype.readInt16BE=function(t,e){e||x(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},h.prototype.readInt32LE=function(t,e){return e||x(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},h.prototype.readInt32BE=function(t,e){return e||x(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},h.prototype.readFloatLE=function(t,e){return e||x(t,4,this.length),o.read(this,t,!0,23,4)},h.prototype.readFloatBE=function(t,e){return e||x(t,4,this.length),o.read(this,t,!1,23,4)},h.prototype.readDoubleLE=function(t,e){return e||x(t,8,this.length),o.read(this,t,!0,52,8)},h.prototype.readDoubleBE=function(t,e){return e||x(t,8,this.length),o.read(this,t,!1,52,8)},h.prototype.writeUIntLE=function(t,e,r,n){(t=+t,e|=0,r|=0,n)||N(this,t,e,r,Math.pow(2,8*r)-1,0);var o=1,s=0;for(this[e]=255&t;++s=0&&(s*=256);)this[e+o]=t/s&255;return e+r},h.prototype.writeUInt8=function(t,e,r){return t=+t,e|=0,r||N(this,t,e,1,255,0),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},h.prototype.writeUInt16LE=function(t,e,r){return t=+t,e|=0,r||N(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):I(this,t,e,!0),e+2},h.prototype.writeUInt16BE=function(t,e,r){return t=+t,e|=0,r||N(this,t,e,2,65535,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):I(this,t,e,!1),e+2},h.prototype.writeUInt32LE=function(t,e,r){return t=+t,e|=0,r||N(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):B(this,t,e,!0),e+4},h.prototype.writeUInt32BE=function(t,e,r){return t=+t,e|=0,r||N(this,t,e,4,4294967295,0),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):B(this,t,e,!1),e+4},h.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e|=0,!n){var o=Math.pow(2,8*r-1);N(this,t,e,r,o-1,-o)}var s=0,i=1,a=0;for(this[e]=255&t;++s>0)-a&255;return e+r},h.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e|=0,!n){var o=Math.pow(2,8*r-1);N(this,t,e,r,o-1,-o)}var s=r-1,i=1,a=0;for(this[e+s]=255&t;--s>=0&&(i*=256);)t<0&&0===a&&0!==this[e+s+1]&&(a=1),this[e+s]=(t/i>>0)-a&255;return e+r},h.prototype.writeInt8=function(t,e,r){return t=+t,e|=0,r||N(this,t,e,1,127,-128),h.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},h.prototype.writeInt16LE=function(t,e,r){return t=+t,e|=0,r||N(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):I(this,t,e,!0),e+2},h.prototype.writeInt16BE=function(t,e,r){return t=+t,e|=0,r||N(this,t,e,2,32767,-32768),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):I(this,t,e,!1),e+2},h.prototype.writeInt32LE=function(t,e,r){return t=+t,e|=0,r||N(this,t,e,4,2147483647,-2147483648),h.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):B(this,t,e,!0),e+4},h.prototype.writeInt32BE=function(t,e,r){return t=+t,e|=0,r||N(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),h.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):B(this,t,e,!1),e+4},h.prototype.writeFloatLE=function(t,e,r){return L(this,t,e,!0,r)},h.prototype.writeFloatBE=function(t,e,r){return L(this,t,e,!1,r)},h.prototype.writeDoubleLE=function(t,e,r){return M(this,t,e,!0,r)},h.prototype.writeDoubleBE=function(t,e,r){return M(this,t,e,!1,r)},h.prototype.copy=function(t,e,r,n){if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e=0;--o)t[o+e]=this[o+r];else if(s<1e3||!h.TYPED_ARRAY_SUPPORT)for(o=0;o>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(s=e;s55295&&r<57344){if(!o){if(r>56319){(e-=3)>-1&&s.push(239,191,189);continue}if(i+1===n){(e-=3)>-1&&s.push(239,191,189);continue}o=r;continue}if(r<56320){(e-=3)>-1&&s.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&(e-=3)>-1&&s.push(239,191,189);if(o=null,r<128){if((e-=1)<0)break;s.push(r)}else if(r<2048){if((e-=2)<0)break;s.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;s.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;s.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return s}function q(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(D,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function $(t,e,r,n){for(var o=0;o=e.length||o>=t.length);++o)e[o+r]=t[o];return o}}).call(this,r(2))},function(t,e){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(t){"object"==typeof window&&(r=window)}t.exports=r},function(t,e,r){"use strict";var n,o="object"==typeof Reflect?Reflect:null,s=o&&"function"==typeof o.apply?o.apply:function(t,e,r){return Function.prototype.apply.call(t,e,r)};n=o&&"function"==typeof o.ownKeys?o.ownKeys:Object.getOwnPropertySymbols?function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:function(t){return Object.getOwnPropertyNames(t)};var i=Number.isNaN||function(t){return t!=t};function a(){a.init.call(this)}t.exports=a,a.EventEmitter=a,a.prototype._events=void 0,a.prototype._eventsCount=0,a.prototype._maxListeners=void 0;var h=10;function u(t){return void 0===t._maxListeners?a.defaultMaxListeners:t._maxListeners}function c(t,e,r,n){var o,s,i,a;if("function"!=typeof r)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof r);if(void 0===(s=t._events)?(s=t._events=Object.create(null),t._eventsCount=0):(void 0!==s.newListener&&(t.emit("newListener",e,r.listener?r.listener:r),s=t._events),i=s[e]),void 0===i)i=s[e]=r,++t._eventsCount;else if("function"==typeof i?i=s[e]=n?[r,i]:[i,r]:n?i.unshift(r):i.push(r),(o=u(t))>0&&i.length>o&&!i.warned){i.warned=!0;var h=new Error("Possible EventEmitter memory leak detected. "+i.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");h.name="MaxListenersExceededWarning",h.emitter=t,h.type=e,h.count=i.length,a=h,console&&console.warn&&console.warn(a)}return t}function f(){for(var t=[],e=0;e0&&(i=e[0]),i instanceof Error)throw i;var a=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw a.context=i,a}var h=o[t];if(void 0===h)return!1;if("function"==typeof h)s(h,this,e);else{var u=h.length,c=g(h,u);for(r=0;r=0;s--)if(r[s]===e||r[s].listener===e){i=r[s].listener,o=s;break}if(o<0)return this;0===o?r.shift():function(t,e){for(;e+1=0;n--)this.removeListener(t,e[n]);return this},a.prototype.listeners=function(t){return p(this,t,!0)},a.prototype.rawListeners=function(t){return p(this,t,!1)},a.listenerCount=function(t,e){return"function"==typeof t.listenerCount?t.listenerCount(e):d.call(t,e)},a.prototype.listenerCount=d,a.prototype.eventNames=function(){return this._eventsCount>0?n(this._events):[]}},function(t,e,r){"use strict";(function(e){t.exports={Client:e.WebSocket||e.MozWebSocket,EventSource:e.EventSource}}).call(this,r(2))},function(t,e,r){"use strict";(function(e){const n=r(0),o=e.alloc(0),s={OPEN:0,CLOSE:1,PING:2,PONG:3,MESSAGE:4,UPGRADE:5,NOOP:6};class i{constructor(t,r,i){n("number"==typeof t),n(t>>>0===t),n(t<=s.NOOP),n("boolean"==typeof i),i?(null==r&&(r=o),n(e.isBuffer(r))):(null==r&&(r=""),n("string"==typeof r)),this.type=t,this.data=r,this.binary=i}toString(){let t="";return this.binary?(t+="b",t+=this.type.toString(10),t+=this.data.toString("base64")):(t+=this.type.toString(10),t+=this.data),t}static fromString(t){n("string"==typeof t);let r,o=t.charCodeAt(0),i=!1;return 98===o?(n(t.length>1),o=t.charCodeAt(1),r=e.from(t.substring(2),"base64"),i=!0):r=t.substring(1),n((o-=48)>=0&&o<=9),n(o<=s.NOOP),new this(o,r,i)}size(){let t=1;return this.binary?t+=this.data.length:t+=e.byteLength(this.data,"utf8"),t}toRaw(){const t=e.allocUnsafe(this.size());return t[0]=this.type,this.binary?this.data.copy(t,1):this.data.length>0&&t.write(this.data,1,"utf8"),t}static fromRaw(t){n(e.isBuffer(t)),n(t.length>0);const r=t[0];return n(r<=s.NOOP),new this(r,t.slice(1),!0)}}i.types=s,i.table=["open","close","ping","pong","message","upgrade","noop"],t.exports=i}).call(this,r(1).Buffer)},function(module,exports,__webpack_require__){"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var bsock=__webpack_require__(7);function stripAfterEquals(t){return t.split("=")[0]}class Client{constructor(t,e,r=!1){this.port=t,this.server=e,this.tls=r}hook(t,e){return this.socket.hook(t,e)}unhook(t){return this.socket.unhook(t)}on(t,e){return this.socket.on(t,e)}destroy(){return this.socket.destroy()}close(){return this.socket.close()}async call(t,...e){return await this.socket.call.apply(this.socket,[t,...e])}async fire(t,...e){return await this.socket.fire.apply(this.socket,[t,...e])}async connect(){this.socket=await bsock.connect(this.port,this.server,this.tls),(await this.info()).forEach(t=>{let e;switch(t.type){case"Call":e=this.callGenerator(t.uniqueName,t.argNames);break;case"Hook":e=this.hookGenerator(t.uniqueName,t.argNames);break;case"Unhook":e=this.unhookGenerator(t.uniqueName,t.argNames)}null==this[t.owner]&&(this[t.owner]={}),this[t.owner][t.name]=e,this[t.owner][t.name].bind(this)})}async info(){return await this.socket.call("info")}callGenerator(fnName,fnArgs){const headerArgs=fnArgs.join(","),argParams=fnArgs.map(stripAfterEquals).join(",");return eval("( () => async ("+headerArgs+') => { return await this.socket.call("'+fnName+'", '+argParams+")} )()")}hookGenerator(fnName,fnArgs){const headerArgs=fnArgs.join(","),argParams=fnArgs.map(stripAfterEquals).join(",");return eval("( () => async ("+headerArgs+(0!==headerArgs.length?",":"")+' callback) => {\n const r = await this.socket.call("'+fnName+'", '+argParams+")\n if(r.uid != null){\n this.socket.hook(res.uid, callback)\n }\n return res\n } )()")}unhookGenerator(fnName,fnArgs){const headerArgs=fnArgs.join(","),argParams=fnArgs.map(stripAfterEquals).join(",");return 1!=fnArgs.length&&console.error("UnhookFunction",fnName,"specified more than one argument: ("+headerArgs+")"),eval("( () => async ("+headerArgs+') => {\n const r = await this.socket.call("'+fnName+'", '+argParams+")\n this.socket.unhook("+argParams+")\n return res\n } )()")}}exports.Client=Client},function(t,e,r){"use strict";const n=r(4),o=r(8),s=r(9);e.WebSocket=n,e.Server=o,e.server=()=>new o,e.createServer=o.createServer.bind(o),e.attach=o.attach.bind(o),e.Socket=s,e.socket=()=>new s,e.connect=s.connect.bind(s)},function(t,e,r){"use strict";const n=r(3);t.exports=class extends n{constructor(t){super(),this.sockets=new Set,this.channels=new Map,this.mounts=[]}attach(){return this}mount(){}async open(){}async close(){}join(){return!0}leave(){return!0}channel(){return null}to(){}all(){}static attach(t,e){return new this(e).attach(t)}static createServer(t){return new this(t)}}},function(t,e,r){"use strict";(function(e){const n=r(0),o=r(3),s=r(4).Client,i=r(13),a=r(5),h=r(14),u=r(22),c=r(23),f=r(24);class l{constructor(t,e,r){this.resolve=t,this.reject=e,this.time=r}}function p(t){return null!==t&&"number"!=typeof t&&"string"!=typeof t?null:t}function d(t){return"string"!=typeof t?"No message.":t}function g(t){return"string"!=typeof t?null:t}function y(t,e,r){if(!t){const t=new TypeError(`'${e}' must be a(n) ${r}.`);throw Error.captureStackTrace&&Error.captureStackTrace(t,y),t}}t.exports=class extends o{constructor(){super(),this.server=null,this.ws=null,this.protocol="",this.url="ws://127.0.0.1:80/socket.io/?transport=websocket",this.ssl=!1,this.host="127.0.0.1",this.port=80,this.inbound=!1,this.handshake=!1,this.opened=!1,this.connected=!1,this.challenge=!1,this.destroyed=!1,this.reconnection=!0,this.time=0,this.sequence=0,this.pingInterval=25e3,this.pingTimeout=6e4,this.lastPing=0,this.parser=new u,this.binary=!1,this.packet=null,this.timer=null,this.jobs=new Map,this.hooks=new Map,this.channels=new Set,this.events=new o,this.buffer=[],this.admin=!1,this.auth=!1}accept(t,e,r,o){n(!this.ws,"Cannot accept twice."),n(t),n(e),n(r),n(r.remoteAddress),n(null!=r.remotePort),n(o);let s="ws",i=r.remoteAddress,a=r.remotePort;return r.encrypted&&(s="wss"),-1!==i.indexOf(":")&&(i=`[${i}]`),a||(a=0),this.server=t,this.binary=-1===e.url.indexOf("b64=1"),this.url=`${s}://${i}:${a}/socket.io/?transport=websocket`,this.ssl="wss"===s,this.host=r.remoteAddress,this.port=r.remotePort,this.inbound=!0,this.ws=o,this.init(),this}connect(t,e,r,o){n(!this.ws,"Cannot connect twice."),"string"==typeof t&&(o=e,[t,e,r]=h.parseURL(t));let i="ws";r&&(i="wss"),e||(e="127.0.0.1"),n("string"==typeof e),n((65535&t)===t,"Must pass a port."),n(!r||"boolean"==typeof r),n(!o||Array.isArray(o));let a=e;-1!==e.indexOf(":")&&"["!==e[0]&&(a=`[${e}]`);const u=`${i}://${a}:${t}/socket.io/?transport=websocket`;return this.binary=!0,this.url=u,this.ssl=r,this.host=e,this.port=t,this.inbound=!1,this.ws=new s(u,o),this.init(),this}init(){this.protocol=this.ws.protocol,this.time=Date.now(),this.observe(),this.parser.on("error",t=>{this.emit("error",t)}),this.parser.on("frame",async t=>{try{await this.handleFrame(t)}catch(t){this.emit("error",t)}}),this.start()}observe(){const t=this.ws;n(t),t.binaryType="arraybuffer",t.onopen=async()=>{await this.onOpen()},t.onmessage=async t=>{await this.onMessage(t)},t.onerror=async t=>{await this.onError(t)},t.onclose=async t=>{await this.onClose(t)}}async onOpen(){this.destroyed||this.inbound&&(n(!this.opened),n(!this.connected),n(!this.handshake),this.opened=!0,this.handshake=!0,await this.emitAsync("open"),this.sendHandshake(),this.connected=!0,await this.emitAsync("connect"),this.sendConnect())}async emitAsync(t,...e){const r=this.listeners(t);for(const t of r)try{await t(...e)}catch(t){this.emit("error",t)}}async onMessage(t){if(this.destroyed)return;let r;try{r=await function(t){return new Promise((r,n)=>{if("string"!=typeof t)if(t&&"object"==typeof t)if(e.isBuffer(t))r(t);else if(t instanceof ArrayBuffer){const n=e.from(t);r(n)}else if(t.buffer instanceof ArrayBuffer){const n=e.from(t.buffer,t.byteOffset,t.byteLength);r(n)}else{if("undefined"!=typeof Blob&&Blob&&t instanceof Blob){const n=new FileReader;return n.onloadend=()=>{const t=e.from(n.result);r(t)},void n.readAsArrayBuffer(t)}n(new Error("Bad data object."))}else n(new Error("Bad data object."));else r(t)})}(t.data)}catch(t){return void this.emit("error",t)}"string"!=typeof r?this.parser.feedBinary(r):this.parser.feedString(r)}async onError(t){this.destroyed||(this.emit("error",new Error(t.message)),this.inbound?this.destroy():this.close())}async onClose(t){if(this.destroyed)return;if(1e3===t.code||1001===t.code)return this.connected||this.emit("error",new Error("Could not connect.")),this.inbound?void this.destroy():void this.close();const e=c[t.code]||"UNKNOWN_CODE",r=t.reason||"Unknown reason",n=new Error(`Websocket Closed: ${r} (code=${e}).`);n.reason=t.reason||"",n.code=t.code||0,this.emit("error",n),this.inbound?this.destroy():this.reconnection?this.close():this.destroy()}close(){if(!this.destroyed){this.time=Date.now(),this.packet=null,this.handshake=!1,this.connected=!1,this.challenge=!1,this.sequence=0,this.lastPing=0;for(const[t,e]of this.jobs)this.jobs.delete(t),e.reject(new Error("Job timed out."));n(this.ws),this.ws.onopen=()=>{},this.ws.onmessage=()=>{},this.ws.onerror=()=>{},this.ws.onclose=()=>{},this.ws.close(),this.emitAsync("disconnect")}}error(t){this.destroyed||this.emit("error",new Error(t))}destroy(){this.destroyed||(this.close(),this.stop(),this.opened=!1,this.destroyed=!0,this.buffer.length=0,this.emitAsync("close"),this.removeAllListeners(),this.on("error",()=>{}))}send(t){this.destroyed||(n(this.ws),t.binary&&this.binary?this.ws.send(t.toRaw()):this.ws.send(t.toString()))}reconnect(){n(!this.inbound),this.close(),this.ws=new s(this.url),this.time=Date.now(),this.observe()}start(){n(this.ws),n(null==this.timer),this.timer=setInterval(()=>this.stall(),5e3)}stop(){null!=this.timer&&(clearInterval(this.timer),this.timer=null)}stall(){const t=Date.now();if(n(this.ws),!this.connected)return t-this.time>1e4?this.inbound||!this.reconnection?(this.error("Timed out waiting for connection."),void this.destroy()):(this.error("Timed out waiting for connection. Reconnecting..."),void this.reconnect()):void 0;for(const[e,r]of this.jobs)t-r.time>6e5&&(this.jobs.delete(e),r.reject(new Error("Job timed out.")));return this.inbound||this.challenge?!this.inbound&&t-this.lastPing>this.pingTimeout?(this.error("Connection is stalling (ping)."),this.inbound?void this.destroy():void this.close()):void 0:(this.challenge=!0,this.lastPing=t,void this.sendPing())}async handleFrame(t){if(!this.destroyed)switch(t.type){case a.types.OPEN:return this.handleOpen(t);case a.types.CLOSE:return this.handleClose(t);case a.types.PING:return this.handlePing(t);case a.types.PONG:return this.handlePong(t);case a.types.MESSAGE:return this.handleMessage(t);case a.types.UPGRADE:return this.handleUpgrade(t);case a.types.NOOP:return this.handleNoop(t);default:throw new Error("Unknown frame.")}}async handleOpen(t){if(this.inbound)throw new Error("Inbound socket sent an open frame.");if(t.binary)throw new Error("Received a binary open frame.");if(this.handshake)throw new Error("Duplicate open frame.");const e=JSON.parse(t.data);y(e&&"object"==typeof e,"open","object");const{pingInterval:r,pingTimeout:n}=e;y(r>>>0===r,"interval","uint32"),y(n>>>0===n,"timeout","uint32"),this.pingInterval=r,this.pingTimeout=n,this.handshake=!0,this.opened||(this.opened=!0,await this.emitAsync("open"))}async handleClose(t){if(this.inbound)throw new Error("Inbound socket sent a close frame.");this.close()}async handlePing(){if(!this.inbound)throw new Error("Outbound socket sent a ping frame.");this.sendPong()}async handlePong(){if(this.inbound)throw new Error("Inbound socket sent a pong frame.");if(!this.challenge)return this.error("Remote node sent bad pong."),void this.destroy();this.challenge=!1}async handleMessage(t){if(this.packet){const e=this.packet;if(!t.binary)throw new Error("Received non-binary frame as attachment.");return e.buffers.push(t.data),e.buffers.length===e.attachments?(this.packet=null,this.handlePacket(e)):void 0}if(t.binary)throw new Error("Received binary frame as a message.");const e=i.fromString(t.data);if(!(e.attachments>0))return this.handlePacket(e);this.packet=e}async handleUpgrade(t){if(!this.inbound)throw new Error("Outbound socket sent an upgrade frame.");throw new Error("Cannot upgrade from websocket.")}async handleNoop(t){}sendFrame(t,e,r){this.send(new a(t,e,r))}sendOpen(t){this.sendFrame(a.types.OPEN,t,!1)}sendClose(t){this.sendFrame(a.types.CLOSE,t,!1)}sendPing(t){this.sendFrame(a.types.PING,t,!1)}sendPong(t){this.sendFrame(a.types.PONG,t,!1)}sendMessage(t){this.sendFrame(a.types.MESSAGE,t,!1)}sendBinary(t){this.sendFrame(a.types.MESSAGE,t,!0)}sendHandshake(){const t=JSON.stringify({sid:"00000000000000000000",upgrades:[],pingInterval:this.pingInterval,pingTimeout:this.pingTimeout});this.sendOpen(t)}async handlePacket(t){if(!this.destroyed)switch(t.type){case i.types.CONNECT:return this.handleConnect();case i.types.DISCONNECT:return this.handleDisconnect();case i.types.EVENT:case i.types.BINARY_EVENT:{const e=t.getData();return y(Array.isArray(e),"args","array"),y(e.length>0,"args","array"),y("string"==typeof e[0],"event","string"),-1!==t.id?this.handleCall(t.id,e):this.handleEvent(e)}case i.types.ACK:case i.types.BINARY_ACK:{y(-1!==t.id,"id","uint32");const e=t.getData();y(null==e||Array.isArray(e),"args","array");let r=null,n=null;return e&&e.length>0&&(r=e[0]),e&&e.length>1&&(n=e[1]),null==n&&(n=null),r?(y("object"==typeof r,"error","object"),this.handleError(t.id,r)):this.handleAck(t.id,n)}case i.types.ERROR:{const e=t.getData();return y(e&&"object"==typeof e,"error","object"),this.handleError(-1,e)}default:throw new Error("Unknown packet.")}}async handleConnect(){if(this.inbound)throw new Error("Inbound socket sent connect packet.");this.connected=!0,await this.emitAsync("connect");for(const t of this.buffer)this.sendPacket(t);this.buffer.length=0}async handleDisconnect(){this.close()}async handleEvent(t){try{const e=t[0];if(f.hasOwnProperty(e))throw new Error(`Cannot emit blacklisted event: ${e}.`);this.events.emit(...t)}catch(t){this.emit("error",t),this.sendError(-1,t)}}async handleCall(t,e){let r;try{const t=e.shift();if(f.hasOwnProperty(t))throw new Error(`Cannot emit blacklisted event: ${t}.`);const n=this.hooks.get(t);if(!n)throw new Error(`Call not found: ${t}.`);r=await n(...e)}catch(e){return this.emit("error",e),void this.sendError(t,e)}null==r&&(r=null),this.sendAck(t,r)}async handleAck(t,e){const r=this.jobs.get(t);if(!r)throw new Error(`Job not found for ${t}.`);this.jobs.delete(t),r.resolve(e)}async handleError(t,e){const r=d(e.message),n=g(e.name),o=g(e.type),s=p(e.code);if(-1===t){const t=new Error(r);return t.name=n,t.type=o,t.code=s,void this.emit("error",t)}const i=this.jobs.get(t);if(!i)throw new Error(`Job not found for ${t}.`);this.jobs.delete(t);const a=new Error(r);a.name=n,a.type=o,a.code=s,i.reject(a)}sendPacket(t){this.sendMessage(t.toString());for(const e of t.buffers)this.sendBinary(e)}sendConnect(){this.sendPacket(new i(i.types.CONNECT))}sendDisconnect(){this.sendPacket(new i(i.types.DISCONNECT))}sendEvent(t){const e=new i;e.type=i.types.EVENT,e.setData(t),this.connected?this.sendPacket(e):this.buffer.push(e)}sendCall(t,e){const r=new i;r.type=i.types.EVENT,r.id=t,r.setData(e),this.connected?this.sendPacket(r):this.buffer.push(r)}sendAck(t,e){const r=new i;r.type=i.types.ACK,r.id=t,r.setData([null,e]),this.sendPacket(r)}sendError(t,e){const r=d(e.message),n=g(e.name),o=g(e.type),s=p(e.code);if(-1===t){const t=new i;return t.type=i.types.ERROR,t.setData({message:r,name:n,type:o,code:s}),void this.sendPacket(t)}const a=new i;a.type=i.types.ACK,a.id=t,a.setData([{message:r,name:n,type:o,code:s}]),this.sendPacket(a)}bind(t,e){y("string"==typeof t,"event","string"),y("function"==typeof e,"handler","function"),n(!f.hasOwnProperty(t),"Blacklisted event."),this.events.on(t,e)}unbind(t,e){y("string"==typeof t,"event","string"),y("function"==typeof e,"handler","function"),n(!f.hasOwnProperty(t),"Blacklisted event."),this.events.removeListener(t,e)}fire(...t){y(t.length>0,"event","string"),y("string"==typeof t[0],"event","string"),this.sendEvent(t)}hook(t,e){y("string"==typeof t,"event","string"),y("function"==typeof e,"handler","function"),n(!this.hooks.has(t),"Hook already bound."),n(!f.hasOwnProperty(t),"Blacklisted event."),this.hooks.set(t,e)}unhook(t){y("string"==typeof t,"event","string"),n(!f.hasOwnProperty(t),"Blacklisted event."),this.hooks.delete(t)}call(...t){y(t.length>0,"event","string"),y("string"==typeof t[0],"event","string");const e=this.sequence;return this.sequence+=1,this.sequence>>>=0,n(!this.jobs.has(e),"ID collision."),this.sendCall(e,t),new Promise((t,r)=>{this.jobs.set(e,new l(t,r,Date.now()))})}channel(t){return this.channels.has(t)}join(t){return!!this.server&&this.server.join(this,t)}leave(t){return!!this.server&&this.server.leave(this,t)}static accept(t,e,r,n){return(new this).accept(t,e,r,n)}static connect(t,e,r,n){return(new this).connect(t,e,r,n)}}}).call(this,r(1).Buffer)},function(t,e,r){"use strict";e.byteLength=function(t){var e=u(t),r=e[0],n=e[1];return 3*(r+n)/4-n},e.toByteArray=function(t){var e,r,n=u(t),i=n[0],a=n[1],h=new s(function(t,e,r){return 3*(e+r)/4-r}(0,i,a)),c=0,f=a>0?i-4:i;for(r=0;r>16&255,h[c++]=e>>8&255,h[c++]=255&e;2===a&&(e=o[t.charCodeAt(r)]<<2|o[t.charCodeAt(r+1)]>>4,h[c++]=255&e);1===a&&(e=o[t.charCodeAt(r)]<<10|o[t.charCodeAt(r+1)]<<4|o[t.charCodeAt(r+2)]>>2,h[c++]=e>>8&255,h[c++]=255&e);return h},e.fromByteArray=function(t){for(var e,r=t.length,o=r%3,s=[],i=0,a=r-o;ia?a:i+16383));1===o?(e=t[r-1],s.push(n[e>>2]+n[e<<4&63]+"==")):2===o&&(e=(t[r-2]<<8)+t[r-1],s.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"="));return s.join("")};for(var n=[],o=[],s="undefined"!=typeof Uint8Array?Uint8Array:Array,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,h=i.length;a0)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 c(t,e,r){for(var o,s,i=[],a=e;a>18&63]+n[s>>12&63]+n[s>>6&63]+n[63&s]);return i.join("")}o["-".charCodeAt(0)]=62,o["_".charCodeAt(0)]=63},function(t,e){e.read=function(t,e,r,n,o){var s,i,a=8*o-n-1,h=(1<>1,c=-7,f=r?o-1:0,l=r?-1:1,p=t[e+f];for(f+=l,s=p&(1<<-c)-1,p>>=-c,c+=a;c>0;s=256*s+t[e+f],f+=l,c-=8);for(i=s&(1<<-c)-1,s>>=-c,c+=n;c>0;i=256*i+t[e+f],f+=l,c-=8);if(0===s)s=1-u;else{if(s===h)return i?NaN:1/0*(p?-1:1);i+=Math.pow(2,n),s-=u}return(p?-1:1)*i*Math.pow(2,s-n)},e.write=function(t,e,r,n,o,s){var i,a,h,u=8*s-o-1,c=(1<>1,l=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:s-1,d=n?1:-1,g=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,i=c):(i=Math.floor(Math.log(e)/Math.LN2),e*(h=Math.pow(2,-i))<1&&(i--,h*=2),(e+=i+f>=1?l/h:l*Math.pow(2,1-f))*h>=2&&(i++,h/=2),i+f>=c?(a=0,i=c):i+f>=1?(a=(e*h-1)*Math.pow(2,o),i+=f):(a=e*Math.pow(2,f-1)*Math.pow(2,o),i=0));o>=8;t[r+p]=255&a,p+=d,a/=256,o-=8);for(i=i<0;t[r+p]=255&i,p+=d,i/=256,u-=8);t[r+p-d]|=128*g}},function(t,e){var r={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==r.call(t)}},function(t,e,r){"use strict";(function(e){const n=r(0),o={CONNECT:0,DISCONNECT:1,EVENT:2,ACK:3,ERROR:4,BINARY_EVENT:5,BINARY_ACK:6};class s{constructor(t){this.type=t||0,this.attachments=0,this.nsp="/",this.id=-1,this.data="",this.buffers=[]}setData(t){n(void 0!==t),n("number"!=typeof t),n("function"!=typeof t);const[r,s]=function(t){const r=[],n=function t(r,n,o,s){if(null===n||"object"!=typeof n)return n;if(e.isBuffer(n)){const t=s.get(n);if(null!=t)return t;const e={_placeholder:!0,num:o.length};return s.set(n,e),o.push(n),e}if(s.has(n))throw new TypeError("Converting circular structure to JSON.");if(Array.isArray(n)){const e=[];s.set(n,null);for(let r=0;r0)switch(this.type){case o.EVENT:this.type=o.BINARY_EVENT;break;case o.ACK:this.type=o.BINARY_ACK}return this}getData(){return 0===this.data.length?null:(t=this.data,e=this.buffers,JSON.parse(t,(t,r)=>(function(t){return null!==t&&"object"==typeof t&&!0===t._placeholder&&t.num>>>0===t.num})(r)&&r.num0);let e=0,r=0,s=0,a="/",h=-1,u="";switch([e,r]=function(t,e){const r=t.charCodeAt(e)-48;return r<0||r>9?-1:[e+1,r]}(t,e),n(-1!==r),n(r<=o.BINARY_ACK),r){case o.BINARY_EVENT:case o.BINARY_ACK:[e,s]=i(t,e),n(-1!==s),n(e9)break;o*=10,o+=s,n((r+=1)<=10)}return n(o<=4294967295),0===r&&(o=-1),[e,o]}s.types=o,t.exports=s}).call(this,r(1).Buffer)},function(t,e,r){"use strict";const n=r(0),o=r(15);e.parseURL=function(t){-1===t.indexOf("://")&&(t=`ws://${t}`);const e=o.parse(t);if("http:"!==e.protocol&&"https:"!==e.protocol&&"ws:"!==e.protocol&&"wss:"!==e.protocol)throw new Error("Invalid protocol for websocket URL.");if(!e.hostname)throw new Error("Malformed URL.");const r=e.hostname;let s=80,i=!1;return"https:"!==e.protocol&&"wss:"!==e.protocol||(s=443,i=!0),e.port&&(s=parseInt(e.port,10),n((65535&s)===s),n(0!==s)),[s,r,i]}},function(t,e,r){"use strict";var n=r(16),o=r(18);function s(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}e.parse=v,e.resolve=function(t,e){return v(t,!1,!0).resolve(e)},e.resolveObject=function(t,e){return t?v(t,!1,!0).resolveObject(e):e},e.format=function(t){o.isString(t)&&(t=v(t));return t instanceof s?t.format():s.prototype.format.call(t)},e.Url=s;var i=/^([a-z0-9.+-]+:)/i,a=/:[0-9]*$/,h=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,u=["{","}","|","\\","^","`"].concat(["<",">",'"',"`"," ","\r","\n","\t"]),c=["'"].concat(u),f=["%","/","?",";","#"].concat(c),l=["/","?","#"],p=/^[+a-z0-9A-Z_-]{0,63}$/,d=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,g={javascript:!0,"javascript:":!0},y={javascript:!0,"javascript:":!0},m={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},w=r(19);function v(t,e,r){if(t&&o.isObject(t)&&t instanceof s)return t;var n=new s;return n.parse(t,e,r),n}s.prototype.parse=function(t,e,r){if(!o.isString(t))throw new TypeError("Parameter 'url' must be a string, not "+typeof t);var s=t.indexOf("?"),a=-1!==s&&s127?N+="x":N+=x[I];if(!N.match(p)){var U=j.slice(0,k),L=j.slice(k+1),M=x.match(d);M&&(U.push(M[1]),L.unshift(M[2])),L.length&&(v="/"+L.join(".")+v),this.hostname=U.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),T||(this.hostname=n.toASCII(this.hostname));var D=this.port?":"+this.port:"",Y=this.hostname||"";this.host=Y+D,this.href+=this.host,T&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==v[0]&&(v="/"+v))}if(!g[A])for(k=0,C=c.length;k0)&&r.host.split("@"))&&(r.auth=T.shift(),r.host=r.hostname=T.shift());return r.search=t.search,r.query=t.query,o.isNull(r.pathname)&&o.isNull(r.search)||(r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")),r.href=r.format(),r}if(!O.length)return r.pathname=null,r.search?r.path="/"+r.search:r.path=null,r.href=r.format(),r;for(var _=O.slice(-1)[0],R=(r.host||t.host||O.length>1)&&("."===_||".."===_)||""===_,k=0,P=O.length;P>=0;P--)"."===(_=O[P])?O.splice(P,1):".."===_?(O.splice(P,1),k++):k&&(O.splice(P,1),k--);if(!E&&!A)for(;k--;k)O.unshift("..");!E||""===O[0]||O[0]&&"/"===O[0].charAt(0)||O.unshift(""),R&&"/"!==O.join("/").substr(-1)&&O.push("");var T,j=""===O[0]||O[0]&&"/"===O[0].charAt(0);S&&(r.hostname=r.host=j?"":O.length?O.shift():"",(T=!!(r.host&&r.host.indexOf("@")>0)&&r.host.split("@"))&&(r.auth=T.shift(),r.host=r.hostname=T.shift()));return(E=E||r.host&&O.length)&&!j&&O.unshift(""),O.length?r.pathname=O.join("/"):(r.pathname=null,r.path=null),o.isNull(r.pathname)&&o.isNull(r.search)||(r.path=(r.pathname?r.pathname:"")+(r.search?r.search:"")),r.auth=t.auth||r.auth,r.slashes=r.slashes||t.slashes,r.href=r.format(),r},s.prototype.parseHost=function(){var t=this.host,e=a.exec(t);e&&(":"!==(e=e[0])&&(this.port=e.substr(1)),t=t.substr(0,t.length-e.length)),t&&(this.hostname=t)}},function(t,e,r){(function(t,n){var o;/*! https://mths.be/punycode v1.4.1 by @mathias */!function(s){e&&e.nodeType,t&&t.nodeType;var i="object"==typeof n&&n;i.global!==i&&i.window!==i&&i.self;var a,h=2147483647,u=36,c=1,f=26,l=38,p=700,d=72,g=128,y="-",m=/^xn--/,w=/[^\x20-\x7E]/,v=/[\x2E\u3002\uFF0E\uFF61]/g,b={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},E=u-c,A=Math.floor,O=String.fromCharCode;function S(t){throw new RangeError(b[t])}function _(t,e){for(var r=t.length,n=[];r--;)n[r]=e(t[r]);return n}function R(t,e){var r=t.split("@"),n="";return r.length>1&&(n=r[0]+"@",t=r[1]),n+_((t=t.replace(v,".")).split("."),e).join(".")}function k(t){for(var e,r,n=[],o=0,s=t.length;o=55296&&e<=56319&&o65535&&(e+=O((t-=65536)>>>10&1023|55296),t=56320|1023&t),e+=O(t)})).join("")}function T(t,e){return t+22+75*(t<26)-((0!=e)<<5)}function j(t,e,r){var n=0;for(t=r?A(t/p):t>>1,t+=A(t/e);t>E*f>>1;n+=u)t=A(t/E);return A(n+(E+1)*t/(t+l))}function C(t){var e,r,n,o,s,i,a,l,p,m,w,v=[],b=t.length,E=0,O=g,_=d;for((r=t.lastIndexOf(y))<0&&(r=0),n=0;n=128&&S("not-basic"),v.push(t.charCodeAt(n));for(o=r>0?r+1:0;o=b&&S("invalid-input"),((l=(w=t.charCodeAt(o++))-48<10?w-22:w-65<26?w-65:w-97<26?w-97:u)>=u||l>A((h-E)/i))&&S("overflow"),E+=l*i,!(l<(p=a<=_?c:a>=_+f?f:a-_));a+=u)i>A(h/(m=u-p))&&S("overflow"),i*=m;_=j(E-s,e=v.length+1,0==s),A(E/e)>h-O&&S("overflow"),O+=A(E/e),E%=e,v.splice(E++,0,O)}return P(v)}function x(t){var e,r,n,o,s,i,a,l,p,m,w,v,b,E,_,R=[];for(v=(t=k(t)).length,e=g,r=0,s=d,i=0;i=e&&wA((h-r)/(b=n+1))&&S("overflow"),r+=(a-e)*b,e=a,i=0;ih&&S("overflow"),w==e){for(l=r,p=u;!(l<(m=p<=s?c:p>=s+f?f:p-s));p+=u)_=l-m,E=u-m,R.push(O(T(m+_%E,0))),l=A(_/E);R.push(O(T(l,0))),s=j(r,b,n==o),r=0,++n}++r,++e}return R.join("")}a={version:"1.4.1",ucs2:{decode:k,encode:P},decode:C,encode:x,toASCII:function(t){return R(t,(function(t){return w.test(t)?"xn--"+x(t):t}))},toUnicode:function(t){return R(t,(function(t){return m.test(t)?C(t.slice(4).toLowerCase()):t}))}},void 0===(o=function(){return a}.call(e,r,e,t))||(t.exports=o)}()}).call(this,r(17)(t),r(2))},function(t,e){t.exports=function(t){return t.webpackPolyfill||(t.deprecate=function(){},t.paths=[],t.children||(t.children=[]),Object.defineProperty(t,"loaded",{enumerable:!0,get:function(){return t.l}}),Object.defineProperty(t,"id",{enumerable:!0,get:function(){return t.i}}),t.webpackPolyfill=1),t}},function(t,e,r){"use strict";t.exports={isString:function(t){return"string"==typeof t},isObject:function(t){return"object"==typeof t&&null!==t},isNull:function(t){return null===t},isNullOrUndefined:function(t){return null==t}}},function(t,e,r){"use strict";e.decode=e.parse=r(20),e.encode=e.stringify=r(21)},function(t,e,r){"use strict";function n(t,e){return Object.prototype.hasOwnProperty.call(t,e)}t.exports=function(t,e,r,s){e=e||"&",r=r||"=";var i={};if("string"!=typeof t||0===t.length)return i;var a=/\+/g;t=t.split(e);var h=1e3;s&&"number"==typeof s.maxKeys&&(h=s.maxKeys);var u=t.length;h>0&&u>h&&(u=h);for(var c=0;c=0?(f=g.substr(0,y),l=g.substr(y+1)):(f=g,l=""),p=decodeURIComponent(f),d=decodeURIComponent(l),n(i,p)?o(i[p])?i[p].push(d):i[p]=[i[p],d]:i[p]=d}return i};var o=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)}},function(t,e,r){"use strict";var n=function(t){switch(typeof t){case"string":return t;case"boolean":return t?"true":"false";case"number":return isFinite(t)?t:"";default:return""}};t.exports=function(t,e,r,a){return e=e||"&",r=r||"=",null===t&&(t=void 0),"object"==typeof t?s(i(t),(function(i){var a=encodeURIComponent(n(i))+r;return o(t[i])?s(t[i],(function(t){return a+encodeURIComponent(n(t))})).join(e):a+encodeURIComponent(n(t[i]))})).join(e):a?encodeURIComponent(n(a))+r+encodeURIComponent(n(t)):""};var o=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)};function s(t,e){if(t.map)return t.map(e);for(var r=[],n=0;ni)return void this.error("Frame too large.");let r;try{r=s.fromRaw(t)}catch(t){return void this.emit("error",t)}this.emit("frame",r)}feedString(t){if(n("string"==typeof t),e.byteLength(t,"utf8")>i)return void this.error("Frame too large.");let r;try{r=s.fromString(t)}catch(t){return void this.emit("error",t)}this.emit("frame",r)}}}).call(this,r(1).Buffer)},function(t,e,r){"use strict";t.exports={1e3:"NORMAL_CLOSURE",1001:"GOING_AWAY",1002:"PROTOCOL_ERROR",1003:"UNSUPPORTED_DATA",1004:"RESERVED",1005:"NO_STATUS_RECVD",1006:"ABNORMAL_CLOSURE",1007:"INVALID_FRAME_PAYLOAD_DATA",1008:"POLICY_VIOLATION",1009:"MESSAGE_TOO_BIG",1010:"MISSING_EXTENSION",1011:"INTERNAL_ERROR",1012:"SERVICE_RESTART",1013:"TRY_AGAIN_LATER",1014:"BAD_GATEWAY",1015:"TLS_HANDSHAKE"}},function(t,e,r){"use strict";t.exports={connect:!0,connect_error:!0,connect_timeout:!0,connecting:!0,disconnect:!0,error:!0,reconnect:!0,reconnect_attempt:!0,reconnect_failed:!0,reconnect_error:!0,reconnecting:!0,ping:!0,pong:!0}}])); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index e067de8..89423b8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { - "name": "rpclib", - "version": "1.0.0", + "name": "rpclibrary", + "version": "1.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index fd36cb0..dacd72f 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,14 @@ { - "name": "rpclib", - "version": "1.0.0", + "name": "rpclibrary", + "version": "1.0.1", "description": "", "scripts": { - "build": "npm run clean; npm run tsc; npm run webpack", "tsc": "tsc", - "webpack": "webpack --config src/webpack.prod.js --progress --colors", - "clean": "rm -rf lib" + "webpack": "webpack", + "build-lib": "npm run webpack --config ./src/webpack.js", + "build-test": "npm run webpack --config ./test/webpack.js", + "build": "npm run clean && npm run tsc && npm run build-lib && npm run build-test", + "clean": "rm -rf lib ./*.js ./*.d.ts" }, "author": "", "license": "ISC", @@ -25,7 +27,6 @@ "uuid": "^3.3.3" }, "files": [ - "./lib/Backend.js", - "./lib/Frontend.js" + "lib/*.js" ] } diff --git a/src/Server.ts b/src/Backend.ts similarity index 91% rename from src/Server.ts rename to src/Backend.ts index 79fc8f9..4f7497b 100644 --- a/src/Server.ts +++ b/src/Backend.ts @@ -5,9 +5,17 @@ import bsock = require('bsock'); import * as T from './Types'; import * as U from './Utils'; -import * as I from './Interfaces'; +import * as I from './Interfaces'; +import * as R from './Responses'; -export class Server{ +export { + T as Types, + U as Utils, + I as Interfaces, + R as Responses +} + +export class Backend{ private ws = http.createServer() private io = bsock.createServer() diff --git a/src/Client.ts b/src/Frontend.ts similarity index 96% rename from src/Client.ts rename to src/Frontend.ts index fd8e91c..9154798 100644 --- a/src/Client.ts +++ b/src/Frontend.ts @@ -2,8 +2,13 @@ var bsock = require('bsock') +import * as T from './Types'; import * as I from './Interfaces'; -import * as T from './Types'; + +export { + T as Types, + I as Interfaces, +} //fix args with defaults like "force = true" -> "force" @@ -11,7 +16,7 @@ function stripAfterEquals(str:string){ return str.split("=")[0] } -export class Client implements I.Socket{ +export class Frontend implements I.Socket{ private socket: I.Socket constructor(public port:number, private server: string, private tls: boolean = false){ diff --git a/src/webpack.prod.js b/src/webpack.prod.js deleted file mode 100644 index dba9774..0000000 --- a/src/webpack.prod.js +++ /dev/null @@ -1,66 +0,0 @@ -const path = require('path'); -const TerserPlugin = require('terser-webpack-plugin'); - -const frontendConf = { - mode: 'production', - target: "web", - entry: path.resolve(__dirname, 'Client.ts'), - output: { - path: path.resolve(__dirname, '../lib'), - filename: 'Frontend.js', - libraryTarget: 'commonjs', - }, - module: { - rules: [ - { test: /\.ts?$/, loader: "ts-loader" } - ] - }, - resolve: { - extensions: [".ts", ".tsx", ".js"] - }, - optimization: { - minimize: true, - minimizer: [ - new TerserPlugin({ - parallel: true, - exclude: [ - /\.\/(.*)\/.ts/, - /\.\/(.*).ts/, - ], - }), - ], - }, -} - -const backendConf = { - mode: 'production', - target: "node", - entry: path.resolve(__dirname, 'Server.ts'), - output: { - path: path.resolve(__dirname, '../lib'), - filename: 'Backend.js', - libraryTarget: 'commonjs', - }, - module: { - rules: [ - { test: /\.ts?$/, loader: "ts-loader" } - ] - }, - resolve: { - extensions: [".ts", ".tsx", ".js"] - }, - optimization: { - minimize: true, - minimizer: [ - new TerserPlugin({ - parallel: true, - exclude: [ - /\.\/(.*)\/.ts/, - /\.\/(.*).ts/, - ], - }), - ], - }, -} - -module.exports = [frontendConf, backendConf] diff --git a/test/TestBackend.ts b/test/TestBackend.ts new file mode 100644 index 0000000..ccf0be1 --- /dev/null +++ b/test/TestBackend.ts @@ -0,0 +1,11 @@ +import { Backend } from '../src/Backend' + +const testServer = new Backend(20000, [{ + name: "HelloWorldRPCGroup", + publicRPCs: () => [], + localRPCs: () => [{ + type: 'Call', + name: 'echo', + call: async (s:string) => s, + }] +}]) \ No newline at end of file diff --git a/test/TestFrontend.ts b/test/TestFrontend.ts new file mode 100644 index 0000000..1b81a63 --- /dev/null +++ b/test/TestFrontend.ts @@ -0,0 +1,7 @@ +import { Frontend } from '../src/Frontend' + +const testClient = new Frontend(20000, 'localhost') +testClient.connect().then(_ => { + testClient.info().then(console.log) + testClient["HelloWorldRPCGroup"].echo("x").then(console.log) +}) diff --git a/test/test.ts b/test/test.ts deleted file mode 100644 index 2c12800..0000000 --- a/test/test.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Server } from '../src/Server' -import {Client} from '../src/Client' - -new Server(20000, [{ - name: "HelloWorldRPCGroup", - publicRPCs: () => [], - localRPCs: () => [{ - type: 'Call', - name: 'echo', - call: async (s:string) => s, - }] -}]) - -const caller = new Client(20000, 'localhost') -caller.connect().then(_ => { - caller.info().then(console.log) - caller["HelloWorldRPCGroup"].echo("x").then(console.log) -}) diff --git a/tsconfig.json b/tsconfig.json index 91c2f63..e8e2973 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,6 +5,7 @@ "target": "ESnext", "module": "commonjs", "declaration": true, + "outDir": "./lib", "strict": true, "experimentalDecorators": true },