V extends your in-memory variables to also be saved/persisted instantly. Variables are instantly synchronized between all running instances of V in a room. When you (re)start in a room, variables and constants are reloaded/rehydrated automatically.
11 | 12 | ### Current Features 13 | - Keep your variables in the cloud 14 | - Sync variables between instances 15 | - Automatic reloaded/rehydrated on start-up 16 | 17 | #### Requires ES6 Proxy (Node 6+ and new browsers) 18 | 19 | ### Coming Soon: 20 | - Web GUI 21 | - History - Time machine 22 | - Events pub/sub 23 | 24 | ## Install 25 | 26 | ### Node 27 | ```sh 28 | npm install --save v 29 | or 30 | npm i -S v 31 | ``` 32 | 33 | ### Browser 34 | jsDelivr CDN: 35 | ```html 36 | 37 | ``` 38 | 39 | Unpkg CDN: 40 | ```html 41 | 42 | ``` 43 | 44 | More CDNs coming soon 45 | 46 | ## API 47 | 48 | ### Constructor (3 Ways to do it) 49 | 50 | If no roomId is passed, a new one will be assigned automatically and printed in the console. 51 | 52 | ##### NodeJS **only** with deasync support 53 | ```js 54 | const V = require('v') 55 | const v = new V([roomId]) 56 | ``` 57 | 58 | ##### Callback 59 | ```js 60 | const V = require('v') 61 | V([roomId,] v => { 62 | ... 63 | }) 64 | ``` 65 | 66 | ##### Promise 67 | ```js 68 | const V = require('v') 69 | V([roomId]).then(v => { 70 | ... 71 | }).catch(e => { 72 | ... 73 | }) 74 | ``` 75 | 76 | #### Custom Opts 77 | 78 | The `opts` object has the following options and their default options listed 79 | ```js 80 | myOpts = { 81 | roomId: '', 82 | server: 'ws(s)://my-domain.com' 83 | } 84 | ``` 85 | 86 | Use it: 87 | ```js 88 | const v = new V(myOpts) 89 | ``` 90 | 91 | ## Debug logs 92 | 93 | **V** comes with extensive debugging logs. Each **V** instance and constructor-call has it own debug namespace. 94 | 95 | In **node**, enable debug logs by setting the `DEBUG` environment variable to `*` 96 | 97 | ```bash 98 | DEBUG=* node myProgram.js 99 | ``` 100 | 101 | In the **browser**, enable debug logs by running this in the developer console: 102 | 103 | ```js 104 | localStorage.debug = '*' 105 | ``` 106 | 107 | Disable by running this: 108 | 109 | ```js 110 | localStorage.removeItem('debug') 111 | ``` 112 | 113 | ## License 114 | MIT Copyright © [Diego Rodríguez Baquero](https://diegorbaquero.com) 115 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const EventEmitter = require('events').EventEmitter 2 | const _debug = require('debug') 3 | const _WebSocket = require('simple-websocket') 4 | let deasync 5 | try { 6 | deasync = require('deasync') 7 | } catch (e) { 8 | _debug('V')('Couldn\'t load deasync') 9 | } 10 | 11 | let instanceCounter = 1 12 | let consCounter = 1 13 | 14 | class V extends EventEmitter { 15 | constructor (opts, cb) { 16 | super() 17 | 18 | const self = this 19 | 20 | // Hide EventEmitter properties from enumeration 21 | Object.defineProperty(self, '_events', { value: self._events, enumerable: false, configurable: false, writable: true }) 22 | Object.defineProperty(self, '_maxListeners', { value: self._events, enumerable: false, configurable: false, writable: true }) 23 | 24 | // Define numerated contructor debug object 25 | Object.defineProperty(self, '_debug', { 26 | value: _debug('V:constructor-' + consCounter++), 27 | writable: true 28 | }) 29 | 30 | self._debug('constructor %o', opts) 31 | 32 | let proxy 33 | 34 | const ws = new _WebSocket(opts.server) 35 | 36 | Object.defineProperty(self, '_socket', { value: ws, writable: true }) 37 | 38 | ws.on('data', onMessage) 39 | ws.on('close', onClose) 40 | ws.on('error', onError) 41 | ws.on('connect', () => { 42 | self._debug('Socket opened') 43 | 44 | if (!opts.roomId) { 45 | self._debug('Requesting new roomId...') 46 | self._requestedRoomId = true 47 | send({ type: 'requestRoomId' }) 48 | } else { 49 | Object.defineProperty(self, '_roomId', { value: opts.roomId }) 50 | send({ type: 'startWithId', data: opts.roomId }) 51 | } 52 | }) 53 | 54 | if (deasync && deasync.loopWhile) { 55 | deasync.loopWhile(() => proxy === undefined) 56 | return proxy 57 | } 58 | 59 | // Proxy handler with object tree 60 | function handler (tree = []) { 61 | // self._debug('new handler %o', tree) 62 | return { 63 | get (obj, key) { 64 | if (typeof key === 'symbol' || key === 'domain' || key === 'keys') return obj[key] 65 | const treeKey = tree.concat([key]).join('.') 66 | if (!key.startsWith('_')) self._debug('get %s', treeKey) 67 | if (key in obj) { 68 | if (!key.startsWith('_') && typeof obj[key] === 'object') { 69 | self._debug('New proxy for key %s', key) 70 | const newTree = tree.slice() 71 | newTree.push(key) 72 | return new Proxy(obj[key], handler(newTree)) 73 | } 74 | return obj[key] 75 | } 76 | return undefined 77 | }, 78 | set (obj, key, val) { 79 | const treeKey = tree.concat([key]).join('.') 80 | self._debug('set %s=%o', treeKey, val) 81 | try { 82 | if (obj[key] === val) return true 83 | obj[key] = val 84 | if (!self._closed && !key.startsWith('_')) { 85 | send({ 86 | type: 'set', 87 | key: treeKey, 88 | data: val 89 | }) 90 | } 91 | return true 92 | } catch (e) { 93 | self._debug('Failed to set readonly property %o', e) 94 | return false 95 | } 96 | }, 97 | deleteProperty (obj, key) { 98 | const treeKey = tree.concat([key]).join('.') 99 | self._debug('deleteProperty %s', treeKey) 100 | delete obj[key] 101 | if (!self._closed) { 102 | send({ 103 | type: 'delete', 104 | key: treeKey 105 | }) 106 | } 107 | return true 108 | } 109 | } 110 | } 111 | function send (data, sendingWs = self._socket) { 112 | self._debug('Sending %o', data) 113 | sendingWs.send(stringify(data)) 114 | } 115 | function initWithId (id) { 116 | self._debug('Init with id: %s', id) 117 | Object.defineProperty(self, '_roomId', { value: id }) 118 | init() 119 | } 120 | function init () { 121 | if (!self._closed) { 122 | Object.defineProperty(self, '_debug', { 123 | value: _debug('v' + instanceCounter++ + ':' + self._roomId) 124 | }) 125 | Object.defineProperty(self, 'keys', { 126 | get () { 127 | return Object.keys(self).filter(key => !key.startsWith('_') && key !== 'domain') 128 | } 129 | }) 130 | } 131 | self._closed = false 132 | proxy = new Proxy(self, handler()) 133 | self.checkToUnref() 134 | self._debug('Ready') 135 | if (cb) return cb(proxy) 136 | } 137 | function onMessage (message) { 138 | message = JSON.parse(message) 139 | self._debug('Received %o', message) 140 | switch (message.type) { 141 | case 'roomId': { 142 | self._debug('Use %s as your roomId', message.data) 143 | console.log(`Use ${message.data} as your roomId`) 144 | initWithId(message.data) 145 | break 146 | } 147 | case 'start': { 148 | const data = message.data 149 | const vars = data.vars 150 | self._debug('vars: %O', vars) 151 | for (const key in vars) { 152 | const varOrConst = vars[ key ] 153 | // self._debug(typeof varOrConst) 154 | if (varOrConst && typeof varOrConst === 'object' && varOrConst.isConst) { 155 | // self._debug('Rehidrating constant') 156 | Object.defineProperty(self, key, { value: vars[ key ].val, enumerable: true }) 157 | } else { 158 | // self._debug('Rehidrating variable') 159 | self[ key ] = vars[ key ] 160 | } 161 | } 162 | init() 163 | break 164 | } 165 | case 'set': { 166 | const setKey = message.key 167 | self._debug('sync set %s', setKey) 168 | try { 169 | if (!setKey.includes('.')) { 170 | self[ setKey ] = message.data 171 | } else { 172 | const tree = setKey.split('.') 173 | let obj = self 174 | for (let i = 0; i < tree.length - 1; i++) { 175 | let k = tree[i] 176 | if (k in obj) { 177 | obj = obj[k] 178 | } else { 179 | obj[k] = {} 180 | } 181 | } 182 | obj[tree[tree.length - 1]] = message.data 183 | } 184 | self.emit('set', { key: message.key, value: message.data }) 185 | } catch (e) { 186 | self._debug('Failed to sync set') 187 | } 188 | break 189 | } 190 | case 'delete': { 191 | const deleteKey = message.key 192 | self._debug('sync delete %s', deleteKey) 193 | if (!deleteKey.includes('.')) { 194 | delete self[ deleteKey ] 195 | } else { 196 | const tree = deleteKey.split('.') 197 | let obj = self 198 | for (let i = 0; i < tree.length - 1; i++) { 199 | let k = tree[i] 200 | if (k in obj) { 201 | obj = obj[k] 202 | } else { 203 | obj[k] = {} 204 | } 205 | } 206 | delete obj[tree[tree.length - 1]] 207 | } 208 | self.emit('delete', message.key) 209 | break 210 | } 211 | case 'destroy': { 212 | self.close(true) 213 | self.emit('destroyed') 214 | break 215 | } 216 | case 'error': { 217 | const errorMessage = message.data 218 | self._debug('Error: %s', errorMessage) 219 | console.error(errorMessage) 220 | self.close() 221 | throw new Error(errorMessage) 222 | } 223 | default: { 224 | self._debug('Received unknown message type') 225 | } 226 | } 227 | } 228 | function onClose (reason = 'Not specified') { 229 | self._debug('Socket closed %s', reason) 230 | self._closed = true 231 | if (!self._closing && !self._error) { 232 | reconnect() 233 | } 234 | } 235 | function onError (err) { 236 | self._debug('Socket error %o', err) 237 | self._error = true 238 | self.close() 239 | throw err 240 | } 241 | function reconnect (retry = 1) { 242 | if (self._closing || self._error) return false 243 | setTimeout(() => { 244 | const ws = new _WebSocket(opts.server) 245 | 246 | Object.defineProperty(self, '_socket', { value: ws, writable: true }) 247 | 248 | ws.on('error', () => { 249 | self._debug('Failed to reconnect, retrying...') 250 | reconnect(++retry) 251 | }) 252 | ws.on('connect', () => { 253 | ws.on('data', onMessage) 254 | ws.on('close', onClose) 255 | self._debug('Socket opened') 256 | send({ type: 'startWithId', data: self._roomId }) 257 | }) 258 | }, Math.pow(2, retry) * 1000) 259 | } 260 | } 261 | 262 | addListener (eventName, cb) { 263 | this.ref() 264 | super.addListener(eventName, cb) 265 | } 266 | 267 | on (eventName, cb) { 268 | this.ref() 269 | super.on(eventName, cb) 270 | } 271 | 272 | once (eventName, cb) { 273 | this.ref() 274 | super.once(eventName, (data) => { 275 | cb(data) 276 | }) 277 | } 278 | 279 | prependListener (eventName, cb) { 280 | this.ref() 281 | super.prependListener(eventName, cb) 282 | } 283 | 284 | prependOnceListener (eventName, cb) { 285 | this.ref() 286 | super.prependOnceListener(eventName, cb) 287 | } 288 | 289 | removeListener (eventName, cb) { 290 | super.removeListener(eventName, cb) 291 | this.checkToUnref() 292 | } 293 | 294 | removeAllListeners (eventName) { 295 | super.removeAllListeners(eventName) 296 | this.checkToUnref() 297 | } 298 | 299 | ref () { 300 | if (this._socket._ws && this._socket._ws._socket && this._socket._ws._socket.ref) { 301 | this._socket._ws._socket.ref() 302 | } 303 | } 304 | 305 | checkToUnref () { 306 | if (this._socket._ws && this._socket._ws._socket && this._socket._ws._socket.unref) { 307 | let counter = 0 308 | this.eventNames().forEach(event => { 309 | counter += this.listenerCount(event) 310 | }) 311 | if (!counter) this._socket._ws._socket.unref() 312 | } 313 | } 314 | 315 | close (destroying = false) { 316 | this._closing = true 317 | this._debug('close') 318 | if (!destroying && this._requestedRoomId) { 319 | this._debug('Remember to set your roomId to %s', this._roomId) 320 | console.log(`Remember to set your roomId to ${this._roomId}`) 321 | } 322 | if (this._socket) { 323 | this._socket.destroy() 324 | } 325 | } 326 | 327 | destroy () { 328 | this._debug('destroy') 329 | this._socket.send(stringify({ type: 'destroy' })) 330 | this.close(true) 331 | } 332 | 333 | const (key, val) { 334 | _debug('V:const')('%s %o', key, val) 335 | Object.defineProperty(this, key, { value: val, enumerable: true }) 336 | this._socket.send(stringify({ type: 'set', key: key, data: { val: val, isConst: true } })) 337 | } 338 | } 339 | 340 | function stringify (data) { 341 | return JSON.stringify(data) 342 | } 343 | 344 | const defaultsOps = { 345 | roomId: '', 346 | server: 'wss://api.vars.online' 347 | } 348 | 349 | module.exports = function (opts = defaultsOps, cb) { 350 | // If only callback is passed, fix params 351 | if (typeof opts === 'function') { 352 | cb = opts 353 | opts = defaultsOps 354 | } 355 | if (typeof opts === 'string') { 356 | opts = { roomId: opts } 357 | } 358 | Object.keys(defaultsOps).forEach(k => { 359 | if (!opts[k]) opts[k] = defaultsOps[k] 360 | }) 361 | if (cb || !deasync || !deasync.loopWhile) { 362 | if (typeof cb === 'function') return new V(opts, cb) 363 | return new Promise(resolve => new V(opts, resolve)) 364 | } 365 | return new V(opts) 366 | } 367 | -------------------------------------------------------------------------------- /logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /v.min.js: -------------------------------------------------------------------------------- 1 | var _Mathround=Math.round,_Mathfloor=Math.floor,_Mathabs=Math.abs,_StringfromCharCode=String.fromCharCode,_Mathmin=Math.min,_Mathpow=Math.pow;(function(w){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=w();else if("function"==typeof define&&define.amd)define([],w);else{var S;S="undefined"==typeof window?"undefined"==typeof global?"undefined"==typeof self?this:self:global:window,S.V=w()}})(function(){return function E(R,C,I){function A(O,T){if(!C[O]){if(!R[O]){var D="function"==typeof require&&require;if(!T&&D)return D(O,!0);if(M)return M(O,!0);var q=new Error("Cannot find module '"+O+"'");throw q.code="MODULE_NOT_FOUND",q}var P=C[O]={exports:{}};R[O][0].call(P.exports,function(W){var F=R[O][1][W];return A(F?F:W)},P,P.exports,E,R,C,I)}return C[O].exports}for(var M="function"==typeof require&&require,U=0;UQ?Q:G+$));return 1==K?(Y=N[H-1],J+=D[Y>>2],J+=D[63&Y<<4],J+="=="):2==K&&(Y=(N[H-2]<<8)+N[H-1],J+=D[Y>>10],J+=D[63&Y>>4],J+=D[63&Y<<2],J+="="),X.push(J),X.join("")};for(var D=[],q=[],P="undefined"==typeof Uint8Array?Array:Uint8Array,W="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",F=0,z=W.length;FO)throw new RangeError("size is too large");var W=P,F=q;F===void 0&&(W=void 0,F=0);var z=new M(D);if("string"==typeof F)for(var N=new M(F,W),Y=N.length,H=-1;++H O)throw new RangeError("size is too large");return new M(D)},C.from=function(D,q,P){if("function"==typeof M.from&&(!I.Uint8Array||Uint8Array.from!==M.from))return M.from(D,q,P);if("number"==typeof D)throw new TypeError("\"value\" argument must not be a number");if("string"==typeof D)return new M(D,q);if("undefined"!=typeof ArrayBuffer&&D instanceof ArrayBuffer){var W=q;if(1===arguments.length)return new M(D);"undefined"==typeof W&&(W=0);var F=P;if("undefined"==typeof F&&(F=D.byteLength-W),W>=D.byteLength)throw new RangeError("'offset' is out of bounds");if(F>D.byteLength-W)throw new RangeError("'length' is out of bounds");return new M(D.slice(W,W+F))}if(M.isBuffer(D)){var z=new M(D.length);return D.copy(z,0,0,D.length),z}if(D){if(Array.isArray(D)||"undefined"!=typeof ArrayBuffer&&D.buffer instanceof ArrayBuffer||"length"in D)return new M(D);if("Buffer"===D.type&&Array.isArray(D.data))return new M(D.data)}throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")},C.allocUnsafeSlow=function(D){if("function"==typeof M.allocUnsafeSlow)return M.allocUnsafeSlow(D);if("number"!=typeof D)throw new TypeError("size must be a number");if(D>=O)throw new RangeError("size is too large");return new U(D)}}).call(this,"undefined"==typeof global?"undefined"==typeof self?"undefined"==typeof window?{}:window:self:global)},{buffer:5}],5:[function(E,R,C){"use strict";function A(Ie){if(Ie>Ee)throw new RangeError("Invalid typed array length");var Ae=new Uint8Array(Ie);return Ae.__proto__=M.prototype,Ae}function M(Ie,Ae,Me){if("number"==typeof Ie){if("string"==typeof Ae)throw new Error("If encoding is specified then the first argument must be a string");return D(Ie)}return U(Ie,Ae,Me)}function U(Ie,Ae,Me){if("number"==typeof Ie)throw new TypeError("\"value\" argument must not be a number");return Ie instanceof ArrayBuffer?W(Ie,Ae,Me):"string"==typeof Ie?q(Ie,Ae):F(Ie)}function O(Ie){if("number"!=typeof Ie)throw new TypeError("\"size\" argument must be a number");else if(0>Ie)throw new RangeError("\"size\" argument must not be negative")}function T(Ie,Ae,Me){return O(Ie),0>=Ie?A(Ie):void 0===Ae?A(Ie):"string"==typeof Me?A(Ie).fill(Ae,Me):A(Ie).fill(Ae)}function D(Ie){return O(Ie),A(0>Ie?0:0|z(Ie))}function q(Ie,Ae){if(("string"!=typeof Ae||""===Ae)&&(Ae="utf8"),!M.isEncoding(Ae))throw new TypeError("\"encoding\" must be a valid string encoding");var Me=0|Y(Ie,Ae),je=A(Me),Ue=je.write(Ie,Ae);return Ue!==Me&&(je=je.slice(0,Ue)),je}function P(Ie){for(var Ae=0>Ie.length?0:0|z(Ie.length),Me=A(Ae),je=0;je Ae||Ie.byteLength =Ee)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Ee.toString(16)+" bytes");return 0|Ie}function Y(Ie,Ae){if(M.isBuffer(Ie))return Ie.length;if(ArrayBuffer.isView(Ie)||Ie instanceof ArrayBuffer)return Ie.byteLength;"string"!=typeof Ie&&(Ie=""+Ie);var Me=Ie.length;if(0===Me)return 0;for(var je=!1;;)switch(Ae){case"ascii":case"latin1":case"binary":return Me;case"utf8":case"utf-8":case void 0:return ye(Ie).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*Me;case"hex":return Me>>>1;case"base64":return ke(Ie).length;default:if(je)return ye(Ie).length;Ae=(""+Ae).toLowerCase(),je=!0;}}function H(Ie,Ae,Me){var je=!1;if((void 0===Ae||0>Ae)&&(Ae=0),Ae>this.length)return"";if((void 0===Me||Me>this.length)&&(Me=this.length),0>=Me)return"";if(Me>>>=0,Ae>>>=0,Me<=Ae)return"";for(Ie||(Ie="utf8");;)switch(Ie){case"hex":return de(this,Ae,Me);case"utf8":case"utf-8":return oe(this,Ae,Me);case"ascii":return ie(this,Ae,Me);case"latin1":case"binary":return ae(this,Ae,Me);case"base64":return ne(this,Ae,Me);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return le(this,Ae,Me);default:if(je)throw new TypeError("Unknown encoding: "+Ie);Ie=(Ie+"").toLowerCase(),je=!0;}}function K(Ie,Ae,Me){var je=Ie[Ae];Ie[Ae]=Ie[Me],Ie[Me]=je}function J(Ie,Ae,Me,je,Ue){if(0===Ie.length)return-1;if("string"==typeof Me?(je=Me,Me=0):2147483647 Me&&(Me=-2147483648),Me=+Me,isNaN(Me)&&(Me=Ue?0:Ie.length-1),0>Me&&(Me=Ie.length+Me),Me>=Ie.length){if(Ue)return-1;Me=Ie.length-1}else if(0>Me)if(Ue)Me=0;else return-1;if("string"==typeof Ae&&(Ae=M.from(Ae,je)),M.isBuffer(Ae))return 0===Ae.length?-1:X(Ie,Ae,Me,je,Ue);if("number"==typeof Ae)return Ae&=255,"function"==typeof Uint8Array.prototype.indexOf?Ue?Uint8Array.prototype.indexOf.call(Ie,Ae,Me):Uint8Array.prototype.lastIndexOf.call(Ie,Ae,Me):X(Ie,[Ae],Me,je,Ue);throw new TypeError("val must be string, number or Buffer")}function X(Ie,Ae,Me,je,Ue){function Oe(Ne,Ve){return 1==Te?Ne[Ve]:Ne.readUInt16BE(Ve*Te)}var Te=1,De=Ie.length,qe=Ae.length;if(void 0!==je&&(je=(je+"").toLowerCase(),"ucs2"===je||"ucs-2"===je||"utf16le"===je||"utf-16le"===je)){if(2>Ie.length||2>Ae.length)return-1;Te=2,De/=2,qe/=2,Me/=2}var Pe;if(Ue){var We=-1;for(Pe=Me;Pe De&&(Me=De-qe),Pe=Me;0<=Pe;Pe--){for(var Fe=!0,ze=0;ze Ue&&(je=Ue)):je=Ue;var Oe=Ae.length;if(0!=Oe%2)throw new TypeError("Invalid hex string");je>Oe/2&&(je=Oe/2);for(var De,Te=0;Te Oe&&(Te=Oe):2==De?(qe=Ie[Ue+1],128==(192&qe)&&(Fe=(31&Oe)<<6|63&qe,127 Fe||57343 Fe&&(Te=Fe))):void 0}null===Te?(Te=65533,De=1):65535 >>10),Te=56320|1023&Te),je.push(Te),Ue+=De}return se(je)}function se(Ie){var Ae=Ie.length;if(Ae<=Re)return _StringfromCharCode.apply(String,Ie);for(var Me="",je=0;je Ae)&&(Ae=0),(!Me||0>Me||Me>je)&&(Me=je);for(var Ue="",Oe=Ae;Oe Ie)throw new RangeError("offset is not uint");if(Ie+Ae>Me)throw new RangeError("Trying to access beyond buffer length")}function fe(Ie,Ae,Me,je,Ue,Oe){if(!M.isBuffer(Ie))throw new TypeError("\"buffer\" argument must be a Buffer instance");if(Ae>Ue||Ae Ie.length)throw new RangeError("Index out of range")}function ce(Ie,Ae,Me,je){if(Me+je>Ie.length)throw new RangeError("Index out of range");if(0>Me)throw new RangeError("Index out of range")}function pe(Ie,Ae,Me,je,Ue){return Ae=+Ae,Me>>>=0,Ue||ce(Ie,Ae,Me,4,3.4028234663852886e38,-3.4028234663852886e38),Be.write(Ie,Ae,Me,je,23,4),Me+4}function ge(Ie,Ae,Me,je,Ue){return Ae=+Ae,Me>>>=0,Ue||ce(Ie,Ae,Me,8,1.7976931348623157e308,-1.7976931348623157e308),Be.write(Ie,Ae,Me,je,52,8),Me+8}function he(Ie){if(Ie=be(Ie).replace(Ce,""),2>Ie.length)return"";for(;0!=Ie.length%4;)Ie+="=";return Ie}function be(Ie){return Ie.trim?Ie.trim():Ie.replace(/^\s+|\s+$/g,"")}function me(Ie){return 16>Ie?"0"+Ie.toString(16):Ie.toString(16)}function ye(Ie,Ae){Ae=Ae||Infinity;for(var Me,je=Ie.length,Ue=null,Oe=[],Te=0;Te Me){if(!Ue){if(56319 Me){-1<(Ae-=3)&&Oe.push(239,191,189),Ue=Me;continue}Me=(Ue-55296<<10|Me-56320)+65536}else Ue&&-1<(Ae-=3)&&Oe.push(239,191,189);if(Ue=null,128>Me){if(0>(Ae-=1))break;Oe.push(Me)}else if(2048>Me){if(0>(Ae-=2))break;Oe.push(192|Me>>6,128|63&Me)}else if(65536>Me){if(0>(Ae-=3))break;Oe.push(224|Me>>12,128|63&Me>>6,128|63&Me)}else if(1114112>Me){if(0>(Ae-=4))break;Oe.push(240|Me>>18,128|63&Me>>12,128|63&Me>>6,128|63&Me)}else throw new Error("Invalid code point")}return Oe}function we(Ie){for(var Ae=[],Me=0;Me (Ae-=2));++Te)Me=Ie.charCodeAt(Te),je=Me>>8,Ue=Me%256,Oe.push(Ue),Oe.push(je);return Oe}function ke(Ie){return Se.toByteArray(he(Ie))}function xe(Ie,Ae,Me,je){for(var Ue=0;Ue =Ae.length||Ue>=Ie.length);++Ue)Ae[Ue+Me]=Ie[Ue];return Ue}function Le(Ie){return Ie!==Ie}var Se=E("base64-js"),Be=E("ieee754");C.Buffer=M,C.SlowBuffer=function(Ie){return+Ie!=Ie&&(Ie=0),M.alloc(+Ie)},C.INSPECT_MAX_BYTES=50;var Ee=2147483647;C.kMaxLength=Ee,M.TYPED_ARRAY_SUPPORT=function(){try{var Ie=new Uint8Array(1);return Ie.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===Ie.foo()}catch(Ae){return!1}}(),M.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),"undefined"!=typeof Symbol&&Symbol.species&&M[Symbol.species]===M&&Object.defineProperty(M,Symbol.species,{value:null,configurable:!0,enumerable:!1,writable:!1}),M.poolSize=8192,M.from=function(Ie,Ae,Me){return U(Ie,Ae,Me)},M.prototype.__proto__=Uint8Array.prototype,M.__proto__=Uint8Array,M.alloc=function(Ie,Ae,Me){return T(Ie,Ae,Me)},M.allocUnsafe=function(Ie){return D(Ie)},M.allocUnsafeSlow=function(Ie){return D(Ie)},M.isBuffer=function(Ae){return null!=Ae&&!0===Ae._isBuffer},M.compare=function(Ae,Me){if(!M.isBuffer(Ae)||!M.isBuffer(Me))throw new TypeError("Arguments must be Buffers");if(Ae===Me)return 0;for(var je=Ae.length,Ue=Me.length,Oe=0,Te=_Mathmin(je,Ue);Oe Me&&(Ae+=" ... "))," "},M.prototype.compare=function(Ae,Me,je,Ue,Oe){if(!M.isBuffer(Ae))throw new TypeError("Argument must be a Buffer");if(void 0===Me&&(Me=0),void 0===je&&(je=Ae?Ae.length:0),void 0===Ue&&(Ue=0),void 0===Oe&&(Oe=this.length),0>Me||je>Ae.length||0>Ue||Oe>this.length)throw new RangeError("out of range index");if(Ue>=Oe&&Me>=je)return 0;if(Ue>=Oe)return-1;if(Me>=je)return 1;if(Me>>>=0,je>>>=0,Ue>>>=0,Oe>>>=0,this===Ae)return 0;for(var Te=Oe-Ue,De=je-Me,qe=_Mathmin(Te,De),Pe=this.slice(Ue,Oe),We=Ae.slice(Me,je),Fe=0;Fe >>=0,isFinite(je)?(je>>>=0,void 0===Ue&&(Ue="utf8")):(Ue=je,je=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var Oe=this.length-Me;if((void 0===je||je>Oe)&&(je=Oe),0 je||0>Me)||Me>this.length)throw new RangeError("Attempt to write outside buffer bounds");Ue||(Ue="utf8");for(var Te=!1;;)switch(Ue){case"hex":return $(this,Ae,Me,je);case"utf8":case"utf-8":return G(this,Ae,Me,je);case"ascii":return Q(this,Ae,Me,je);case"latin1":case"binary":return Z(this,Ae,Me,je);case"base64":return ee(this,Ae,Me,je);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return te(this,Ae,Me,je);default:if(Te)throw new TypeError("Unknown encoding: "+Ue);Ue=(""+Ue).toLowerCase(),Te=!0;}},M.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var Re=4096;M.prototype.slice=function(Ae,Me){var je=this.length;Ae=~~Ae,Me=void 0===Me?je:~~Me,0>Ae?(Ae+=je,0>Ae&&(Ae=0)):Ae>je&&(Ae=je),0>Me?(Me+=je,0>Me&&(Me=0)):Me>je&&(Me=je),Me >>=0,Me>>>=0,je||ue(Ae,Me,this.length);for(var Ue=this[Ae],Oe=1,Te=0;++Te >>=0,Me>>>=0,je||ue(Ae,Me,this.length);for(var Ue=this[Ae+--Me],Oe=1;0 >>=0,Me||ue(Ae,1,this.length),this[Ae]},M.prototype.readUInt16LE=function(Ae,Me){return Ae>>>=0,Me||ue(Ae,2,this.length),this[Ae]|this[Ae+1]<<8},M.prototype.readUInt16BE=function(Ae,Me){return Ae>>>=0,Me||ue(Ae,2,this.length),this[Ae]<<8|this[Ae+1]},M.prototype.readUInt32LE=function(Ae,Me){return Ae>>>=0,Me||ue(Ae,4,this.length),(this[Ae]|this[Ae+1]<<8|this[Ae+2]<<16)+16777216*this[Ae+3]},M.prototype.readUInt32BE=function(Ae,Me){return Ae>>>=0,Me||ue(Ae,4,this.length),16777216*this[Ae]+(this[Ae+1]<<16|this[Ae+2]<<8|this[Ae+3])},M.prototype.readIntLE=function(Ae,Me,je){Ae>>>=0,Me>>>=0,je||ue(Ae,Me,this.length);for(var Ue=this[Ae],Oe=1,Te=0;++Te =Oe&&(Ue-=_Mathpow(2,8*Me)),Ue},M.prototype.readIntBE=function(Ae,Me,je){Ae>>>=0,Me>>>=0,je||ue(Ae,Me,this.length);for(var Ue=Me,Oe=1,Te=this[Ae+--Ue];0 =Oe&&(Te-=_Mathpow(2,8*Me)),Te},M.prototype.readInt8=function(Ae,Me){return Ae>>>=0,Me||ue(Ae,1,this.length),128&this[Ae]?-1*(255-this[Ae]+1):this[Ae]},M.prototype.readInt16LE=function(Ae,Me){Ae>>>=0,Me||ue(Ae,2,this.length);var je=this[Ae]|this[Ae+1]<<8;return 32768&je?4294901760|je:je},M.prototype.readInt16BE=function(Ae,Me){Ae>>>=0,Me||ue(Ae,2,this.length);var je=this[Ae+1]|this[Ae]<<8;return 32768&je?4294901760|je:je},M.prototype.readInt32LE=function(Ae,Me){return Ae>>>=0,Me||ue(Ae,4,this.length),this[Ae]|this[Ae+1]<<8|this[Ae+2]<<16|this[Ae+3]<<24},M.prototype.readInt32BE=function(Ae,Me){return Ae>>>=0,Me||ue(Ae,4,this.length),this[Ae]<<24|this[Ae+1]<<16|this[Ae+2]<<8|this[Ae+3]},M.prototype.readFloatLE=function(Ae,Me){return Ae>>>=0,Me||ue(Ae,4,this.length),Be.read(this,Ae,!0,23,4)},M.prototype.readFloatBE=function(Ae,Me){return Ae>>>=0,Me||ue(Ae,4,this.length),Be.read(this,Ae,!1,23,4)},M.prototype.readDoubleLE=function(Ae,Me){return Ae>>>=0,Me||ue(Ae,8,this.length),Be.read(this,Ae,!0,52,8)},M.prototype.readDoubleBE=function(Ae,Me){return Ae>>>=0,Me||ue(Ae,8,this.length),Be.read(this,Ae,!1,52,8)},M.prototype.writeUIntLE=function(Ae,Me,je,Ue){if(Ae=+Ae,Me>>>=0,je>>>=0,!Ue){var Oe=_Mathpow(2,8*je)-1;fe(this,Ae,Me,je,Oe,0)}var Te=1,De=0;for(this[Me]=255&Ae;++De >>=0,je>>>=0,!Ue){var Oe=_Mathpow(2,8*je)-1;fe(this,Ae,Me,je,Oe,0)}var Te=je-1,De=1;for(this[Me+Te]=255&Ae;0<=--Te&&(De*=256);)this[Me+Te]=255&Ae/De;return Me+je},M.prototype.writeUInt8=function(Ae,Me,je){return Ae=+Ae,Me>>>=0,je||fe(this,Ae,Me,1,255,0),this[Me]=255&Ae,Me+1},M.prototype.writeUInt16LE=function(Ae,Me,je){return Ae=+Ae,Me>>>=0,je||fe(this,Ae,Me,2,65535,0),this[Me]=255&Ae,this[Me+1]=Ae>>>8,Me+2},M.prototype.writeUInt16BE=function(Ae,Me,je){return Ae=+Ae,Me>>>=0,je||fe(this,Ae,Me,2,65535,0),this[Me]=Ae>>>8,this[Me+1]=255&Ae,Me+2},M.prototype.writeUInt32LE=function(Ae,Me,je){return Ae=+Ae,Me>>>=0,je||fe(this,Ae,Me,4,4294967295,0),this[Me+3]=Ae>>>24,this[Me+2]=Ae>>>16,this[Me+1]=Ae>>>8,this[Me]=255&Ae,Me+4},M.prototype.writeUInt32BE=function(Ae,Me,je){return Ae=+Ae,Me>>>=0,je||fe(this,Ae,Me,4,4294967295,0),this[Me]=Ae>>>24,this[Me+1]=Ae>>>16,this[Me+2]=Ae>>>8,this[Me+3]=255&Ae,Me+4},M.prototype.writeIntLE=function(Ae,Me,je,Ue){if(Ae=+Ae,Me>>>=0,!Ue){var Oe=_Mathpow(2,8*je-1);fe(this,Ae,Me,je,Oe-1,-Oe)}var Te=0,De=1,qe=0;for(this[Me]=255&Ae;++Te Ae&&0==qe&&0!==this[Me+Te-1]&&(qe=1),this[Me+Te]=255&(Ae/De>>0)-qe;return Me+je},M.prototype.writeIntBE=function(Ae,Me,je,Ue){if(Ae=+Ae,Me>>>=0,!Ue){var Oe=_Mathpow(2,8*je-1);fe(this,Ae,Me,je,Oe-1,-Oe)}var Te=je-1,De=1,qe=0;for(this[Me+Te]=255&Ae;0<=--Te&&(De*=256);)0>Ae&&0==qe&&0!==this[Me+Te+1]&&(qe=1),this[Me+Te]=255&(Ae/De>>0)-qe;return Me+je},M.prototype.writeInt8=function(Ae,Me,je){return Ae=+Ae,Me>>>=0,je||fe(this,Ae,Me,1,127,-128),0>Ae&&(Ae=255+Ae+1),this[Me]=255&Ae,Me+1},M.prototype.writeInt16LE=function(Ae,Me,je){return Ae=+Ae,Me>>>=0,je||fe(this,Ae,Me,2,32767,-32768),this[Me]=255&Ae,this[Me+1]=Ae>>>8,Me+2},M.prototype.writeInt16BE=function(Ae,Me,je){return Ae=+Ae,Me>>>=0,je||fe(this,Ae,Me,2,32767,-32768),this[Me]=Ae>>>8,this[Me+1]=255&Ae,Me+2},M.prototype.writeInt32LE=function(Ae,Me,je){return Ae=+Ae,Me>>>=0,je||fe(this,Ae,Me,4,2147483647,-2147483648),this[Me]=255&Ae,this[Me+1]=Ae>>>8,this[Me+2]=Ae>>>16,this[Me+3]=Ae>>>24,Me+4},M.prototype.writeInt32BE=function(Ae,Me,je){return Ae=+Ae,Me>>>=0,je||fe(this,Ae,Me,4,2147483647,-2147483648),0>Ae&&(Ae=4294967295+Ae+1),this[Me]=Ae>>>24,this[Me+1]=Ae>>>16,this[Me+2]=Ae>>>8,this[Me+3]=255&Ae,Me+4},M.prototype.writeFloatLE=function(Ae,Me,je){return pe(this,Ae,Me,!0,je)},M.prototype.writeFloatBE=function(Ae,Me,je){return pe(this,Ae,Me,!1,je)},M.prototype.writeDoubleLE=function(Ae,Me,je){return ge(this,Ae,Me,!0,je)},M.prototype.writeDoubleBE=function(Ae,Me,je){return ge(this,Ae,Me,!1,je)},M.prototype.copy=function(Ae,Me,je,Ue){if(je||(je=0),Ue||0===Ue||(Ue=this.length),Me>=Ae.length&&(Me=Ae.length),Me||(Me=0),0 Me)throw new RangeError("targetStart out of bounds");if(0>je||je>=this.length)throw new RangeError("sourceStart out of bounds");if(0>Ue)throw new RangeError("sourceEnd out of bounds");Ue>this.length&&(Ue=this.length),Ae.length-Me Oe)for(Te=0;Te Oe&&(Ae=Oe)}if(void 0!==Ue&&"string"!=typeof Ue)throw new TypeError("encoding must be a string");if("string"==typeof Ue&&!M.isEncoding(Ue))throw new TypeError("Unknown encoding: "+Ue)}else"number"==typeof Ae&&(Ae&=255);if(0>Me||this.length >>=0,je=je===void 0?this.length:je>>>0,Ae||(Ae=0);var Te;if("number"==typeof Ae)for(Te=Me;Te T||isNaN(T))throw TypeError("n must be a positive number");return this._maxListeners=T,this},I.prototype.emit=function(T){var D,q,P,W,F,z;if(this._events||(this._events={}),"error"===T&&(!this._events.error||U(this._events.error)&&!this._events.error.length))if(D=arguments[1],D instanceof Error)throw D;else{var N=new Error("Uncaught, unspecified \"error\" event. ("+D+")");throw N.context=D,N}if(q=this._events[T],O(q))return!1;if(A(q))switch(arguments.length){case 1:q.call(this);break;case 2:q.call(this,arguments[1]);break;case 3:q.call(this,arguments[1],arguments[2]);break;default:W=Array.prototype.slice.call(arguments,1),q.apply(this,W);}else if(U(q))for(W=Array.prototype.slice.call(arguments,1),z=q.slice(),P=z.length,F=0;F q&&(this._events[T].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[T].length),"function"==typeof console.trace&&console.trace())),this},I.prototype.on=I.prototype.addListener,I.prototype.once=function(T,D){function q(){this.removeListener(T,q),P||(P=!0,D.apply(this,arguments))}if(!A(D))throw TypeError("listener must be a function");var P=!1;return q.listener=D,this.on(T,q),this},I.prototype.removeListener=function(T,D){var q,P,W,F;if(!A(D))throw TypeError("listener must be a function");if(!this._events||!this._events[T])return this;if(q=this._events[T],W=q.length,P=-1,q===D||A(q.listener)&&q.listener===D)delete this._events[T],this._events.removeListener&&this.emit("removeListener",T,D);else if(U(q)){for(F=W;0
P)return this;1===q.length?(q.length=0,delete this._events[T]):q.splice(P,1),this._events.removeListener&&this.emit("removeListener",T,D)}return this},I.prototype.removeAllListeners=function(T){var D,q;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[T]&&delete this._events[T],this;if(0===arguments.length){for(D in this._events)"removeListener"!==D&&this.removeAllListeners(D);return this.removeAllListeners("removeListener"),this._events={},this}if(q=this._events[T],A(q))this.removeListener(T,q);else if(q)for(;q.length;)this.removeListener(T,q[q.length-1]);return delete this._events[T],this},I.prototype.listeners=function(T){var D;return D=this._events&&this._events[T]?A(this._events[T])?[this._events[T]]:this._events[T].slice():[],D},I.prototype.listenerCount=function(T){if(this._events){var D=this._events[T];if(A(D))return 1;if(D)return D.length}return 0},I.listenerCount=function(T,D){return T.listenerCount(D)}},{}],10:[function(E,R,C){C.read=function(I,A,M,U,O){var T,D,q=8*O-U-1,P=(1< >1,F=-7,z=M?O-1:0,N=M?-1:1,Y=I[A+z];for(z+=N,T=Y&(1<<-F)-1,Y>>=-F,F+=q;0>=-F,F+=U;0 >1,N=23===O?5.960464477539063e-8-6.617444900424222e-24:0,Y=U?0:T-1,H=U?1:-1,K=0>A||0===A&&0>1/A?1:0;for(A=_Mathabs(A),isNaN(A)||A===Infinity?(q=isNaN(A)?1:0,D=F):(D=_Mathfloor(Math.log(A)/Math.LN2),1>A*(P=_Mathpow(2,-D))&&(D--,P*=2),A+=1<=D+z?N/P:N*_Mathpow(2,1-z),2<=A*P&&(D++,P/=2),D+z>=F?(q=0,D=F):1<=D+z?(q=(A*P-1)*_Mathpow(2,O),D+=z):(q=A*_Mathpow(2,z-1)*_Mathpow(2,O),D=0));8<=O;I[M+Y]=255&q,Y+=H,q/=256,O-=8);for(D=D< =q?_Mathround(W/q)+"d":W>=D?_Mathround(W/D)+"h":W>=T?_Mathround(W/T)+"m":W>=O?_Mathround(W/O)+"s":W+"ms"}function M(W){return U(W,q,"day")||U(W,D,"hour")||U(W,T,"minute")||U(W,O,"second")||W+" ms"}function U(W,F,z){return W =we?ve=we:(ve--,ve|=ve>>>1,ve|=ve>>>2,ve|=ve>>>4,ve|=ve>>>8,ve|=ve>>>16,ve++),ve}function q(ve,ke){return 0>=ve||0===ke.length&&ke.ended?0:ke.objectMode?1:ve===ve?(ve>ke.highWaterMark&&(ke.highWaterMark=D(ve)),ve<=ke.length?ve:ke.ended?ke.length:(ke.needReadable=!0,0)):ke.flowing&&ke.length?ke.buffer.head.data.length:ke.length}function P(ve,ke){var xe=null;return ce.isBuffer(ke)||"string"==typeof ke||null===ke||void 0===ke||ve.objectMode||(xe=new TypeError("Invalid non-string/buffer chunk")),xe}function W(ve,ke){if(!ke.ended){if(ke.decoder){var xe=ke.decoder.end();xe&&xe.length&&(ke.buffer.push(xe),ke.length+=ke.objectMode?1:xe.length)}ke.ended=!0,F(ve)}}function F(ve){var ke=ve._readableState;ke.needReadable=!1,ke.emittedReadable||(be("emitReadable",ke.flowing),ke.emittedReadable=!0,ke.sync?ie(z,ve):z(ve))}function z(ve){be("emit readable"),ve.emit("readable"),$(ve)}function N(ve,ke){ke.readingMore||(ke.readingMore=!0,ie(Y,ve,ke))}function Y(ve,ke){for(var xe=ke.length;!ke.reading&&!ke.flowing&&!ke.ended&&ke.length =ke.length?(xe=ke.decoder?ke.buffer.join(""):1===ke.buffer.length?ke.buffer.head.data:ke.buffer.concat(ke.length),ke.buffer.clear()):xe=Q(ve,ke.buffer,ke.decoder),xe}function Q(ve,ke,xe){var Le;return ve Be.length?Be.length:ve;if(Se+=Ee===Be.length?Be:Be.slice(0,ve),ve-=Ee,0===ve){Ee===Be.length?(++Le,ke.head=xe.next?xe.next:ke.tail=null):(ke.head=xe,xe.data=Be.slice(Ee));break}++Le}return ke.length-=Le,Se}function ee(ve,ke){var xe=pe.allocUnsafe(ve),Le=ke.head,Se=1;for(Le.data.copy(xe),ve-=Le.data.length;Le=Le.next;){var Be=Le.data,Ee=ve>Be.length?Be.length:ve;if(Be.copy(xe,xe.length-ve,0,Ee),ve-=Ee,0===ve){Ee===Be.length?(++Se,ke.head=Le.next?Le.next:ke.tail=null):(ke.head=Le,Le.data=Be.slice(Ee));break}++Se}return ke.length-=Se,xe}function te(ve){var ke=ve._readableState;if(0 =ke.highWaterMark||ke.ended))return be("read: emitReadable",ke.length,ke.ended),0===ke.length&&ke.ended?te(this):F(this),null;if(ve=q(ve,ke),0===ve&&ke.ended)return 0===ke.length&&te(this),null;var Le=ke.needReadable;be("need readable",Le),(0===ke.length||ke.length-ve >>0),T=this.head,D=0;T;)T.data.copy(O,D),D+=T.data.length,T=T.next;return O}},{buffer:5,"buffer-shims":4}],24:[function(E,R,C){(function(I){var A=function(){try{return E("stream")}catch(M){}}();C=R.exports=E("./lib/_stream_readable.js"),C.Stream=A||C,C.Readable=C,C.Writable=E("./lib/_stream_writable.js"),C.Duplex=E("./lib/_stream_duplex.js"),C.Transform=E("./lib/_stream_transform.js"),C.PassThrough=E("./lib/_stream_passthrough.js"),!I.browser&&"disable"===I.env.READABLE_STREAM&&A&&(R.exports=A)}).call(this,E("_process"))},{"./lib/_stream_duplex.js":18,"./lib/_stream_passthrough.js":19,"./lib/_stream_readable.js":20,"./lib/_stream_transform.js":21,"./lib/_stream_writable.js":22,_process:16}],25:[function(E,R){(function(I,A){function M(F){var z=this;if(!(z instanceof M))return new M(F);if(F||(F={}),"string"==typeof F&&(F={url:F}),null==F.url&&null==F.socket)throw new Error("Missing required `url` or `socket` option");if(null!=F.url&&null!=F.socket)throw new Error("Must specify either `url` or `socket` option, not both");if(z._id=T(4).toString("hex").slice(0,7),z._debug("new websocket: %o",F),F=Object.assign({allowHalfOpen:!1},F),D.Duplex.call(z,F),z.connected=!1,z.destroyed=!1,z._chunk=null,z._cb=null,z._interval=null,F.socket)z.url=F.socket.url,z._ws=F.socket;else{z.url=F.url;try{z._ws="function"==typeof q?new P(F.url,F):new P(F.url)}catch(N){return void I.nextTick(function(){z._onError(N)})}}z._ws.binaryType="arraybuffer",z._ws.onopen=function(){z._onOpen()},z._ws.onmessage=function(N){z._onMessage(N)},z._ws.onclose=function(){z._onClose()},z._ws.onerror=function(){z._onError(new Error("connection error to "+z.url))},z._onFinishBound=function(){z._onFinish()},z.once("finish",z._onFinishBound)}R.exports=M;var U=E("debug")("simple-websocket"),O=E("inherits"),T=E("randombytes"),D=E("readable-stream"),q=E("ws"),P="function"==typeof q?q:WebSocket,W=65536;O(M,D.Duplex),M.WEBSOCKET_SUPPORT=!!P,M.prototype.send=function(F){this._ws.send(F)},M.prototype.destroy=function(F){this._destroy(null,F)},M.prototype._destroy=function(F,z){var N=this;if(!N.destroyed){if(z&&N.once("close",z),N._debug("destroy (error: %s)",F&&F.message),N.readable=N.writable=!1,N._readableState.ended||N.push(null),N._writableState.finished||N.end(),N.connected=!1,N.destroyed=!0,clearInterval(N._interval),N._interval=null,N._chunk=null,N._cb=null,N._onFinishBound&&N.removeListener("finish",N._onFinishBound),N._onFinishBound=null,N._ws){var Y=N._ws,H=function(){Y.onclose=null};if(Y.readyState===P.CLOSED)H();else try{Y.onclose=H,Y.close()}catch(K){H()}Y.onopen=null,Y.onmessage=null,Y.onerror=null}N._ws=null,F&&N.emit("error",F),N.emit("close")}},M.prototype._read=function(){},M.prototype._write=function(F,z,N){if(this.destroyed)return N(new Error("cannot write after socket is destroyed"));if(this.connected){try{this.send(F)}catch(Y){return this._onError(Y)}"function"!=typeof q&&this._ws.bufferedAmount>W?(this._debug("start backpressure: bufferedAmount %d",this._ws.bufferedAmount),this._cb=N):N(null)}else this._debug("write before connect"),this._chunk=F,this._cb=N},M.prototype._onFinish=function(){function F(){setTimeout(function(){z._destroy()},100)}var z=this;z.destroyed||(z.connected?F():z.once("connect",F))},M.prototype._onMessage=function(F){if(!this.destroyed){var z=F.data;z instanceof ArrayBuffer&&(z=new A(z)),this.push(z)}},M.prototype._onOpen=function(){var F=this;if(!(F.connected||F.destroyed)){if(F.connected=!0,F._chunk){try{F.send(F._chunk)}catch(N){return F._onError(N)}F._chunk=null,F._debug("sent chunk from \"write before connect\"");var z=F._cb;F._cb=null,z(null)}"function"!=typeof q&&(F._interval=setInterval(function(){F._onInterval()},150),F._interval.unref&&F._interval.unref()),F._debug("connect"),F.emit("connect")}},M.prototype._onInterval=function(){if(this._cb&&this._ws&&!(this._ws.bufferedAmount>W)){this._debug("ending backpressure: bufferedAmount %d",this._ws.bufferedAmount);var F=this._cb;this._cb=null,F(null)}},M.prototype._onClose=function(){this.destroyed||(this._debug("on close"),this._destroy())},M.prototype._onError=function(F){this.destroyed||(this._debug("error: %s",F.message||F),this._destroy(F))},M.prototype._debug=function(){var F=[].slice.call(arguments);F[0]="["+this._id+"] "+F[0],U.apply(null,F)}}).call(this,E("_process"),E("buffer").Buffer)},{_process:16,buffer:5,debug:7,inherits:11,randombytes:17,"readable-stream":24,ws:3}],26:[function(E,R,C){function I(q){if(q&&!T(q))throw new Error("Unknown encoding: "+q)}function A(q){return q.toString(this.encoding)}function M(q){this.charReceived=q.length%2,this.charLength=this.charReceived?2:0}function U(q){this.charReceived=q.length%3,this.charLength=this.charReceived?3:0}var O=E("buffer").Buffer,T=O.isEncoding||function(q){switch(q&&q.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1;}},D=C.StringDecoder=function(q){switch(this.encoding=(q||"utf8").toLowerCase().replace(/[-_]/,""),I(q),this.encoding){case"utf8":this.surrogateSize=3;break;case"ucs2":case"utf16le":this.surrogateSize=2,this.detectIncompleteChar=M;break;case"base64":this.surrogateSize=3,this.detectIncompleteChar=U;break;default:return void(this.write=A);}this.charBuffer=new O(6),this.charReceived=0,this.charLength=0};D.prototype.write=function(q){for(var W,P="";this.charLength;){if(W=q.length>=this.charLength-this.charReceived?this.charLength-this.charReceived:q.length,q.copy(this.charBuffer,this.charReceived,0,W),this.charReceived+=W,this.charReceived =F){this.charLength+=this.surrogateSize,P="";continue}if(this.charReceived=this.charLength=0,0===q.length)return P;break}this.detectIncompleteChar(q);var z=q.length;this.charLength&&(q.copy(this.charBuffer,0,q.length-this.charReceived,z),z-=this.charReceived),P+=q.toString(this.encoding,0,z);var z=P.length-1,F=P.charCodeAt(z);if(55296<=F&&56319>=F){var N=this.surrogateSize;return this.charLength+=N,this.charReceived+=N,this.charBuffer.copy(this.charBuffer,N,0,N),q.copy(this.charBuffer,0,0,N),P.substring(0,z)}return P},D.prototype.detectIncompleteChar=function(q){for(var W,P=3<=q.length?3:q.length;0 >5){this.charLength=2;break}if(2>=P&&14==W>>4){this.charLength=3;break}if(3>=P&&30==W>>3){this.charLength=4;break}}this.charReceived=P},D.prototype.end=function(q){var P="";if(q&&q.length&&(P=this.write(q)),this.charReceived){var W=this.charReceived,F=this.charBuffer,z=this.encoding;P+=F.slice(0,W).toString(z)}return P}},{buffer:5}],27:[function(E,R){(function(I){function M(U){try{if(!I.localStorage)return!1}catch(T){return!1}var O=I.localStorage[U];return null!=O&&"true"===(O+"").toLowerCase()}R.exports=function(U,O){if(M("noDeprecation"))return U;var D=!1;return function(){if(!D){if(M("throwDeprecation"))throw new Error(O);else M("traceDeprecation")?console.trace(O):console.warn(O);D=!0}return U.apply(this,arguments)}}}).call(this,"undefined"==typeof global?"undefined"==typeof self?"undefined"==typeof window?{}:window:self:global)},{}]},{},[1])(1)}); 2 | 3 | --------------------------------------------------------------------------------