UNPKG

socket-signaler-client

Version:

Client for SocketIO WebRTC streaming webcam chatrooms

102 lines (58 loc) 82.7 kB
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ !function(e,t){"use strict";"function"==typeof define&&define.amd?define(["https://cdnjs.cloudflare.com/ajax/libs/EventEmitter/4.2.11/EventEmitter.min.js","https://cdn.socket.io/socket.io-1.3.3.js"],function(e,n){return t(window,e,n)}):"object"==typeof exports?module.exports=t(window,require("wolfy87-eventemitter"),require("socket.io-client")):e.PeerConnectionClient=t(window,e.EventEmitter,e.io)}(this,function(e,t,n){"use strict";function i(t){this.peerConnections=[],this.constraints=navigator.mozGetUserMedia?{offerToReceiveAudio:!0,offerToReceiveVideo:!0}:{mandatory:{OfferToReceiveAudio:!0,OfferToReceiveVideo:!0}},this.iceServers={iceServers:[{url:"stun:stun.services.mozilla.com"},{url:"stun:stun.l.google.com:19302"}]},this.setupRTCObjects=function(){this.PeerConnection=e.RTCPeerConnection||e.mozRTCPeerConnection||e.webkitRTCPeerConnection,this.SessionDescription=e.RTCSessionDescription||e.mozRTCSessionDescription||e.webkitRTCSessionDescription,navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia,this.RTCIceCandidate=e.RTCIceCandidate||e.mozRTCIceCandidate},this.generateDefaults=function(t){return t=t||{},t.server=t.server||"http://"+e.location.host+"/",t.room=t.room||"default",t.debug=t.debug||!1,t},this.bindEvents=function(){this.socket.on("initialized",this.getPeerList.bind(this)),this.socket.on("list",this.generateConnections.bind(this)),this.socket.on("offer",this.createAnswer.bind(this)),this.socket.on("answer",this.handleAnswer.bind(this)),this.socket.on("icecandidate",this.receiveIceCandidate.bind(this)),this.socket.on("newconnection",this.addPeer.bind(this)),this.socket.on("disconnect",this.disconnectConnection.bind(this)),this.socket.on("peerconnected",this.peerConnected.bind(this)),this.socket.on("streamremoved",this.removeRemoteStream.bind(this))},this.getPeerList=function(){this.socket.emit("list")},this.generateConnections=function(e){t.debug&&console.log("Received list, creating connection(s) for "+e.length+" peers"),e.forEach(this.addPeer.bind(this))},this.addPeer=function(e,t){if(!this.hasPeer(e)){console.log("Adding peer: "+e);var n={connection:new this.PeerConnection(this.iceServers),id:e};return n=this.bindConnectionEvents(n,t),this.peerConnections.push(n),this.localStream&&this.addStreamToPeer(this.localStream,n),n}},this.bindConnectionEvents=function(e,n){return t.debug&&console.log("Binding connection events for peer: "+e.id),e.connection.onicecandidate=function(n){t.debug&&"verbose"===t.debug&&console.log("Sending ICE candidate to "+e.id),t.debug&&"verbose"===t.debug&&console.log("Full event ",n),t.debug&&"verbose"===t.debug&&console.log("Stringified event ",JSON.stringify(n)),console.log(Object.keys(n)),n.candidate&&this.socket.emit("icecandidate",{target:e.id,candidate:n.candidate})}.bind(this),e.connection.onaddstream=function(i){t.debug&&console.log("Remote stream added from "+e.id),n?t.debug&&console.log("onaddstream event suppressed"):this.emit("remoteStreamAdded",i.stream,e.id)}.bind(this),e.connection.ondatachannel=function(n){t.debug&&console.log("Data channel added from "+e.id),this.emit("dataChannelAdded",n.channel,e.id)}.bind(this),e.connection.oniceconnectionstatechange=function(){switch(e.connection.iceConnectionState){case"disconnected":case"failed":this.logError("iceConnectionState is disconnected, closing connections to "+e.id),e.connection.close();break;case"completed":e.connection.onicecandidate=function(){}}}.bind(this),e},this.createOffer=function(e){t.debug&&console.log("Creating offer for: "+e.id),e.connection.createOffer(function(t){e.connection.setLocalDescription(new this.SessionDescription(t),this.sendOffer({target:e.id,offer:t}),this.logError)}.bind(this),this.logError,this.constraints)},this.sendOffer=function(e){t.debug&&console.log("Sending offer to "+e.target),this.socket.emit("offer",e)},this.createAnswer=function(e){var n=this.getPeer(e.sender),i=e.offer;t.debug&&console.log("Creating answer for "+n.id),n.connection.setRemoteDescription(new this.SessionDescription(i),function(){n.connection.createAnswer(function(e){n.connection.setLocalDescription(new this.SessionDescription(e),this.sendAnswer({target:n.id,answer:e}),this.logError)}.bind(this),this.logError,this.constraints)}.bind(this),this.logError)},this.sendAnswer=function(e){t.debug&&console.log("Sent answer to peer: "+e.target),this.socket.emit("answer",e)},this.handleAnswer=function(e){var n=this.getPeer(e.sender),i=e.answer;t.debug&&console.log("Handling answer from: "+n.id),n.connection.setRemoteDescription(new this.SessionDescription(i),function(){this.peerConnected(n.id),this.socket.emit("peerconnected",n.id)}.bind(this),this.logError)},this.peerConnected=function(e){this.emit("peerconnected",e),t.debug&&console.log("Signaling with peer: "+e)},this.disconnectConnection=function(e){var n=this.getPeer(e);n.connection.close(),this.emit("peerDisconnected",e),this.emit("remoteStreamRemoved",e),t.debug&&console.log("Disconnected with peer: "+e),this.peerConnections.forEach(function(t,n,i){t.id===e&&i.splice(n,1)})},this.getPeer=function(e){var t;return this.peerConnections.forEach(function(n){n.id===e&&(t=n)}),t||(t=this.addPeer(e)),t},this.hasPeer=function(e){var t=!1;return this.peerConnections.forEach(function(n){n.id===e&&(t=!0)}),t},this.logError=function(e){console.error(t.debug?e:"There was an error with the signaller")},this.addStream=function(e){this.peerConnections.forEach(function(t){this.addStreamToPeer(e,t)}.bind(this))},this.addStreamToPeer=function(e,n){t.debug&&console.log("Stream added to "+n.id),n.connection.addStream(e),this.createOffer(n)},this.addLocalStream=function(e){e=e||{},navigator.getUserMedia({audio:e.audio||!0,video:e.video||!0},function(e){this.localStream=e,this.addStream(e),this.emit("localStreamAdded",e),t.debug&&console.log("Local stream added")}.bind(this),this.logError)},this.removeLocalStream=function(){this.localStream.stop(),this.localStream=void 0,this.peerConnections.forEach(function(e){t.debug&&console.log("Local stream removed from "+e.id),this.socket.emit("streamremoved",e.id),this.regenStream(e,!0)}.bind(this)),this.emit("localStreamRemoved")},this.removeRemoteStream=function(e){this.emit("remoteStreamRemoved",e),t.debug&&console.log("Removing stream from: "+e),this.regenStream(this.getPeer(e))},this.regenStream=function(e,n){t.debug&&console.log("Regenerating PeerConnection for "+e.id),n=n&&e.connection.getRemoteStreams().length,e.connection=new this.PeerConnection(this.iceServers),this.bindConnectionEvents(e,n),this.localStream&&this.addStreamToPeer(this.localStream,e)},this.receiveIceCandidate=function(e){if(t.debug&&"verbose"===t.debug&&console.log("Received candidate",e.candidate),e.candidate.candidate){var n=this.getPeer(e.sender),i=e.candidate.candidate,o=e.candidate.sdpMLineIndex;t.debug&&"verbose"===t.debug&&console.log("Added ICE candidate from "+n.id),n.connection.addIceCandidate(new this.RTCIceCandidate({candidate:i,sdpMLineIndex:o}))}},this.setupRTCObjects(),t=this.generateDefaults(t),this.socket=n(t.server+t.room),this.bindEvents()}return i.prototype=new t,i}); },{"socket.io-client":2,"wolfy87-eventemitter":52}],2:[function(require,module,exports){ module.exports=require("./lib/"); },{"./lib/":3}],3:[function(require,module,exports){ function lookup(e,r){"object"==typeof e&&(r=e,e=void 0),r=r||{};var o,c=url(e),a=c.source,t=c.id;return r.forceNew||r["force new connection"]||!1===r.multiplex?(debug("ignoring socket cache for %s",a),o=Manager(a,r)):(cache[t]||(debug("new io instance for %s",a),cache[t]=Manager(a,r)),o=cache[t]),o.socket(c.path)}var url=require("./url"),parser=require("socket.io-parser"),Manager=require("./manager"),debug=require("debug")("socket.io-client");module.exports=exports=lookup;var cache=exports.managers={};exports.protocol=parser.protocol,exports.connect=lookup,exports.Manager=require("./manager"),exports.Socket=require("./socket"); },{"./manager":4,"./socket":6,"./url":7,"debug":11,"socket.io-parser":47}],4:[function(require,module,exports){ function Manager(e,t){return this instanceof Manager?(e&&"object"==typeof e&&(t=e,e=void 0),t=t||{},t.path=t.path||"/socket.io",this.nsps={},this.subs=[],this.opts=t,this.reconnection(t.reconnection!==!1),this.reconnectionAttempts(t.reconnectionAttempts||1/0),this.reconnectionDelay(t.reconnectionDelay||1e3),this.reconnectionDelayMax(t.reconnectionDelayMax||5e3),this.randomizationFactor(t.randomizationFactor||.5),this.backoff=new Backoff({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(null==t.timeout?2e4:t.timeout),this.readyState="closed",this.uri=e,this.connected=[],this.encoding=!1,this.packetBuffer=[],this.encoder=new parser.Encoder,this.decoder=new parser.Decoder,this.autoConnect=t.autoConnect!==!1,void(this.autoConnect&&this.open())):new Manager(e,t)}var url=require("./url"),eio=require("engine.io-client"),Socket=require("./socket"),Emitter=require("component-emitter"),parser=require("socket.io-parser"),on=require("./on"),bind=require("component-bind"),object=require("object-component"),debug=require("debug")("socket.io-client:manager"),indexOf=require("indexof"),Backoff=require("backo2");module.exports=Manager,Manager.prototype.emitAll=function(){this.emit.apply(this,arguments);for(var e in this.nsps)this.nsps[e].emit.apply(this.nsps[e],arguments)},Manager.prototype.updateSocketIds=function(){for(var e in this.nsps)this.nsps[e].id=this.engine.id},Emitter(Manager.prototype),Manager.prototype.reconnection=function(e){return arguments.length?(this._reconnection=!!e,this):this._reconnection},Manager.prototype.reconnectionAttempts=function(e){return arguments.length?(this._reconnectionAttempts=e,this):this._reconnectionAttempts},Manager.prototype.reconnectionDelay=function(e){return arguments.length?(this._reconnectionDelay=e,this.backoff&&this.backoff.setMin(e),this):this._reconnectionDelay},Manager.prototype.randomizationFactor=function(e){return arguments.length?(this._randomizationFactor=e,this.backoff&&this.backoff.setJitter(e),this):this._randomizationFactor},Manager.prototype.reconnectionDelayMax=function(e){return arguments.length?(this._reconnectionDelayMax=e,this.backoff&&this.backoff.setMax(e),this):this._reconnectionDelayMax},Manager.prototype.timeout=function(e){return arguments.length?(this._timeout=e,this):this._timeout},Manager.prototype.maybeReconnectOnOpen=function(){!this.reconnecting&&this._reconnection&&0===this.backoff.attempts&&this.reconnect()},Manager.prototype.open=Manager.prototype.connect=function(e){if(debug("readyState %s",this.readyState),~this.readyState.indexOf("open"))return this;debug("opening %s",this.uri),this.engine=eio(this.uri,this.opts);var t=this.engine,n=this;this.readyState="opening",this.skipReconnect=!1;var o=on(t,"open",function(){n.onopen(),e&&e()}),i=on(t,"error",function(t){if(debug("connect_error"),n.cleanup(),n.readyState="closed",n.emitAll("connect_error",t),e){var o=new Error("Connection error");o.data=t,e(o)}else n.maybeReconnectOnOpen()});if(!1!==this._timeout){var r=this._timeout;debug("connect attempt will timeout after %d",r);var c=setTimeout(function(){debug("connect attempt timed out after %d",r),o.destroy(),t.close(),t.emit("error","timeout"),n.emitAll("connect_timeout",r)},r);this.subs.push({destroy:function(){clearTimeout(c)}})}return this.subs.push(o),this.subs.push(i),this},Manager.prototype.onopen=function(){debug("open"),this.cleanup(),this.readyState="open",this.emit("open");var e=this.engine;this.subs.push(on(e,"data",bind(this,"ondata"))),this.subs.push(on(this.decoder,"decoded",bind(this,"ondecoded"))),this.subs.push(on(e,"error",bind(this,"onerror"))),this.subs.push(on(e,"close",bind(this,"onclose")))},Manager.prototype.ondata=function(e){this.decoder.add(e)},Manager.prototype.ondecoded=function(e){this.emit("packet",e)},Manager.prototype.onerror=function(e){debug("error",e),this.emitAll("error",e)},Manager.prototype.socket=function(e){var t=this.nsps[e];if(!t){t=new Socket(this,e),this.nsps[e]=t;var n=this;t.on("connect",function(){t.id=n.engine.id,~indexOf(n.connected,t)||n.connected.push(t)})}return t},Manager.prototype.destroy=function(e){var t=indexOf(this.connected,e);~t&&this.connected.splice(t,1),this.connected.length||this.close()},Manager.prototype.packet=function(e){debug("writing packet %j",e);var t=this;t.encoding?t.packetBuffer.push(e):(t.encoding=!0,this.encoder.encode(e,function(e){for(var n=0;n<e.length;n++)t.engine.write(e[n]);t.encoding=!1,t.processPacketQueue()}))},Manager.prototype.processPacketQueue=function(){if(this.packetBuffer.length>0&&!this.encoding){var e=this.packetBuffer.shift();this.packet(e)}},Manager.prototype.cleanup=function(){for(var e;e=this.subs.shift();)e.destroy();this.packetBuffer=[],this.encoding=!1,this.decoder.destroy()},Manager.prototype.close=Manager.prototype.disconnect=function(){this.skipReconnect=!0,this.backoff.reset(),this.readyState="closed",this.engine&&this.engine.close()},Manager.prototype.onclose=function(e){debug("close"),this.cleanup(),this.backoff.reset(),this.readyState="closed",this.emit("close",e),this._reconnection&&!this.skipReconnect&&this.reconnect()},Manager.prototype.reconnect=function(){if(this.reconnecting||this.skipReconnect)return this;var e=this;if(this.backoff.attempts>=this._reconnectionAttempts)debug("reconnect failed"),this.backoff.reset(),this.emitAll("reconnect_failed"),this.reconnecting=!1;else{var t=this.backoff.duration();debug("will wait %dms before reconnect attempt",t),this.reconnecting=!0;var n=setTimeout(function(){e.skipReconnect||(debug("attempting reconnect"),e.emitAll("reconnect_attempt",e.backoff.attempts),e.emitAll("reconnecting",e.backoff.attempts),e.skipReconnect||e.open(function(t){t?(debug("reconnect attempt error"),e.reconnecting=!1,e.reconnect(),e.emitAll("reconnect_error",t.data)):(debug("reconnect success"),e.onreconnect())}))},t);this.subs.push({destroy:function(){clearTimeout(n)}})}},Manager.prototype.onreconnect=function(){var e=this.backoff.attempts;this.reconnecting=!1,this.backoff.reset(),this.updateSocketIds(),this.emitAll("reconnect",e)}; },{"./on":5,"./socket":6,"./url":7,"backo2":8,"component-bind":9,"component-emitter":10,"debug":11,"engine.io-client":12,"indexof":43,"object-component":44,"socket.io-parser":47}],5:[function(require,module,exports){ function on(n,o,e){return n.on(o,e),{destroy:function(){n.removeListener(o,e)}}}module.exports=on; },{}],6:[function(require,module,exports){ function Socket(t,e){this.io=t,this.nsp=e,this.json=this,this.ids=0,this.acks={},this.io.autoConnect&&this.open(),this.receiveBuffer=[],this.sendBuffer=[],this.connected=!1,this.disconnected=!0}var parser=require("socket.io-parser"),Emitter=require("component-emitter"),toArray=require("to-array"),on=require("./on"),bind=require("component-bind"),debug=require("debug")("socket.io-client:socket"),hasBin=require("has-binary");module.exports=exports=Socket;var events={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},emit=Emitter.prototype.emit;Emitter(Socket.prototype),Socket.prototype.subEvents=function(){if(!this.subs){var t=this.io;this.subs=[on(t,"open",bind(this,"onopen")),on(t,"packet",bind(this,"onpacket")),on(t,"close",bind(this,"onclose"))]}},Socket.prototype.open=Socket.prototype.connect=function(){return this.connected?this:(this.subEvents(),this.io.open(),"open"==this.io.readyState&&this.onopen(),this)},Socket.prototype.send=function(){var t=toArray(arguments);return t.unshift("message"),this.emit.apply(this,t),this},Socket.prototype.emit=function(t){if(events.hasOwnProperty(t))return emit.apply(this,arguments),this;var e=toArray(arguments),s=parser.EVENT;hasBin(e)&&(s=parser.BINARY_EVENT);var i={type:s,data:e};return"function"==typeof e[e.length-1]&&(debug("emitting packet with ack id %d",this.ids),this.acks[this.ids]=e.pop(),i.id=this.ids++),this.connected?this.packet(i):this.sendBuffer.push(i),this},Socket.prototype.packet=function(t){t.nsp=this.nsp,this.io.packet(t)},Socket.prototype.onopen=function(){debug("transport is open - connecting"),"/"!=this.nsp&&this.packet({type:parser.CONNECT})},Socket.prototype.onclose=function(t){debug("close (%s)",t),this.connected=!1,this.disconnected=!0,delete this.id,this.emit("disconnect",t)},Socket.prototype.onpacket=function(t){if(t.nsp==this.nsp)switch(t.type){case parser.CONNECT:this.onconnect();break;case parser.EVENT:this.onevent(t);break;case parser.BINARY_EVENT:this.onevent(t);break;case parser.ACK:this.onack(t);break;case parser.BINARY_ACK:this.onack(t);break;case parser.DISCONNECT:this.ondisconnect();break;case parser.ERROR:this.emit("error",t.data)}},Socket.prototype.onevent=function(t){var e=t.data||[];debug("emitting event %j",e),null!=t.id&&(debug("attaching ack callback to event"),e.push(this.ack(t.id))),this.connected?emit.apply(this,e):this.receiveBuffer.push(e)},Socket.prototype.ack=function(t){var e=this,s=!1;return function(){if(!s){s=!0;var i=toArray(arguments);debug("sending ack %j",i);var n=hasBin(i)?parser.BINARY_ACK:parser.ACK;e.packet({type:n,id:t,data:i})}}},Socket.prototype.onack=function(t){debug("calling ack %s with %j",t.id,t.data);var e=this.acks[t.id];e.apply(this,t.data),delete this.acks[t.id]},Socket.prototype.onconnect=function(){this.connected=!0,this.disconnected=!1,this.emit("connect"),this.emitBuffered()},Socket.prototype.emitBuffered=function(){var t;for(t=0;t<this.receiveBuffer.length;t++)emit.apply(this,this.receiveBuffer[t]);for(this.receiveBuffer=[],t=0;t<this.sendBuffer.length;t++)this.packet(this.sendBuffer[t]);this.sendBuffer=[]},Socket.prototype.ondisconnect=function(){debug("server disconnect (%s)",this.nsp),this.destroy(),this.onclose("io server disconnect")},Socket.prototype.destroy=function(){if(this.subs){for(var t=0;t<this.subs.length;t++)this.subs[t].destroy();this.subs=null}this.io.destroy(this)},Socket.prototype.close=Socket.prototype.disconnect=function(){return this.connected&&(debug("performing disconnect (%s)",this.nsp),this.packet({type:parser.DISCONNECT})),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}; },{"./on":5,"component-bind":9,"component-emitter":10,"debug":11,"has-binary":41,"socket.io-parser":47,"to-array":51}],7:[function(require,module,exports){ (function (global){ function url(t,o){var r=t,o=o||global.location;return null==t&&(t=o.protocol+"//"+o.host),"string"==typeof t&&("/"==t.charAt(0)&&(t="/"==t.charAt(1)?o.protocol+t:o.hostname+t),/^(https?|wss?):\/\//.test(t)||(debug("protocol-less url %s",t),t="undefined"!=typeof o?o.protocol+"//"+t:"https://"+t),debug("parse %s",t),r=parseuri(t)),r.port||(/^(http|ws)$/.test(r.protocol)?r.port="80":/^(http|ws)s$/.test(r.protocol)&&(r.port="443")),r.path=r.path||"/",r.id=r.protocol+"://"+r.host+":"+r.port,r.href=r.protocol+"://"+r.host+(o&&o.port==r.port?"":":"+r.port),r}var parseuri=require("parseuri"),debug=require("debug")("socket.io-client:url");module.exports=url; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{"debug":11,"parseuri":45}],8:[function(require,module,exports){ function Backoff(t){t=t||{},this.ms=t.min||100,this.max=t.max||1e4,this.factor=t.factor||2,this.jitter=t.jitter>0&&t.jitter<=1?t.jitter:0,this.attempts=0}module.exports=Backoff,Backoff.prototype.duration=function(){var t=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var o=Math.random(),i=Math.floor(o*this.jitter*t);t=0==(1&Math.floor(10*o))?t-i:t+i}return 0|Math.min(t,this.max)},Backoff.prototype.reset=function(){this.attempts=0},Backoff.prototype.setMin=function(t){this.ms=t},Backoff.prototype.setMax=function(t){this.max=t},Backoff.prototype.setJitter=function(t){this.jitter=t}; },{}],9:[function(require,module,exports){ var slice=[].slice;module.exports=function(n,r){if("string"==typeof r&&(r=n[r]),"function"!=typeof r)throw new Error("bind() requires a function");var e=slice.call(arguments,2);return function(){return r.apply(n,e.concat(slice.call(arguments)))}}; },{}],10:[function(require,module,exports){ function Emitter(t){return t?mixin(t):void 0}function mixin(t){for(var e in Emitter.prototype)t[e]=Emitter.prototype[e];return t}module.exports=Emitter,Emitter.prototype.on=Emitter.prototype.addEventListener=function(t,e){return this._callbacks=this._callbacks||{},(this._callbacks[t]=this._callbacks[t]||[]).push(e),this},Emitter.prototype.once=function(t,e){function i(){r.off(t,i),e.apply(this,arguments)}var r=this;return this._callbacks=this._callbacks||{},i.fn=e,this.on(t,i),this},Emitter.prototype.off=Emitter.prototype.removeListener=Emitter.prototype.removeAllListeners=Emitter.prototype.removeEventListener=function(t,e){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var i=this._callbacks[t];if(!i)return this;if(1==arguments.length)return delete this._callbacks[t],this;for(var r,s=0;s<i.length;s++)if(r=i[s],r===e||r.fn===e){i.splice(s,1);break}return this},Emitter.prototype.emit=function(t){this._callbacks=this._callbacks||{};var e=[].slice.call(arguments,1),i=this._callbacks[t];if(i){i=i.slice(0);for(var r=0,s=i.length;s>r;++r)i[r].apply(this,e)}return this},Emitter.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks[t]||[]},Emitter.prototype.hasListeners=function(t){return!!this.listeners(t).length}; },{}],11:[function(require,module,exports){ function debug(e){return debug.enabled(e)?function(n){n=coerce(n);var u=new Date,o=u-(debug[e]||u);debug[e]=u,n=e+" "+n+" +"+debug.humanize(o),window.console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}:function(){}}function coerce(e){return e instanceof Error?e.stack||e.message:e}module.exports=debug,debug.names=[],debug.skips=[],debug.enable=function(e){try{localStorage.debug=e}catch(n){}for(var u=(e||"").split(/[\s,]+/),o=u.length,t=0;o>t;t++)e=u[t].replace("*",".*?"),"-"===e[0]?debug.skips.push(new RegExp("^"+e.substr(1)+"$")):debug.names.push(new RegExp("^"+e+"$"))},debug.disable=function(){debug.enable("")},debug.humanize=function(e){var n=1e3,u=6e4,o=60*u;return e>=o?(e/o).toFixed(1)+"h":e>=u?(e/u).toFixed(1)+"m":e>=n?(e/n|0)+"s":e+"ms"},debug.enabled=function(e){for(var n=0,u=debug.skips.length;u>n;n++)if(debug.skips[n].test(e))return!1;for(var n=0,u=debug.names.length;u>n;n++)if(debug.names[n].test(e))return!0;return!1};try{window.localStorage&&debug.enable(localStorage.debug)}catch(e){} },{}],12:[function(require,module,exports){ module.exports=require("./lib/"); },{"./lib/":13}],13:[function(require,module,exports){ module.exports=require("./socket"),module.exports.parser=require("engine.io-parser"); },{"./socket":14,"engine.io-parser":26}],14:[function(require,module,exports){ (function (global){ function noop(){}function Socket(e,t){if(!(this instanceof Socket))return new Socket(e,t);if(t=t||{},e&&"object"==typeof e&&(t=e,e=null),e&&(e=parseuri(e),t.host=e.host,t.secure="https"==e.protocol||"wss"==e.protocol,t.port=e.port,e.query&&(t.query=e.query)),this.secure=null!=t.secure?t.secure:global.location&&"https:"==location.protocol,t.host){var r=t.host.split(":");t.hostname=r.shift(),r.length?t.port=r.pop():t.port||(t.port=this.secure?"443":"80")}this.agent=t.agent||!1,this.hostname=t.hostname||(global.location?location.hostname:"localhost"),this.port=t.port||(global.location&&location.port?location.port:this.secure?443:80),this.query=t.query||{},"string"==typeof this.query&&(this.query=parseqs.decode(this.query)),this.upgrade=!1!==t.upgrade,this.path=(t.path||"/engine.io").replace(/\/$/,"")+"/",this.forceJSONP=!!t.forceJSONP,this.jsonp=!1!==t.jsonp,this.forceBase64=!!t.forceBase64,this.enablesXDR=!!t.enablesXDR,this.timestampParam=t.timestampParam||"t",this.timestampRequests=t.timestampRequests,this.transports=t.transports||["polling","websocket"],this.readyState="",this.writeBuffer=[],this.callbackBuffer=[],this.policyPort=t.policyPort||843,this.rememberUpgrade=t.rememberUpgrade||!1,this.binaryType=null,this.onlyBinaryUpgrades=t.onlyBinaryUpgrades,this.pfx=t.pfx||null,this.key=t.key||null,this.passphrase=t.passphrase||null,this.cert=t.cert||null,this.ca=t.ca||null,this.ciphers=t.ciphers||null,this.rejectUnauthorized=t.rejectUnauthorized||null,this.open()}function clone(e){var t={};for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r]);return t}var transports=require("./transports"),Emitter=require("component-emitter"),debug=require("debug")("engine.io-client:socket"),index=require("indexof"),parser=require("engine.io-parser"),parseuri=require("parseuri"),parsejson=require("parsejson"),parseqs=require("parseqs");module.exports=Socket,Socket.priorWebsocketSuccess=!1,Emitter(Socket.prototype),Socket.protocol=parser.protocol,Socket.Socket=Socket,Socket.Transport=require("./transport"),Socket.transports=require("./transports"),Socket.parser=require("engine.io-parser"),Socket.prototype.createTransport=function(e){debug('creating transport "%s"',e);var t=clone(this.query);t.EIO=parser.protocol,t.transport=e,this.id&&(t.sid=this.id);var r=new transports[e]({agent:this.agent,hostname:this.hostname,port:this.port,secure:this.secure,path:this.path,query:t,forceJSONP:this.forceJSONP,jsonp:this.jsonp,forceBase64:this.forceBase64,enablesXDR:this.enablesXDR,timestampRequests:this.timestampRequests,timestampParam:this.timestampParam,policyPort:this.policyPort,socket:this,pfx:this.pfx,key:this.key,passphrase:this.passphrase,cert:this.cert,ca:this.ca,ciphers:this.ciphers,rejectUnauthorized:this.rejectUnauthorized});return r},Socket.prototype.open=function(){var e;if(this.rememberUpgrade&&Socket.priorWebsocketSuccess&&-1!=this.transports.indexOf("websocket"))e="websocket";else{if(0==this.transports.length){var t=this;return void setTimeout(function(){t.emit("error","No transports available")},0)}e=this.transports[0]}this.readyState="opening";var e;try{e=this.createTransport(e)}catch(r){return this.transports.shift(),void this.open()}e.open(),this.setTransport(e)},Socket.prototype.setTransport=function(e){debug("setting transport %s",e.name);var t=this;this.transport&&(debug("clearing existing transport %s",this.transport.name),this.transport.removeAllListeners()),this.transport=e,e.on("drain",function(){t.onDrain()}).on("packet",function(e){t.onPacket(e)}).on("error",function(e){t.onError(e)}).on("close",function(){t.onClose("transport close")})},Socket.prototype.probe=function(e){function t(){if(h.onlyBinaryUpgrades){var t=!this.supportsBinary&&h.transport.supportsBinary;c=c||t}c||(debug('probe transport "%s" opened',e),p.send([{type:"ping",data:"probe"}]),p.once("packet",function(t){if(!c)if("pong"==t.type&&"probe"==t.data){if(debug('probe transport "%s" pong',e),h.upgrading=!0,h.emit("upgrading",p),!p)return;Socket.priorWebsocketSuccess="websocket"==p.name,debug('pausing current transport "%s"',h.transport.name),h.transport.pause(function(){c||"closed"!=h.readyState&&(debug("changing transport and sending upgrade packet"),a(),h.setTransport(p),p.send([{type:"upgrade"}]),h.emit("upgrade",p),p=null,h.upgrading=!1,h.flush())})}else{debug('probe transport "%s" failed',e);var r=new Error("probe error");r.transport=p.name,h.emit("upgradeError",r)}}))}function r(){c||(c=!0,a(),p.close(),p=null)}function s(t){var s=new Error("probe error: "+t);s.transport=p.name,r(),debug('probe transport "%s" failed because of error: %s',e,t),h.emit("upgradeError",s)}function o(){s("transport closed")}function i(){s("socket closed")}function n(e){p&&e.name!=p.name&&(debug('"%s" works - aborting "%s"',e.name,p.name),r())}function a(){p.removeListener("open",t),p.removeListener("error",s),p.removeListener("close",o),h.removeListener("close",i),h.removeListener("upgrading",n)}debug('probing transport "%s"',e);var p=this.createTransport(e,{probe:1}),c=!1,h=this;Socket.priorWebsocketSuccess=!1,p.once("open",t),p.once("error",s),p.once("close",o),this.once("close",i),this.once("upgrading",n),p.open()},Socket.prototype.onOpen=function(){if(debug("socket open"),this.readyState="open",Socket.priorWebsocketSuccess="websocket"==this.transport.name,this.emit("open"),this.flush(),"open"==this.readyState&&this.upgrade&&this.transport.pause){debug("starting upgrade probes");for(var e=0,t=this.upgrades.length;t>e;e++)this.probe(this.upgrades[e])}},Socket.prototype.onPacket=function(e){if("opening"==this.readyState||"open"==this.readyState)switch(debug('socket receive: type "%s", data "%s"',e.type,e.data),this.emit("packet",e),this.emit("heartbeat"),e.type){case"open":this.onHandshake(parsejson(e.data));break;case"pong":this.setPing();break;case"error":var t=new Error("server error");t.code=e.data,this.emit("error",t);break;case"message":this.emit("data",e.data),this.emit("message",e.data)}else debug('packet received with socket readyState "%s"',this.readyState)},Socket.prototype.onHandshake=function(e){this.emit("handshake",e),this.id=e.sid,this.transport.query.sid=e.sid,this.upgrades=this.filterUpgrades(e.upgrades),this.pingInterval=e.pingInterval,this.pingTimeout=e.pingTimeout,this.onOpen(),"closed"!=this.readyState&&(this.setPing(),this.removeListener("heartbeat",this.onHeartbeat),this.on("heartbeat",this.onHeartbeat))},Socket.prototype.onHeartbeat=function(e){clearTimeout(this.pingTimeoutTimer);var t=this;t.pingTimeoutTimer=setTimeout(function(){"closed"!=t.readyState&&t.onClose("ping timeout")},e||t.pingInterval+t.pingTimeout)},Socket.prototype.setPing=function(){var e=this;clearTimeout(e.pingIntervalTimer),e.pingIntervalTimer=setTimeout(function(){debug("writing ping packet - expecting pong within %sms",e.pingTimeout),e.ping(),e.onHeartbeat(e.pingTimeout)},e.pingInterval)},Socket.prototype.ping=function(){this.sendPacket("ping")},Socket.prototype.onDrain=function(){for(var e=0;e<this.prevBufferLen;e++)this.callbackBuffer[e]&&this.callbackBuffer[e]();this.writeBuffer.splice(0,this.prevBufferLen),this.callbackBuffer.splice(0,this.prevBufferLen),this.prevBufferLen=0,0==this.writeBuffer.length?this.emit("drain"):this.flush()},Socket.prototype.flush=function(){"closed"!=this.readyState&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length&&(debug("flushing %d packets in socket",this.writeBuffer.length),this.transport.send(this.writeBuffer),this.prevBufferLen=this.writeBuffer.length,this.emit("flush"))},Socket.prototype.write=Socket.prototype.send=function(e,t){return this.sendPacket("message",e,t),this},Socket.prototype.sendPacket=function(e,t,r){if("closing"!=this.readyState&&"closed"!=this.readyState){var s={type:e,data:t};this.emit("packetCreate",s),this.writeBuffer.push(s),this.callbackBuffer.push(r),this.flush()}},Socket.prototype.close=function(){function e(){s.onClose("forced close"),debug("socket closing - telling transport to close"),s.transport.close()}function t(){s.removeListener("upgrade",t),s.removeListener("upgradeError",t),e()}function r(){s.once("upgrade",t),s.once("upgradeError",t)}if("opening"==this.readyState||"open"==this.readyState){this.readyState="closing";var s=this;this.writeBuffer.length?this.once("drain",function(){this.upgrading?r():e()}):this.upgrading?r():e()}return this},Socket.prototype.onError=function(e){debug("socket error %j",e),Socket.priorWebsocketSuccess=!1,this.emit("error",e),this.onClose("transport error",e)},Socket.prototype.onClose=function(e,t){if("opening"==this.readyState||"open"==this.readyState||"closing"==this.readyState){debug('socket close with reason: "%s"',e);var r=this;clearTimeout(this.pingIntervalTimer),clearTimeout(this.pingTimeoutTimer),setTimeout(function(){r.writeBuffer=[],r.callbackBuffer=[],r.prevBufferLen=0},0),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),this.readyState="closed",this.id=null,this.emit("close",e,t)}},Socket.prototype.filterUpgrades=function(e){for(var t=[],r=0,s=e.length;s>r;r++)~index(this.transports,e[r])&&t.push(e[r]);return t}; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{"./transport":15,"./transports":16,"component-emitter":10,"debug":23,"engine.io-parser":26,"indexof":43,"parsejson":37,"parseqs":38,"parseuri":39}],15:[function(require,module,exports){ function Transport(t){this.path=t.path,this.hostname=t.hostname,this.port=t.port,this.secure=t.secure,this.query=t.query,this.timestampParam=t.timestampParam,this.timestampRequests=t.timestampRequests,this.readyState="",this.agent=t.agent||!1,this.socket=t.socket,this.enablesXDR=t.enablesXDR,this.pfx=t.pfx,this.key=t.key,this.passphrase=t.passphrase,this.cert=t.cert,this.ca=t.ca,this.ciphers=t.ciphers,this.rejectUnauthorized=t.rejectUnauthorized}var parser=require("engine.io-parser"),Emitter=require("component-emitter");module.exports=Transport,Emitter(Transport.prototype),Transport.timestamps=0,Transport.prototype.onError=function(t,e){var r=new Error(t);return r.type="TransportError",r.description=e,this.emit("error",r),this},Transport.prototype.open=function(){return("closed"==this.readyState||""==this.readyState)&&(this.readyState="opening",this.doOpen()),this},Transport.prototype.close=function(){return("opening"==this.readyState||"open"==this.readyState)&&(this.doClose(),this.onClose()),this},Transport.prototype.send=function(t){if("open"!=this.readyState)throw new Error("Transport not open");this.write(t)},Transport.prototype.onOpen=function(){this.readyState="open",this.writable=!0,this.emit("open")},Transport.prototype.onData=function(t){var e=parser.decodePacket(t,this.socket.binaryType);this.onPacket(e)},Transport.prototype.onPacket=function(t){this.emit("packet",t)},Transport.prototype.onClose=function(){this.readyState="closed",this.emit("close")}; },{"component-emitter":10,"engine.io-parser":26}],16:[function(require,module,exports){ (function (global){ function polling(e){var o,t=!1,r=!1,n=!1!==e.jsonp;if(global.location){var i="https:"==location.protocol,l=location.port;l||(l=i?443:80),t=e.hostname!=location.hostname||l!=e.port,r=e.secure!=i}if(e.xdomain=t,e.xscheme=r,o=new XMLHttpRequest(e),"open"in o&&!e.forceJSONP)return new XHR(e);if(!n)throw new Error("JSONP disabled");return new JSONP(e)}var XMLHttpRequest=require("xmlhttprequest"),XHR=require("./polling-xhr"),JSONP=require("./polling-jsonp"),websocket=require("./websocket");exports.polling=polling,exports.websocket=websocket; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{"./polling-jsonp":17,"./polling-xhr":18,"./websocket":20,"xmlhttprequest":21}],17:[function(require,module,exports){ (function (global){ function empty(){}function JSONPPolling(e){Polling.call(this,e),this.query=this.query||{},callbacks||(global.___eio||(global.___eio=[]),callbacks=global.___eio),this.index=callbacks.length;var t=this;callbacks.push(function(e){t.onData(e)}),this.query.j=this.index,global.document&&global.addEventListener&&global.addEventListener("beforeunload",function(){t.script&&(t.script.onerror=empty)},!1)}var Polling=require("./polling"),inherit=require("component-inherit");module.exports=JSONPPolling;var rNewline=/\n/g,rEscapedNewline=/\\n/g,callbacks,index=0;inherit(JSONPPolling,Polling),JSONPPolling.prototype.supportsBinary=!1,JSONPPolling.prototype.doClose=function(){this.script&&(this.script.parentNode.removeChild(this.script),this.script=null),this.form&&(this.form.parentNode.removeChild(this.form),this.form=null,this.iframe=null),Polling.prototype.doClose.call(this)},JSONPPolling.prototype.doPoll=function(){var e=this,t=document.createElement("script");this.script&&(this.script.parentNode.removeChild(this.script),this.script=null),t.async=!0,t.src=this.uri(),t.onerror=function(t){e.onError("jsonp poll error",t)};var i=document.getElementsByTagName("script")[0];i.parentNode.insertBefore(t,i),this.script=t;var r="undefined"!=typeof navigator&&/gecko/i.test(navigator.userAgent);r&&setTimeout(function(){var e=document.createElement("iframe");document.body.appendChild(e),document.body.removeChild(e)},100)},JSONPPolling.prototype.doWrite=function(e,t){function i(){r(),t()}function r(){if(o.iframe)try{o.form.removeChild(o.iframe)}catch(e){o.onError("jsonp polling iframe removal error",e)}try{var t='<iframe src="javascript:0" name="'+o.iframeId+'">';n=document.createElement(t)}catch(e){n=document.createElement("iframe"),n.name=o.iframeId,n.src="javascript:0"}n.id=o.iframeId,o.form.appendChild(n),o.iframe=n}var o=this;if(!this.form){var n,a=document.createElement("form"),l=document.createElement("textarea"),s=this.iframeId="eio_iframe_"+this.index;a.className="socketio",a.style.position="absolute",a.style.top="-1000px",a.style.left="-1000px",a.target=s,a.method="POST",a.setAttribute("accept-charset","utf-8"),l.name="d",a.appendChild(l),document.body.appendChild(a),this.form=a,this.area=l}this.form.action=this.uri(),r(),e=e.replace(rEscapedNewline,"\\\n"),this.area.value=e.replace(rNewline,"\\n");try{this.form.submit()}catch(c){}this.iframe.attachEvent?this.iframe.onreadystatechange=function(){"complete"==o.iframe.readyState&&i()}:this.iframe.onload=i}; }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{"./polling":19,"component-inherit":22}],18:[function(require,module,exports){ (function (global){ function empty(){}function XHR(t){if(Polling.call(this,t),global.location){var e="https:"==location.protocol,s=location.port;s||(s=e?443:80),this.xd=t.hostname!=global.location.hostname||s!=t.port,this.xs=t.secure!=e}}function Request(t){this.method=t.method||"GET",this.uri=t.uri,this.xd=!!t.xd,this.xs=!!t.xs,this.async=!1!==t.async,this.data=void 0!=t.data?t.data:null,this.agent=t.agent,this.isBinary=t.isBinary,this.supportsBinary=t.supportsBinary,this.enablesXDR=t.enablesXDR,this.pfx=t.pfx,this.key=t.key,this.passphrase=t.passphrase,this.cert=t.cert,this.ca=t.ca,this.ciphers=t.ciphers,this.rejectUnauthorized=t.rejectUnauthorized,this.create()}function unloadHandler(){for(var t in Request.requests)Request.requests.hasOwnProperty(t)&&Request.requests[t].abort()}var XMLHttpRequest=require("xmlhttprequest"),Polling=require("./polling"),Emitter=require("component-emitter"),inherit=require("component-inherit"),debug=require("debug")("engine.io-client:polling-xhr");module.exports=XHR,module.exports.Request=Request,inherit(XHR,Polling),XHR.prototype.supportsBinary=!0,XHR.prototype.request=function(t){return t=t||{},t.uri=this.uri(),t.xd=this.xd,t.xs=this.xs,t.agent=this.agent||!1,t.supportsBinary=this.supportsBinary,t.enablesXDR=this.enablesXDR,t.pfx=this.pfx,t.key=this.key,t.passphrase=this.passphrase,t.cert=this.cert,t.ca=this.ca,t.ciphers=this.ciphers,t.rejectUnauthorized=this.rejectUnauthorized,new Request(t)},XHR.prototype.doWrite=function(t,e){var s="string"!=typeof t&&void 0!==t,r=this.request({method:"POST",data:t,isBinary:s}),i=this;r.on("success",e),r.on("error",function(t){i.onError("xhr post error",t)}),this.sendXhr=r},XHR.prototype.doPoll=function(){debug("xhr poll");var t=this.request(),e=this;t.on("data",function(t){e.onData(t)}),t.on("error",function(t){e.onError("xhr poll error",t)}),this.pollXhr=t},Emitter(Request.prototype),Request.prototype.create=function(){var t={agent:this.agent,xdomain:this.xd,xscheme:this.xs,enablesXDR:this.enablesXDR};t.pfx=this.pfx,t.key=this.key,t.passphrase=this.passphrase,t.cert=this.cert,t.ca=this.ca,t.ciphers=this.ciphers,t.rejectUnauthorized=this.rejectUnauthorized;var e=this.xhr=new XMLHttpRequest(t),s=this;try{if(debug("xhr open %s: %s",this.method,this.uri),e.open(this.method,this.uri,this.async),this.supportsBinary&&(e.responseType="arraybuffer"),"POST"==this.method)try{this.isBinary?e.setRequestHeader("Content-type","application/octet-stream"):e.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(r){}"withCredentials"in e&&(e.withCredentials=!0),this.hasXDR()?(e.onload=function(){s.onLoad()},e.onerror=function(){s.onError(e.responseText)}):e.onreadystatechange=function(){4==e.readyState&&(200==e.status||1223==e.status?s.onLoad():setTimeout(function(){s.onError(e.status)},0))},debug("xhr data %s",this.data),e.send(this.data)}catch(r){return void setTimeout(function(){s.onError(r)},0)}global.document&&(this.index=Request.requestsCount++,Request.requests[this.index]=this)},Request.prototype.onSuccess=function(){this.emit("success"),this.cleanup()},Request.prototype.onData=function(t){this.emit("data",t),this.onSuccess()},Request.prototype.onError=function(t){this.emit("error",t),this.cleanup(!0)},Request.prototype.cleanup=function(t){if("undefined"!=typeof this.xhr&&null!==this.xhr){if(this.hasXDR()?this.xhr.onload=this.xhr.onerror=empty:this.xhr.onreadystatechange=empty,t)try{this.xhr.abort()}catch(e){}global.document&&delete Request.requests[this.index],this.xhr=null}},Request.prototype.onLoad=function(){var t;try{var e;try{e=this.xhr.getResponseHeader("Content-Type").split(";")[0]}catch(s){}t="application/octet-stream"===e?this.xhr.response:this.supportsBinary?"ok":this.xhr.responseText}catch(s){this.onError(s)}null!=t&&this.onData(t)},Request.prototype.hasXDR=function(){return"undefined"!=typeof global.XDomainRequest&&!this.xs&&this.enablesXDR},Request.prototype.abort=function(){this.cleanup()},global.document&&(Request.requestsCount=0,Request.requests={},global.attachEvent?global.attachEvent("onunload",unloadHandler):global.addEventListener&&global.addEventListener("beforeunload",unloadHandler,!1)); }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{"./polling":19,"component-emitter":10,"component-inherit":22,"debug":23,"xmlhttprequest":21}],19:[function(require,module,exports){ function Polling(t){var e=t&&t.forceBase64;(!hasXHR2||e)&&(this.supportsBinary=!1),Transport.call(this,t)}var Transport=require("../transport"),parseqs=require("parseqs"),parser=require("engine.io-parser"),inherit=require("component-inherit"),debug=require("debug")("engine.io-client:polling");module.exports=Polling;var hasXHR2=function(){var t=require("xmlhttprequest"),e=new t({xdomain:!1});return null!=e.responseType}();inherit(Polling,Transport),Polling.prototype.name="polling",Polling.prototype.doOpen=function(){this.poll()},Polling.prototype.pause=function(t){function e(){debug("paused"),i.readyState="paused",t()}var i=this;if(this.readyState="pausing",this.polling||!this.writable){var o=0;this.polling&&(debug("we are currently polling - waiting to pause"),o++,this.once("pollComplete",function(){debug("pre-pause polling complete"),--o||e()})),this.writable||(debug("we are currently writing - waiting to pause"),o++,this.once("drain",function(){debug("pre-pause writing complete"),--o||e()}))}else e()},Polling.prototype.poll=function(){debug("polling"),this.polling=!0,this.doPoll(),this.emit("poll")},Polling.prototype.onData=function(t){var e=this;debug("polling got data %s",t);var i=function(t){return"opening"==e.readyState&&e.onOpen(),"close"==t.type?(e.onClose(),!1):void e.onPacket(t)};parser.decodePayload(t,this.socket.binaryType,i),"closed"!=this.readyState&&(this.polling=!1,this.emit("pollComplete"),"open"==this.readyState?this.poll():debug('ignoring poll - transport state "%s"',this.readyState))},Polling.prototype.doClose=function(){function t(){debug("writing close packet"),e.write([{type:"close"}])}var e=this;"open"==this.readyState?(debug("transport open - closing"),t()):(debug("transport not open - deferring close"),this.once("open",t))},Polling.prototype.write=function(t){var e=this;this.writable=!1;var i=function(){e.writable=!0,e.emit("drain")},e=this;parser.encodePayload(t,this.supportsBinary,function(t){e.doWrite(t,i)})},Polling.prototype.uri=function(){var t=this.query||{},e=this.secure?"https":"http",i="";return!1!==this.timestampRequests&&(t[this.timestampParam]=+new Date+"-"+Transport.timestamps++),this.supportsBinary||t.sid||(t.b64=1),t=parseqs.encode(t),this.port&&("https"==e&&443!=this.port||"http"==e&&80!=this.port)&&(i=":"+this.port),t.length&&(t="?"+t),e+"://"+this.hostname+i+this.path+t}; },{"../transport":15,"component-inherit":22,"debug":23,"engine.io-parser":26,"parseqs":38,"xmlhttprequest":21}],20:[function(require,module,exports){ function WS(t){var e=t&&t.forceBase64;e&&(this.supportsBinary=!1),Transport.call(this,t)}var Transport=require("../transport"),parser=require("engine.io-parser"),parseqs=require("parseqs"),inherit=require("component-inherit"),debug=require("debug")("engine.io-client:websocket"),WebSocket=require("ws");module.exports=WS,inherit(WS,Transport),WS.prototype.name="websocket",WS.prototype.supportsBinary=!0,WS.prototype.doOpen=function(){if(this.check()){var t=this.uri(),e=void 0,s={agent:this.agent};s.pfx=this.pfx,s.key=this.key,s.passphrase=this.passphrase,s.cert=this.cert,s.ca=this.ca,s.ciphers=this.ciphers,s.rejectUnauthorized=this.rejectUnauthorized,this.ws=new WebSocket(t,e,s),void 0===this.ws.binaryType&&(this.supportsBinary=!1),this.ws.binaryType="arraybuffer",this.addEventListeners()}},WS.prototype.addEventListeners=function(){var t=this;this.ws.onopen=function(){t.onOpen()},this.ws.onclose=function(){t.onClose()},this.ws.onmessage=function(e){t.onData(e.data)},this.ws.onerror=function(e){t.onError("websocket error",e)}},"undefined"!=typeof navigator&&/iPad|iPhone|iPod/i.test(navigator.userAgent)&&(WS.prototype.onData=function(t){var e=this;setTimeout(function(){Transport.prototype.onData.call(e,t)},0)}),WS.prototype.write=function(t){function e(){s.writable=!0,s.emit("drain")}var s=this;this.writable=!1;for(var r=0,o=t.length;o>r;r++)parser.encodePacket(t[r],this.supportsBinary,function(t){try{s.ws.send(t)}catch(e){debug("websocket closed before onclose event")}});setTimeout(e,0)},WS.prototype.onClose=function(){Transport.prototype.onClose.call(this)},WS.prototype.doClose=function(){"undefined"!=typeof this.ws&&this.ws.close()},WS.prototype.uri=function(){var t=this.query||{},e=this.secure?"wss":"ws",s="";return this.port&&("wss"==e&&443!=this.port||"ws"==e&&80!=this.port)&&(s=":"+this.port),this.timestampRequests&&(t[this.timestampParam]=+new Date),this.supportsBinary||(t.b64=1),t=parseqs.encode(t),t.length&&(t="?"+t),e+"://"+this.hostname+s+this.path+t},WS.prototype.check=function(){return!(!WebSocket||"__initialize"in WebSocket&&this.name===WS.prototype.name)}; },{"../transport":15,"component-inherit":22,"debug":23,"engine.io-parser":26,"parseqs":38,"ws":40}],21:[function(require,module,exports){ var hasCORS=require("has-cors");module.exports=function(e){var t=e.xdomain,n=e.xscheme,r=e.enablesXDR;try{if("undefined"!=typeof XMLHttpRequest&&(!t||hasCORS))return new XMLHttpRequest}catch(a){}try{if("undefined"!=typeof XDomainRequest&&!n&&r)return new XDomainRequest}catch(a){}if(!t)try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(a){}}; },{"has-cors":35}],22:[function(require,module,exports){ module.exports=function(o,t){var p=function(){};p.prototype=t.prototype,o.prototype=new p,o.prototype.constructor=o}; },{}],23:[function(require,module,exports){ function useColors(){return"WebkitAppearance"in document.documentElement.style||window.console&&(console.firebug||console.exception&&console.table)||navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31}function formatArgs(){var o=arguments,e=this.useColors;if(o[0]=(e?"%c":"")+this.namespace+(e?" %c":" ")+o[0]+(e?"%c ":" ")+"+"+exports.humanize(this.diff),!e)return o;var r="color: "+this.color;o=[o[0],r,"color: inherit"].concat(Array.prototype.slice.call(o,1));var t=0,n=0;return o[0].replace(/%[a-z%]/g,function(o){"%%"!==o&&(t++,"%c"===o&&(n=t))}),o.splice(n,0,r),o}function log(){return"object"==typeof console&&"function"==typeof console.log&&Function.prototype.apply.call(console.log,console,arguments)}function save(o){try{null==o?localStorage.removeItem("debug"):localStorage.debug=o}catch(e){}}function load(){var o;try{o=localStorage.debug}catch(e){}return o}exports=module.exports=require("./debug"),exports.log=log,exports.formatArgs=formatArgs,exports.save=save,exports.load=load,exports.useColors=useColors,exports.colors=["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"],exports.formatters.j=function(o){return JSON.stringify(o)},exports.enable(load()); },{"./debug":24}],24:[function(require,module,exports){ function selectColor(){return exports.colors[prevColor++%exports.colors.length]}function debug(e){function r(){}function o(){var e=o,r=+new Date,s=r-(prevTime||r);e.diff=s,e.prev=prevTime,e.curr=r,prevTime=r,null==e.useColors&&(e.useColors=exports.useColors()),null==e.color&&e.useColors&&(e.color=selectColor());var t=Array.prototype.slice.call(arguments);t[0]=exports.coerce(t[0]),"string"!=typeof t[0]&&(t=["%o"].concat(t));var n=0;t[0]=t[0].replace(/%([a-z%])/g,function(r,o){if("%%"===r)return r;n++;var s=exports.formatters[o];if("function"==typeof s){var p=t[n];r=s.call(e,p),t.splice(n,1),n--}return r}),"function"==typeof exports.formatArgs&&(t=exports.formatArgs.apply(e,t));var p=o.log||exports.log||console.log.bind(console);p.apply(e,t)}r.enabled=!1,o.enabled=!0;var s=exports.enabled(e)?o:r;return s.namespace=e,s}function enable(e){exports.save(e);for(var r=(e||"").split(/[\s,]+/),o=r.length,s=0;o>s;s++)r[s]&&(e=r[s].replace(/\*/g,".*?"),"-"===e[0]?exports.skips.