UNPKG

avs-proxy

Version:

Proxy for avs-rpc

97 lines 67.4 kB
!function(C){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=C();else if("function"==typeof define&&define.amd)define([],C);else{var e;"undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self);e.proxy=C()}}(function(){return function e(k,g,a){function c(d,s){if(!g[d]){if(!k[d]){var m="function"==typeof require&&require;if(!s&&m)return m(d,!0);if(b)return b(d,!0);m=Error("Cannot find module '"+d+"'");throw m.code="MODULE_NOT_FOUND", m;}m=g[d]={exports:{}};k[d][0].call(m.exports,function(a){var n=k[d][1][a];return c(n?n:a)},m,m.exports,e,k,g,a)}return g[d].exports}for(var b="function"==typeof require&&require,d=0;d<a.length;d++)c(a[d]);return c}({1:[function(e,k,g){(function(){var a,c,b,d,f=[].slice,s={}.hasOwnProperty,m=function(a,n){function p(){this.constructor=a}for(var h in n)s.call(n,h)&&(a[h]=n[h]);p.prototype=n.prototype;a.prototype=new p;a.__super__=n.prototype;return a};d=e("circular-json");a=function(){return function(a, n,p){this.local=a;this.asynchronous=p;this[n]=function(h){return function(p,a,b){var c;console.log("rpc "+p+": executing local "+n+" - asynchronous: "+h.asynchronous);return(c=h.local)[n].apply(c,f.call(a).concat([b]))}}(this)}}();c=function(){function a(){var n,p,h,t;n=arguments[0];p=2<=arguments.length?f.call(arguments,1):[];this.rpc=n;this.uid=(Math.random()+"").substring(2,8);h=0;for(t=p.length;h<t;h++)n=p[h],this[n]=new Function("","var arg, args, cb, last, _i, _len; args = []; for (_i = 0, _len = arguments.length; _i < _len; _i++) { args.push(arguments[_i]); } last = arguments[arguments.length - 1]; if (typeof last === 'function') { cb = last; args.pop()} return this.rpc._request({method:'"+ n+"', args:args, cb:cb, id:'"+this.uid+"-'+(++this.count)});")}a.prototype.count=0;return a}();g.Rpc=b=function(){function b(){this.locals=[];this.callbacks=[];this._out=function(a){return function(p,h){return a.log("rpc "+p.id+" error: no rpc out route defined")}}(this)}b.prototype.cbID=0;b.prototype.out=function(a){return this._out=a};b.prototype._request=function(a){var p;a.cb&&"function"===typeof a.cb&&(this.callbacks[p=a.method+(" cb"+this.cbID++)]=a.cb,a.cb=p);p=d.stringify(a);this.log("rpc "+ a.id+": out "+p);this._out(a,p);return p};b.prototype._reply=function(a,p){if(a.cb)return this._request({method:a.cb,args:p,id:a.id})};b.prototype._error=function(a,p){if(a.cb)return this._request({method:a.cb,args:p,err:!0,id:a.id})};b.prototype.process=function(a){var p,h,b,c,r;try{"string"===typeof a?c=d.parse(a):a=d.stringify(c=a);if(c&&c.method){b=this.locals[c.method];this.log("rpc "+c.id+": in "+a);if(b)return b.asynchronous?b[c.method](c.id,c.args,function(h){return function(a,p){return p? h._error(c,p):h._reply(c,a)}}(this)):this._reply(c,b[c.method](c.id,c.args));if(this.callbacks[c.method])return c.err?h=c.args:r=c.args,this.callbacks[c.method](r,h),delete this.callbacks[c.method];this.log(p="error: method "+c.method+" is unknown");return this._error(c,p)}this.log(p="rpc error: message is null");this._error({method:"missing"},p)}catch(f){return this.log(p="error in "+c.method+": "+f),this._error(c,p)}};b.prototype._splat=function(){var a;a=1<=arguments.length?f.call(arguments,0): [];return 1===arguments.length&&"string"!==typeof arguments[0]?arguments[0]:a};b.prototype.remote=function(){var a;a=1<=arguments.length?f.call(arguments,0):[];return function(a,h,b){b.prototype=a.prototype;b=new b;a=a.apply(b,h);return Object(a)===a?a:b}(c,[this].concat(f.call(this._splat.apply(this,a))),function(){})};b.prototype.implement=function(){var a,b;a=arguments[0];b=2<=arguments.length?f.call(arguments,1):[];return this._expose.apply(this,[a,!1].concat(f.call(this._splat.apply(this,b))))}; b.prototype.implementAsync=function(){var a,b;a=arguments[0];b=2<=arguments.length?f.call(arguments,1):[];return this._expose.apply(this,[a,!0].concat(f.call(this._splat.apply(this,b))))};b.prototype._expose=function(){var b,p,h,c,d,r,m;p=arguments[0];b=arguments[1];c=3<=arguments.length?f.call(arguments,2):[];if(!c.length){for(h in p)"function"===typeof p[h]&&"_"!==h.charAt(0)&&c.push(h);this.log("rpc methods found: "+c)}m=[];d=0;for(r=c.length;d<r;d++)h=c[d],p[h]?(this.locals[h]&&this.log("rpc warning: duplicate method "+ h+", now asynchronous: "+b),m.push(this.locals[h]=new a(p,h,b))):m.push(this.log("rpc warning: local object has no method "+h));return m};b.prototype.log=function(a){return console.log(128>a.length?a:a.substring(0,127)+" ...")};return b}();g.wsRpc=function(a){function b(a){b.__super__.constructor.call(this);a&&a.send&&this.out(function(h,b){return a.send(b,function(h){return function(a){if(a)return h.log(a.toString())}}(this))});this["in"](a)}m(b,a);b.prototype["in"]=function(a){if(a)return a.on? a.on("message",function(a){return function(b,c){if(!c.binary)return a.process(b)}}(this)):a.onmessage=function(a){return function(b){if(b.data.length)return a.process(b.data)}}(this)};return b}(b);g.angularRpc=function(a){function b(a){b.__super__.constructor.call(this);this.out(function(h,b){return a.post("/rpc",h).success(function(a){return function(h){if(h)return a.process(h)}}(this))})}m(b,a);return b}(b);g.xmlHttpRpc=function(a){function b(a){b.__super__.constructor.call(this);this.out(function(h, b){a.open("POST","/rpc",!0);a.setRequestHeader("Content-type","application/json");a.onload(function(h){return function(){return h.process(a.response)}}(this));return a.send(b)})}m(b,a);return b}(b);g.ioRpc=function(a){function b(a,h){this.socket=a;this.tag=null!=h?h:"rpc";this.locals=[];if(this.socket)this.socket.on(this.tag,function(a){return function(h,b){return a.process(h,b)}}(this))}m(b,a);b.prototype._request=function(a){var h,b;this.log("rpc "+a.id+": out "+this.tag+" "+(b=d.stringify(a))); h=a.cb||function(){};if(this.socket)return this.socket.emit(this.tag,b,function(){return h.apply(this,arguments)})};b.prototype.process=function(a,h){var b,c,r;r=d.parse(a);this.log("rpc "+r.id+": in "+this.tag+" "+a);if(c=this.locals[r.method])try{return b=r.args||[],b.push(function(a){return function(){return h.apply(a,arguments)}}(this)),c.asynchronous?c[r.method](r.id,b):h(c[r.method](r.id,b))}catch(f){return h(null,"error in "+r.method+": "+f)}else return h(null,"error: method "+r.method+" is unknown")}; return b}(b)}).call(this)},{"circular-json":2}],2:[function(e,k,g){function a(a,b,c){var p=[],m=[a],e=[a],l=[c?"~":"[Circular]"],g=a,k=1,w;return function(a,h){b&&(h=b.call(this,a,h));""!==a&&(g!==this&&(w=k-n.call(m,this)-1,k-=w,m.splice(k,m.length),p.splice(k-1,p.length),g=this),"object"===typeof h&&h?(k=m.push(g=h),w=n.call(e,h),0>w?(w=e.push(h)-1,c?(p.push((""+a).replace(s,d)),l[w]="~"+p.join("~")):l[w]=l[0]):h=l[w]):"string"===typeof h&&c&&(h=h.replace(d,f).replace("~",d)));return h}}function c(a){return function(c, m){var r="string"===typeof m;if(r&&"~"===m.charAt(0))return new p(m.slice(1));""===c&&(m=b(m,m,{}));r&&(m=m.replace(l,"~").replace(f,d));return a?a.call(this,c,m):m}}function b(a,c,d){if(c instanceof Array)for(var r=0,f=c.length;r<f;r++)c[r]=b(a,c[r],d);else if(c instanceof p)if(c.length)if(d.hasOwnProperty(c))c=d[c];else{for(var r=c.split("~"),f=0,n=r.length;f<n;a=a[r[f++].replace(m,"~")]);c=d[c]=a}else c=a;else if(c instanceof Object)for(r in c)c.hasOwnProperty(r)&&(c[r]=b(a,c[r],d));return c}var d= "\\x"+("0"+(126).toString(16)).slice(-2),f="\\"+d,s=new RegExp(d,"g"),m=new RegExp(f,"g"),l=new RegExp("(?:^|[^\\\\])"+f),n=[].indexOf||function(a){for(var b=this.length;b--&&this[b]!==a;);return b},p=String;this.stringify=function(h,b,c,p){return JSON.stringify(h,a(h,b,!p),c)};this.parse=function(a,b){return JSON.parse(a,c(b))}},{}],3:[function(e,k,g){k.exports=e("./lib/")},{"./lib/":4}],4:[function(e,k,g){function a(a,b){"object"==typeof a&&(b=a,a=void 0);b=b||{};var n=c(a),p=n.source,h=n.id;b.forceNew|| b["force new connection"]||!1===b.multiplex?(f("ignoring socket cache for %s",p),p=d(p,b)):(s[h]||(f("new io instance for %s",p),s[h]=d(p,b)),p=s[h]);return p.socket(n.path)}var c=e("./url"),b=e("socket.io-parser"),d=e("./manager"),f=e("debug")("socket.io-client");k.exports=g=a;var s=g.managers={};g.protocol=b.protocol;g.connect=a;g.Manager=e("./manager");g.Socket=e("./socket")},{"./manager":5,"./socket":7,"./url":8,debug:11,"socket.io-parser":42}],5:[function(e,k,g){function a(b,c){if(!(this instanceof a))return new a(b,c);b&&"object"==typeof b&&(c=b,b=void 0);c=c||{};c.path=c.path||"/socket.io";this.nsps={};this.subs=[];this.opts=c;this.reconnection(!1!==c.reconnection);this.reconnectionAttempts(c.reconnectionAttempts||Infinity);this.reconnectionDelay(c.reconnectionDelay||1E3);this.reconnectionDelayMax(c.reconnectionDelayMax||5E3);this.timeout(null==c.timeout?2E4:c.timeout);this.readyState="closed";this.uri=b;this.connected=[];this.attempts=0;this.encoding=!1;this.packetBuffer=[];this.encoder= new d.Encoder;this.decoder=new d.Decoder;(this.autoConnect=!1!==c.autoConnect)&&this.open()}e("./url");var c=e("engine.io-client"),b=e("./socket");g=e("component-emitter");var d=e("socket.io-parser"),f=e("./on"),s=e("component-bind");e("object-component");var m=e("debug")("socket.io-client:manager"),l=e("indexof");k.exports=a;a.prototype.emitAll=function(){this.emit.apply(this,arguments);for(var a in this.nsps)this.nsps[a].emit.apply(this.nsps[a],arguments)};g(a.prototype);a.prototype.reconnection= function(a){if(!arguments.length)return this._reconnection;this._reconnection=!!a;return this};a.prototype.reconnectionAttempts=function(a){if(!arguments.length)return this._reconnectionAttempts;this._reconnectionAttempts=a;return this};a.prototype.reconnectionDelay=function(a){if(!arguments.length)return this._reconnectionDelay;this._reconnectionDelay=a;return this};a.prototype.reconnectionDelayMax=function(a){if(!arguments.length)return this._reconnectionDelayMax;this._reconnectionDelayMax=a;return this}; a.prototype.timeout=function(a){if(!arguments.length)return this._timeout;this._timeout=a;return this};a.prototype.maybeReconnectOnOpen=function(){this.openReconnect||this.reconnecting||!this._reconnection||0!==this.attempts||(this.openReconnect=!0,this.reconnect())};a.prototype.open=a.prototype.connect=function(a){m("readyState %s",this.readyState);if(~this.readyState.indexOf("open"))return this;m("opening %s",this.uri);var b=this.engine=c(this.uri,this.opts),h=this;this.readyState="opening";this.skipReconnect= !1;var d=f(b,"open",function(){h.onopen();a&&a()}),e=f(b,"error",function(b){m("connect_error");h.cleanup();h.readyState="closed";h.emitAll("connect_error",b);if(a){var c=Error("Connection error");c.data=b;a(c)}h.maybeReconnectOnOpen()});if(!1!==this._timeout){var r=this._timeout;m("connect attempt will timeout after %d",r);var g=setTimeout(function(){m("connect attempt timed out after %d",r);d.destroy();b.close();b.emit("error","timeout");h.emitAll("connect_timeout",r)},r);this.subs.push({destroy:function(){clearTimeout(g)}})}this.subs.push(d); this.subs.push(e);return this};a.prototype.onopen=function(){m("open");this.cleanup();this.readyState="open";this.emit("open");var a=this.engine;this.subs.push(f(a,"data",s(this,"ondata")));this.subs.push(f(this.decoder,"decoded",s(this,"ondecoded")));this.subs.push(f(a,"error",s(this,"onerror")));this.subs.push(f(a,"close",s(this,"onclose")))};a.prototype.ondata=function(a){this.decoder.add(a)};a.prototype.ondecoded=function(a){this.emit("packet",a)};a.prototype.onerror=function(a){m("error",a); this.emitAll("error",a)};a.prototype.socket=function(a){var c=this.nsps[a];if(!c){c=new b(this,a);this.nsps[a]=c;var h=this;c.on("connect",function(){~l(h.connected,c)||h.connected.push(c)})}return c};a.prototype.destroy=function(a){a=l(this.connected,a);~a&&this.connected.splice(a,1);this.connected.length||this.close()};a.prototype.packet=function(a){m("writing packet %j",a);var b=this;b.encoding?b.packetBuffer.push(a):(b.encoding=!0,this.encoder.encode(a,function(a){for(var c=0;c<a.length;c++)b.engine.write(a[c]); b.encoding=!1;b.processPacketQueue()}))};a.prototype.processPacketQueue=function(){if(0<this.packetBuffer.length&&!this.encoding){var a=this.packetBuffer.shift();this.packet(a)}};a.prototype.cleanup=function(){for(var a;a=this.subs.shift();)a.destroy();this.packetBuffer=[];this.encoding=!1;this.decoder.destroy()};a.prototype.close=a.prototype.disconnect=function(){this.skipReconnect=!0;this.readyState="closed";this.engine&&this.engine.close()};a.prototype.onclose=function(a){m("close");this.cleanup(); this.readyState="closed";this.emit("close",a);this._reconnection&&!this.skipReconnect&&this.reconnect()};a.prototype.reconnect=function(){if(this.reconnecting||this.skipReconnect)return this;var a=this;this.attempts++;if(this.attempts>this._reconnectionAttempts)m("reconnect failed"),this.emitAll("reconnect_failed"),this.reconnecting=!1;else{var b=this.attempts*this.reconnectionDelay(),b=Math.min(b,this.reconnectionDelayMax());m("will wait %dms before reconnect attempt",b);this.reconnecting=!0;var c= setTimeout(function(){a.skipReconnect||(m("attempting reconnect"),a.emitAll("reconnect_attempt",a.attempts),a.emitAll("reconnecting",a.attempts),a.skipReconnect||a.open(function(b){b?(m("reconnect attempt error"),a.reconnecting=!1,a.reconnect(),a.emitAll("reconnect_error",b.data)):(m("reconnect success"),a.onreconnect())}))},b);this.subs.push({destroy:function(){clearTimeout(c)}})}};a.prototype.onreconnect=function(){var a=this.attempts;this.attempts=0;this.reconnecting=!1;this.emitAll("reconnect", a)}},{"./on":6,"./socket":7,"./url":8,"component-bind":9,"component-emitter":10,debug:11,"engine.io-client":12,indexof:38,"object-component":39,"socket.io-parser":42}],6:[function(e,k,g){k.exports=function(a,c,b){a.on(c,b);return{destroy:function(){a.removeListener(c,b)}}}},{}],7:[function(e,k,g){function a(a,b){this.io=a;this.nsp=b;this.json=this;this.ids=0;this.acks={};this.io.autoConnect&&this.open();this.receiveBuffer=[];this.sendBuffer=[];this.connected=!1;this.disconnected=!0}var c=e("socket.io-parser"); g=e("component-emitter");var b=e("to-array"),d=e("./on"),f=e("component-bind"),s=e("debug")("socket.io-client:socket"),m=e("has-binary");k.exports=a;var l={connect:1,connect_error:1,connect_timeout:1,disconnect:1,error:1,reconnect:1,reconnect_attempt:1,reconnect_failed:1,reconnect_error:1,reconnecting:1},n=g.prototype.emit;g(a.prototype);a.prototype.subEvents=function(){if(!this.subs){var a=this.io;this.subs=[d(a,"open",f(this,"onopen")),d(a,"packet",f(this,"onpacket")),d(a,"close",f(this,"onclose"))]}}; a.prototype.open=a.prototype.connect=function(){if(this.connected)return this;this.subEvents();this.io.open();if("open"==this.io.readyState)this.onopen();return this};a.prototype.send=function(){var a=b(arguments);a.unshift("message");this.emit.apply(this,a);return this};a.prototype.emit=function(a){if(l.hasOwnProperty(a))return n.apply(this,arguments),this;var h=b(arguments),d=c.EVENT;m(h)&&(d=c.BINARY_EVENT);d={type:d,data:h};"function"==typeof h[h.length-1]&&(s("emitting packet with ack id %d", this.ids),this.acks[this.ids]=h.pop(),d.id=this.ids++);this.connected?this.packet(d):this.sendBuffer.push(d);return this};a.prototype.packet=function(a){a.nsp=this.nsp;this.io.packet(a)};a.prototype.onopen=function(){s("transport is open - connecting");"/"!=this.nsp&&this.packet({type:c.CONNECT})};a.prototype.onclose=function(a){s("close (%s)",a);this.connected=!1;this.disconnected=!0;this.emit("disconnect",a)};a.prototype.onpacket=function(a){if(a.nsp==this.nsp)switch(a.type){case c.CONNECT:this.onconnect(); break;case c.EVENT:this.onevent(a);break;case c.BINARY_EVENT:this.onevent(a);break;case c.ACK:this.onack(a);break;case c.BINARY_ACK:this.onack(a);break;case c.DISCONNECT:this.ondisconnect();break;case c.ERROR:this.emit("error",a.data)}};a.prototype.onevent=function(a){var b=a.data||[];s("emitting event %j",b);null!=a.id&&(s("attaching ack callback to event"),b.push(this.ack(a.id)));this.connected?n.apply(this,b):this.receiveBuffer.push(b)};a.prototype.ack=function(a){var h=this,d=!1;return function(){if(!d){d= !0;var f=b(arguments);s("sending ack %j",f);var r=m(f)?c.BINARY_ACK:c.ACK;h.packet({type:r,id:a,data:f})}}};a.prototype.onack=function(a){s("calling ack %s with %j",a.id,a.data);this.acks[a.id].apply(this,a.data);delete this.acks[a.id]};a.prototype.onconnect=function(){this.connected=!0;this.disconnected=!1;this.emit("connect");this.emitBuffered()};a.prototype.emitBuffered=function(){var a;for(a=0;a<this.receiveBuffer.length;a++)n.apply(this,this.receiveBuffer[a]);this.receiveBuffer=[];for(a=0;a< this.sendBuffer.length;a++)this.packet(this.sendBuffer[a]);this.sendBuffer=[]};a.prototype.ondisconnect=function(){s("server disconnect (%s)",this.nsp);this.destroy();this.onclose("io server disconnect")};a.prototype.destroy=function(){if(this.subs){for(var a=0;a<this.subs.length;a++)this.subs[a].destroy();this.subs=null}this.io.destroy(this)};a.prototype.close=a.prototype.disconnect=function(){this.connected&&(s("performing disconnect (%s)",this.nsp),this.packet({type:c.DISCONNECT}));this.destroy(); if(this.connected)this.onclose("io client disconnect");return this}},{"./on":6,"component-bind":9,"component-emitter":10,debug:11,"has-binary":36,"socket.io-parser":42,"to-array":46}],8:[function(e,k,g){(function(a){var c=e("parseuri"),b=e("debug")("socket.io-client:url");k.exports=function(d,f){var e=d;f=f||a.location;null==d&&(d=f.protocol+"//"+f.hostname);"string"==typeof d&&("/"==d.charAt(0)&&(d="/"==d.charAt(1)?f.protocol+d:f.hostname+d),/^(https?|wss?):\/\//.test(d)||(b("protocol-less url %s", d),d="undefined"!=typeof f?f.protocol+"//"+d:"https://"+d),b("parse %s",d),e=c(d));e.port||(/^(http|ws)$/.test(e.protocol)?e.port="80":/^(http|ws)s$/.test(e.protocol)&&(e.port="443"));e.path=e.path||"/";e.id=e.protocol+"://"+e.host+":"+e.port;e.href=e.protocol+"://"+e.host+(f&&f.port==e.port?"":":"+e.port);return e}}).call(this,"undefined"!==typeof global?global:"undefined"!==typeof self?self:"undefined"!==typeof window?window:{})},{debug:11,parseuri:40}],9:[function(e,k,g){var a=[].slice;k.exports= function(c,b){"string"==typeof b&&(b=c[b]);if("function"!=typeof b)throw Error("bind() requires a function");var d=a.call(arguments,2);return function(){return b.apply(c,d.concat(a.call(arguments)))}}},{}],10:[function(e,k,g){function a(c){if(c){for(var b in a.prototype)c[b]=a.prototype[b];return c}}k.exports=a;a.prototype.on=a.prototype.addEventListener=function(a,b){this._callbacks=this._callbacks||{};(this._callbacks[a]=this._callbacks[a]||[]).push(b);return this};a.prototype.once=function(a,b){function d(){f.off(a, d);b.apply(this,arguments)}var f=this;this._callbacks=this._callbacks||{};d.fn=b;this.on(a,d);return this};a.prototype.off=a.prototype.removeListener=a.prototype.removeAllListeners=a.prototype.removeEventListener=function(a,b){this._callbacks=this._callbacks||{};if(0==arguments.length)return this._callbacks={},this;var d=this._callbacks[a];if(!d)return this;if(1==arguments.length)return delete this._callbacks[a],this;for(var f,e=0;e<d.length;e++)if(f=d[e],f===b||f.fn===b){d.splice(e,1);break}return this}; a.prototype.emit=function(a){this._callbacks=this._callbacks||{};var b=[].slice.call(arguments,1),d=this._callbacks[a];if(d)for(var d=d.slice(0),f=0,e=d.length;f<e;++f)d[f].apply(this,b);return this};a.prototype.listeners=function(a){this._callbacks=this._callbacks||{};return this._callbacks[a]||[]};a.prototype.hasListeners=function(a){return!!this.listeners(a).length}},{}],11:[function(e,k,g){function a(b){return a.enabled(b)?function(c){c instanceof Error&&(c=c.stack||c.message);var f=new Date, e=f-(a[b]||f);a[b]=f;c=b+" "+c+" +"+a.humanize(e);window.console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}:function(){}}k.exports=a;a.names=[];a.skips=[];a.enable=function(b){try{localStorage.debug=b}catch(c){}for(var f=(b||"").split(/[\s,]+/),e=f.length,m=0;m<e;m++)b=f[m].replace("*",".*?"),"-"===b[0]?a.skips.push(new RegExp("^"+b.substr(1)+"$")):a.names.push(new RegExp("^"+b+"$"))};a.disable=function(){a.enable("")};a.humanize=function(a){return 36E5<=a?(a/36E5).toFixed(1)+ "h":6E4<=a?(a/6E4).toFixed(1)+"m":1E3<=a?(a/1E3|0)+"s":a+"ms"};a.enabled=function(b){for(var c=0,f=a.skips.length;c<f;c++)if(a.skips[c].test(b))return!1;c=0;for(f=a.names.length;c<f;c++)if(a.names[c].test(b))return!0;return!1};try{window.localStorage&&a.enable(localStorage.debug)}catch(c){}},{}],12:[function(e,k,g){k.exports=e("./lib/")},{"./lib/":13}],13:[function(e,k,g){k.exports=e("./socket");k.exports.parser=e("engine.io-parser")},{"./socket":14,"engine.io-parser":23}],14:[function(e,k,g){(function(a){function c(b, d){if(!(this instanceof c))return new c(b,d);d=d||{};b&&"object"==typeof b&&(d=b,b=null);b&&(b=l(b),d.host=b.host,d.secure="https"==b.protocol||"wss"==b.protocol,d.port=b.port,b.query&&(d.query=b.query));this.secure=null!=d.secure?d.secure:a.location&&"https:"==location.protocol;if(d.host){var f=d.host.split(":");d.hostname=f.shift();f.length&&(d.port=f.pop())}this.agent=d.agent||!1;this.hostname=d.hostname||(a.location?location.hostname:"localhost");this.port=d.port||(a.location&&location.port?location.port: this.secure?443:80);this.query=d.query||{};"string"==typeof this.query&&(this.query=p.decode(this.query));this.upgrade=!1!==d.upgrade;this.path=(d.path||"/engine.io").replace(/\/$/,"")+"/";this.forceJSONP=!!d.forceJSONP;this.jsonp=!1!==d.jsonp;this.forceBase64=!!d.forceBase64;this.enablesXDR=!!d.enablesXDR;this.timestampParam=d.timestampParam||"t";this.timestampRequests=d.timestampRequests;this.transports=d.transports||["polling","websocket"];this.readyState="";this.writeBuffer=[];this.callbackBuffer= [];this.policyPort=d.policyPort||843;this.rememberUpgrade=d.rememberUpgrade||!1;this.open();this.binaryType=null;this.onlyBinaryUpgrades=d.onlyBinaryUpgrades}var b=e("./transports"),d=e("component-emitter"),f=e("debug")("engine.io-client:socket"),g=e("indexof"),m=e("engine.io-parser"),l=e("parseuri"),n=e("parsejson"),p=e("parseqs");k.exports=c;c.priorWebsocketSuccess=!1;d(c.prototype);c.protocol=m.protocol;c.Socket=c;c.Transport=e("./transport");c.transports=e("./transports");c.parser=e("engine.io-parser"); c.prototype.createTransport=function(a){f('creating transport "%s"',a);var c=this.query,d={},r;for(r in c)c.hasOwnProperty(r)&&(d[r]=c[r]);d.EIO=m.protocol;d.transport=a;this.id&&(d.sid=this.id);return new b[a]({agent:this.agent,hostname:this.hostname,port:this.port,secure:this.secure,path:this.path,query:d,forceJSONP:this.forceJSONP,jsonp:this.jsonp,forceBase64:this.forceBase64,enablesXDR:this.enablesXDR,timestampRequests:this.timestampRequests,timestampParam:this.timestampParam,policyPort:this.policyPort, socket:this})};c.prototype.open=function(){var a;if(this.rememberUpgrade&&c.priorWebsocketSuccess&&-1!=this.transports.indexOf("websocket"))a="websocket";else{if(0==this.transports.length){var b=this;setTimeout(function(){b.emit("error","No transports available")},0);return}a=this.transports[0]}this.readyState="opening";try{a=this.createTransport(a)}catch(d){this.transports.shift();this.open();return}a.open();this.setTransport(a)};c.prototype.setTransport=function(a){f("setting transport %s",a.name); var b=this;this.transport&&(f("clearing existing transport %s",this.transport.name),this.transport.removeAllListeners());this.transport=a;a.on("drain",function(){b.onDrain()}).on("packet",function(a){b.onPacket(a)}).on("error",function(a){b.onError(a)}).on("close",function(){b.onClose("transport close")})};c.prototype.probe=function(a){function b(){if(s.onlyBinaryUpgrades){var d=!this.supportsBinary&&s.transport.supportsBinary;n=n||d}n||(f('probe transport "%s" opened',a),l.send([{type:"ping",data:"probe"}]), l.once("packet",function(b){n||("pong"==b.type&&"probe"==b.data?(f('probe transport "%s" pong',a),s.upgrading=!0,s.emit("upgrading",l),l&&(c.priorWebsocketSuccess="websocket"==l.name,f('pausing current transport "%s"',s.transport.name),s.transport.pause(function(){n||"closed"==s.readyState||(f("changing transport and sending upgrade packet"),g(),s.setTransport(l),l.send([{type:"upgrade"}]),s.emit("upgrade",l),l=null,s.upgrading=!1,s.flush())}))):(f('probe transport "%s" failed',a),b=Error("probe error"), b.transport=l.name,s.emit("upgradeError",b)))}))}function d(){n||(n=!0,g(),l.close(),l=null)}function r(b){var c=Error("probe error: "+b);c.transport=l.name;d();f('probe transport "%s" failed because of error: %s',a,b);s.emit("upgradeError",c)}function m(){r("transport closed")}function e(){r("socket closed")}function p(a){l&&a.name!=l.name&&(f('"%s" works - aborting "%s"',a.name,l.name),d())}function g(){l.removeListener("open",b);l.removeListener("error",r);l.removeListener("close",m);s.removeListener("close", e);s.removeListener("upgrading",p)}f('probing transport "%s"',a);var l=this.createTransport(a,{probe:1}),n=!1,s=this;c.priorWebsocketSuccess=!1;l.once("open",b);l.once("error",r);l.once("close",m);this.once("close",e);this.once("upgrading",p);l.open()};c.prototype.onOpen=function(){f("socket open");this.readyState="open";c.priorWebsocketSuccess="websocket"==this.transport.name;this.emit("open");this.flush();if("open"==this.readyState&&this.upgrade&&this.transport.pause){f("starting upgrade probes"); for(var a=0,b=this.upgrades.length;a<b;a++)this.probe(this.upgrades[a])}};c.prototype.onPacket=function(a){if("opening"==this.readyState||"open"==this.readyState)switch(f('socket receive: type "%s", data "%s"',a.type,a.data),this.emit("packet",a),this.emit("heartbeat"),a.type){case "open":this.onHandshake(n(a.data));break;case "pong":this.setPing();break;case "error":var b=Error("server error");b.code=a.data;this.emit("error",b);break;case "message":this.emit("data",a.data),this.emit("message",a.data)}else f('packet received with socket readyState "%s"', this.readyState)};c.prototype.onHandshake=function(a){this.emit("handshake",a);this.id=a.sid;this.transport.query.sid=a.sid;this.upgrades=this.filterUpgrades(a.upgrades);this.pingInterval=a.pingInterval;this.pingTimeout=a.pingTimeout;this.onOpen();"closed"!=this.readyState&&(this.setPing(),this.removeListener("heartbeat",this.onHeartbeat),this.on("heartbeat",this.onHeartbeat))};c.prototype.onHeartbeat=function(a){clearTimeout(this.pingTimeoutTimer);var b=this;b.pingTimeoutTimer=setTimeout(function(){if("closed"!= b.readyState)b.onClose("ping timeout")},a||b.pingInterval+b.pingTimeout)};c.prototype.setPing=function(){var a=this;clearTimeout(a.pingIntervalTimer);a.pingIntervalTimer=setTimeout(function(){f("writing ping packet - expecting pong within %sms",a.pingTimeout);a.ping();a.onHeartbeat(a.pingTimeout)},a.pingInterval)};c.prototype.ping=function(){this.sendPacket("ping")};c.prototype.onDrain=function(){for(var a=0;a<this.prevBufferLen;a++)if(this.callbackBuffer[a])this.callbackBuffer[a]();this.writeBuffer.splice(0, this.prevBufferLen);this.callbackBuffer.splice(0,this.prevBufferLen);this.prevBufferLen=0;0==this.writeBuffer.length?this.emit("drain"):this.flush()};c.prototype.flush=function(){"closed"!=this.readyState&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length&&(f("flushing %d packets in socket",this.writeBuffer.length),this.transport.send(this.writeBuffer),this.prevBufferLen=this.writeBuffer.length,this.emit("flush"))};c.prototype.write=c.prototype.send=function(a,b){this.sendPacket("message", a,b);return this};c.prototype.sendPacket=function(a,b,c){"closing"!=this.readyState&&"closed"!=this.readyState&&(a={type:a,data:b},this.emit("packetCreate",a),this.writeBuffer.push(a),this.callbackBuffer.push(c),this.flush())};c.prototype.close=function(){if("opening"==this.readyState||"open"==this.readyState){var a=function(){d.once("upgrade",b);d.once("upgradeError",b)},b=function(){d.removeListener("upgrade",b);d.removeListener("upgradeError",b);c()},c=function(){d.onClose("forced close");f("socket closing - telling transport to close"); d.transport.close()};this.readyState="closing";var d=this;if(this.writeBuffer.length)this.once("drain",function(){this.upgrading?a():c()});else this.upgrading?a():c()}return this};c.prototype.onError=function(a){f("socket error %j",a);c.priorWebsocketSuccess=!1;this.emit("error",a);this.onClose("transport error",a)};c.prototype.onClose=function(a,b){if("opening"==this.readyState||"open"==this.readyState||"closing"==this.readyState){f('socket close with reason: "%s"',a);var c=this;clearTimeout(this.pingIntervalTimer); clearTimeout(this.pingTimeoutTimer);setTimeout(function(){c.writeBuffer=[];c.callbackBuffer=[];c.prevBufferLen=0},0);this.transport.removeAllListeners("close");this.transport.close();this.transport.removeAllListeners();this.readyState="closed";this.id=null;this.emit("close",a,b)}};c.prototype.filterUpgrades=function(a){for(var b=[],c=0,d=a.length;c<d;c++)~g(this.transports,a[c])&&b.push(a[c]);return b}}).call(this,"undefined"!==typeof global?global:"undefined"!==typeof self?self:"undefined"!==typeof window? window:{})},{"./transport":15,"./transports":16,"component-emitter":10,debug:11,"engine.io-parser":23,indexof:38,parsejson:32,parseqs:33,parseuri:34}],15:[function(e,k,g){function a(a){this.path=a.path;this.hostname=a.hostname;this.port=a.port;this.secure=a.secure;this.query=a.query;this.timestampParam=a.timestampParam;this.timestampRequests=a.timestampRequests;this.readyState="";this.agent=a.agent||!1;this.socket=a.socket;this.enablesXDR=a.enablesXDR}var c=e("engine.io-parser");e=e("component-emitter"); k.exports=a;e(a.prototype);a.timestamps=0;a.prototype.onError=function(a,c){var f=Error(a);f.type="TransportError";f.description=c;this.emit("error",f);return this};a.prototype.open=function(){if("closed"==this.readyState||""==this.readyState)this.readyState="opening",this.doOpen();return this};a.prototype.close=function(){if("opening"==this.readyState||"open"==this.readyState)this.doClose(),this.onClose();return this};a.prototype.send=function(a){if("open"==this.readyState)this.write(a);else throw Error("Transport not open"); };a.prototype.onOpen=function(){this.readyState="open";this.writable=!0;this.emit("open")};a.prototype.onData=function(a){a=c.decodePacket(a,this.socket.binaryType);this.onPacket(a)};a.prototype.onPacket=function(a){this.emit("packet",a)};a.prototype.onClose=function(){this.readyState="closed";this.emit("close")}},{"component-emitter":10,"engine.io-parser":23}],16:[function(e,k,g){(function(a){var c=e("xmlhttprequest"),b=e("./polling-xhr"),d=e("./polling-jsonp"),f=e("./websocket");g.polling=function(f){var m= !1,e=!1,g=!1!==f.jsonp;a.location&&(e="https:"==location.protocol,(m=location.port)||(m=e?443:80),m=f.hostname!=location.hostname||m!=f.port,e=f.secure!=e);f.xdomain=m;f.xscheme=e;if("open"in new c(f)&&!f.forceJSONP)return new b(f);if(!g)throw Error("JSONP disabled");return new d(f)};g.websocket=f}).call(this,"undefined"!==typeof global?global:"undefined"!==typeof self?self:"undefined"!==typeof window?window:{})},{"./polling-jsonp":17,"./polling-xhr":18,"./websocket":20,xmlhttprequest:21}],17:[function(e, k,g){(function(a){function c(){}function b(b){d.call(this,b);this.query=this.query||{};l||(a.___eio||(a.___eio=[]),l=a.___eio);this.index=l.length;var f=this;l.push(function(a){f.onData(a)});this.query.j=this.index;a.document&&a.addEventListener&&a.addEventListener("beforeunload",function(){f.script&&(f.script.onerror=c)})}var d=e("./polling"),f=e("component-inherit");k.exports=b;var g=/\n/g,m=/\\n/g,l;f(b,d);b.prototype.supportsBinary=!1;b.prototype.doClose=function(){this.script&&(this.script.parentNode.removeChild(this.script), this.script=null);this.form&&(this.form.parentNode.removeChild(this.form),this.iframe=this.form=null);d.prototype.doClose.call(this)};b.prototype.doPoll=function(){var a=this,b=document.createElement("script");this.script&&(this.script.parentNode.removeChild(this.script),this.script=null);b.async=!0;b.src=this.uri();b.onerror=function(b){a.onError("jsonp poll error",b)};var c=document.getElementsByTagName("script")[0];c.parentNode.insertBefore(b,c);this.script=b;"undefined"!=typeof navigator&&/gecko/i.test(navigator.userAgent)&& setTimeout(function(){var a=document.createElement("iframe");document.body.appendChild(a);document.body.removeChild(a)},100)};b.prototype.doWrite=function(a,b){function c(){d();b()}function d(){if(f.iframe)try{f.form.removeChild(f.iframe)}catch(a){f.onError("jsonp polling iframe removal error",a)}try{x=document.createElement('<iframe src="javascript:0" name="'+f.iframeId+'">')}catch(b){x=document.createElement("iframe"),x.name=f.iframeId,x.src="javascript:0"}x.id=f.iframeId;f.form.appendChild(x); f.iframe=x}var f=this;if(!this.form){var e=document.createElement("form"),l=document.createElement("textarea"),k=this.iframeId="eio_iframe_"+this.index,x;e.className="socketio";e.style.position="absolute";e.style.top="-1000px";e.style.left="-1000px";e.target=k;e.method="POST";e.setAttribute("accept-charset","utf-8");l.name="d";e.appendChild(l);document.body.appendChild(e);this.form=e;this.area=l}this.form.action=this.uri();d();a=a.replace(m,"\\\n");this.area.value=a.replace(g,"\\n");try{this.form.submit()}catch(D){}this.iframe.attachEvent? this.iframe.onreadystatechange=function(){"complete"==f.iframe.readyState&&c()}:this.iframe.onload=c}}).call(this,"undefined"!==typeof global?global:"undefined"!==typeof self?self:"undefined"!==typeof window?window:{})},{"./polling":19,"component-inherit":22}],18:[function(e,k,g){(function(a){function c(){}function b(b){m.call(this,b);if(a.location){var c="https:"==location.protocol,d=location.port;d||(d=c?443:80);this.xd=b.hostname!=a.location.hostname||d!=b.port;this.xs=b.secure!=c}}function d(a){this.method= a.method||"GET";this.uri=a.uri;this.xd=!!a.xd;this.xs=!!a.xs;this.async=!1!==a.async;this.data=void 0!=a.data?a.data:null;this.agent=a.agent;this.isBinary=a.isBinary;this.supportsBinary=a.supportsBinary;this.enablesXDR=a.enablesXDR;this.create()}function f(){for(var a in d.requests)d.requests.hasOwnProperty(a)&&d.requests[a].abort()}var g=e("xmlhttprequest"),m=e("./polling"),l=e("component-emitter"),n=e("component-inherit"),p=e("debug")("engine.io-client:polling-xhr");k.exports=b;k.exports.Request= d;n(b,m);b.prototype.supportsBinary=!0;b.prototype.request=function(a){a=a||{};a.uri=this.uri();a.xd=this.xd;a.xs=this.xs;a.agent=this.agent||!1;a.supportsBinary=this.supportsBinary;a.enablesXDR=this.enablesXDR;return new d(a)};b.prototype.doWrite=function(a,b){var c=this.request({method:"POST",data:a,isBinary:"string"!==typeof a&&void 0!==a}),d=this;c.on("success",b);c.on("error",function(a){d.onError("xhr post error",a)});this.sendXhr=c};b.prototype.doPoll=function(){p("xhr poll");var a=this.request(), b=this;a.on("data",function(a){b.onData(a)});a.on("error",function(a){b.onError("xhr poll error",a)});this.pollXhr=a};l(d.prototype);d.prototype.create=function(){var b=this.xhr=new g({agent:this.agent,xdomain:this.xd,xscheme:this.xs,enablesXDR:this.enablesXDR}),c=this;try{p("xhr open %s: %s",this.method,this.uri);b.open(this.method,this.uri,this.async);this.supportsBinary&&(b.responseType="arraybuffer");if("POST"==this.method)try{this.isBinary?b.setRequestHeader("Content-type","application/octet-stream"): b.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(f){}"withCredentials"in b&&(b.withCredentials=!0);this.hasXDR()?(b.onload=function(){c.onLoad()},b.onerror=function(){c.onError(b.responseText)}):b.onreadystatechange=function(){if(4==b.readyState)if(200==b.status||1223==b.status)c.onLoad();else setTimeout(function(){c.onError(b.status)},0)};p("xhr data %s",this.data);b.send(this.data)}catch(e){setTimeout(function(){c.onError(e)},0);return}a.document&&(this.index=d.requestsCount++, d.requests[this.index]=this)};d.prototype.onSuccess=function(){this.emit("success");this.cleanup()};d.prototype.onData=function(a){this.emit("data",a);this.onSuccess()};d.prototype.onError=function(a){this.emit("error",a);this.cleanup()};d.prototype.cleanup=function(){if("undefined"!=typeof this.xhr&&null!==this.xhr){this.hasXDR()?this.xhr.onload=this.xhr.onerror=c:this.xhr.onreadystatechange=c;try{this.xhr.abort()}catch(b){}a.document&&delete d.requests[this.index];this.xhr=null}};d.prototype.onLoad= function(){var a;try{var b;try{b=this.xhr.getResponseHeader("Content-Type").split(";")[0]}catch(c){}a="application/octet-stream"===b?this.xhr.response:this.supportsBinary?"ok":this.xhr.responseText}catch(d){this.onError(d)}if(null!=a)this.onData(a)};d.prototype.hasXDR=function(){return"undefined"!==typeof a.XDomainRequest&&!this.xs&&this.enablesXDR};d.prototype.abort=function(){this.cleanup()};a.document&&(d.requestsCount=0,d.requests={},a.attachEvent?a.attachEvent("onunload",f):a.addEventListener&& a.addEventListener("beforeunload",f))}).call(this,"undefined"!==typeof global?global:"undefined"!==typeof self?self:"undefined"!==typeof window?window:{})},{"./polling":19,"component-emitter":10,"component-inherit":22,debug:11,xmlhttprequest:21}],19:[function(e,k,g){function a(a){var b=a&&a.forceBase64;if(!s||b)this.supportsBinary=!1;c.call(this,a)}var c=e("../transport"),b=e("parseqs"),d=e("engine.io-parser");g=e("component-inherit");var f=e("debug")("engine.io-client:polling");k.exports=a;var s= null!=(new (e("xmlhttprequest"))({xdomain:!1})).responseType;g(a,c);a.prototype.name="polling";a.prototype.doOpen=function(){this.poll()};a.prototype.pause=function(a){function b(){f("paused");c.readyState="paused";a()}var c=this;this.readyState="pausing";if(this.polling||!this.writable){var d=0;this.polling&&(f("we are currently polling - waiting to pause"),d++,this.once("pollComplete",function(){f("pre-pause polling complete");--d||b()}));this.writable||(f("we are currently writing - waiting to pause"), d++,this.once("drain",function(){f("pre-pause writing complete");--d||b()}))}else b()};a.prototype.poll=function(){f("polling");this.polling=!0;this.doPoll();this.emit("poll")};a.prototype.onData=function(a){var b=this;f("polling got data %s",a);d.decodePayload(a,this.socket.binaryType,function(a,c,d){if("opening"==b.readyState)b.onOpen();if("close"==a.type)return b.onClose(),!1;b.onPacket(a)});"closed"!=this.readyState&&(this.polling=!1,this.emit("pollComplete"),"open"==this.readyState?this.poll(): f('ignoring poll - transport state "%s"',this.readyState))};a.prototype.doClose=function(){function a(){f("writing close packet");b.write([{type:"close"}])}var b=this;"open"==this.readyState?(f("transport open - closing"),a()):(f("transport not open - deferring close"),this.once("open",a))};a.prototype.write=function(a){var b=this;this.writable=!1;var c=function(){b.writable=!0;b.emit("drain")},b=this;d.encodePayload(a,this.supportsBinary,function(a){b.doWrite(a,c)})};a.prototype.uri=function(){var a= this.query||{},d=this.secure?"https":"http",f="";!1!==this.timestampRequests&&(a[this.timestampParam]=+new Date+"-"+c.timestamps++);this.supportsBinary||a.sid||(a.b64=1);a=b.encode(a);this.port&&("https"==d&&443!=this.port||"http"==d&&80!=this.port)&&(f=":"+this.port);a.length&&(a="?"+a);return d+"://"+this.hostname+f+this.path+a}},{"../transport":15,"component-inherit":22,debug:11,"engine.io-parser":23,parseqs:33,xmlhttprequest:21}],20:[function(e,k,g){function a(a){a&&a.forceBase64&&(this.supportsBinary= !1);c.call(this,a)}var c=e("../transport"),b=e("engine.io-parser"),d=e("parseqs");g=e("component-inherit");var f=e("debug")("engine.io-client:websocket"),s=e("ws");k.exports=a;g(a,c);a.prototype.name="websocket";a.prototype.supportsBinary=!0;a.prototype.doOpen=function(){if(this.check()){var a=this.uri();this.ws=new s(a,void 0,{agent:this.agent});void 0===this.ws.binaryType&&(this.supportsBinary=!1);this.ws.binaryType="arraybuffer";this.addEventListeners()}};a.prototype.addEventListeners=function(){var a= this;this.ws.onopen=function(){a.onOpen()};this.ws.onclose=function(){a.onClose()};this.ws.onmessage=function(b){a.onData(b.data)};this.ws.onerror=function(b){a.onError("websocket error",b)}};"undefined"!=typeof navigator&&/iPad|iPhone|iPod/i.test(navigator.userAgent)&&(a.prototype.onData=function(a){var b=this;setTimeout(function(){c.prototype.onData.call(b,a)},0)});a.prototype.write=function(a){var c=this;this.writable=!1;for(var d=0,e=a.length;d<e;d++)b.encodePacket(a[d],this.supportsBinary,function(a){try{c.ws.send(a)}catch(b){f("websocket closed before onclose event")}}); setTimeout(function(){c.writable=!0;c.emit("drain")},0)};a.prototype.onClose=function(){c.prototype.onClose.call(this)};a.prototype.doClose=function(){"undefined"!==typeof this.ws&&this.ws.close()};a.prototype.uri=function(){var a=this.query||{},b=this.secure?"wss":"ws",c="";this.port&&("wss"==b&&443!=this.port||"ws"==b&&80!=this.port)&&(c=":"+this.port);this.timestampRequests&&(a[this.timestampParam]=+new Date);this.supportsBinary||(a.b64=1);a=d.encode(a);a.length&&(a="?"+a);return b+"://"+this.hostname+ c+this.path+a};a.prototype.check=function(){return!!s&&!("__initialize"in s&&this.name===a.prototype.name)}},{"../transport":15,"component-inherit":22,debug:11,"engine.io-parser":23,parseqs:33,ws:35}],21:[function(e,k,g){var a=e("has-cors");k.exports=function(c){var b=c.xdomain,d=c.xscheme;c=c.enablesXDR;try{if("undefined"!=typeof XMLHttpRequest&&(!b||a))return new XMLHttpRequest}catch(f){}try{if("undefined"!=typeof XDomainRequest&&!d&&c)return new XDomainRequest}catch(e){}if(!b)try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(g){}}}, {"has-cors":30}],22:[function(e,k,g){k.exports=function(a,c){var b=function(){};b.prototype=c.prototype;a.prototype=new b;a.prototype.constructor=a}},{}],23:[function(e,k,g){(function(a){function c(a,b,c){if(!b)return g.encodeBase64Packet(a,c);var d=new FileReader;d.onload=function(){a.data=d.result;g.encodePacket(a,b,!0,c)};return d.readAsArrayBuffer(a.data)}function b(a,b,c){var d=Array(a.length);c=m(a.length,c);for(var f=function(a,c,f){b(c,function(b,c){d[a]=c;f(b,d)})},e=0;e<a.length;e++)f(e, a[e],c)}var d=e("./keys"),f=e("arraybuffer.slice"),s=e("base64-arraybuffer"),m=e("after"),l=e("utf8"),n=navigator.userAgent.match(/Android/i);g.protocol=3;var p=g.packets={open:0,close:1,ping:2,pong:3,message:4,upgrade:5,noop:6},h=d(p),k={type:"error",data:"parser error"},u=e("blob");g.encodePacket=function(b,d,f,e){"function"==typeof d&&(e=d,d=!1);"function"==typeof f&&(e=f,f=null);var h=void 0===b.data?void 0:b.data.buffer||b.data;if(a.ArrayBuffer&&h instanceof ArrayBuffer){if(d){f=b.data;d=new Uint8Array(f); f=new Uint8Array(1+f.byteLength);f[0]=p[b.type];for(b=0;b<d.length;b++)f[b+1]=d[b];b=e(f.buffer)}else b=g.encodeBase64Packet(b,e);return b}if(u&&h instanceof a.Blob)return d?n?b=c(b,d,e):(d=new Uint8Array(1),d[0]=p[b.type],b=new u([d.buffer,b.data]),b=e(b)):b=g.encodeBase64Packet(b,e),b;d=p[b.type];void 0!==b.data&&(d+=f?l.encode(String(b.data)):String(b.data));return e(""+d)};g.encodeBase64Packet=function(b,c){var d="b"+g.packets[b.type];if(u&&b.data instanceof u){var f=new FileReader;f.onload=function(){var a= f.result.split(",")[1];c(d+a)};return f.readAsDataURL(b.data)}var e;try{e=String.fromCharCode.apply(null,new Uint8Array(b.data))}catch(h){e=new Uint8Array(b.data);for(var m=Array(e.length),p=0;p<e.length;p++)m[p]=e[p];e=String.fromCharCode.apply(null,m)}d+=a.btoa(e);return c(d)};g.decodePacket=function(a,b,c){if("string"==typeof a||void 0===a){if("b"==a.charAt(0))return g.decodeBase64Packet(a.substr(1),b);if(c)try{a=l.decode(a)}catch(d){return k}c=a.charAt(0);return Number(c)==c&&h[c]?1<a.length? {type:h[c],data:a.substring(1)}:{type:h[c]}:k}c=(new Uint8Array(a))[0];a=f(a,1);u&&"blob"===b&&(a=new u([a]));return{type:h[c],data:a}};g.decodeBase64Packet=function(b,c){var d=h[b.charAt(0)];if(!a.ArrayBuffer)return{type:d,data:{base64:!0,data:b.substr(1)}};var f=s.decode(b.substr(1));"blob"===c&&u&&(f=new u([f]));return{type:d,data:f}};g.encodePayload=function(a,c,d){"function"==typeof c&&(d=c,c=null);if(c)return u&&!n?g.encodePayloadAsBlob(a,d):g.encodePayloadAsArrayBuffer(a,d);if(!a.length)return d("0:"); b(a,function(a,b){g.encodePacket(a,c,!0,function(a){b(null,a.length+":"+a)})},function(a,b){return d(b.join(""))})};g.decodePayload=function(a,b,c){if("string"!=typeof a)return g.decodePayloadAsBinary(a,b,c);"function"===typeof b&&(c=b,b=null);var d;if(""==a)return c(k,0,1);d="";for(var f,e,h=0,m=a.length;h<m;h++)if(e=a.charAt(h),":"!=e)d+=e;else{if(""==d||d!=(f=Number(d)))return c(k,0,1);e=a.substr(h+1,f);if(d!=e.length)return c(k,0,1);if(e.length){d=g.decodePacket(e,b,!0);if(k.type==d.type&&k.data== d.data)return c(k,0,1);if(!1===c(d,h+f,m))return}h+=f;d=""}if(""!=d)return c(k,0,1)};g.encodePayloadAsArrayBuffer=function(a,c){if(!a.length)return c(new ArrayBuffer(0));b(a,function(a,b){g.encodePacket(a,!0,!0,function(a){return b(null,a)})},function(a,b){var d=b.reduce(function(a,b){var c;c="string"===typeof b?b.length:b.byteLength;return a+c.toString().length+c+2},0),f=new Uint8Array(d),e=0;b.forEach(function(a){var b="string"===typeof a,c=a;if(b){for(var c=new Uint8Array(a.length),d=0;d<a.length;d++)c[d]= a.charCodeAt(d);c=c.buffer}b?f[e++]=0:f[e++]=1;a=c.byteLength.toString();for(d=0;d<a.length;d++)f[e++]=parseInt(a[d]);f[e++]=255;c=new Uint8Array(c);for(d=0;d<c.length;d++)f[e++]=c[d]});return c(f.buffer)})};g.encodePayloadAsBlob=function(a,c){b(a,function(a,b){g.encodePacket(a,!0,!0,function(a){var c=new Uint8Array(1);c[0]=1;if("string"===typeof a){for(var d=new Uint8Array(a.length),f=0;f<a.length;f++)d[f]=a.charCodeAt(f);a=d.buffer;c[0]=0}for(var d=(a instanceof ArrayBuffer?a.byteLength:a.size).toString(), e=new Uint8Array(d.length+1),f=0;f<d.length;f++)e[f]=parseInt(d[f]);e[d.length]=255;u&&(a=new u([c.buffer,e.buffer,a]),b(null,a))})},function(a,b){return c(new u(b))})};g.decodePayloadAsBinary=function(a,b,c){"function"===typeof b&&(c=b,b=null);for(var d=[],e=!1;0<a.byteLength;){for(var h=new Uint8Array(a),m=0===h[0],p="",l=1;255!=h[l];l++){if(310<p.length){e=!0;break}p+=h[l]}if(e)return c(k,0,1);a=f(a,2+p.length);p=parseInt(p);h=f(a,0,p);if(m)try{h=String.fromCharCode.apply(null,new Uint8Array(h))}catch(s){for(m= new Uint8Array(h),h="",l=0;l<m.length;l++)h+=String.fromCharCode(m[l])}d.push(h);a=f(a,p)}var n=d.length;d.forEach(function(a,d){c(g.decodePacket(a,b,!0),d,n)})}}).call(this,"undefined"!==typeof global?global:"undefined"!==typeof self?self:"undefined"!==typeof window?window:{})},{"./keys":24,after:25,"arraybuffer.slice":26,"base64-arraybuffer":27,blob:28,utf8:29}],24:[function(e,k,g){k.exports=Object.keys||function(a){var c=[],b=Object.prototype.hasOwnProperty,d;for(d in a)b.call(a,d)&&c.push(d); return c}},{}],25:[function(e,k,g){function a(){}k.exports=function(c,b,d){function f(a,c){if(0>=f.count)throw Error("after called too many times");--f.count;a?(e=!0,b(a),b=d):0!==f.count||e||b(null,c)}var e=!1;d=d||a;f.count=c;return 0===c?b():f}},{}],26:[function(e,k,g){k.exports=function(a,c,b){var d=a.byteLength;c=c||0;b=b||d;if(a.slice)return a.slice(c,b);0>c&&(c+=d);0>b&&(b+=d);b>d&&(b=d);if(c>=d||c>=b||0===d)return new ArrayBuffer(0);a=new Uint8Array(a);for(var d=new Uint8Array(b-c),f=0;c< b;c++,f++)d[f]=a[c];return d.buffer}},{}],27:[function(e,k,g){(function(a){g.encode=function(c){c=new Uint8Array(c);var b,d=c.length,f="";for(b=0;b<d;b+=3)f+=a[c[b]>>2],f+=a[(c[b]&3)<<4|c[b+1]>>4],f+=a[(c[b+1]&15)<<2|c[b+2]>>6],f+=a[c[b+2]&63];2===d%3?f=f.substring(0,f.length-1)+"=":1===d%3&&(f=f.substring(0,f.length-2)+"==");return f};g.decode=function(c){var b=.75*c.length,d=c.length,f=0,e,m,g,k;"="===c[c.length-1]&&(b--,"="===c[c.length-2]&&b--);for(var p=new ArrayBuffer(b),h=new Uint8Array(p), b=0;b<d;b+=4)e=a.indexOf(c[b]),m=a.indexOf(c[b+1]),g=a.indexOf(c[b+2]),k=a.indexOf(c[b+3]),h[f++]=e<<2|m>>4,h[f++]=(m&15)<<4|g>>2,h[f++]=(g&3)<<6|k&63;return p}})("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")},{}],28:[function(e,k,g){(function(a){function c(a,c){c=c||{};for(var d=new b,f=0;f<a.length;f++)d.append(a[f]);return c.type?d.getBlob(c.type):d.getBlob()}var b=a.BlobBuilder||a.WebKitBlobBuilder||a.MSBlobBuilder||a.MozBlobBuilder,d;try{d=2==(new Blob(["hi"])).size}catch(f){d= !1}var e=b&&b.prototype.append&&b.prototype.getBlob;a=d?a.Blob:e?c:void 0;k.exports=a}).call(this,"undefined"!==typeof global?global:"undefined"!==typeof self?self:"undefined"!==typeof window?window:{})},{}],29:[function(e,k,g){(function(a){(function(c){function b(a){for(var b=[],c=0,d=a.length,f,e;c<d;)f=a.charCodeAt(c++),55296<=f&&56319>=f&&c<d?(e=a.charCodeAt(c++),56320==(e&64512)?b.push(((f&1023)<<10)+(e&1023)+65536):(b.push(f),c--)):b.push(f);return b}function d(){if(t>=h)throw Error("Invalid byte index"); var a=p[t]&255;t++;if(128==(a&192))return a&63;throw Error("Invalid continuation byte");}function f(){var a,b,c,f;if(t>h)throw Error("Invalid byte index");if(t==h)return!1;a=p[t]&255;t++;if(0==(a&128))return a;if(192==(a&224)){b=d();a=(a&31)<<6|b;if(128<=a)return a;throw Error("Invalid continuation byte");}if(224==(a&240)){b=d();c=d();a=(a&15)<<12|b<<6|c;if(2048<=a)return a;throw Error("Invalid continuation byte");}if(240==(a&248)&&(b=d(),c=d(),f=d(),a=(a&15)<<18|b<<12|c<<6|f,65536<=a&&1114111>=a))return a; throw Error("Invalid UTF-8 detected");}var e="object"==typeof g&&g,m="object"==typeof k&&k&&k.exports==e&&k,l="object"==typeof a&&a;if(l.global===l||l.window===l)c=l;var n=String.fromCharCode,p,h,t,l={version:"2.0.0",encode:function(a){a=b(a);for(var c=a.length,d=-1,f,e="";++d<c;){f=a[d];if(0==(f&4294967168))f=n(f);else{var h="";0==(f&4294965248)?h=n(f>>6&31|192):0==(f&4294901760)?(h=n(f>>12&15|224),h+=n(f>>6&63|128)):0==(f&4292870144)&&(h=n(f>>18&7|240),h+=n(f>>12&63|128),h+=n(f>>6&63|128));f=h+= n(f&63|128)}e+=f}return e},decode:function(a){p=b(a);h=p.length;t=0;a=[];for(var c;!1!==(c=f());)a.push(c);c=a.length;for(var d=-1,e,g="";++d<c;)e=a[d],65535<e&&(e-=65536,g+=n(e>>>10&1023|55296),e=56320|e&1023),g+=n(e);return g}};if(e&&!e.nodeType)if(m)m.exports=l;else{c={}.hasOwnProperty;for(var u in l)c.call(l,u)&&(e[u]=l[u])}else c.utf8=l})(this)}).call(this,"undefined"!==typeof global?global:"undefined"!==typeof self?self:"undefined"!==typeof window?window:{})