-
Notifications
You must be signed in to change notification settings - Fork 109
/
deepstream.min.js
5 lines (5 loc) · 95.5 KB
/
deepstream.min.js
1
2
3
4
5
/*! deepstream.io-client-js 1.0.1 (c)2016 deepstreamHub GmbH, with parts (c)2016 Joyent and contributers @licence Apache-2.0*/
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.deepstream=a()}}(function(){var a;return function b(a,c,d){function e(g,h){if(!c[g]){if(!a[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};a[g][0].call(k.exports,function(b){var c=a[g][1][b];return e(c?c:b)},k,k.exports,b,a,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){function d(a){if(a)return e(a)}function e(a){for(var b in d.prototype)a[b]=d.prototype[b];return a}b.exports=d,d.prototype.on=d.prototype.addEventListener=function(a,b){return this._callbacks=this._callbacks||{},(this._callbacks[a]=this._callbacks[a]||[]).push(b),this},d.prototype.once=function(a,b){function c(){d.off(a,c),b.apply(this,arguments)}var d=this;return this._callbacks=this._callbacks||{},c.fn=b,this.on(a,c),this},d.prototype.off=d.prototype.removeListener=d.prototype.removeAllListeners=d.prototype.removeEventListener=function(a,b){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var c=this._callbacks[a];if(!c)return this;if(1==arguments.length)return delete this._callbacks[a],this;for(var d,e=0;e<c.length;e++)if(d=c[e],d===b||d.fn===b){c.splice(e,1);break}return this},d.prototype.emit=function(a){this._callbacks=this._callbacks||{};var b=[].slice.call(arguments,1),c=this._callbacks[a];if(c){c=c.slice(0);for(var d=0,e=c.length;d<e;++d)c[d].apply(this,b)}return this},d.prototype.listeners=function(a){return this._callbacks=this._callbacks||{},this._callbacks[a]||[]},d.prototype.hasListeners=function(a){return!!this.listeners(a).length}},{}],2:[function(a,b,c){b.exports=a("./lib/")},{"./lib/":3}],3:[function(a,b,c){b.exports=a("./socket"),b.exports.parser=a("engine.io-parser")},{"./socket":4,"engine.io-parser":16}],4:[function(a,b,c){(function(c){function d(a,b){if(!(this instanceof d))return new d(a,b);b=b||{},a&&"object"==typeof a&&(b=a,a=null),a?(a=k(a),b.hostname=a.host,b.secure="https"==a.protocol||"wss"==a.protocol,b.port=a.port,a.query&&(b.query=a.query)):b.host&&(b.hostname=k(b.host).host),this.secure=null!=b.secure?b.secure:c.location&&"https:"==location.protocol,b.hostname&&!b.port&&(b.port=this.secure?"443":"80"),this.agent=b.agent||!1,this.hostname=b.hostname||(c.location?location.hostname:"localhost"),this.port=b.port||(c.location&&location.port?location.port:this.secure?443:80),this.query=b.query||{},"string"==typeof this.query&&(this.query=m.decode(this.query)),this.upgrade=!1!==b.upgrade,this.path=(b.path||"/engine.io").replace(/\/$/,"")+"/",this.forceJSONP=!!b.forceJSONP,this.jsonp=!1!==b.jsonp,this.forceBase64=!!b.forceBase64,this.enablesXDR=!!b.enablesXDR,this.timestampParam=b.timestampParam||"t",this.timestampRequests=b.timestampRequests,this.transports=b.transports||["polling","websocket"],this.readyState="",this.writeBuffer=[],this.policyPort=b.policyPort||843,this.rememberUpgrade=b.rememberUpgrade||!1,this.binaryType=null,this.onlyBinaryUpgrades=b.onlyBinaryUpgrades,this.perMessageDeflate=!1!==b.perMessageDeflate&&(b.perMessageDeflate||{}),!0===this.perMessageDeflate&&(this.perMessageDeflate={}),this.perMessageDeflate&&null==this.perMessageDeflate.threshold&&(this.perMessageDeflate.threshold=1024),this.pfx=b.pfx||null,this.key=b.key||null,this.passphrase=b.passphrase||null,this.cert=b.cert||null,this.ca=b.ca||null,this.ciphers=b.ciphers||null,this.rejectUnauthorized=void 0===b.rejectUnauthorized||b.rejectUnauthorized;var e="object"==typeof c&&c;e.global===e&&b.extraHeaders&&Object.keys(b.extraHeaders).length>0&&(this.extraHeaders=b.extraHeaders),this.open()}function e(a){var b={};for(var c in a)a.hasOwnProperty(c)&&(b[c]=a[c]);return b}var f=a("./transports"),g=a("component-emitter"),h=a("debug")("engine.io-client:socket"),i=a("indexof"),j=a("engine.io-parser"),k=a("parseuri"),l=a("parsejson"),m=a("parseqs");b.exports=d,d.priorWebsocketSuccess=!1,g(d.prototype),d.protocol=j.protocol,d.Socket=d,d.Transport=a("./transport"),d.transports=a("./transports"),d.parser=a("engine.io-parser"),d.prototype.createTransport=function(a){h('creating transport "%s"',a);var b=e(this.query);b.EIO=j.protocol,b.transport=a,this.id&&(b.sid=this.id);var c=new f[a]({agent:this.agent,hostname:this.hostname,port:this.port,secure:this.secure,path:this.path,query:b,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,perMessageDeflate:this.perMessageDeflate,extraHeaders:this.extraHeaders});return c},d.prototype.open=function(){var a;if(this.rememberUpgrade&&d.priorWebsocketSuccess&&this.transports.indexOf("websocket")!=-1)a="websocket";else{if(0===this.transports.length){var b=this;return void setTimeout(function(){b.emit("error","No transports available")},0)}a=this.transports[0]}this.readyState="opening";try{a=this.createTransport(a)}catch(c){return this.transports.shift(),void this.open()}a.open(),this.setTransport(a)},d.prototype.setTransport=function(a){h("setting transport %s",a.name);var b=this;this.transport&&(h("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")})},d.prototype.probe=function(a){function b(){if(m.onlyBinaryUpgrades){var b=!this.supportsBinary&&m.transport.supportsBinary;l=l||b}l||(h('probe transport "%s" opened',a),k.send([{type:"ping",data:"probe"}]),k.once("packet",function(b){if(!l)if("pong"==b.type&&"probe"==b.data){if(h('probe transport "%s" pong',a),m.upgrading=!0,m.emit("upgrading",k),!k)return;d.priorWebsocketSuccess="websocket"==k.name,h('pausing current transport "%s"',m.transport.name),m.transport.pause(function(){l||"closed"!=m.readyState&&(h("changing transport and sending upgrade packet"),j(),m.setTransport(k),k.send([{type:"upgrade"}]),m.emit("upgrade",k),k=null,m.upgrading=!1,m.flush())})}else{h('probe transport "%s" failed',a);var c=new Error("probe error");c.transport=k.name,m.emit("upgradeError",c)}}))}function c(){l||(l=!0,j(),k.close(),k=null)}function e(b){var d=new Error("probe error: "+b);d.transport=k.name,c(),h('probe transport "%s" failed because of error: %s',a,b),m.emit("upgradeError",d)}function f(){e("transport closed")}function g(){e("socket closed")}function i(a){k&&a.name!=k.name&&(h('"%s" works - aborting "%s"',a.name,k.name),c())}function j(){k.removeListener("open",b),k.removeListener("error",e),k.removeListener("close",f),m.removeListener("close",g),m.removeListener("upgrading",i)}h('probing transport "%s"',a);var k=this.createTransport(a,{probe:1}),l=!1,m=this;d.priorWebsocketSuccess=!1,k.once("open",b),k.once("error",e),k.once("close",f),this.once("close",g),this.once("upgrading",i),k.open()},d.prototype.onOpen=function(){if(h("socket open"),this.readyState="open",d.priorWebsocketSuccess="websocket"==this.transport.name,this.emit("open"),this.flush(),"open"==this.readyState&&this.upgrade&&this.transport.pause){h("starting upgrade probes");for(var a=0,b=this.upgrades.length;a<b;a++)this.probe(this.upgrades[a])}},d.prototype.onPacket=function(a){if("opening"==this.readyState||"open"==this.readyState)switch(h('socket receive: type "%s", data "%s"',a.type,a.data),this.emit("packet",a),this.emit("heartbeat"),a.type){case"open":this.onHandshake(l(a.data));break;case"pong":this.setPing(),this.emit("pong");break;case"error":var b=new Error("server error");b.code=a.data,this.onError(b);break;case"message":this.emit("data",a.data),this.emit("message",a.data)}else h('packet received with socket readyState "%s"',this.readyState)},d.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))},d.prototype.onHeartbeat=function(a){clearTimeout(this.pingTimeoutTimer);var b=this;b.pingTimeoutTimer=setTimeout(function(){"closed"!=b.readyState&&b.onClose("ping timeout")},a||b.pingInterval+b.pingTimeout)},d.prototype.setPing=function(){var a=this;clearTimeout(a.pingIntervalTimer),a.pingIntervalTimer=setTimeout(function(){h("writing ping packet - expecting pong within %sms",a.pingTimeout),a.ping(),a.onHeartbeat(a.pingTimeout)},a.pingInterval)},d.prototype.ping=function(){var a=this;this.sendPacket("ping",function(){a.emit("ping")})},d.prototype.onDrain=function(){this.writeBuffer.splice(0,this.prevBufferLen),this.prevBufferLen=0,0===this.writeBuffer.length?this.emit("drain"):this.flush()},d.prototype.flush=function(){"closed"!=this.readyState&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length&&(h("flushing %d packets in socket",this.writeBuffer.length),this.transport.send(this.writeBuffer),this.prevBufferLen=this.writeBuffer.length,this.emit("flush"))},d.prototype.write=d.prototype.send=function(a,b,c){return this.sendPacket("message",a,b,c),this},d.prototype.sendPacket=function(a,b,c,d){if("function"==typeof b&&(d=b,b=void 0),"function"==typeof c&&(d=c,c=null),"closing"!=this.readyState&&"closed"!=this.readyState){c=c||{},c.compress=!1!==c.compress;var e={type:a,data:b,options:c};this.emit("packetCreate",e),this.writeBuffer.push(e),d&&this.once("flush",d),this.flush()}},d.prototype.close=function(){function a(){d.onClose("forced close"),h("socket closing - telling transport to close"),d.transport.close()}function b(){d.removeListener("upgrade",b),d.removeListener("upgradeError",b),a()}function c(){d.once("upgrade",b),d.once("upgradeError",b)}if("opening"==this.readyState||"open"==this.readyState){this.readyState="closing";var d=this;this.writeBuffer.length?this.once("drain",function(){this.upgrading?c():a()}):this.upgrading?c():a()}return this},d.prototype.onError=function(a){h("socket error %j",a),d.priorWebsocketSuccess=!1,this.emit("error",a),this.onClose("transport error",a)},d.prototype.onClose=function(a,b){if("opening"==this.readyState||"open"==this.readyState||"closing"==this.readyState){h('socket close with reason: "%s"',a);var c=this;clearTimeout(this.pingIntervalTimer),clearTimeout(this.pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),this.readyState="closed",this.id=null,this.emit("close",a,b),c.writeBuffer=[],c.prevBufferLen=0}},d.prototype.filterUpgrades=function(a){for(var b=[],c=0,d=a.length;c<d;c++)~i(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":5,"./transports":6,"component-emitter":1,debug:13,"engine.io-parser":16,indexof:26,parsejson:27,parseqs:28,parseuri:29}],5:[function(a,b,c){function d(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,this.pfx=a.pfx,this.key=a.key,this.passphrase=a.passphrase,this.cert=a.cert,this.ca=a.ca,this.ciphers=a.ciphers,this.rejectUnauthorized=a.rejectUnauthorized,this.extraHeaders=a.extraHeaders}var e=a("engine.io-parser"),f=a("component-emitter");b.exports=d,f(d.prototype),d.prototype.onError=function(a,b){var c=new Error(a);return c.type="TransportError",c.description=b,this.emit("error",c),this},d.prototype.open=function(){return"closed"!=this.readyState&&""!=this.readyState||(this.readyState="opening",this.doOpen()),this},d.prototype.close=function(){return"opening"!=this.readyState&&"open"!=this.readyState||(this.doClose(),this.onClose()),this},d.prototype.send=function(a){if("open"!=this.readyState)throw new Error("Transport not open");this.write(a)},d.prototype.onOpen=function(){this.readyState="open",this.writable=!0,this.emit("open")},d.prototype.onData=function(a){var b=e.decodePacket(a,this.socket.binaryType);this.onPacket(b)},d.prototype.onPacket=function(a){this.emit("packet",a)},d.prototype.onClose=function(){this.readyState="closed",this.emit("close")}},{"component-emitter":1,"engine.io-parser":16}],6:[function(a,b,c){(function(b){function d(a){var c,d=!1,h=!1,i=!1!==a.jsonp;if(b.location){var j="https:"==location.protocol,k=location.port;k||(k=j?443:80),d=a.hostname!=location.hostname||k!=a.port,h=a.secure!=j}if(a.xdomain=d,a.xscheme=h,c=new e(a),"open"in c&&!a.forceJSONP)return new f(a);if(!i)throw new Error("JSONP disabled");return new g(a)}var e=a("xmlhttprequest-ssl"),f=a("./polling-xhr"),g=a("./polling-jsonp"),h=a("./websocket");c.polling=d,c.websocket=h}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./polling-jsonp":7,"./polling-xhr":8,"./websocket":10,"xmlhttprequest-ssl":11}],7:[function(a,b,c){(function(c){function d(){}function e(a){f.call(this,a),this.query=this.query||{},h||(c.___eio||(c.___eio=[]),h=c.___eio),this.index=h.length;var b=this;h.push(function(a){b.onData(a)}),this.query.j=this.index,c.document&&c.addEventListener&&c.addEventListener("beforeunload",function(){b.script&&(b.script.onerror=d)},!1)}var f=a("./polling"),g=a("component-inherit");b.exports=e;var h,i=/\n/g,j=/\\n/g;g(e,f),e.prototype.supportsBinary=!1,e.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),f.prototype.doClose.call(this)},e.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?c.parentNode.insertBefore(b,c):(document.head||document.body).appendChild(b),this.script=b;var d="undefined"!=typeof navigator&&/gecko/i.test(navigator.userAgent);d&&setTimeout(function(){var a=document.createElement("iframe");document.body.appendChild(a),document.body.removeChild(a)},100)},e.prototype.doWrite=function(a,b){function c(){d(),b()}function d(){if(e.iframe)try{e.form.removeChild(e.iframe)}catch(a){e.onError("jsonp polling iframe removal error",a)}try{var b='<iframe src="javascript:0" name="'+e.iframeId+'">';f=document.createElement(b)}catch(a){f=document.createElement("iframe"),f.name=e.iframeId,f.src="javascript:0"}f.id=e.iframeId,e.form.appendChild(f),e.iframe=f}var e=this;if(!this.form){var f,g=document.createElement("form"),h=document.createElement("textarea"),k=this.iframeId="eio_iframe_"+this.index;g.className="socketio",g.style.position="absolute",g.style.top="-1000px",g.style.left="-1000px",g.target=k,g.method="POST",g.setAttribute("accept-charset","utf-8"),h.name="d",g.appendChild(h),document.body.appendChild(g),this.form=g,this.area=h}this.form.action=this.uri(),d(),a=a.replace(j,"\\\n"),this.area.value=a.replace(i,"\\n");try{this.form.submit()}catch(l){}this.iframe.attachEvent?this.iframe.onreadystatechange=function(){"complete"==e.iframe.readyState&&c()}:this.iframe.onload=c}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./polling":9,"component-inherit":12}],8:[function(a,b,c){(function(c){function d(){}function e(a){if(i.call(this,a),c.location){var b="https:"==location.protocol,d=location.port;d||(d=b?443:80),this.xd=a.hostname!=c.location.hostname||d!=a.port,this.xs=a.secure!=b}else this.extraHeaders=a.extraHeaders}function f(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.pfx=a.pfx,this.key=a.key,this.passphrase=a.passphrase,this.cert=a.cert,this.ca=a.ca,this.ciphers=a.ciphers,this.rejectUnauthorized=a.rejectUnauthorized,this.extraHeaders=a.extraHeaders,this.create()}function g(){for(var a in f.requests)f.requests.hasOwnProperty(a)&&f.requests[a].abort()}var h=a("xmlhttprequest-ssl"),i=a("./polling"),j=a("component-emitter"),k=a("component-inherit"),l=a("debug")("engine.io-client:polling-xhr");b.exports=e,b.exports.Request=f,k(e,i),e.prototype.supportsBinary=!0,e.prototype.request=function(a){return 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,a.pfx=this.pfx,a.key=this.key,a.passphrase=this.passphrase,a.cert=this.cert,a.ca=this.ca,a.ciphers=this.ciphers,a.rejectUnauthorized=this.rejectUnauthorized,a.extraHeaders=this.extraHeaders,new f(a)},e.prototype.doWrite=function(a,b){var c="string"!=typeof a&&void 0!==a,d=this.request({method:"POST",data:a,isBinary:c}),e=this;d.on("success",b),d.on("error",function(a){e.onError("xhr post error",a)}),this.sendXhr=d},e.prototype.doPoll=function(){l("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},j(f.prototype),f.prototype.create=function(){var a={agent:this.agent,xdomain:this.xd,xscheme:this.xs,enablesXDR:this.enablesXDR};a.pfx=this.pfx,a.key=this.key,a.passphrase=this.passphrase,a.cert=this.cert,a.ca=this.ca,a.ciphers=this.ciphers,a.rejectUnauthorized=this.rejectUnauthorized;var b=this.xhr=new h(a),d=this;try{l("xhr open %s: %s",this.method,this.uri),b.open(this.method,this.uri,this.async);try{if(this.extraHeaders){b.setDisableHeaderCheck(!0);for(var e in this.extraHeaders)this.extraHeaders.hasOwnProperty(e)&&b.setRequestHeader(e,this.extraHeaders[e])}}catch(g){}if(this.supportsBinary&&(b.responseType="arraybuffer"),"POST"==this.method)try{this.isBinary?b.setRequestHeader("Content-type","application/octet-stream"):b.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(g){}"withCredentials"in b&&(b.withCredentials=!0),this.hasXDR()?(b.onload=function(){d.onLoad()},b.onerror=function(){d.onError(b.responseText)}):b.onreadystatechange=function(){4==b.readyState&&(200==b.status||1223==b.status?d.onLoad():setTimeout(function(){d.onError(b.status)},0))},l("xhr data %s",this.data),b.send(this.data)}catch(g){return void setTimeout(function(){d.onError(g)},0)}c.document&&(this.index=f.requestsCount++,f.requests[this.index]=this)},f.prototype.onSuccess=function(){this.emit("success"),this.cleanup()},f.prototype.onData=function(a){this.emit("data",a),this.onSuccess()},f.prototype.onError=function(a){this.emit("error",a),this.cleanup(!0)},f.prototype.cleanup=function(a){if("undefined"!=typeof this.xhr&&null!==this.xhr){if(this.hasXDR()?this.xhr.onload=this.xhr.onerror=d:this.xhr.onreadystatechange=d,a)try{this.xhr.abort()}catch(b){}c.document&&delete f.requests[this.index],this.xhr=null}},f.prototype.onLoad=function(){var a;try{var b;try{b=this.xhr.getResponseHeader("Content-Type").split(";")[0]}catch(c){}if("application/octet-stream"===b)a=this.xhr.response;else if(this.supportsBinary)try{a=String.fromCharCode.apply(null,new Uint8Array(this.xhr.response))}catch(c){for(var d=new Uint8Array(this.xhr.response),e=[],f=0,g=d.length;f<g;f++)e.push(d[f]);a=String.fromCharCode.apply(null,e)}else a=this.xhr.responseText}catch(c){this.onError(c)}null!=a&&this.onData(a)},f.prototype.hasXDR=function(){return"undefined"!=typeof c.XDomainRequest&&!this.xs&&this.enablesXDR},f.prototype.abort=function(){this.cleanup()},c.document&&(f.requestsCount=0,f.requests={},c.attachEvent?c.attachEvent("onunload",g):c.addEventListener&&c.addEventListener("beforeunload",g,!1))}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./polling":9,"component-emitter":1,"component-inherit":12,debug:13,"xmlhttprequest-ssl":11}],9:[function(a,b,c){function d(a){var b=a&&a.forceBase64;k&&!b||(this.supportsBinary=!1),e.call(this,a)}var e=a("../transport"),f=a("parseqs"),g=a("engine.io-parser"),h=a("component-inherit"),i=a("yeast"),j=a("debug")("engine.io-client:polling");b.exports=d;var k=function(){var b=a("xmlhttprequest-ssl"),c=new b({xdomain:!1});return null!=c.responseType}();h(d,e),d.prototype.name="polling",d.prototype.doOpen=function(){this.poll()},d.prototype.pause=function(a){function b(){j("paused"),c.readyState="paused",a()}var c=this;if(this.readyState="pausing",this.polling||!this.writable){var d=0;this.polling&&(j("we are currently polling - waiting to pause"),d++,this.once("pollComplete",function(){j("pre-pause polling complete"),--d||b()})),this.writable||(j("we are currently writing - waiting to pause"),d++,this.once("drain",function(){j("pre-pause writing complete"),--d||b()}))}else b()},d.prototype.poll=function(){j("polling"),this.polling=!0,this.doPoll(),this.emit("poll")},d.prototype.onData=function(a){var b=this;j("polling got data %s",a);var c=function(a,c,d){return"opening"==b.readyState&&b.onOpen(),"close"==a.type?(b.onClose(),!1):void b.onPacket(a)};g.decodePayload(a,this.socket.binaryType,c),"closed"!=this.readyState&&(this.polling=!1,this.emit("pollComplete"),"open"==this.readyState?this.poll():j('ignoring poll - transport state "%s"',this.readyState))},d.prototype.doClose=function(){function a(){j("writing close packet"),b.write([{type:"close"}])}var b=this;"open"==this.readyState?(j("transport open - closing"),a()):(j("transport not open - deferring close"),this.once("open",a))},d.prototype.write=function(a){var b=this;this.writable=!1;var c=function(){b.writable=!0,b.emit("drain")},b=this;g.encodePayload(a,this.supportsBinary,function(a){b.doWrite(a,c)})},d.prototype.uri=function(){var a=this.query||{},b=this.secure?"https":"http",c="";!1!==this.timestampRequests&&(a[this.timestampParam]=i()),this.supportsBinary||a.sid||(a.b64=1),a=f.encode(a),this.port&&("https"==b&&443!=this.port||"http"==b&&80!=this.port)&&(c=":"+this.port),a.length&&(a="?"+a);var d=this.hostname.indexOf(":")!==-1;return b+"://"+(d?"["+this.hostname+"]":this.hostname)+c+this.path+a}},{"../transport":5,"component-inherit":12,debug:13,"engine.io-parser":16,parseqs:28,"xmlhttprequest-ssl":11,yeast:30}],10:[function(a,b,c){(function(c){function d(a){var b=a&&a.forceBase64;b&&(this.supportsBinary=!1),this.perMessageDeflate=a.perMessageDeflate,e.call(this,a)}var e=a("../transport"),f=a("engine.io-parser"),g=a("parseqs"),h=a("component-inherit"),i=a("yeast"),j=a("debug")("engine.io-client:websocket"),k=c.WebSocket||c.MozWebSocket,l=k;if(!l&&"undefined"==typeof window)try{l=a("ws")}catch(m){}b.exports=d,h(d,e),d.prototype.name="websocket",d.prototype.supportsBinary=!0,d.prototype.doOpen=function(){if(this.check()){var a=this.uri(),b=void 0,c={agent:this.agent,perMessageDeflate:this.perMessageDeflate};c.pfx=this.pfx,c.key=this.key,c.passphrase=this.passphrase,c.cert=this.cert,c.ca=this.ca,c.ciphers=this.ciphers,c.rejectUnauthorized=this.rejectUnauthorized,this.extraHeaders&&(c.headers=this.extraHeaders),this.ws=k?new l(a):new l(a,b,c),void 0===this.ws.binaryType&&(this.supportsBinary=!1),this.ws.supports&&this.ws.supports.binary?(this.supportsBinary=!0,this.ws.binaryType="buffer"):this.ws.binaryType="arraybuffer",this.addEventListeners()}},d.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)&&(d.prototype.onData=function(a){var b=this;setTimeout(function(){e.prototype.onData.call(b,a)},0)}),d.prototype.write=function(a){function b(){d.emit("flush"),setTimeout(function(){d.writable=!0,d.emit("drain")},0)}var d=this;this.writable=!1;for(var e=a.length,g=0,h=e;g<h;g++)!function(a){f.encodePacket(a,d.supportsBinary,function(f){if(!k){var g={};if(a.options&&(g.compress=a.options.compress),d.perMessageDeflate){var h="string"==typeof f?c.Buffer.byteLength(f):f.length;h<d.perMessageDeflate.threshold&&(g.compress=!1)}}try{k?d.ws.send(f):d.ws.send(f,g)}catch(i){j("websocket closed before onclose event")}--e||b()})}(a[g])},d.prototype.onClose=function(){e.prototype.onClose.call(this)},d.prototype.doClose=function(){"undefined"!=typeof this.ws&&this.ws.close()},d.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]=i()),this.supportsBinary||(a.b64=1),a=g.encode(a),a.length&&(a="?"+a);var d=this.hostname.indexOf(":")!==-1;return b+"://"+(d?"["+this.hostname+"]":this.hostname)+c+this.path+a},d.prototype.check=function(){return!(!l||"__initialize"in l&&this.name===d.prototype.name)}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../transport":5,"component-inherit":12,debug:13,"engine.io-parser":16,parseqs:28,ws:32,yeast:30}],11:[function(a,b,c){var d=a("has-cors");b.exports=function(a){var b=a.xdomain,c=a.xscheme,e=a.enablesXDR;try{if("undefined"!=typeof XMLHttpRequest&&(!b||d))return new XMLHttpRequest}catch(f){}try{if("undefined"!=typeof XDomainRequest&&!c&&e)return new XDomainRequest}catch(f){}if(!b)try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(f){}}},{"has-cors":25}],12:[function(a,b,c){b.exports=function(a,b){var c=function(){};c.prototype=b.prototype,a.prototype=new c,a.prototype.constructor=a}},{}],13:[function(a,b,c){function d(){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 e(){var a=arguments,b=this.useColors;if(a[0]=(b?"%c":"")+this.namespace+(b?" %c":" ")+a[0]+(b?"%c ":" ")+"+"+c.humanize(this.diff),!b)return a;var d="color: "+this.color;a=[a[0],d,"color: inherit"].concat(Array.prototype.slice.call(a,1));var e=0,f=0;return a[0].replace(/%[a-z%]/g,function(a){"%%"!==a&&(e++,"%c"===a&&(f=e))}),a.splice(f,0,d),a}function f(){return"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}function g(a){try{null==a?c.storage.removeItem("debug"):c.storage.debug=a}catch(b){}}function h(){var a;try{a=c.storage.debug}catch(b){}return a}function i(){try{return window.localStorage}catch(a){}}c=b.exports=a("./debug"),c.log=f,c.formatArgs=e,c.save=g,c.load=h,c.useColors=d,c.storage="undefined"!=typeof chrome&&"undefined"!=typeof chrome.storage?chrome.storage.local:i(),c.colors=["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"],c.formatters.j=function(a){return JSON.stringify(a)},c.enable(h())},{"./debug":14}],14:[function(a,b,c){function d(){return c.colors[k++%c.colors.length]}function e(a){function b(){}function e(){var a=e,b=+new Date,f=b-(j||b);a.diff=f,a.prev=j,a.curr=b,j=b,null==a.useColors&&(a.useColors=c.useColors()),null==a.color&&a.useColors&&(a.color=d());var g=Array.prototype.slice.call(arguments);g[0]=c.coerce(g[0]),"string"!=typeof g[0]&&(g=["%o"].concat(g));var h=0;g[0]=g[0].replace(/%([a-z%])/g,function(b,d){if("%%"===b)return b;h++;var e=c.formatters[d];if("function"==typeof e){var f=g[h];b=e.call(a,f),g.splice(h,1),h--}return b}),"function"==typeof c.formatArgs&&(g=c.formatArgs.apply(a,g));var i=e.log||c.log||console.log.bind(console);i.apply(a,g)}b.enabled=!1,e.enabled=!0;var f=c.enabled(a)?e:b;return f.namespace=a,f}function f(a){c.save(a);for(var b=(a||"").split(/[\s,]+/),d=b.length,e=0;e<d;e++)b[e]&&(a=b[e].replace(/\*/g,".*?"),"-"===a[0]?c.skips.push(new RegExp("^"+a.substr(1)+"$")):c.names.push(new RegExp("^"+a+"$")))}function g(){c.enable("")}function h(a){var b,d;for(b=0,d=c.skips.length;b<d;b++)if(c.skips[b].test(a))return!1;for(b=0,d=c.names.length;b<d;b++)if(c.names[b].test(a))return!0;return!1}function i(a){return a instanceof Error?a.stack||a.message:a}c=b.exports=e,c.coerce=i,c.disable=g,c.enable=f,c.enabled=h,c.humanize=a("ms"),c.names=[],c.skips=[],c.formatters={};var j,k=0},{ms:15}],15:[function(a,b,c){function d(a){if(a=""+a,!(a.length>1e4)){var b=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(a);if(b){var c=parseFloat(b[1]),d=(b[2]||"ms").toLowerCase();switch(d){case"years":case"year":case"yrs":case"yr":case"y":return c*l;case"days":case"day":case"d":return c*k;case"hours":case"hour":case"hrs":case"hr":case"h":return c*j;case"minutes":case"minute":case"mins":case"min":case"m":return c*i;case"seconds":case"second":case"secs":case"sec":case"s":return c*h;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return c}}}}function e(a){return a>=k?Math.round(a/k)+"d":a>=j?Math.round(a/j)+"h":a>=i?Math.round(a/i)+"m":a>=h?Math.round(a/h)+"s":a+"ms"}function f(a){return g(a,k,"day")||g(a,j,"hour")||g(a,i,"minute")||g(a,h,"second")||a+" ms"}function g(a,b,c){if(!(a<b))return a<1.5*b?Math.floor(a/b)+" "+c:Math.ceil(a/b)+" "+c+"s"}var h=1e3,i=60*h,j=60*i,k=24*j,l=365.25*k;b.exports=function(a,b){return b=b||{},"string"==typeof a?d(a):b["long"]?f(a):e(a)}},{}],16:[function(a,b,c){(function(b){function d(a,b){var d="b"+c.packets[a.type]+a.data.data;return b(d)}function e(a,b,d){if(!b)return c.encodeBase64Packet(a,d);var e=a.data,f=new Uint8Array(e),g=new Uint8Array(1+e.byteLength);g[0]=r[a.type];for(var h=0;h<f.length;h++)g[h+1]=f[h];return d(g.buffer)}function f(a,b,d){if(!b)return c.encodeBase64Packet(a,d);var e=new FileReader;return e.onload=function(){a.data=e.result,c.encodePacket(a,b,!0,d)},e.readAsArrayBuffer(a.data)}function g(a,b,d){if(!b)return c.encodeBase64Packet(a,d);if(q)return f(a,b,d);var e=new Uint8Array(1);e[0]=r[a.type];var g=new u([e.buffer,a.data]);return d(g)}function h(a,b,c){for(var d=new Array(a.length),e=m(a.length,c),f=function(a,c,e){b(c,function(b,c){d[a]=c,e(b,d)})},g=0;g<a.length;g++)f(g,a[g],e)}var i=a("./keys"),j=a("has-binary"),k=a("arraybuffer.slice"),l=a("base64-arraybuffer"),m=a("after"),n=a("utf8"),o=navigator.userAgent.match(/Android/i),p=/PhantomJS/i.test(navigator.userAgent),q=o||p;c.protocol=3;var r=c.packets={open:0,close:1,ping:2,pong:3,message:4,upgrade:5,noop:6},s=i(r),t={type:"error",data:"parser error"},u=a("blob");c.encodePacket=function(a,c,f,h){"function"==typeof c&&(h=c,c=!1),"function"==typeof f&&(h=f,f=null);var i=void 0===a.data?void 0:a.data.buffer||a.data;if(b.ArrayBuffer&&i instanceof ArrayBuffer)return e(a,c,h);if(u&&i instanceof b.Blob)return g(a,c,h);if(i&&i.base64)return d(a,h);var j=r[a.type];return void 0!==a.data&&(j+=f?n.encode(String(a.data)):String(a.data)),h(""+j)},c.encodeBase64Packet=function(a,d){var e="b"+c.packets[a.type];if(u&&a.data instanceof b.Blob){var f=new FileReader;return f.onload=function(){var a=f.result.split(",")[1];d(e+a)},f.readAsDataURL(a.data)}var g;try{g=String.fromCharCode.apply(null,new Uint8Array(a.data))}catch(h){for(var i=new Uint8Array(a.data),j=new Array(i.length),k=0;k<i.length;k++)j[k]=i[k];g=String.fromCharCode.apply(null,j)}return e+=b.btoa(g),d(e)},c.decodePacket=function(a,b,d){if("string"==typeof a||void 0===a){if("b"==a.charAt(0))return c.decodeBase64Packet(a.substr(1),b);if(d)try{a=n.decode(a)}catch(e){return t}var f=a.charAt(0);return Number(f)==f&&s[f]?a.length>1?{
type:s[f],data:a.substring(1)}:{type:s[f]}:t}var g=new Uint8Array(a),f=g[0],h=k(a,1);return u&&"blob"===b&&(h=new u([h])),{type:s[f],data:h}},c.decodeBase64Packet=function(a,c){var d=s[a.charAt(0)];if(!b.ArrayBuffer)return{type:d,data:{base64:!0,data:a.substr(1)}};var e=l.decode(a.substr(1));return"blob"===c&&u&&(e=new u([e])),{type:d,data:e}},c.encodePayload=function(a,b,d){function e(a){return a.length+":"+a}function f(a,d){c.encodePacket(a,!!g&&b,!0,function(a){d(null,e(a))})}"function"==typeof b&&(d=b,b=null);var g=j(a);return b&&g?u&&!q?c.encodePayloadAsBlob(a,d):c.encodePayloadAsArrayBuffer(a,d):a.length?void h(a,f,function(a,b){return d(b.join(""))}):d("0:")},c.decodePayload=function(a,b,d){if("string"!=typeof a)return c.decodePayloadAsBinary(a,b,d);"function"==typeof b&&(d=b,b=null);var e;if(""==a)return d(t,0,1);for(var f,g,h="",i=0,j=a.length;i<j;i++){var k=a.charAt(i);if(":"!=k)h+=k;else{if(""==h||h!=(f=Number(h)))return d(t,0,1);if(g=a.substr(i+1,f),h!=g.length)return d(t,0,1);if(g.length){if(e=c.decodePacket(g,b,!0),t.type==e.type&&t.data==e.data)return d(t,0,1);var l=d(e,i+f,j);if(!1===l)return}i+=f,h=""}}return""!=h?d(t,0,1):void 0},c.encodePayloadAsArrayBuffer=function(a,b){function d(a,b){c.encodePacket(a,!0,!0,function(a){return b(null,a)})}return a.length?void h(a,d,function(a,c){var d=c.reduce(function(a,b){var c;return c="string"==typeof b?b.length:b.byteLength,a+c.toString().length+c+2},0),e=new Uint8Array(d),f=0;return c.forEach(function(a){var b="string"==typeof a,c=a;if(b){for(var d=new Uint8Array(a.length),g=0;g<a.length;g++)d[g]=a.charCodeAt(g);c=d.buffer}b?e[f++]=0:e[f++]=1;for(var h=c.byteLength.toString(),g=0;g<h.length;g++)e[f++]=parseInt(h[g]);e[f++]=255;for(var d=new Uint8Array(c),g=0;g<d.length;g++)e[f++]=d[g]}),b(e.buffer)}):b(new ArrayBuffer(0))},c.encodePayloadAsBlob=function(a,b){function d(a,b){c.encodePacket(a,!0,!0,function(a){var c=new Uint8Array(1);if(c[0]=1,"string"==typeof a){for(var d=new Uint8Array(a.length),e=0;e<a.length;e++)d[e]=a.charCodeAt(e);a=d.buffer,c[0]=0}for(var f=a instanceof ArrayBuffer?a.byteLength:a.size,g=f.toString(),h=new Uint8Array(g.length+1),e=0;e<g.length;e++)h[e]=parseInt(g[e]);if(h[g.length]=255,u){var i=new u([c.buffer,h.buffer,a]);b(null,i)}})}h(a,d,function(a,c){return b(new u(c))})},c.decodePayloadAsBinary=function(a,b,d){"function"==typeof b&&(d=b,b=null);for(var e=a,f=[],g=!1;e.byteLength>0;){for(var h=new Uint8Array(e),i=0===h[0],j="",l=1;255!=h[l];l++){if(j.length>310){g=!0;break}j+=h[l]}if(g)return d(t,0,1);e=k(e,2+j.length),j=parseInt(j);var m=k(e,0,j);if(i)try{m=String.fromCharCode.apply(null,new Uint8Array(m))}catch(n){var o=new Uint8Array(m);m="";for(var l=0;l<o.length;l++)m+=String.fromCharCode(o[l])}f.push(m),e=k(e,j)}var p=f.length;f.forEach(function(a,e){d(c.decodePacket(a,b,!0),e,p)})}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./keys":17,after:18,"arraybuffer.slice":19,"base64-arraybuffer":20,blob:21,"has-binary":22,utf8:24}],17:[function(a,b,c){b.exports=Object.keys||function(a){var b=[],c=Object.prototype.hasOwnProperty;for(var d in a)c.call(a,d)&&b.push(d);return b}},{}],18:[function(a,b,c){function d(a,b,c){function d(a,e){if(d.count<=0)throw new Error("after called too many times");--d.count,a?(f=!0,b(a),b=c):0!==d.count||f||b(null,e)}var f=!1;return c=c||e,d.count=a,0===a?b():d}function e(){}b.exports=d},{}],19:[function(a,b,c){b.exports=function(a,b,c){var d=a.byteLength;if(b=b||0,c=c||d,a.slice)return a.slice(b,c);if(b<0&&(b+=d),c<0&&(c+=d),c>d&&(c=d),b>=d||b>=c||0===d)return new ArrayBuffer(0);for(var e=new Uint8Array(a),f=new Uint8Array(c-b),g=b,h=0;g<c;g++,h++)f[h]=e[g];return f.buffer}},{}],20:[function(a,b,c){!function(a){"use strict";c.encode=function(b){var c,d=new Uint8Array(b),e=d.length,f="";for(c=0;c<e;c+=3)f+=a[d[c]>>2],f+=a[(3&d[c])<<4|d[c+1]>>4],f+=a[(15&d[c+1])<<2|d[c+2]>>6],f+=a[63&d[c+2]];return e%3===2?f=f.substring(0,f.length-1)+"=":e%3===1&&(f=f.substring(0,f.length-2)+"=="),f},c.decode=function(b){var c,d,e,f,g,h=.75*b.length,i=b.length,j=0;"="===b[b.length-1]&&(h--,"="===b[b.length-2]&&h--);var k=new ArrayBuffer(h),l=new Uint8Array(k);for(c=0;c<i;c+=4)d=a.indexOf(b[c]),e=a.indexOf(b[c+1]),f=a.indexOf(b[c+2]),g=a.indexOf(b[c+3]),l[j++]=d<<2|e>>4,l[j++]=(15&e)<<4|f>>2,l[j++]=(3&f)<<6|63&g;return k}}("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")},{}],21:[function(a,b,c){(function(a){function c(a){for(var b=0;b<a.length;b++){var c=a[b];if(c.buffer instanceof ArrayBuffer){var d=c.buffer;if(c.byteLength!==d.byteLength){var e=new Uint8Array(c.byteLength);e.set(new Uint8Array(d,c.byteOffset,c.byteLength)),d=e.buffer}a[b]=d}}}function d(a,b){b=b||{};var d=new f;c(a);for(var e=0;e<a.length;e++)d.append(a[e]);return b.type?d.getBlob(b.type):d.getBlob()}function e(a,b){return c(a),new Blob(a,b||{})}var f=a.BlobBuilder||a.WebKitBlobBuilder||a.MSBlobBuilder||a.MozBlobBuilder,g=function(){try{var a=new Blob(["hi"]);return 2===a.size}catch(b){return!1}}(),h=g&&function(){try{var a=new Blob([new Uint8Array([1,2])]);return 2===a.size}catch(b){return!1}}(),i=f&&f.prototype.append&&f.prototype.getBlob;b.exports=function(){return g?h?a.Blob:e:i?d:void 0}()}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],22:[function(a,b,c){(function(c){function d(a){function b(a){if(!a)return!1;if(c.Buffer&&c.Buffer.isBuffer(a)||c.ArrayBuffer&&a instanceof ArrayBuffer||c.Blob&&a instanceof Blob||c.File&&a instanceof File)return!0;if(e(a)){for(var d=0;d<a.length;d++)if(b(a[d]))return!0}else if(a&&"object"==typeof a){a.toJSON&&(a=a.toJSON());for(var f in a)if(Object.prototype.hasOwnProperty.call(a,f)&&b(a[f]))return!0}return!1}return b(a)}var e=a("isarray");b.exports=d}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{isarray:23}],23:[function(a,b,c){b.exports=Array.isArray||function(a){return"[object Array]"==Object.prototype.toString.call(a)}},{}],24:[function(b,c,d){(function(b){!function(e){function f(a){for(var b,c,d=[],e=0,f=a.length;e<f;)b=a.charCodeAt(e++),b>=55296&&b<=56319&&e<f?(c=a.charCodeAt(e++),56320==(64512&c)?d.push(((1023&b)<<10)+(1023&c)+65536):(d.push(b),e--)):d.push(b);return d}function g(a){for(var b,c=a.length,d=-1,e="";++d<c;)b=a[d],b>65535&&(b-=65536,e+=u(b>>>10&1023|55296),b=56320|1023&b),e+=u(b);return e}function h(a){if(a>=55296&&a<=57343)throw Error("Lone surrogate U+"+a.toString(16).toUpperCase()+" is not a scalar value")}function i(a,b){return u(a>>b&63|128)}function j(a){if(0==(4294967168&a))return u(a);var b="";return 0==(4294965248&a)?b=u(a>>6&31|192):0==(4294901760&a)?(h(a),b=u(a>>12&15|224),b+=i(a,6)):0==(4292870144&a)&&(b=u(a>>18&7|240),b+=i(a,12),b+=i(a,6)),b+=u(63&a|128)}function k(a){for(var b,c=f(a),d=c.length,e=-1,g="";++e<d;)b=c[e],g+=j(b);return g}function l(){if(t>=s)throw Error("Invalid byte index");var a=255&r[t];if(t++,128==(192&a))return 63&a;throw Error("Invalid continuation byte")}function m(){var a,b,c,d,e;if(t>s)throw Error("Invalid byte index");if(t==s)return!1;if(a=255&r[t],t++,0==(128&a))return a;if(192==(224&a)){var b=l();if(e=(31&a)<<6|b,e>=128)return e;throw Error("Invalid continuation byte")}if(224==(240&a)){if(b=l(),c=l(),e=(15&a)<<12|b<<6|c,e>=2048)return h(e),e;throw Error("Invalid continuation byte")}if(240==(248&a)&&(b=l(),c=l(),d=l(),e=(15&a)<<18|b<<12|c<<6|d,e>=65536&&e<=1114111))return e;throw Error("Invalid UTF-8 detected")}function n(a){r=f(a),s=r.length,t=0;for(var b,c=[];(b=m())!==!1;)c.push(b);return g(c)}var o="object"==typeof d&&d,p="object"==typeof c&&c&&c.exports==o&&c,q="object"==typeof b&&b;q.global!==q&&q.window!==q||(e=q);var r,s,t,u=String.fromCharCode,v={version:"2.0.0",encode:k,decode:n};if("function"==typeof a&&"object"==typeof a.amd&&a.amd)a(function(){return v});else if(o&&!o.nodeType)if(p)p.exports=v;else{var w={},x=w.hasOwnProperty;for(var y in v)x.call(v,y)&&(o[y]=v[y])}else e.utf8=v}(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],25:[function(a,b,c){try{b.exports="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(d){b.exports=!1}},{}],26:[function(a,b,c){var d=[].indexOf;b.exports=function(a,b){if(d)return a.indexOf(b);for(var c=0;c<a.length;++c)if(a[c]===b)return c;return-1}},{}],27:[function(a,b,c){(function(a){var c=/^[\],:{}\s]*$/,d=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,e=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,f=/(?:^|:|,)(?:\s*\[)+/g,g=/^\s+/,h=/\s+$/;b.exports=function(b){return"string"==typeof b&&b?(b=b.replace(g,"").replace(h,""),a.JSON&&JSON.parse?JSON.parse(b):c.test(b.replace(d,"@").replace(e,"]").replace(f,""))?new Function("return "+b)():void 0):null}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],28:[function(a,b,c){c.encode=function(a){var b="";for(var c in a)a.hasOwnProperty(c)&&(b.length&&(b+="&"),b+=encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b},c.decode=function(a){for(var b={},c=a.split("&"),d=0,e=c.length;d<e;d++){var f=c[d].split("=");b[decodeURIComponent(f[0])]=decodeURIComponent(f[1])}return b}},{}],29:[function(a,b,c){var d=/^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,e=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];b.exports=function(a){var b=a,c=a.indexOf("["),f=a.indexOf("]");c!=-1&&f!=-1&&(a=a.substring(0,c)+a.substring(c,f).replace(/:/g,";")+a.substring(f,a.length));for(var g=d.exec(a||""),h={},i=14;i--;)h[e[i]]=g[i]||"";return c!=-1&&f!=-1&&(h.source=b,h.host=h.host.substring(1,h.host.length-1).replace(/;/g,":"),h.authority=h.authority.replace("[","").replace("]","").replace(/;/g,":"),h.ipv6uri=!0),h}},{}],30:[function(a,b,c){"use strict";function d(a){var b="";do b=h[a%i]+b,a=Math.floor(a/i);while(a>0);return b}function e(a){var b=0;for(l=0;l<a.length;l++)b=b*i+j[a.charAt(l)];return b}function f(){var a=d(+new Date);return a!==g?(k=0,g=a):a+"."+d(k++)}for(var g,h="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""),i=64,j={},k=0,l=0;l<i;l++)j[h[l]]=l;f.encode=d,f.decode=e,b.exports=f},{}],31:[function(a,b,c){},{}],32:[function(a,b,c){arguments[4][31][0].apply(c,arguments)},{dup:31}],33:[function(a,b,c){function d(){m&&k&&(m=!1,k.length?l=k.concat(l):n=-1,l.length&&e())}function e(){if(!m){var a=h(d);m=!0;for(var b=l.length;b;){for(k=l,l=[];++n<b;)k&&k[n].run();n=-1,b=l.length}k=null,m=!1,i(a)}}function f(a,b){this.fun=a,this.array=b}function g(){}var h,i,j=b.exports={};!function(){try{h=setTimeout}catch(a){h=function(){throw new Error("setTimeout is not defined")}}try{i=clearTimeout}catch(a){i=function(){throw new Error("clearTimeout is not defined")}}}();var k,l=[],m=!1,n=-1;j.nextTick=function(a){var b=new Array(arguments.length-1);if(arguments.length>1)for(var c=1;c<arguments.length;c++)b[c-1]=arguments[c];l.push(new f(a,b)),1!==l.length||m||h(e,0)},f.prototype.run=function(){this.fun.apply(null,this.array)},j.title="browser",j.browser=!0,j.env={},j.argv=[],j.version="",j.versions={},j.on=g,j.addListener=g,j.once=g,j.off=g,j.removeListener=g,j.removeAllListeners=g,j.emit=g,j.binding=function(a){throw new Error("process.binding is not supported")},j.cwd=function(){return"/"},j.chdir=function(a){throw new Error("process.chdir is not supported")},j.umask=function(){return 0}},{}],34:[function(a,b,c){function d(a,b){return new n(a,b)}var e=a("./constants/constants"),f=a("./constants/merge-strategies"),g=a("component-emitter"),h=a("./message/connection"),i=a("./event/event-handler"),j=a("./rpc/rpc-handler"),k=a("./record/record-handler"),l=a("./webrtc/webrtc-handler"),m=a("./default-options"),n=function(a,b){this._url=a,this._options=this._getOptions(b||{}),this._connection=new h(this,this._url,this._options),this.event=new i(this._options,this._connection,this),this.rpc=new j(this._options,this._connection,this),this.record=new k(this._options,this._connection,this),this.webrtc=new l(this._options,this._connection,this),this._messageCallbacks={},this._messageCallbacks[e.TOPIC.WEBRTC]=this.webrtc._$handle.bind(this.webrtc),this._messageCallbacks[e.TOPIC.EVENT]=this.event._$handle.bind(this.event),this._messageCallbacks[e.TOPIC.RPC]=this.rpc._$handle.bind(this.rpc),this._messageCallbacks[e.TOPIC.RECORD]=this.record._$handle.bind(this.record),this._messageCallbacks[e.TOPIC.ERROR]=this._onErrorMessage.bind(this)};g(n.prototype),n.prototype.login=function(a,b){return this._connection.authenticate(a||{},b),this},n.prototype.close=function(){this._connection.close()},n.prototype.getConnectionState=function(){return this._connection.getState()},n.prototype.getUid=function(){var a=(new Date).getTime().toString(36),b=(1e16*Math.random()).toString(36).replace(".","");return a+"-"+b},n.prototype._$onMessage=function(a){this._messageCallbacks[a.topic]?this._messageCallbacks[a.topic](a):(a.processedError=!0,this._$onError(a.topic,e.EVENT.MESSAGE_PARSE_ERROR,"Received message for unknown topic "+a.topic)),a.action!==e.ACTIONS.ERROR||a.processedError||this._$onError(a.topic,a.data[0],a.data.slice(0))},n.prototype._$onError=function(a,b,c){var d;if(b!==e.EVENT.ACK_TIMEOUT&&b!==e.EVENT.RESPONSE_TIMEOUT||this.getConnectionState()===e.CONNECTION_STATE.AWAITING_AUTHENTICATION&&(d="Your message timed out because you're not authenticated. Have you called login()?",setTimeout(this._$onError.bind(this,e.EVENT.NOT_AUTHENTICATED,e.TOPIC.ERROR,d),1)),!this.hasListeners("error"))throw console.log("--- You can catch all deepstream errors by subscribing to the error event ---"),d=b+": "+c,a&&(d+=" ("+a+")"),new Error(d);this.emit("error",c,b,a),this.emit(b,a,c)},n.prototype._onErrorMessage=function(a){this._$onError(a.topic,a.data[0],a.data[1])},n.prototype._getOptions=function(a){var b,c={};for(b in m)"undefined"==typeof a[b]?c[b]=m[b]:c[b]=a[b];return c},n.prototype.CONSTANTS=e,d.CONSTANTS=e,n.prototype.MERGE_STRATEGIES=f,d.MERGE_STRATEGIES=f,b.exports=d},{"./constants/constants":35,"./constants/merge-strategies":36,"./default-options":37,"./event/event-handler":38,"./message/connection":39,"./record/record-handler":45,"./rpc/rpc-handler":47,"./webrtc/webrtc-handler":57,"component-emitter":1}],35:[function(a,b,c){c.CONNECTION_STATE={},c.CONNECTION_STATE.CLOSED="CLOSED",c.CONNECTION_STATE.AWAITING_CONNECTION="AWAITING_CONNECTION",c.CONNECTION_STATE.CHALLENGING="CHALLENGING",c.CONNECTION_STATE.AWAITING_AUTHENTICATION="AWAITING_AUTHENTICATION",c.CONNECTION_STATE.AUTHENTICATING="AUTHENTICATING",c.CONNECTION_STATE.OPEN="OPEN",c.CONNECTION_STATE.ERROR="ERROR",c.CONNECTION_STATE.RECONNECTING="RECONNECTING",c.MESSAGE_SEPERATOR=String.fromCharCode(30),c.MESSAGE_PART_SEPERATOR=String.fromCharCode(31),c.TYPES={},c.TYPES.STRING="S",c.TYPES.OBJECT="O",c.TYPES.NUMBER="N",c.TYPES.NULL="L",c.TYPES.TRUE="T",c.TYPES.FALSE="F",c.TYPES.UNDEFINED="U",c.TOPIC={},c.TOPIC.CONNECTION="C",c.TOPIC.AUTH="A",c.TOPIC.ERROR="X",c.TOPIC.EVENT="E",c.TOPIC.RECORD="R",c.TOPIC.RPC="P",c.TOPIC.WEBRTC="W",c.TOPIC.PRIVATE="PRIVATE/",c.EVENT={},c.EVENT.CONNECTION_ERROR="connectionError",c.EVENT.CONNECTION_STATE_CHANGED="connectionStateChanged",c.EVENT.ACK_TIMEOUT="ACK_TIMEOUT",c.EVENT.NO_RPC_PROVIDER="NO_RPC_PROVIDER",c.EVENT.RESPONSE_TIMEOUT="RESPONSE_TIMEOUT",c.EVENT.DELETE_TIMEOUT="DELETE_TIMEOUT",c.EVENT.UNSOLICITED_MESSAGE="UNSOLICITED_MESSAGE",c.EVENT.MESSAGE_DENIED="MESSAGE_DENIED",c.EVENT.MESSAGE_PARSE_ERROR="MESSAGE_PARSE_ERROR",c.EVENT.VERSION_EXISTS="VERSION_EXISTS",c.EVENT.NOT_AUTHENTICATED="NOT_AUTHENTICATED",c.EVENT.MESSAGE_PERMISSION_ERROR="MESSAGE_PERMISSION_ERROR",c.EVENT.LISTENER_EXISTS="LISTENER_EXISTS",c.EVENT.NOT_LISTENING="NOT_LISTENING",c.EVENT.TOO_MANY_AUTH_ATTEMPTS="TOO_MANY_AUTH_ATTEMPTS",c.EVENT.IS_CLOSED="IS_CLOSED",c.EVENT.UNKNOWN_CALLEE="UNKNOWN_CALLEE",c.EVENT.RECORD_NOT_FOUND="RECORD_NOT_FOUND",c.ACTIONS={},c.ACTIONS.ACK="A",c.ACTIONS.REDIRECT="RED",c.ACTIONS.CHALLENGE="CH",c.ACTIONS.CHALLENGE_RESPONSE="CHR",c.ACTIONS.READ="R",c.ACTIONS.CREATE="C",c.ACTIONS.UPDATE="U",c.ACTIONS.PATCH="P",c.ACTIONS.DELETE="D",c.ACTIONS.SUBSCRIBE="S",c.ACTIONS.UNSUBSCRIBE="US",c.ACTIONS.HAS="H",c.ACTIONS.SNAPSHOT="SN",c.ACTIONS.INVOKE="I",c.ACTIONS.SUBSCRIPTION_FOR_PATTERN_FOUND="SP",c.ACTIONS.SUBSCRIPTION_FOR_PATTERN_REMOVED="SR",c.ACTIONS.LISTEN="L",c.ACTIONS.UNLISTEN="UL",c.ACTIONS.PROVIDER_UPDATE="PU",c.ACTIONS.QUERY="Q",c.ACTIONS.CREATEORREAD="CR",c.ACTIONS.EVENT="EVT",c.ACTIONS.ERROR="E",c.ACTIONS.REQUEST="REQ",c.ACTIONS.RESPONSE="RES",c.ACTIONS.REJECTION="REJ",c.ACTIONS.WEBRTC_REGISTER_CALLEE="RC",c.ACTIONS.WEBRTC_UNREGISTER_CALLEE="URC",c.ACTIONS.WEBRTC_OFFER="OF",c.ACTIONS.WEBRTC_ANSWER="AN",c.ACTIONS.WEBRTC_ICE_CANDIDATE="IC",c.ACTIONS.WEBRTC_CALL_DECLINED="CD",c.ACTIONS.WEBRTC_CALL_ENDED="CE",c.ACTIONS.WEBRTC_LISTEN_FOR_CALLEES="LC",c.ACTIONS.WEBRTC_UNLISTEN_FOR_CALLEES="ULC",c.ACTIONS.WEBRTC_ALL_CALLEES="WAC",c.ACTIONS.WEBRTC_CALLEE_ADDED="WCA",c.ACTIONS.WEBRTC_CALLEE_REMOVED="WCR",c.ACTIONS.WEBRTC_IS_ALIVE="WIA",c.CALL_STATE={},c.CALL_STATE.INITIAL="INITIAL",c.CALL_STATE.CONNECTING="CONNECTING",c.CALL_STATE.ESTABLISHED="ESTABLISHED",c.CALL_STATE.ACCEPTED="ACCEPTED",c.CALL_STATE.DECLINED="DECLINED",c.CALL_STATE.ENDED="ENDED",c.CALL_STATE.ERROR="ERROR"},{}],36:[function(a,b,c){b.exports={REMOTE_WINS:function(a,b,c,d){d(null,b)},LOCAL_WINS:function(a,b,c,d){d(null,a.get())}}},{}],37:[function(a,b,c){var d=a("./constants/merge-strategies");b.exports={recordPersistDefault:!0,reconnectIntervalIncrement:4e3,maxReconnectAttempts:5,rpcAckTimeout:6e3,rpcResponseTimeout:1e4,subscriptionTimeout:2e3,maxMessagesPerPacket:100,timeBetweenSendingQueuedPackages:16,recordReadAckTimeout:1e3,recordReadTimeout:3e3,recordDeleteTimeout:3e3,calleeAckTimeout:3e3,rtcPeerConnectionConfig:{iceServers:[{url:"stun:stun.services.mozilla.com"},{url:"stun:stun.l.google.com:19302"}]},agent:!1,upgrade:!0,forceJSONP:!1,jsonp:!0,forceBase64:!1,enablesXDR:!1,timestampRequests:!1,timestampParam:"t",policyPort:843,path:"/deepstream",transports:["polling","websocket"],rememberUpgrade:!1,mergeStrategy:d.REMOTE_WINS}},{"./constants/merge-strategies":36}],38:[function(a,b,c){var d=a("../message/message-builder"),e=a("../message/message-parser"),f=a("../utils/ack-timeout-registry"),g=a("../utils/resubscribe-notifier"),h=a("../constants/constants"),i=a("../utils/listener"),j=a("component-emitter"),k=function(a,b,c){this._options=a,this._connection=b,this._client=c,this._emitter=new j,this._listener={},this._ackTimeoutRegistry=new f(c,h.TOPIC.EVENT,this._options.subscriptionTimeout),this._resubscribeNotifier=new g(this._client,this._resubscribe.bind(this))};k.prototype.subscribe=function(a,b){this._emitter.hasListeners(a)||(this._ackTimeoutRegistry.add(a,h.ACTIONS.SUBSCRIBE),this._connection.sendMsg(h.TOPIC.EVENT,h.ACTIONS.SUBSCRIBE,[a])),this._emitter.on(a,b)},k.prototype.unsubscribe=function(a,b){this._emitter.off(a,b),this._emitter.hasListeners(a)||(this._ackTimeoutRegistry.add(a,h.ACTIONS.UNSUBSCRIBE),this._connection.sendMsg(h.TOPIC.EVENT,h.ACTIONS.UNSUBSCRIBE,[a]))},k.prototype.emit=function(a,b){this._connection.sendMsg(h.TOPIC.EVENT,h.ACTIONS.EVENT,[a,d.typed(b)]),this._emitter.emit(a,b)},k.prototype.listen=function(a,b){this._listener[a]?this._client._$onError(h.TOPIC.EVENT,h.EVENT.LISTENER_EXISTS,a):this._listener[a]=new i(h.TOPIC.EVENT,a,b,this._options,this._client,this._connection)},k.prototype.unlisten=function(a){this._listener[a]?(this._ackTimeoutRegistry.add(a,h.EVENT.UNLISTEN),this._listener[a].destroy(),delete this._listener[a]):this._client._$onError(h.TOPIC.EVENT,h.EVENT.NOT_LISTENING,a)},k.prototype._$handle=function(a){var b=a.data[a.action===h.ACTIONS.ACK?1:0];return a.action===h.ACTIONS.EVENT?void(a.data&&2===a.data.length?this._emitter.emit(b,e.convertTyped(a.data[1],this._client)):this._emitter.emit(b)):this._listener[b]?void this._listener[b]._$onMessage(a):a.action===h.ACTIONS.ACK?void this._ackTimeoutRegistry.clear(a):a.action===h.ACTIONS.ERROR?(a.processedError=!0,void this._client._$onError(h.TOPIC.EVENT,a.data[0],a.data[1])):void this._client._$onError(h.TOPIC.EVENT,h.EVENT.UNSOLICITED_MESSAGE,b)},k.prototype._resubscribe=function(){var a=this._emitter._callbacks;for(var b in a)this._connection.sendMsg(h.TOPIC.EVENT,h.ACTIONS.SUBSCRIBE,[b])},b.exports=k},{"../constants/constants":35,"../message/message-builder":40,"../message/message-parser":41,"../utils/ack-timeout-registry":50,"../utils/listener":51,"../utils/resubscribe-notifier":52,"component-emitter":1}],39:[function(a,b,c){var d=a("engine.io-client"),e=a("./message-parser"),f=a("./message-builder"),g=a("../tcp/tcp-connection"),h=a("../utils/utils"),i=a("../constants/constants"),j=function(a,b,c){this._client=a,this._originalUrl=b,this._url=b,this._options=c,this._authParams=null,this._authCallback=null,this._deliberateClose=!1,this._redirecting=!1,this._tooManyAuthAttempts=!1,this._challengeDenied=!1,this._queuedMessages=[],this._reconnectTimeout=null,this._reconnectionAttempt=0,this._currentPacketMessageCount=0,this._sendNextPacketTimeout=null,this._currentMessageResetTimeout=null,this._endpoint=null,this._state=i.CONNECTION_STATE.CLOSED,this._createEndpoint()};j.prototype.getState=function(){return this._state},j.prototype.authenticate=function(a,b){return this._authParams=a,this._authCallback=b,this._tooManyAuthAttempts||this._challengeDenied?void this._client._$onError(i.TOPIC.ERROR,i.EVENT.IS_CLOSED,"this client's connection was closed"):this._deliberateClose===!0&&this._state===i.CONNECTION_STATE.CLOSED?(this._createEndpoint(),void(this._deliberateClose=!1)):void(this._state===i.CONNECTION_STATE.AWAITING_AUTHENTICATION&&this._sendAuthParams())},j.prototype.sendMsg=function(a,b,c){this.send(f.getMsg(a,b,c))},j.prototype.send=function(a){this._queuedMessages.push(a),this._currentPacketMessageCount++,null===this._currentMessageResetTimeout&&(this._currentMessageResetTimeout=h.nextTick(this._resetCurrentMessageCount.bind(this))),this._state===i.CONNECTION_STATE.OPEN&&this._queuedMessages.length<this._options.maxMessagesPerPacket&&this._currentPacketMessageCount<this._options.maxMessagesPerPacket?this._sendQueuedMessages():null===this._sendNextPacketTimeout&&this._queueNextPacket()},j.prototype.close=function(){this._deliberateClose=!0,this._endpoint.close()},j.prototype._createEndpoint=function(){h.isNode?this._endpoint=new g(this._url):this._endpoint=d(this._url,this._options),this._endpoint.on("open",this._onOpen.bind(this)),this._endpoint.on("error",this._onError.bind(this)),this._endpoint.on("close",this._onClose.bind(this)),this._endpoint.on("message",this._onMessage.bind(this))},j.prototype._resetCurrentMessageCount=function(){this._currentPacketMessageCount=0,this._currentMessageResetTimeout=null},j.prototype._sendQueuedMessages=function(){if(this._state===i.CONNECTION_STATE.OPEN){if(0===this._queuedMessages.length)return void(this._sendNextPacketTimeout=null);var a=this._queuedMessages.splice(0,this._options.maxMessagesPerPacket).join("");0!==this._queuedMessages.length?this._queueNextPacket():this._sendNextPacketTimeout=null,this._endpoint.send(a)}},j.prototype._queueNextPacket=function(){var a=this._sendQueuedMessages.bind(this),b=this._options.timeBetweenSendingQueuedPackages;this._sendNextPacketTimeout=setTimeout(a,b)},j.prototype._sendAuthParams=function(){this._setState(i.CONNECTION_STATE.AUTHENTICATING);var a=f.getMsg(i.TOPIC.AUTH,i.ACTIONS.REQUEST,[this._authParams]);this._endpoint.send(a)},j.prototype._onOpen=function(){this._clearReconnect(),this._setState(i.CONNECTION_STATE.AWAITING_CONNECTION)},j.prototype._onError=function(a){this._setState(i.CONNECTION_STATE.ERROR),setTimeout(function(){this._client._$onError(null,i.EVENT.CONNECTION_ERROR,a.toString())}.bind(this),1)},j.prototype._onClose=function(){this._redirecting===!0?(this._redirecting=!1,this._createEndpoint()):this._deliberateClose===!0?this._setState(i.CONNECTION_STATE.CLOSED):(this._originalUrl!==this._url&&(this._url=this._originalUrl,this._createEndpoint()),this._tryReconnect())},j.prototype._onMessage=function(a){var b,c=e.parse(a,this._client);for(b=0;b<c.length;b++)null!==c[b]&&(c[b].topic===i.TOPIC.CONNECTION?this._handleConnectionResponse(c[b]):c[b].topic===i.TOPIC.AUTH?this._handleAuthResponse(c[b]):this._client._$onMessage(c[b]))},j.prototype._handleConnectionResponse=function(a){a.action===i.ACTIONS.ACK?(this._setState(i.CONNECTION_STATE.AWAITING_AUTHENTICATION),this._authParams&&this._sendAuthParams()):a.action===i.ACTIONS.CHALLENGE?(this._setState(i.CONNECTION_STATE.CHALLENGING),this._endpoint.send(f.getMsg(i.TOPIC.CONNECTION,i.ACTIONS.CHALLENGE_RESPONSE,[this._originalUrl]))):a.action===i.ACTIONS.REJECTION?(this._challengeDenied=!0,this.close()):a.action===i.ACTIONS.REDIRECT&&(this._url=a.data[0],this._redirecting=!0,this._endpoint.close())},j.prototype._handleAuthResponse=function(a){a.action===i.ACTIONS.ERROR?(a.data[0]===i.EVENT.TOO_MANY_AUTH_ATTEMPTS?(this._deliberateClose=!0,this._tooManyAuthAttempts=!0):this._setState(i.CONNECTION_STATE.AWAITING_AUTHENTICATION),this._authCallback&&this._authCallback(!1,this._getAuthData(a.data[1]))):a.action===i.ACTIONS.ACK&&(this._setState(i.CONNECTION_STATE.OPEN),this._authCallback&&this._authCallback(!0,this._getAuthData(a.data[0])),this._sendQueuedMessages())},j.prototype._getAuthData=function(a){return void 0===a?null:e.convertTyped(a,this._client)},j.prototype._setState=function(a){this._state=a,this._client.emit(i.EVENT.CONNECTION_STATE_CHANGED,a)},j.prototype._tryReconnect=function(){null===this._reconnectTimeout&&(this._reconnectionAttempt<this._options.maxReconnectAttempts?(this._setState(i.CONNECTION_STATE.RECONNECTING),this._reconnectTimeout=setTimeout(this._tryOpen.bind(this),this._options.reconnectIntervalIncrement*this._reconnectionAttempt),this._reconnectionAttempt++):(this._clearReconnect(),this.close()))},j.prototype._tryOpen=function(){this._endpoint.open(),this._reconnectTimeout=null},j.prototype._clearReconnect=function(){clearTimeout(this._reconnectTimeout),this._reconnectTimeout=null,this._reconnectionAttempt=0},b.exports=j},{"../constants/constants":35,"../tcp/tcp-connection":31,"../utils/utils":54,"./message-builder":40,"./message-parser":41,"engine.io-client":2}],40:[function(a,b,c){var d=a("../constants/constants"),e=d.MESSAGE_PART_SEPERATOR;c.getMsg=function(a,b,c){if(c&&!(c instanceof Array))throw new Error("data must be an array");var f,g=[a,b];if(c)for(f=0;f<c.length;f++)"object"==typeof c[f]?g.push(JSON.stringify(c[f])):g.push(c[f]);return g.join(e)+d.MESSAGE_SEPERATOR},c.typed=function(a){var b=typeof a;if("string"===b)return d.TYPES.STRING+a;if(null===a)return d.TYPES.NULL;if("object"===b)return d.TYPES.OBJECT+JSON.stringify(a);if("number"===b)return d.TYPES.NUMBER+a.toString();if(a===!0)return d.TYPES.TRUE;if(a===!1)return d.TYPES.FALSE;if(void 0===a)return d.TYPES.UNDEFINED;throw new Error("Can't serialize type "+a)}},{"../constants/constants":35}],41:[function(a,b,c){var d=a("../constants/constants"),e=function(){this._actions=this._getActions()};e.prototype.parse=function(a,b){var c,e=[],f=a.split(d.MESSAGE_SEPERATOR);for(c=0;c<f.length;c++)f[c].length>2&&e.push(this._parseMessage(f[c],b));return e},e.prototype.convertTyped=function(a,b){var c=a.charAt(0);if(c===d.TYPES.STRING)return a.substr(1);if(c===d.TYPES.OBJECT)try{return JSON.parse(a.substr(1))}catch(e){return void b._$onError(d.TOPIC.ERROR,d.EVENT.MESSAGE_PARSE_ERROR,e.toString()+"("+a+")")}return c===d.TYPES.NUMBER?parseFloat(a.substr(1)):c===d.TYPES.NULL?null:c===d.TYPES.TRUE||c!==d.TYPES.FALSE&&void(c!==d.TYPES.UNDEFINED&&b._$onError(d.TOPIC.ERROR,d.EVENT.MESSAGE_PARSE_ERROR,"UNKNOWN_TYPE ("+a+")"))},e.prototype._getActions=function(){var a,b={};for(a in d.ACTIONS)b[d.ACTIONS[a]]=a;return b},e.prototype._parseMessage=function(a,b){var c=a.split(d.MESSAGE_PART_SEPERATOR),e={};return c.length<2?(a.processedError=!0,b._$onError(d.TOPIC.ERROR,d.EVENT.MESSAGE_PARSE_ERROR,"Insufficiant message parts"),null):void 0===this._actions[c[1]]?(a.processedError=!0,b._$onError(d.TOPIC.ERROR,d.EVENT.MESSAGE_PARSE_ERROR,"Unknown action "+c[1]),null):(e.raw=a,e.topic=c[0],e.action=c[1],e.data=c.splice(2),e)},b.exports=new e},{"../constants/constants":35}],42:[function(a,b,c){var d=a("./record"),e=a("component-emitter"),f=function(a){this.name=null,this._recordHandler=a,this._record=null,this._subscriptions=[],this._proxyMethod("delete"),this._proxyMethod("set"),this._proxyMethod("unsubscribe"),this._proxyMethod("discard")};e(f.prototype),f.prototype.get=function(a){if(null!==this._record)return this._record.get(a)},f.prototype.subscribe=function(){var a=d.prototype._normalizeArguments(arguments);a.triggerNow=!0,this._subscriptions.push(a),null!==this._record&&this._record.subscribe(a)},f.prototype.unsubscribe=function(){var a,b=d.prototype._normalizeArguments(arguments),c=[];for(a=0;a<this._subscriptions.length;a++)this._subscriptions[a].path===b.path&&this._subscriptions[a].callback===b.callback||c.push(this._subscriptions[a]);this._subscriptions=c,null!==this._record&&this._record.unsubscribe(b)},f.prototype.setName=function(a){this.name=a;var b;if(null!==this._record&&!this._record.isDestroyed){for(b=0;b<this._subscriptions.length;b++)this._record.unsubscribe(this._subscriptions[b]);this._record.discard()}for(this._record=this._recordHandler.getRecord(a),b=0;b<this._subscriptions.length;b++)this._record.subscribe(this._subscriptions[b]);this._record.whenReady(this.emit.bind(this,"ready")),this.emit("nameChanged",a)},f.prototype._proxyMethod=function(a){this[a]=this._callMethodOnRecord.bind(this,a)},f.prototype._callMethodOnRecord=function(a){if(null===this._record)throw new Error("Can`t invoke "+a+". AnonymousRecord not initialised. Call setName first");if("function"!=typeof this._record[a])throw new Error(a+" is not a method on the record");var b=Array.prototype.slice.call(arguments,1);return this._record[a].apply(this._record,b)},b.exports=f},{"./record":46,"component-emitter":1}],43:[function(a,b,c){var d=a("../utils/utils"),e=/[\.\[\]]/g,f="*",g=function(a,b){this._record=a,this._path=String(b),this._tokens=[],this._tokenize()};g.prototype.getValue=function(){var a,b=this._record._$data;for(a=0;a<this._tokens.length;a++){if(void 0===b[this._tokens[a]])return;b=b[this._tokens[a]]}return b},g.prototype.setValue=function(a){var b,c=this._record._$data;for(b=0;b<this._tokens.length-1;b++)c=void 0!==c[this._tokens[b]]?c[this._tokens[b]]:this._tokens[b+1]&&!isNaN(this._tokens[b+1])?c[this._tokens[b]]=[]:c[this._tokens[b]]={};c[this._tokens[b]]=a},g.prototype._tokenize=function(){var a,b,c=this._path.split(e);for(b=0;b<c.length;b++)a=d.trim(c[b]),0!==a.length&&(isNaN(a)?a!==f?this._tokens.push(a):this._tokens.push(!0):this._tokens.push(parseInt(a,10)))},b.exports=g},{"../utils/utils":54}],44:[function(a,b,c){var d=a("component-emitter"),e=a("./record"),f=a("../constants/constants"),g="entry-added",h="entry-removed",i="entry-moved",j=function(a,b,c){this._recordHandler=a,this._record=this._recordHandler.getRecord(b,c),this._record._applyUpdate=this._applyUpdate.bind(this),this._record.on("delete",this.emit.bind(this,"delete")),this._record.on("discard",this._onDiscard.bind(this)),this._record.on("ready",this._onReady.bind(this)),this.isDestroyed=this._record.isDestroyed,this.isReady=this._record.isReady,this.name=b,this._queuedMethods=[],this._beforeStructure=null,this._hasAddListener=null,this._hasRemoveListener=null,this._hasMoveListener=null,this["delete"]=this._record["delete"].bind(this._record),this.discard=this._record.discard.bind(this._record),this.whenReady=this._record.whenReady.bind(this)};d(j.prototype),j.prototype.getEntries=function(){
var a=this._record.get();return a instanceof Array?a:[]},j.prototype.isEmpty=function(){return 0===this.getEntries().length},j.prototype.setEntries=function(a){var b,c="entries must be an array of record names";if(!(a instanceof Array))throw new Error(c);for(b=0;b<a.length;b++)if("string"!=typeof a[b])throw new Error(c);this._record.isReady===!1?this._queuedMethods.push(this.setEntries.bind(this,a)):(this._beforeChange(),this._record.set(a),this._afterChange())},j.prototype.removeEntry=function(a,b){if(this._record.isReady===!1)return void this._queuedMethods.push(this.removeEntry.bind(this,a));var c,d=this._record.get(),e=this._hasIndex(b),f=[];for(c=0;c<d.length;c++)(d[c]!==a||e&&b!==c)&&f.push(d[c]);this._beforeChange(),this._record.set(f),this._afterChange()},j.prototype.addEntry=function(a,b){if("string"!=typeof a)throw new Error("Entry must be a recordName");if(this._record.isReady===!1)return void this._queuedMethods.push(this.addEntry.bind(this,a));var c=this._hasIndex(b),d=this.getEntries();c?d.splice(b,0,a):d.push(a),this._beforeChange(),this._record.set(d),this._afterChange()},j.prototype.subscribe=function(){var a=e.prototype._normalizeArguments(arguments);if(a.path)throw new Error("path is not supported for List.subscribe");a.callback=function(a){a(this.getEntries())}.bind(this,a.callback),this._record.subscribe(a)},j.prototype.unsubscribe=function(){var a=e.prototype._normalizeArguments(arguments);if(a.path)throw new Error("path is not supported for List.unsubscribe");this._record.unsubscribe(a)},j.prototype._onReady=function(){this.isReady=!0;for(var a=0;a<this._queuedMethods.length;a++)this._queuedMethods[a]();this.emit("ready")},j.prototype._onDiscard=function(){this.isDestroyed=!0,this.emit("discard")},j.prototype._applyUpdate=function(a){if(a.action===f.ACTIONS.PATCH)throw new Error("PATCH is not supported for Lists");"["!==a.data[2].charAt(0)&&(a.data[2]="[]"),this._beforeChange(),e.prototype._applyUpdate.call(this._record,a),this._afterChange()},j.prototype._hasIndex=function(a){var b=!1,c=this.getEntries();if(void 0!==a){if(isNaN(a))throw new Error("Index must be a number");if(a!==c.length&&(a>=c.length||a<0))throw new Error("Index must be within current entries");b=!0}return b},j.prototype._beforeChange=function(){this._hasAddListener=this.listeners(g).length>0,this._hasRemoveListener=this.listeners(h).length>0,this._hasMoveListener=this.listeners(i).length>0,this._hasAddListener||this._hasRemoveListener||this._hasMoveListener?this._beforeStructure=this._getStructure():this._beforeStructure=null},j.prototype._afterChange=function(){if(null!==this._beforeStructure){var a,b,c=this._getStructure(),d=this._beforeStructure;if(this._hasRemoveListener)for(a in d)for(b=0;b<d[a].length;b++)void 0!==c[a]&&void 0!==c[a][b]||this.emit(h,a,d[a][b]);if(this._hasAddListener||this._hasMoveListener)for(a in c)if(void 0===d[a])for(b=0;b<c[a].length;b++)this.emit(g,a,c[a][b]);else for(b=0;b<c[a].length;b++)d[a][b]!==c[a][b]&&(void 0===d[a][b]?this.emit(g,a,c[a][b]):this.emit(i,a,c[a][b]))}},j.prototype._getStructure=function(){var a,b={},c=this._record.get();for(a=0;a<c.length;a++)void 0===b[c[a]]?b[c[a]]=[a]:b[c[a]].push(a);return b},b.exports=j},{"../constants/constants":35,"./record":46,"component-emitter":1}],45:[function(a,b,c){var d=a("./record"),e=a("./anonymous-record"),f=a("./list"),g=a("../utils/listener"),h=a("../utils/single-notifier"),i=a("../constants/constants"),j=a("../message/message-parser"),k=a("component-emitter"),l=function(a,b,c){this._options=a,this._connection=b,this._client=c,this._records={},this._lists={},this._listener={},this._destroyEventEmitter=new k,this._hasRegistry=new h(c,b,i.TOPIC.RECORD,i.ACTIONS.HAS,this._options.recordReadTimeout),this._snapshotRegistry=new h(c,b,i.TOPIC.RECORD,i.ACTIONS.SNAPSHOT,this._options.recordReadTimeout)};l.prototype.getRecord=function(a,b){return this._records[a]||(this._records[a]=new d(a,b||{},this._connection,this._options,this._client),this._records[a].on("error",this._onRecordError.bind(this,a)),this._records[a].on("destroyPending",this._onDestroyPending.bind(this,a)),this._records[a].on("delete",this._removeRecord.bind(this,a)),this._records[a].on("discard",this._removeRecord.bind(this,a))),this._records[a].usages++,this._records[a]},l.prototype.getList=function(a,b){return this._lists[a]?this._records[a].usages++:this._lists[a]=new f(this,a,b),this._lists[a]},l.prototype.getAnonymousRecord=function(){return new e(this)},l.prototype.listen=function(a,b){this._listener[a]?this._client._$onError(i.TOPIC.RECORD,i.EVENT.LISTENER_EXISTS,a):this._listener[a]=new g(i.TOPIC.RECORD,a,b,this._options,this._client,this._connection)},l.prototype.unlisten=function(a){this._listener[a]?(this._listener[a].destroy(),delete this._listener[a]):this._client._$onError(i.TOPIC.RECORD,i.EVENT.NOT_LISTENING,a)},l.prototype.snapshot=function(a,b){this._records[a]?b(null,this._records[a].get()):this._snapshotRegistry.request(a,b)},l.prototype.has=function(a,b){this._records[a]?b(null,!0):this._hasRegistry.request(a,b)},l.prototype._$handle=function(a){var b;if(a.action===i.ACTIONS.ERROR&&a.data[0]!==i.EVENT.VERSION_EXISTS&&a.data[0]!==i.ACTIONS.SNAPSHOT&&a.data[0]!==i.ACTIONS.HAS&&a.data[0]!==i.EVENT.MESSAGE_DENIED)return a.processedError=!0,void this._client._$onError(i.TOPIC.RECORD,a.data[0],a.data[1]);if(a.action===i.ACTIONS.ACK||a.action===i.ACTIONS.ERROR){if(b=a.data[1],a.data[0]===i.ACTIONS.DELETE||a.data[0]===i.ACTIONS.UNSUBSCRIBE||a.data[0]===i.EVENT.MESSAGE_DENIED&&a.data[2]===i.ACTIONS.DELETE)return this._destroyEventEmitter.emit("destroy_ack_"+b,a),void(a.data[0]===i.ACTIONS.DELETE&&this._records[b]&&this._records[b]._$onMessage(a));if(a.data[0]===i.ACTIONS.SNAPSHOT)return a.processedError=!0,void this._snapshotRegistry.recieve(b,a.data[2]);if(a.data[0]===i.ACTIONS.HAS)return a.processedError=!0,void this._snapshotRegistry.recieve(b,a.data[2])}else b=a.data[0];var c=!1;this._records[b]&&(c=!0,this._records[b]._$onMessage(a)),a.action===i.ACTIONS.READ&&this._snapshotRegistry.hasRequest(b)&&(c=!0,this._snapshotRegistry.recieve(b,null,JSON.parse(a.data[2]))),a.action===i.ACTIONS.HAS&&this._hasRegistry.hasRequest(b)&&(c=!0,this._hasRegistry.recieve(b,null,j.convertTyped(a.data[1]))),this._listener[b]&&(c=!0,this._listener[b]._$onMessage(a)),c||this._client._$onError(i.TOPIC.RECORD,i.EVENT.UNSOLICITED_MESSAGE,b)},l.prototype._onRecordError=function(a,b){this._client._$onError(i.TOPIC.RECORD,b,a)},l.prototype._onDestroyPending=function(a){var b=this._records[a]._$onMessage.bind(this._records[a]);this._destroyEventEmitter.once("destroy_ack_"+a,b),this._removeRecord(a)},l.prototype._removeRecord=function(a){delete this._records[a],delete this._lists[a]},b.exports=l},{"../constants/constants":35,"../message/message-parser":41,"../utils/listener":51,"../utils/single-notifier":53,"./anonymous-record":42,"./list":44,"./record":46,"component-emitter":1}],46:[function(a,b,c){var d=a("./json-path"),e=a("../utils/utils"),f=a("../utils/resubscribe-notifier"),g=a("component-emitter"),h=a("../constants/constants"),i=a("../message/message-builder"),j=a("../message/message-parser"),k="ALL_EVENT",l=function(a,b,c,d,e){this.name=a,this.usages=0,this._recordOptions=b,this._connection=c,this._client=e,this._options=d,this.isReady=!1,this.isDestroyed=!1,this._$data={},this.version=null,this._paths={},this._oldValue=null,this._oldPathValues=null,this._eventEmitter=new g,this._queuedMethodCalls=[],this._mergeStrategy=null,d.mergeStrategy&&this.setMergeStrategy(d.mergeStrategy),this._resubscribeNotifier=new f(this._client,this._sendRead.bind(this)),this._readAckTimeout=setTimeout(this._onTimeout.bind(this,h.EVENT.ACK_TIMEOUT),this._options.recordReadAckTimeout),this._readTimeout=setTimeout(this._onTimeout.bind(this,h.EVENT.RESPONSE_TIMEOUT),this._options.recordReadTimeout),this._sendRead()};g(l.prototype),l.prototype.setMergeStrategy=function(a){if("function"!=typeof a)throw new Error("Invalid merge strategy: Must be a Function");this._mergeStrategy=a},l.prototype.get=function(a){var b;return b=a?this._getPath(a).getValue():this._$data,e.deepCopy(b)},l.prototype.set=function(a,b){if(1===arguments.length&&"object"!=typeof a)throw new Error("Invalid record data "+a+": Record data must be an object");return this._checkDestroyed("set")?this:this.isReady?2===arguments.length&&e.deepEquals(this._getPath(a).getValue(),b)?this:1===arguments.length&&e.deepEquals(this._$data,a)?this:(this._beginChange(),this.version++,1===arguments.length?(this._$data="object"==typeof a?e.deepCopy(a):a,this._connection.sendMsg(h.TOPIC.RECORD,h.ACTIONS.UPDATE,[this.name,this.version,this._$data])):(this._getPath(a).setValue("object"==typeof b?e.deepCopy(b):b),this._connection.sendMsg(h.TOPIC.RECORD,h.ACTIONS.PATCH,[this.name,this.version,a,i.typed(b)])),this._completeChange(),this):(this._queuedMethodCalls.push({method:"set",args:arguments}),this)},l.prototype.subscribe=function(a,b,c){var d=this._normalizeArguments(arguments);this._checkDestroyed("subscribe")||(this._eventEmitter.on(d.path||k,d.callback),d.triggerNow&&this.isReady&&(d.path?d.callback(this._getPath(d.path).getValue()):d.callback(this._$data)))},l.prototype.unsubscribe=function(a,b){if(!this._checkDestroyed("unsubscribe")){var c=2===arguments.length?a:k;this._eventEmitter.off(c,b)}},l.prototype.discard=function(){this.usages--,this.usages<=0&&this.whenReady(function(){this.emit("destroyPending"),this._discardTimeout=setTimeout(this._onTimeout.bind(this,h.EVENT.ACK_TIMEOUT),this._options.subscriptionTimeout),this._connection.sendMsg(h.TOPIC.RECORD,h.ACTIONS.UNSUBSCRIBE,[this.name])}.bind(this))},l.prototype["delete"]=function(){this._checkDestroyed("delete")||this.whenReady(function(){this.emit("destroyPending"),this._deleteAckTimeout=setTimeout(this._onTimeout.bind(this,h.EVENT.DELETE_TIMEOUT),this._options.recordDeleteTimeout),this._connection.sendMsg(h.TOPIC.RECORD,h.ACTIONS.DELETE,[this.name])}.bind(this))},l.prototype.whenReady=function(a){this.isReady===!0?a(this):this.once("ready",a.bind(this,this))},l.prototype._$onMessage=function(a){a.action===h.ACTIONS.READ?null===this.version?(clearTimeout(this._readTimeout),this._onRead(a)):this._applyUpdate(a,this._client):a.action===h.ACTIONS.ACK?this._processAckMessage(a):a.action===h.ACTIONS.UPDATE||a.action===h.ACTIONS.PATCH?this._applyUpdate(a,this._client):a.data[0]===h.EVENT.VERSION_EXISTS?this._recoverRecord(a.data[2],JSON.parse(a.data[3]),a):a.data[0]===h.EVENT.MESSAGE_DENIED&&(clearInterval(this._readAckTimeout),clearInterval(this._readTimeout))},l.prototype._recoverRecord=function(a,b,c){c.processedError=!0,this._mergeStrategy?this._mergeStrategy(this,b,a,this._onRecordRecovered.bind(this,a)):this.emit("error",h.EVENT.VERSION_EXISTS,"received update for "+a+" but version is "+this.version)},l.prototype._onRecordRecovered=function(a,b,c){b?this.emit("error",h.EVENT.VERSION_EXISTS,"received update for "+a+" but version is "+this.version):(this.version=a,this.set(c))},l.prototype._processAckMessage=function(a){var b=a.data[0];b===h.ACTIONS.SUBSCRIBE?clearTimeout(this._readAckTimeout):b===h.ACTIONS.DELETE?(this.emit("delete"),this._destroy()):b===h.ACTIONS.UNSUBSCRIBE&&(this.emit("discard"),this._destroy())},l.prototype._applyUpdate=function(a){var b,c=parseInt(a.data[1],10);if(b=a.action===h.ACTIONS.PATCH?j.convertTyped(a.data[3],this._client):JSON.parse(a.data[2]),null===this.version)this.version=c;else if(this.version+1!==c)return void(a.action===h.ACTIONS.PATCH?this._connection.sendMsg(h.TOPIC.RECORD,h.ACTIONS.SNAPSHOT,[this.name]):this._recoverRecord(c,b,a));this._beginChange(),this.version=c,a.action===h.ACTIONS.PATCH?this._getPath(a.data[2]).setValue(b):this._$data=b,this._completeChange()},l.prototype._onRead=function(a){this._beginChange(),this.version=parseInt(a.data[1],10),this._$data=JSON.parse(a.data[2]),this._completeChange(),this._setReady()},l.prototype._setReady=function(){this.isReady=!0;for(var a=0;a<this._queuedMethodCalls.length;a++)this[this._queuedMethodCalls[a].method].apply(this,this._queuedMethodCalls[a].args);this._queuedMethodCalls=[],this.emit("ready")},l.prototype._sendRead=function(){this._connection.sendMsg(h.TOPIC.RECORD,h.ACTIONS.CREATEORREAD,[this.name])},l.prototype._getPath=function(a){return this._paths[a]||(this._paths[a]=new d(this,a)),this._paths[a]},l.prototype._beginChange=function(){if(this._eventEmitter._callbacks){var a,b=Object.keys(this._eventEmitter._callbacks);for(this._oldPathValues={},this._eventEmitter.hasListeners(k)&&(this._oldValue=this.get()),a=0;a<b.length;a++)b[a]!==k&&(this._oldPathValues[b[a]]=this._getPath(b[a]).getValue())}},l.prototype._completeChange=function(){if(this._eventEmitter.hasListeners(k)&&!e.deepEquals(this._oldValue,this._$data)&&this._eventEmitter.emit(k,this.get()),this._oldValue=null,null!==this._oldPathValues){var a,b;for(a in this._oldPathValues)b=this._getPath(a).getValue(),b!==this._oldPathValues[a]&&this._eventEmitter.emit(a,b);this._oldPathValues=null}},l.prototype._normalizeArguments=function(a){var b,c={};if(1===a.length&&"object"==typeof a[0])return a[0];for(b=0;b<a.length;b++)"string"==typeof a[b]?c.path=a[b]:"function"==typeof a[b]?c.callback=a[b]:"boolean"==typeof a[b]&&(c.triggerNow=a[b]);return c},l.prototype._clearTimeouts=function(){clearTimeout(this._readAckTimeout),clearTimeout(this._deleteAckTimeout),clearTimeout(this._discardTimeout)},l.prototype._checkDestroyed=function(a){return!!this.isDestroyed&&(this.emit("error","Can't invoke '"+a+"'. Record '"+this.name+"' is already destroyed"),!0)},l.prototype._onTimeout=function(a){this._clearTimeouts(),this.emit("error",a)},l.prototype._destroy=function(){this._clearTimeouts(),this._eventEmitter.off(),this._resubscribeNotifier.destroy(),this.isDestroyed=!0,this.isReady=!1,this._client=null,this._eventEmitter=null,this._connection=null},b.exports=l},{"../constants/constants":35,"../message/message-builder":40,"../message/message-parser":41,"../utils/resubscribe-notifier":52,"../utils/utils":54,"./json-path":43,"component-emitter":1}],47:[function(a,b,c){var d=a("../constants/constants"),e=a("../utils/ack-timeout-registry"),f=a("../utils/resubscribe-notifier"),g=a("./rpc-response"),h=a("./rpc"),i=a("../message/message-parser"),j=a("../message/message-builder"),k=function(a,b,c){this._options=a,this._connection=b,this._client=c,this._rpcs={},this._providers={},this._provideAckTimeouts={},this._ackTimeoutRegistry=new e(c,d.TOPIC.RPC,this._options.subscriptionTimeout),this._resubscribeNotifier=new f(this._client,this._reprovide.bind(this))};k.prototype.provide=function(a,b){if(this._providers[a])throw new Error("RPC "+a+" already registered");this._ackTimeoutRegistry.add(a,d.ACTIONS.SUBSCRIBE),this._providers[a]=b,this._connection.sendMsg(d.TOPIC.RPC,d.ACTIONS.SUBSCRIBE,[a])},k.prototype.unprovide=function(a){this._providers[a]&&(delete this._providers[a],this._ackTimeoutRegistry.add(a,d.ACTIONS.UNSUBSCRIBE),this._connection.sendMsg(d.TOPIC.RPC,d.ACTIONS.UNSUBSCRIBE,[a]))},k.prototype.make=function(a,b,c){var e=this._client.getUid(),f=j.typed(b);this._rpcs[e]=new h(this._options,c,this._client),this._connection.sendMsg(d.TOPIC.RPC,d.ACTIONS.REQUEST,[a,e,f])},k.prototype._getRpc=function(a,b,c){var e=this._rpcs[a];return e?e:(this._client._$onError(d.TOPIC.RPC,d.EVENT.UNSOLICITED_MESSAGE,c),null)},k.prototype._respondToRpc=function(a){var b,c=a.data[0],e=a.data[1],f=null;a.data[2]&&(f=i.convertTyped(a.data[2],this._client)),this._providers[c]?(b=new g(this._connection,c,e),this._providers[c](f,b)):this._connection.sendMsg(d.TOPIC.RPC,d.ACTIONS.REJECTION,[c,e])},k.prototype._$handle=function(a){var b,c,e;if(a.action===d.ACTIONS.REQUEST)return void this._respondToRpc(a);if(a.action===d.ACTIONS.ACK&&(a.data[0]===d.ACTIONS.SUBSCRIBE||a.data[0]===d.ACTIONS.UNSUBSCRIBE))return void this._ackTimeoutRegistry.clear(a);if(a.action===d.ACTIONS.ERROR){if(a.data[0]===d.EVENT.MESSAGE_PERMISSION_ERROR)return;if(a.data[0]===d.EVENT.MESSAGE_DENIED){if(a.data[2]===d.ACTIONS.SUBSCRIBE)return;a.data[2]===d.ACTIONS.REQUEST&&(b=a.data[1],c=a.data[3])}else b=a.data[1],c=a.data[2]}else b=a.data[0],c=a.data[1];e=this._getRpc(c,b,a.raw),null!==e&&(a.action===d.ACTIONS.ACK?e.ack():a.action===d.ACTIONS.RESPONSE?(e.respond(a.data[2]),delete this._rpcs[c]):a.action===d.ACTIONS.ERROR&&(a.processedError=!0,e.error(a.data[0]),delete this._rpcs[c]))},k.prototype._reprovide=function(){for(var a in this._providers)this._connection.sendMsg(d.TOPIC.RPC,d.ACTIONS.SUBSCRIBE,[a])},b.exports=k},{"../constants/constants":35,"../message/message-builder":40,"../message/message-parser":41,"../utils/ack-timeout-registry":50,"../utils/resubscribe-notifier":52,"./rpc":49,"./rpc-response":48}],48:[function(a,b,c){var d=a("../constants/constants"),e=a("../utils/utils"),f=a("../message/message-builder"),g=function(a,b,c){this._connection=a,this._name=b,this._correlationId=c,this._isAcknowledged=!1,this._isComplete=!1,this.autoAck=!0,e.nextTick(this._performAutoAck.bind(this))};g.prototype.ack=function(){this._isAcknowledged===!1&&(this._connection.sendMsg(d.TOPIC.RPC,d.ACTIONS.ACK,[this._name,this._correlationId]),this._isAcknowledged=!0)},g.prototype.reject=function(){this.autoAck=!1,this._isComplete=!0,this._isAcknowledged=!0,this._connection.sendMsg(d.TOPIC.RPC,d.ACTIONS.REJECTION,[this._name,this._correlationId])},g.prototype.error=function(a){this.autoAck=!1,this._isComplete=!0,this._isAcknowledged=!0,this._connection.sendMsg(d.TOPIC.RPC,d.ACTIONS.ERROR,[a,this._name,this._correlationId])},g.prototype.send=function(a){if(this._isComplete===!0)throw new Error("Rpc "+this._name+" already completed");var b=f.typed(a);this._connection.sendMsg(d.TOPIC.RPC,d.ACTIONS.RESPONSE,[this._name,this._correlationId,b]),this._isComplete=!0},g.prototype._performAutoAck=function(){this.autoAck===!0&&this.ack()},b.exports=g},{"../constants/constants":35,"../message/message-builder":40,"../utils/utils":54}],49:[function(a,b,c){var d=a("../constants/constants"),e=a("../message/message-parser"),f=function(a,b,c){this._options=a,this._callback=b,this._client=c,this._ackTimeout=setTimeout(this.error.bind(this,d.EVENT.ACK_TIMEOUT),this._options.rpcAckTimeout),this._responseTimeout=setTimeout(this.error.bind(this,d.EVENT.RESPONSE_TIMEOUT),this._options.rpcResponseTimeout)};f.prototype.ack=function(){clearTimeout(this._ackTimeout)},f.prototype.respond=function(a){var b=e.convertTyped(a,this._client);this._callback(null,b),this._complete()},f.prototype.error=function(a){this._callback(a),this._complete()},f.prototype._complete=function(){clearTimeout(this._ackTimeout),clearTimeout(this._responseTimeout)},b.exports=f},{"../constants/constants":35,"../message/message-parser":41}],50:[function(a,b,c){var d=a("../constants/constants"),e=a("component-emitter"),f=function(a,b,c){this._client=a,this._topic=b,this._timeoutDuration=c,this._register={}};e(f.prototype),f.prototype.add=function(a,b){var c=b?b+a:a;this._register[c]&&this.clear({data:[b,a]}),this._register[c]=setTimeout(this._onTimeout.bind(this,c,a),this._timeoutDuration)},f.prototype.clear=function(a){var b=a.data[1],c=a.data[0]+b,e=this._register[c]||this._register[b];e?clearTimeout(e):this._client._$onError(this._topic,d.EVENT.UNSOLICITED_MESSAGE,a.raw)},f.prototype._onTimeout=function(a,b){delete this._register[a];var c="No ACK message received in time for "+b;this._client._$onError(this._topic,d.EVENT.ACK_TIMEOUT,c),this.emit("timeout",b)},b.exports=f},{"../constants/constants":35,"component-emitter":1}],51:[function(a,b,c){var d=a("../constants/constants"),e=a("./resubscribe-notifier"),f=function(a,b,c,d,f,g){this._type=a,this._callback=c,this._pattern=b,this._options=d,this._client=f,this._connection=g,this._ackTimeout=setTimeout(this._onAckTimeout.bind(this),this._options.subscriptionTimeout),this._resubscribeNotifier=new e(f,this._sendListen.bind(this)),this._sendListen()};f.prototype.destroy=function(){this._connection.sendMsg(this._type,d.ACTIONS.UNLISTEN,[this._pattern]),this._resubscribeNotifier.destroy(),this._callback=null,this._pattern=null,this._client=null,this._connection=null},f.prototype._$onMessage=function(a){if(a.action===d.ACTIONS.ACK)clearTimeout(this._ackTimeout);else{var b=a.action===d.ACTIONS.SUBSCRIPTION_FOR_PATTERN_FOUND;this._callback(a.data[1],b)}},f.prototype._sendListen=function(){this._connection.sendMsg(this._type,d.ACTIONS.LISTEN,[this._pattern])},f.prototype._onAckTimeout=function(){this._client._$onError(this._type,d.EVENT.ACK_TIMEOUT,"No ACK message received in time for "+this._pattern)},b.exports=f},{"../constants/constants":35,"./resubscribe-notifier":52}],52:[function(a,b,c){var d=a("../constants/constants"),e=function(a,b){this._client=a,this._resubscribe=b,this._isReconnecting=!1,this._connectionStateChangeHandler=this._handleConnectionStateChanges.bind(this),this._client.on("connectionStateChanged",this._connectionStateChangeHandler)};e.prototype.destroy=function(){this._client.removeListener("connectionStateChanged",this._connectionStateChangeHandler),this._connectionStateChangeHandler=null,this._client=null},e.prototype._handleConnectionStateChanges=function(){var a=this._client.getConnectionState();a===d.CONNECTION_STATE.RECONNECTING&&this._isReconnecting===!1&&(this._isReconnecting=!0),a===d.CONNECTION_STATE.OPEN&&this._isReconnecting===!0&&(this._isReconnecting=!1,this._resubscribe())},b.exports=e},{"../constants/constants":35}],53:[function(a,b,c){var d=a("../constants/constants"),e=a("./resubscribe-notifier"),f=function(a,b,c,d,f){this._client=a,this._connection=b,this._topic=c,this._action=d,this._timeoutDuration=f,this._requests={},this._resubscribeNotifier=new e(this._client,this._resendRequests.bind(this))};f.prototype.hasRequest=function(a){return!!this._requests[a]},f.prototype.request=function(a,b){var c;this._requests[a]||(this._requests[a]=[],this._connection.sendMsg(this._topic,this._action,[a])),c=setTimeout(this._onResponseTimeout.bind(this,a),this._timeoutDuration),this._requests[a].push({timeout:c,callback:b})},f.prototype.recieve=function(a,b,c){var d=this._requests[a];for(i=0;i<d.length;i++)entry=d[i],clearTimeout(entry.timeout),entry.callback(b,c);delete this._requests[a]},f.prototype._onResponseTimeout=function(a){var b="No response received in time for "+this._topic+"|"+this._action+"|"+a;this._client._$onError(this._topic,d.EVENT.RESPONSE_TIMEOUT,b)},f.prototype._resendRequests=function(){for(var a in this._requests)this._connection.sendMsg(this._topic,this._action,[this._requests[a]])},b.exports=f},{"../constants/constants":35,"./resubscribe-notifier":52}],54:[function(a,b,c){(function(a){var b=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,d="object";c.isNode="undefined"!=typeof a&&"[object process]"===a.toString(),c.nextTick=function(b){c.isNode?a.nextTick(b):setTimeout(b,0)},c.trim=function(a){return a.trim?a.trim():a.replace(b,"")},c.deepEquals=function(a,b){return typeof a!==d||typeof b!==d?a===b:JSON.stringify(a)===JSON.stringify(b)},c.deepCopy=function(a){return typeof a===d?JSON.parse(JSON.stringify(a)):a}}).call(this,a("_process"))},{_process:33}],55:[function(a,b,c){var d=a("./webrtc-connection"),e=a("component-emitter"),f=a("../constants/constants"),g=function(a,b){this._connection=a.connection,this._localId=a.localId,this._remoteId=a.remoteId,this._localStream=a.localStream,this._offer=a.offer,this._$webRtcConnection=null,this._bufferedIceCandidates=[],this._options=b,this.state=f.CALL_STATE.INITIAL,this.metaData=a.metaData||null,this.callee=a.isOutgoing?a.remoteId:a.localId,this.isOutgoing=a.isOutgoing,this.isIncoming=!a.isOutgoing,this.isAccepted=!1,this.isDeclined=!1,this.isOutgoing&&this._initiate()};e(g.prototype),g.prototype.accept=function(a){if(this.isAccepted)throw new Error("Incoming call is already accepted");if(this.isDeclined)throw new Error("Can't accept incoming call. Call was already declined");this.isAccepted=!0,this._$webRtcConnection=new d(this._connection,this._options,this._localId,this._remoteId),a&&this._$webRtcConnection.addStream(a),this._$webRtcConnection.setRemoteDescription(new RTCSessionDescription(this._offer)),this._$webRtcConnection.createAnswer(),this._$webRtcConnection.on("stream",this._onEstablished.bind(this)),this._$webRtcConnection.on("error",this.emit.bind(this,"error"));for(var b=0;b<this._bufferedIceCandidates.length;b++)this._$webRtcConnection.addIceCandidate(this._bufferedIceCandidates[b]);this._bufferedIceCandidates=[],this._stateChange(f.CALL_STATE.ACCEPTED)},g.prototype.decline=function(a){if(this.isAccepted)throw new Error("Can't decline incoming call. Call was already accepted");if(this.isDeclined)throw new Error("Incoming call was already declined");this.isDeclined=!0,this._connection.sendMsg(f.TOPIC.WEBRTC,f.ACTIONS.WEBRTC_CALL_DECLINED,[this._localId,this._remoteId,a||null]),this._$declineReceived(a||null)},g.prototype.end=function(){this._connection.sendMsg(f.TOPIC.WEBRTC,f.ACTIONS.WEBRTC_CALL_ENDED,[this._localId,this._remoteId,null]),this._$close()},g.prototype._$close=function(){this._stateChange(f.CALL_STATE.ENDED),this._$webRtcConnection&&this._$webRtcConnection.close(),this.emit("ended")},g.prototype._$addIceCandidate=function(a){this.isIncoming&&this.isAccepted===!1?this._bufferedIceCandidates.push(a):this._$webRtcConnection.addIceCandidate(a)},g.prototype._$declineReceived=function(a){this.isDeclined=!0,this.isAccepted=!1,this._stateChange(f.CALL_STATE.DECLINED),this.emit("declined",a)},g.prototype._stateChange=function(a){this.state=a,this.emit("stateChange",a)},g.prototype._initiate=function(){this._stateChange(f.CALL_STATE.CONNECTING),this._$webRtcConnection=new d(this._connection,this._options,this._localId,this._remoteId),this._$webRtcConnection.initiate(this._localStream,this.metaData),this._$webRtcConnection.on("stream",this._onEstablished.bind(this))},g.prototype._onEstablished=function(a){this.isDeclined=!1,this.isAccepted=!0,this._stateChange(f.CALL_STATE.ESTABLISHED),this.emit("established",a)},b.exports=g},{"../constants/constants":35,"./webrtc-connection":56,"component-emitter":1}],56:[function(a,b,c){var d=a("component-emitter"),e=a("../constants/constants"),f=function(){},g=function(a,b,c,d){this._connection=a,this._remoteId=d,this._localId=c,this._peerConnection=new RTCPeerConnection(b.rtcPeerConnectionConfig),this._peerConnection.onaddstream=this._onStream.bind(this),this._peerConnection.onicecandidate=this._onIceCandidate.bind(this),this._peerConnection.oniceconnectionstatechange=this._onIceConnectionStateChange.bind(this),this._constraints={mandatory:{OfferToReceiveAudio:!0,OfferToReceiveVideo:!0}}};d(g.prototype),g.prototype.initiate=function(a,b){this._peerConnection.addStream(a),this._peerConnection.createOffer(this._onOfferCreated.bind(this,b),this._onError.bind(this))},g.prototype.close=function(){this._peerConnection.close()},g.prototype.addStream=function(a){this._peerConnection.addStream(a)},g.prototype.setRemoteDescription=function(a){this._peerConnection.setRemoteDescription(a,f,this._onError.bind(this))},g.prototype.createAnswer=function(){this._peerConnection.createAnswer(this._onAnswerCreated.bind(this),this._onError.bind(this),this._constraints)},g.prototype.addIceCandidate=function(a){this._peerConnection.addIceCandidate(a,f,this._onError.bind(this))},g.prototype._onStream=function(a){this.emit("stream",a.stream)},g.prototype._onOfferCreated=function(a,b){this._sendMsg(e.ACTIONS.WEBRTC_OFFER,JSON.stringify({sdp:b.sdp,type:b.type,meta:a})),this._peerConnection.setLocalDescription(b,f,this._onError.bind(this))},g.prototype._onAnswerCreated=function(a){this._sendMsg(e.ACTIONS.WEBRTC_ANSWER,a.toJSON()),this._peerConnection.setLocalDescription(a,f,this._onError.bind(this))},g.prototype._sendMsg=function(a,b){this._connection.sendMsg(e.TOPIC.WEBRTC,a,[this._localId,this._remoteId,b])},g.prototype._onIceCandidate=function(a){a.candidate&&this._sendMsg(e.ACTIONS.WEBRTC_ICE_CANDIDATE,a.candidate.toJSON())},g.prototype._onIceConnectionStateChange=function(){"disconnected"===this._peerConnection.iceConnectionState&&this._connection.sendMsg(e.TOPIC.WEBRTC,e.ACTIONS.WEBRTC_IS_ALIVE,[this._remoteId])},g.prototype._onError=function(a){this.emit("error",a)},b.exports=g},{"../constants/constants":35,"component-emitter":1}],57:[function(a,b,c){var d=a("../constants/constants"),e=(a("./webrtc-connection"),a("./webrtc-call")),f=a("../utils/ack-timeout-registry"),g="callee-update",h=function(a,b,c){this._options=a,this._connection=b,this._client=c,this._localCallees={},this._remoteCallees=[],this._remoteCalleesCallback=null,this._ackTimeoutRegistry=new f(c,d.TOPIC.WEBRTC,this._options.calleeAckTimeout),this._ackTimeoutRegistry.on("timeout",this._removeCallee.bind(this)),this._calls={}};h.prototype.registerCallee=function(a,b){if(this._checkCompatibility(),"string"!=typeof a)throw new Error("Invalid callee name "+a);if("function"!=typeof b)throw new Error("Callback is not a function");if(this._localCallees[a])throw new Error("Callee "+a+" is already registered");this._localCallees[a]=b,this._ackTimeoutRegistry.add(a),this._connection.sendMsg(d.TOPIC.WEBRTC,d.ACTIONS.WEBRTC_REGISTER_CALLEE,[a])},h.prototype.unregisterCallee=function(a){if(!this._localCallees[a])throw new Error("Callee is not registered");this._removeCallee(a),this._ackTimeoutRegistry.add(a),this._connection.sendMsg(d.TOPIC.WEBRTC,d.ACTIONS.WEBRTC_UNREGISTER_CALLEE,[a])},h.prototype.makeCall=function(a,b,c){if(this._checkCompatibility(),"string"!=typeof a)throw new Error("Callee must be provided as string");if("object"!=typeof b)throw new Error("metaData must be provided");if(this._calls[a])throw new Error("Call with "+a+" is already in progress");var d=this._client.getUid();return this._ackTimeoutRegistry.add(d),this._createCall(a,{isOutgoing:!0,connection:this._connection,localId:d,remoteId:a,localStream:c,offer:null,metaData:b})},h.prototype.listenForCallees=function(a){if(null!==this._remoteCalleesCallback)throw new Error("Already listening for callees");this._remoteCalleesCallback=a,this._ackTimeoutRegistry.add(g),this._connection.sendMsg(d.TOPIC.WEBRTC,d.ACTIONS.WEBRTC_LISTEN_FOR_CALLEES)},h.prototype.unlistenForCallees=function(){if(!this._remoteCalleesCallback)throw new Error("Not listening for callees");this._remoteCalleesCallback=null,this._ackTimeoutRegistry.add(g),this._connection.sendMsg(d.TOPIC.WEBRTC,d.ACTIONS.WEBRTC_UNLISTEN_FOR_CALLEES)},h.prototype._handleIncomingCall=function(a){var b=a.data[0],c=a.data[1],d=JSON.parse(a.data[2]),e=this._createCall(b,{isOutgoing:!1,connection:this._connection,localId:c,remoteId:b,localStream:null,metaData:d.meta,offer:d});this._localCallees[c](e,d.meta)},h.prototype._removeCall=function(a){delete this._calls[a]},h.prototype._createCall=function(a,b){return this._calls[a]=new e(b,this._options),this._calls[a].on("ended",this._removeCall.bind(this,a)),this._calls[a]},h.prototype._isValidMessage=function(a){return 3===a.data.length&&"string"==typeof a.data[0]&&"string"==typeof a.data[1]&&"string"==typeof a.data[2]},h.prototype._isCalleeUpdate=function(a){return a.action===d.ACTIONS.WEBRTC_ALL_CALLEES||a.action===d.ACTIONS.WEBRTC_CALLEE_ADDED||a.action===d.ACTIONS.WEBRTC_CALLEE_REMOVED},h.prototype._checkCompatibility=function(){if("undefined"==typeof RTCPeerConnection||"undefined"==typeof RTCSessionDescription||"undefined"==typeof RTCIceCandidate){var a="RTC global objects not detected. \n";throw a+="deepstream expects a standardized WebRtc implementation (e.g. no vendor prefixes etc.) \n",a+="until WebRtc is fully supported, we recommend including the official WebRTC adapter script \n",a+="which can be found at https://github.com/webrtc/adapter",new Error(a)}},h.prototype._removeCallee=function(a){delete this._localCallees[a]},h.prototype._processCalleeUpdate=function(a){if(null===this._remoteCalleesCallback)return void this._client._$onError(d.TOPIC.WEBRTC,d.EVENT.UNSOLICITED_MESSAGE,a.raw);a.action===d.ACTIONS.WEBRTC_ALL_CALLEES&&(this._remoteCallees=a.data);var b=this._remoteCallees.indexOf(a.data[0]);
if(a.action===d.ACTIONS.WEBRTC_CALLEE_ADDED){if(b!==-1)return;this._remoteCallees.push(a.data[0])}else if(a.action===d.ACTIONS.WEBRTC_CALLEE_REMOVED){if(b===-1)return;this._remoteCallees.splice(b,1)}this._remoteCalleesCallback(this._remoteCallees)},h.prototype._$handle=function(a){var b,c,e;return a.action===d.ACTIONS.ERROR?void this._client._$onError(d.TOPIC.WEBRTC,a.data[0],a.data[1]):a.action===d.ACTIONS.ACK?void this._ackTimeoutRegistry.clear(a):this._isCalleeUpdate(a)?void this._processCalleeUpdate(a):a.action===d.ACTIONS.WEBRTC_IS_ALIVE?void("false"===a.data[1]&&this._calls[a.data[0]]&&this._calls[a.data[0]]._$close()):this._isValidMessage(a)?a.action===d.ACTIONS.WEBRTC_OFFER?void this._handleIncomingCall(a):(b=this._calls[a.data[0]]||this._calls[a.data[1]])?a.action===d.ACTIONS.WEBRTC_ANSWER?(c=new RTCSessionDescription(JSON.parse(a.data[2])),void b._$webRtcConnection.setRemoteDescription(c)):a.action===d.ACTIONS.WEBRTC_ICE_CANDIDATE?(e=new RTCIceCandidate(JSON.parse(a.data[2])),void b._$addIceCandidate(e)):a.action===d.ACTIONS.WEBRTC_CALL_DECLINED?void b._$declineReceived(a.data[2]):a.action===d.ACTIONS.WEBRTC_CALL_ENDED?void b._$close():void this._client._$onError(d.TOPIC.WEBRTC,d.EVENT.EVENT.MESSAGE_PARSE_ERROR,"unsupported action "+a.action):void this._client._$onError(d.TOPIC.WEBRTC,d.EVENT.UNSOLICITED_MESSAGE,a.raw):void this._client._$onError(d.TOPIC.WEBRTC,d.EVENT.MESSAGE_PARSE_ERROR,a)},b.exports=h},{"../constants/constants":35,"../utils/ack-timeout-registry":50,"./webrtc-call":55,"./webrtc-connection":56}]},{},[34])(34)});