diff --git a/.travis.yml b/.travis.yml index 6b8531064..6784e8c90 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,7 @@ script: - npm run reporter - npm run e2e - npm run specs + - npm run build after_script: "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js" diff --git a/CHANGELOG.md b/CHANGELOG.md index d10cfd85f..47cd54d9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [2.1.5] - 2017-05-03 + +### Bug Fixes +- Calling login() with a callback (but no auth data) now behaves as you would expect. +- Fix issue where client did not emit `MAX_RECONNECTION_ATTEMPTS_REACHED` event by [@rbarroetavena](@rbarroetavena). + ## [2.1.4] - 2017-04-11 ### Enhancements diff --git a/dist/deepstream.js b/dist/deepstream.js index 5afb0f01e..57afdd20c 100644 --- a/dist/deepstream.js +++ b/dist/deepstream.js @@ -358,6 +358,10 @@ process.off = noop; process.removeListener = noop; process.removeAllListeners = noop; process.emit = noop; +process.prependListener = noop; +process.prependOnceListener = noop; + +process.listeners = function (name) { return [] } process.binding = function (name) { throw new Error('process.binding is not supported'); @@ -1916,8 +1920,12 @@ Emitter(Client.prototype); // eslint-disable-line * @public * @returns {Client} */ -Client.prototype.login = function (authParams, callback) { - this._connection.authenticate(authParams || {}, callback); +Client.prototype.login = function (authParamsOrCallback, callback) { + if (typeof authParamsOrCallback === 'function') { + this._connection.authenticate({}, authParamsOrCallback); + } else { + this._connection.authenticate(authParamsOrCallback || {}, callback); + } return this; }; diff --git a/dist/deepstream.min.js b/dist/deepstream.min.js index fc11a7c55..d83011a82 100644 --- a/dist/deepstream.min.js +++ b/dist/deepstream.min.js @@ -1,5 +1,5 @@ /*! deepstream.io-client-js 2.1.4 (c)2017 deepstreamHub GmbH, with parts (c)2017 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 a(b,c,d){function e(g,h){if(!c[g]){if(!b[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:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c||a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g1)for(var c=1;c1&&(d=c[0]+"@",a=c[1]),a=a.replace(H,"."),d+g(a.split("."),b).join(".")}function i(a){for(var b,c,d=[],e=0,f=a.length;e=55296&&b<=56319&&e65535&&(a-=65536,b+=L(a>>>10&1023|55296),a=56320|1023&a),b+=L(a)}).join("")}function k(a){return a-48<10?a-22:a-65<26?a-65:a-97<26?a-97:x}function l(a,b){return a+22+75*(a<26)-((0!=b)<<5)}function m(a,b,c){var d=0;for(a=c?K(a/B):a>>1,a+=K(a/b);a>J*z>>1;d+=x)a=K(a/J);return K(d+(J+1)*a/(a+A))}function n(a){var b,c,d,e,g,h,i,l,n,o,p=[],q=a.length,r=0,s=D,t=C;for(c=a.lastIndexOf(E),c<0&&(c=0),d=0;d=128&&f("not-basic"),p.push(a.charCodeAt(d));for(e=c>0?c+1:0;e=q&&f("invalid-input"),l=k(a.charCodeAt(e++)),(l>=x||l>K((w-r)/h))&&f("overflow"),r+=l*h,n=i<=t?y:i>=t+z?z:i-t,!(lK(w/o)&&f("overflow"),h*=o;b=p.length+1,t=m(r-g,b,0==g),K(r/b)>w-s&&f("overflow"),s+=K(r/b),r%=b,p.splice(r++,0,s)}return j(p)}function o(a){var b,c,d,e,g,h,j,k,n,o,p,q,r,s,t,u=[];for(a=i(a),q=a.length,b=D,c=0,g=C,h=0;h=b&&pK((w-c)/r)&&f("overflow"),c+=(j-b)*r,b=j,h=0;hw&&f("overflow"),p==b){for(k=c,n=x;o=n<=g?y:n>=g+z?z:n-g,!(k= 0x80 (not a basic code point)","invalid-input":"Invalid input"},J=x-y,K=Math.floor,L=String.fromCharCode;if(u={version:"1.4.1",ucs2:{decode:i,encode:j},decode:n,encode:o,toASCII:q,toUnicode:p},"function"==typeof a&&"object"==typeof a.amd&&a.amd)a("punycode",function(){return u});else if(r&&s)if(c.exports==r)s.exports=u;else for(v in u)u.hasOwnProperty(v)&&(r[v]=u[v]);else e.punycode=u}(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],5:[function(a,b,c){"use strict";function d(a,b){return Object.prototype.hasOwnProperty.call(a,b)}b.exports=function(a,b,c,f){b=b||"&",c=c||"=";var g={};if("string"!=typeof a||0===a.length)return g;a=a.split(b);var h=1e3;f&&"number"==typeof f.maxKeys&&(h=f.maxKeys);var i=a.length;h>0&&i>h&&(i=h);for(var j=0;j=0?(k=o.substr(0,p),l=o.substr(p+1)):(k=o,l=""),m=decodeURIComponent(k),n=decodeURIComponent(l),d(g,m)?e(g[m])?g[m].push(n):g[m]=[g[m],n]:g[m]=n}return g};var e=Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)}},{}],6:[function(a,b,c){"use strict";function d(a,b){if(a.map)return a.map(b);for(var c=[],d=0;d",'"',"`"," ","\r","\n","\t"],o=["{","}","|","\\","^","`"].concat(n),p=["'"].concat(o),q=["%","/","?",";","#"].concat(p),r=["/","?","#"],s={javascript:!0,"javascript:":!0},t={javascript:!0,"javascript:":!0},u={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},v=a("querystring");d.prototype.parse=function(a,b,c){if(!j.isString(a))throw new TypeError("Parameter 'url' must be a string, not "+typeof a);var d=a.indexOf("?"),e=-1!==d&&d127?F+="x":F+=E[G];if(!F.match(/^[+a-z0-9A-Z_-]{0,63}$/)){var I=C.slice(0,x),J=C.slice(x+1),K=E.match(/^([+a-z0-9A-Z_-]{0,63})(.*)$/);K&&(I.push(K[1]),J.unshift(K[2])),J.length&&(g="/"+J.join(".")+g),this.hostname=I.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),B||(this.hostname=i.toASCII(this.hostname));var L=this.port?":"+this.port:"",M=this.hostname||"";this.host=M+L,this.href+=this.host,B&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==g[0]&&(g="/"+g))}if(!s[n])for(var x=0,D=p.length;x0)&&c.host.split("@");z&&(c.auth=z.shift(),c.host=c.hostname=z.shift())}return c.search=a.search,c.query=a.query,j.isNull(c.pathname)&&j.isNull(c.search)||(c.path=(c.pathname?c.pathname:"")+(c.search?c.search:"")),c.href=c.format(),c}if(!x.length)return c.pathname=null,c.search?c.path="/"+c.search:c.path=null,c.href=c.format(),c;for(var A=x.slice(-1)[0],B=(c.host||a.host||x.length>1)&&("."===A||".."===A)||""===A,C=0,D=x.length;D>=0;D--)A=x[D],"."===A?x.splice(D,1):".."===A?(x.splice(D,1),C++):C&&(x.splice(D,1),C--);if(!v&&!w)for(;C--;C)x.unshift("..");!v||""===x[0]||x[0]&&"/"===x[0].charAt(0)||x.unshift(""),B&&"/"!==x.join("/").substr(-1)&&x.push("");var E=""===x[0]||x[0]&&"/"===x[0].charAt(0);if(y){c.hostname=c.host=E?"":x.length?x.shift():"";var z=!!(c.host&&c.host.indexOf("@")>0)&&c.host.split("@");z&&(c.auth=z.shift(),c.host=c.hostname=z.shift())}return v=v||c.host&&x.length,v&&!E&&x.unshift(""),x.length?c.pathname=x.join("/"):(c.pathname=null,c.path=null),j.isNull(c.pathname)&&j.isNull(c.search)||(c.path=(c.pathname?c.pathname:"")+(c.search?c.search:"")),c.auth=a.auth||c.auth,c.slashes=c.slashes||a.slashes,c.href=c.format(),c},d.prototype.parseHost=function(){var a=this.host,b=l.exec(a);b&&(b=b[0],":"!==b&&(this.port=b.substr(1)),a=a.substr(0,a.length-b.length)),a&&(this.hostname=a)}},{"./util":9,punycode:4,querystring:7}],9:[function(a,b,c){"use strict";b.exports={isString:function(a){return"string"==typeof a},isObject:function(a){return"object"==typeof a&&null!==a},isNull:function(a){return null===a},isNullOrUndefined:function(a){return null==a}}},{}],10:[function(a,b,c){"use strict";function d(a,b){return new o(a,b)}var e=a("./constants/constants"),f=a("./constants/merge-strategies"),g=a("component-emitter2"),h=a("./message/connection"),i=a("./event/event-handler"),j=a("./rpc/rpc-handler"),k=a("./record/record-handler"),l=a("./presence/presence-handler"),m=a("./default-options"),n=a("./utils/ack-timeout-registry"),o=function(a,b){this._url=a,this._options=this._getOptions(b||{}),this._connection=new h(this,this._url,this._options),this._ackTimeoutRegistry=new n(this,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.presence=new l(this._options,this._connection,this),this._messageCallbacks={},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.PRESENCE]=this.presence._$handle.bind(this.presence),this._messageCallbacks[e.TOPIC.ERROR]=this._onErrorMessage.bind(this)};g(o.prototype),o.prototype.login=function(a,b){return this._connection.authenticate(a||{},b),this},o.prototype.close=function(){this._connection.close()},o.prototype.getConnectionState=function(){return this._connection.getState()},o.prototype.getUid=function(){return(new Date).getTime().toString(36)+"-"+(1e16*Math.random()).toString(36).replace(".","")},o.prototype._$getAckTimeoutRegistry=function(){return this._ackTimeoutRegistry},o.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))},o.prototype._$onError=function(a,b,c){var d=void 0;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)},o.prototype._onErrorMessage=function(a){this._$onError(a.topic,a.data[0],a.data[1])},o.prototype._getOptions=function(a){var b={};for(var c in m)void 0===a[c]?b[c]=m[c]:b[c]=a[c];return b},o.prototype.CONSTANTS=e,d.CONSTANTS=e,o.prototype.MERGE_STRATEGIES=f,d.MERGE_STRATEGIES=f,b.exports=d},{"./constants/constants":11,"./constants/merge-strategies":12,"./default-options":13,"./event/event-handler":14,"./message/connection":15,"./presence/presence-handler":18,"./record/record-handler":22,"./rpc/rpc-handler":24,"./utils/ack-timeout-registry":27,"component-emitter2":2}],11:[function(a,b,c){"use strict";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.PRESENCE="U",c.TOPIC.PRIVATE="PRIVATE/",c.EVENT={},c.EVENT.CONNECTION_ERROR="connectionError",c.EVENT.CONNECTION_STATE_CHANGED="connectionStateChanged",c.EVENT.MAX_RECONNECTION_ATTEMPTS_REACHED="MAX_RECONNECTION_ATTEMPTS_REACHED",c.EVENT.CONNECTION_AUTHENTICATION_TIMEOUT="CONNECTION_AUTHENTICATION_TIMEOUT",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.INVALID_AUTH_MSG="INVALID_AUTH_MSG",c.EVENT.IS_CLOSED="IS_CLOSED",c.EVENT.RECORD_NOT_FOUND="RECORD_NOT_FOUND",c.EVENT.NOT_SUBSCRIBED="NOT_SUBSCRIBED",c.ACTIONS={},c.ACTIONS.PING="PI",c.ACTIONS.PONG="PO",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.SUBSCRIPTION_HAS_PROVIDER="SH",c.ACTIONS.LISTEN="L",c.ACTIONS.UNLISTEN="UL",c.ACTIONS.LISTEN_ACCEPT="LA",c.ACTIONS.LISTEN_REJECT="LR",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.PRESENCE_JOIN="PNJ",c.ACTIONS.PRESENCE_LEAVE="PNL",c.ACTIONS.QUERY="Q",c.ACTIONS.WRITE_ACKNOWLEDGEMENT="WA",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"},{}],12:[function(a,b,c){"use strict";b.exports={REMOTE_WINS:function(a,b,c,d){d(null,b)},LOCAL_WINS:function(a,b,c,d){d(null,a.get())}}},{}],13:[function(a,b,c){"use strict";var d=a("./constants/merge-strategies");b.exports={heartbeatInterval:3e4,reconnectIntervalIncrement:4e3,maxReconnectInterval:18e4,maxReconnectAttempts:5,rpcAckTimeout:6e3,rpcResponseTimeout:1e4,subscriptionTimeout:2e3,maxMessagesPerPacket:100,timeBetweenSendingQueuedPackages:16,recordReadAckTimeout:15e3,recordReadTimeout:15e3,recordDeleteTimeout:15e3,path:"/deepstream",mergeStrategy:d.REMOTE_WINS,recordDeepCopy:!0,nodeSocketOptions:null}},{"./constants/merge-strategies":12}],14:[function(a,b,c){"use strict";var d=a("../message/message-builder"),e=a("../message/message-parser"),f=a("../utils/resubscribe-notifier"),g=a("../constants/constants"),h=a("../utils/listener"),i=a("component-emitter2"),j=function(a,b,c){this._options=a,this._connection=b,this._client=c,this._emitter=new i,this._listener={},this._ackTimeoutRegistry=c._$getAckTimeoutRegistry(),this._resubscribeNotifier=new f(this._client,this._resubscribe.bind(this))};j.prototype.subscribe=function(a,b){if("string"!=typeof a||0===a.length)throw new Error("invalid argument name");if("function"!=typeof b)throw new Error("invalid argument callback");this._emitter.hasListeners(a)||(this._ackTimeoutRegistry.add({topic:g.TOPIC.EVENT,action:g.ACTIONS.SUBSCRIBE,name:a}),this._connection.sendMsg(g.TOPIC.EVENT,g.ACTIONS.SUBSCRIBE,[a])),this._emitter.on(a,b)},j.prototype.unsubscribe=function(a,b){if("string"!=typeof a||0===a.length)throw new Error("invalid argument name");if(void 0!==b&&"function"!=typeof b)throw new Error("invalid argument callback");this._emitter.off(a,b),this._emitter.hasListeners(a)||(this._ackTimeoutRegistry.add({topic:g.TOPIC.EVENT,action:g.ACTIONS.UNSUBSCRIBE,name:a}),this._connection.sendMsg(g.TOPIC.EVENT,g.ACTIONS.UNSUBSCRIBE,[a]))},j.prototype.emit=function(a,b){if("string"!=typeof a||0===a.length)throw new Error("invalid argument name");this._connection.sendMsg(g.TOPIC.EVENT,g.ACTIONS.EVENT,[a,d.typed(b)]),this._emitter.emit(a,b)},j.prototype.listen=function(a,b){if("string"!=typeof a||0===a.length)throw new Error("invalid argument pattern");if("function"!=typeof b)throw new Error("invalid argument callback");if(this._listener[a]&&!this._listener[a].destroyPending)return void this._client._$onError(g.TOPIC.EVENT,g.EVENT.LISTENER_EXISTS,a);this._listener[a]&&this._listener[a].destroy(),this._listener[a]=new h(g.TOPIC.EVENT,a,b,this._options,this._client,this._connection)},j.prototype.unlisten=function(a){if("string"!=typeof a||0===a.length)throw new Error("invalid argument pattern");var b=this._listener[a];b&&!b.destroyPending?b.sendDestroy():this._listener[a]?(this._ackTimeoutRegistry.add({topic:g.TOPIC.EVENT,action:g.EVENT.UNLISTEN,name:a}),this._listener[a].destroy(),delete this._listener[a]):this._client._$onError(g.TOPIC.RECORD,g.EVENT.NOT_LISTENING,a)},j.prototype._$handle=function(a){var b=a.data[a.action===g.ACTIONS.ACK?1:0];if(a.action===g.ACTIONS.EVENT)return void(a.data&&2===a.data.length?this._emitter.emit(b,e.convertTyped(a.data[1],this._client)):this._emitter.emit(b));if(a.action===g.ACTIONS.ACK&&a.data[0]===g.ACTIONS.UNLISTEN&&this._listener[b]&&this._listener[b].destroyPending)return this._listener[b].destroy(),void delete this._listener[b];if(this._listener[b])return void this._listener[b]._$onMessage(a);if(a.action!==g.ACTIONS.SUBSCRIPTION_FOR_PATTERN_REMOVED&&a.action!==g.ACTIONS.SUBSCRIPTION_HAS_PROVIDER)return a.action===g.ACTIONS.ACK?void this._ackTimeoutRegistry.clear(a):a.action===g.ACTIONS.ERROR?(a.data[0]===g.EVENT.MESSAGE_DENIED?this._ackTimeoutRegistry.remove({topic:g.TOPIC.EVENT,name:a.data[1],action:a.data[2]}):a.data[0]===g.EVENT.NOT_SUBSCRIBED&&this._ackTimeoutRegistry.remove({topic:g.TOPIC.EVENT,name:a.data[1],action:g.ACTIONS.UNSUBSCRIBE}),a.processedError=!0,void this._client._$onError(g.TOPIC.EVENT,a.data[0],a.data[1])):void this._client._$onError(g.TOPIC.EVENT,g.EVENT.UNSOLICITED_MESSAGE,b)},j.prototype._resubscribe=function(){var a=this._emitter._callbacks;for(var b in a)this._connection.sendMsg(g.TOPIC.EVENT,g.ACTIONS.SUBSCRIBE,[b])},b.exports=j},{"../constants/constants":11,"../message/message-builder":16,"../message/message-parser":17,"../utils/listener":28,"../utils/resubscribe-notifier":29,"component-emitter2":2}],15:[function(a,b,c){(function(c){"use strict";var d="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},e=c.WebSocket||c.MozWebSocket,f=a("ws"),g=a("./message-parser"),h=a("./message-builder"),i=a("../utils/utils"),j=a("../constants/constants"),k=function(a,b,c){this._client=a,this._options=c,this._authParams=null,this._authCallback=null,this._deliberateClose=!1,this._redirecting=!1,this._tooManyAuthAttempts=!1,this._connectionAuthenticationTimeout=!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._lastHeartBeat=null,this._heartbeatInterval=null,this._originalUrl=i.parseUrl(b,this._options.path),this._url=this._originalUrl,this._state=j.CONNECTION_STATE.CLOSED,this._createEndpoint()};k.prototype.getState=function(){return this._state},k.prototype.authenticate=function(a,b){return"object"!==(void 0===a?"undefined":d(a))?void this._client._$onError(j.TOPIC.ERROR,j.EVENT.INVALID_AUTH_MSG,"authParams is not an object"):(this._authParams=a,this._authCallback=b,this._tooManyAuthAttempts||this._challengeDenied||this._connectionAuthenticationTimeout?void this._client._$onError(j.TOPIC.ERROR,j.EVENT.IS_CLOSED,"this client's connection was closed"):!0===this._deliberateClose&&this._state===j.CONNECTION_STATE.CLOSED?(this._createEndpoint(),void(this._deliberateClose=!1)):void(this._state===j.CONNECTION_STATE.AWAITING_AUTHENTICATION&&this._sendAuthParams()))},k.prototype.sendMsg=function(a,b,c){this.send(h.getMsg(a,b,c))},k.prototype.send=function(a){this._queuedMessages.push(a),this._currentPacketMessageCount++,null===this._currentMessageResetTimeout&&(this._currentMessageResetTimeout=i.nextTick(this._resetCurrentMessageCount.bind(this))),this._state===j.CONNECTION_STATE.OPEN&&this._queuedMessages.lengtha&&(clearInterval(this._heartbeatInterval),this._client._$onError(j.TOPIC.CONNECTION,j.EVENT.CONNECTION_ERROR,"heartbeat not received in the last "+a+" milliseconds"),this._endpoint.close())},k.prototype._onOpen=function(){this._clearReconnect(),this._lastHeartBeat=Date.now(),this._heartbeatInterval=i.setInterval(this._checkHeartBeat.bind(this),this._options.heartbeatInterval),this._setState(j.CONNECTION_STATE.AWAITING_CONNECTION)},k.prototype._onError=function(a){var b=this;clearInterval(this._heartbeatInterval),this._setState(j.CONNECTION_STATE.ERROR),setTimeout(function(){var c=void 0;c="ECONNRESET"===a.code||"ECONNREFUSED"===a.code?"Can't connect! Deepstream server unreachable on "+b._originalUrl:a.toString(),b._client._$onError(j.TOPIC.CONNECTION,j.EVENT.CONNECTION_ERROR,c)},1)},k.prototype._onClose=function(){clearInterval(this._heartbeatInterval),!0===this._redirecting?(this._redirecting=!1,this._createEndpoint()):!0===this._deliberateClose?this._setState(j.CONNECTION_STATE.CLOSED):this._tryReconnect()},k.prototype._onMessage=function(a){for(var b=g.parse(a.data,this._client),c=0;c2&&c.push(this._parseMessage(e[f],b));return c},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(c){return void b._$onError(d.TOPIC.ERROR,d.EVENT.MESSAGE_PARSE_ERROR,c.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={};for(var b in d.ACTIONS)a[d.ACTIONS[b]]=b;return a},e.prototype._parseMessage=function(a,b){var c=a.split(d.MESSAGE_PART_SEPERATOR),e={};return c.length<2?(b._$onError(d.TOPIC.ERROR,d.EVENT.MESSAGE_PARSE_ERROR,"Insufficiant message parts"),null):void 0===this._actions[c[1]]?(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":11}],18:[function(a,b,c){"use strict";var d=a("component-emitter2"),e=a("../constants/constants"),f=a("../utils/resubscribe-notifier"),g=function(a,b,c){this._options=a,this._connection=b,this._client=c,this._emitter=new d,this._ackTimeoutRegistry=c._$getAckTimeoutRegistry(),this._resubscribeNotifier=new f(this._client,this._resubscribe.bind(this))};g.prototype.getAll=function(a){this._emitter.hasListeners(e.ACTIONS.QUERY)||this._connection.sendMsg(e.TOPIC.PRESENCE,e.ACTIONS.QUERY,[e.ACTIONS.QUERY]),this._emitter.once(e.ACTIONS.QUERY,a)},g.prototype.subscribe=function(a){if(void 0!==a&&"function"!=typeof a)throw new Error("invalid argument callback");this._emitter.hasListeners(e.TOPIC.PRESENCE)||(this._ackTimeoutRegistry.add({topic:e.TOPIC.PRESENCE,action:e.ACTIONS.SUBSCRIBE,name:e.TOPIC.PRESENCE}),this._connection.sendMsg(e.TOPIC.PRESENCE,e.ACTIONS.SUBSCRIBE,[e.ACTIONS.SUBSCRIBE])),this._emitter.on(e.TOPIC.PRESENCE,a)},g.prototype.unsubscribe=function(a){if(void 0!==a&&"function"!=typeof a)throw new Error("invalid argument callback");this._emitter.off(e.TOPIC.PRESENCE,a),this._emitter.hasListeners(e.TOPIC.PRESENCE)||(this._ackTimeoutRegistry.add({topic:e.TOPIC.PRESENCE,action:e.ACTIONS.UNSUBSCRIBE,name:e.TOPIC.PRESENCE}),this._connection.sendMsg(e.TOPIC.PRESENCE,e.ACTIONS.UNSUBSCRIBE,[e.ACTIONS.UNSUBSCRIBE]))},g.prototype._$handle=function(a){a.action===e.ACTIONS.ERROR&&a.data[0]===e.EVENT.MESSAGE_DENIED?(this._ackTimeoutRegistry.remove(e.TOPIC.PRESENCE,a.data[1]),a.processedError=!0,this._client._$onError(e.TOPIC.PRESENCE,e.EVENT.MESSAGE_DENIED,a.data[1])):a.action===e.ACTIONS.ACK?this._ackTimeoutRegistry.clear(a):a.action===e.ACTIONS.PRESENCE_JOIN?this._emitter.emit(e.TOPIC.PRESENCE,a.data[0],!0):a.action===e.ACTIONS.PRESENCE_LEAVE?this._emitter.emit(e.TOPIC.PRESENCE,a.data[0],!1):a.action===e.ACTIONS.QUERY?this._emitter.emit(e.ACTIONS.QUERY,a.data):this._client._$onError(e.TOPIC.PRESENCE,e.EVENT.UNSOLICITED_MESSAGE,a.action)},g.prototype._resubscribe=function(){var a=this._emitter._callbacks;a&&a[e.TOPIC.PRESENCE]&&this._connection.sendMsg(e.TOPIC.PRESENCE,e.ACTIONS.SUBSCRIBE,[e.ACTIONS.SUBSCRIBE])},b.exports=g},{"../constants/constants":11,"../utils/resubscribe-notifier":29,"component-emitter2":2}],19:[function(a,b,c){"use strict";var d=a("./record"),e=a("component-emitter2"),f=function(a){this.name=null,this._recordHandler=a,this._record=null,this._subscriptions=[],this._proxyMethod("delete"),this._proxyMethod("set"),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=d.prototype._normalizeArguments(arguments),b=[],c=void 0;for(c=0;c=c.length||a<0))throw new Error("Index must be within current entries");b=!0}return b},g.prototype._beforeChange=function(){this._hasAddListener=this.listeners("entry-added").length>0,this._hasRemoveListener=this.listeners("entry-removed").length>0,this._hasMoveListener=this.listeners("entry-moved").length>0,this._hasAddListener||this._hasRemoveListener||this._hasMoveListener?this._beforeStructure=this._getStructure():this._beforeStructure=null},g.prototype._afterChange=function(){if(null!==this._beforeStructure){var a=this._getStructure(),b=this._beforeStructure,c=void 0,d=void 0;if(this._hasRemoveListener)for(c in b)for(d=0;d1?a.topic+a.data[0]+(a.data[1]?a.data[1]:""):a.topic+a.action+a.data[0],this._register[b]&&clearTimeout(this._register[b].__timeout),delete this._register[b]},f.prototype._onTimeout=function(a){if(delete this._register[this._getUniqueName(a)],a.callback)delete a.__timeout,delete a.timeout,a.callback(a);else{var b="No ACK message received in time"+(a.name?" for "+a.name:"");this._client._$onError(a.topic,a.event,b)}},f.prototype._getUniqueName=function(a){return a.topic+a.action+(a.name?a.name:"")},f.prototype._onConnectionStateChanged=function(a){if(a!==d.CONNECTION_STATE.OPEN)for(var b in this._register)clearTimeout(this._register[b].__timeout)},b.exports=f},{"../constants/constants":11,"component-emitter2":2}],28:[function(a,b,c){"use strict";var d=a("../constants/constants"),e=a("./resubscribe-notifier"),f=function(a,b,c,f,g,h){this._topic=a,this._callback=c,this._pattern=b,this._options=f,this._client=g,this._connection=h,this._ackTimeoutRegistry=g._$getAckTimeoutRegistry(),this._ackTimeoutRegistry.add({topic:this._topic,name:b,action:d.ACTIONS.LISTEN}),this._resubscribeNotifier=new e(g,this._sendListen.bind(this)),this._sendListen(),this.destroyPending=!1};f.prototype.sendDestroy=function(){this.destroyPending=!0,this._connection.sendMsg(this._topic,d.ACTIONS.UNLISTEN,[this._pattern]),this._resubscribeNotifier.destroy()},f.prototype.destroy=function(){this._callback=null,this._pattern=null,this._client=null,this._connection=null},f.prototype.accept=function(a){this._connection.sendMsg(this._topic,d.ACTIONS.LISTEN_ACCEPT,[this._pattern,a])},f.prototype.reject=function(a){this._connection.sendMsg(this._topic,d.ACTIONS.LISTEN_REJECT,[this._pattern,a])},f.prototype._createCallbackResponse=function(a){return{accept:this.accept.bind(this,a.data[1]),reject:this.reject.bind(this,a.data[1])}},f.prototype._$onMessage=function(a){a.action===d.ACTIONS.ACK?this._ackTimeoutRegistry.clear(a):a.action===d.ACTIONS.SUBSCRIPTION_FOR_PATTERN_FOUND?this._callback(a.data[1],!0,this._createCallbackResponse(a)):a.action===d.ACTIONS.SUBSCRIPTION_FOR_PATTERN_REMOVED?this._callback(a.data[1],!1):this._client._$onError(this._topic,d.EVENT.UNSOLICITED_MESSAGE,a.data[0]+"|"+a.data[1])},f.prototype._sendListen=function(){this._connection.sendMsg(this._topic,d.ACTIONS.LISTEN,[this._pattern])},b.exports=f},{"../constants/constants":11,"./resubscribe-notifier":29}],29:[function(a,b,c){"use strict";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&&!1===this._isReconnecting&&(this._isReconnecting=!0),a===d.CONNECTION_STATE.OPEN&&!0===this._isReconnecting&&(this._isReconnecting=!1,this._resubscribe())},b.exports=e},{"../constants/constants":11}],30:[function(a,b,c){"use strict";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._ackTimeoutRegistry=a._$getAckTimeoutRegistry(),this._resubscribeNotifier=new e(this._client,this._resendRequests.bind(this)),this._onResponseTimeout=this._onResponseTimeout.bind(this)};f.prototype.hasRequest=function(a){return!!this._requests[a]},f.prototype.request=function(a,b){this._requests[a]||(this._requests[a]=[],this._connection.sendMsg(this._topic,this._action,[a]));var c=this._ackTimeoutRegistry.add({topic:this._topic,event:d.EVENT.RESPONSE_TIMEOUT,name:a,action:this._action,timeout:this._timeoutDuration,callback:this._onResponseTimeout});this._requests[a].push({callback:b,ackId:c})},f.prototype.recieve=function(a,b,c){var e=this._requests[a];if(!e)return void this._client._$onError(this._topic,d.EVENT.UNSOLICITED_MESSAGE,"no entry for "+a);for(var f=0;f1)for(var c=1;c1&&(d=c[0]+"@",a=c[1]),a=a.replace(H,"."),d+g(a.split("."),b).join(".")}function i(a){for(var b,c,d=[],e=0,f=a.length;e=55296&&b<=56319&&e65535&&(a-=65536,b+=L(a>>>10&1023|55296),a=56320|1023&a),b+=L(a)}).join("")}function k(a){return a-48<10?a-22:a-65<26?a-65:a-97<26?a-97:x}function l(a,b){return a+22+75*(a<26)-((0!=b)<<5)}function m(a,b,c){var d=0;for(a=c?K(a/B):a>>1,a+=K(a/b);a>J*z>>1;d+=x)a=K(a/J);return K(d+(J+1)*a/(a+A))}function n(a){var b,c,d,e,g,h,i,l,n,o,p=[],q=a.length,r=0,s=D,t=C;for(c=a.lastIndexOf(E),c<0&&(c=0),d=0;d=128&&f("not-basic"),p.push(a.charCodeAt(d));for(e=c>0?c+1:0;e=q&&f("invalid-input"),l=k(a.charCodeAt(e++)),(l>=x||l>K((w-r)/h))&&f("overflow"),r+=l*h,n=i<=t?y:i>=t+z?z:i-t,!(lK(w/o)&&f("overflow"),h*=o;b=p.length+1,t=m(r-g,b,0==g),K(r/b)>w-s&&f("overflow"),s+=K(r/b),r%=b,p.splice(r++,0,s)}return j(p)}function o(a){var b,c,d,e,g,h,j,k,n,o,p,q,r,s,t,u=[];for(a=i(a),q=a.length,b=D,c=0,g=C,h=0;h=b&&pK((w-c)/r)&&f("overflow"),c+=(j-b)*r,b=j,h=0;hw&&f("overflow"),p==b){for(k=c,n=x;o=n<=g?y:n>=g+z?z:n-g,!(k= 0x80 (not a basic code point)","invalid-input":"Invalid input"},J=x-y,K=Math.floor,L=String.fromCharCode;if(u={version:"1.4.1",ucs2:{decode:i,encode:j},decode:n,encode:o,toASCII:q,toUnicode:p},"function"==typeof a&&"object"==typeof a.amd&&a.amd)a("punycode",function(){return u});else if(r&&s)if(c.exports==r)s.exports=u;else for(v in u)u.hasOwnProperty(v)&&(r[v]=u[v]);else e.punycode=u}(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],5:[function(a,b,c){"use strict";function d(a,b){return Object.prototype.hasOwnProperty.call(a,b)}b.exports=function(a,b,c,f){b=b||"&",c=c||"=";var g={};if("string"!=typeof a||0===a.length)return g;a=a.split(b);var h=1e3;f&&"number"==typeof f.maxKeys&&(h=f.maxKeys);var i=a.length;h>0&&i>h&&(i=h);for(var j=0;j=0?(k=o.substr(0,p),l=o.substr(p+1)):(k=o,l=""),m=decodeURIComponent(k),n=decodeURIComponent(l),d(g,m)?e(g[m])?g[m].push(n):g[m]=[g[m],n]:g[m]=n}return g};var e=Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)}},{}],6:[function(a,b,c){"use strict";function d(a,b){if(a.map)return a.map(b);for(var c=[],d=0;d",'"',"`"," ","\r","\n","\t"],o=["{","}","|","\\","^","`"].concat(n),p=["'"].concat(o),q=["%","/","?",";","#"].concat(p),r=["/","?","#"],s={javascript:!0,"javascript:":!0},t={javascript:!0,"javascript:":!0},u={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},v=a("querystring");d.prototype.parse=function(a,b,c){if(!j.isString(a))throw new TypeError("Parameter 'url' must be a string, not "+typeof a);var d=a.indexOf("?"),e=-1!==d&&d127?F+="x":F+=E[G];if(!F.match(/^[+a-z0-9A-Z_-]{0,63}$/)){var I=C.slice(0,x),J=C.slice(x+1),K=E.match(/^([+a-z0-9A-Z_-]{0,63})(.*)$/);K&&(I.push(K[1]),J.unshift(K[2])),J.length&&(g="/"+J.join(".")+g),this.hostname=I.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),B||(this.hostname=i.toASCII(this.hostname));var L=this.port?":"+this.port:"",M=this.hostname||"";this.host=M+L,this.href+=this.host,B&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==g[0]&&(g="/"+g))}if(!s[n])for(var x=0,D=p.length;x0)&&c.host.split("@");z&&(c.auth=z.shift(),c.host=c.hostname=z.shift())}return c.search=a.search,c.query=a.query,j.isNull(c.pathname)&&j.isNull(c.search)||(c.path=(c.pathname?c.pathname:"")+(c.search?c.search:"")),c.href=c.format(),c}if(!x.length)return c.pathname=null,c.search?c.path="/"+c.search:c.path=null,c.href=c.format(),c;for(var A=x.slice(-1)[0],B=(c.host||a.host||x.length>1)&&("."===A||".."===A)||""===A,C=0,D=x.length;D>=0;D--)A=x[D],"."===A?x.splice(D,1):".."===A?(x.splice(D,1),C++):C&&(x.splice(D,1),C--);if(!v&&!w)for(;C--;C)x.unshift("..");!v||""===x[0]||x[0]&&"/"===x[0].charAt(0)||x.unshift(""),B&&"/"!==x.join("/").substr(-1)&&x.push("");var E=""===x[0]||x[0]&&"/"===x[0].charAt(0);if(y){c.hostname=c.host=E?"":x.length?x.shift():"";var z=!!(c.host&&c.host.indexOf("@")>0)&&c.host.split("@");z&&(c.auth=z.shift(),c.host=c.hostname=z.shift())}return v=v||c.host&&x.length,v&&!E&&x.unshift(""),x.length?c.pathname=x.join("/"):(c.pathname=null,c.path=null),j.isNull(c.pathname)&&j.isNull(c.search)||(c.path=(c.pathname?c.pathname:"")+(c.search?c.search:"")),c.auth=a.auth||c.auth,c.slashes=c.slashes||a.slashes,c.href=c.format(),c},d.prototype.parseHost=function(){var a=this.host,b=l.exec(a);b&&(b=b[0],":"!==b&&(this.port=b.substr(1)),a=a.substr(0,a.length-b.length)),a&&(this.hostname=a)}},{"./util":9,punycode:4,querystring:7}],9:[function(a,b,c){"use strict";b.exports={isString:function(a){return"string"==typeof a},isObject:function(a){return"object"==typeof a&&null!==a},isNull:function(a){return null===a},isNullOrUndefined:function(a){return null==a}}},{}],10:[function(a,b,c){"use strict";function d(a,b){return new o(a,b)}var e=a("./constants/constants"),f=a("./constants/merge-strategies"),g=a("component-emitter2"),h=a("./message/connection"),i=a("./event/event-handler"),j=a("./rpc/rpc-handler"),k=a("./record/record-handler"),l=a("./presence/presence-handler"),m=a("./default-options"),n=a("./utils/ack-timeout-registry"),o=function(a,b){this._url=a,this._options=this._getOptions(b||{}),this._connection=new h(this,this._url,this._options),this._ackTimeoutRegistry=new n(this,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.presence=new l(this._options,this._connection,this),this._messageCallbacks={},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.PRESENCE]=this.presence._$handle.bind(this.presence),this._messageCallbacks[e.TOPIC.ERROR]=this._onErrorMessage.bind(this)};g(o.prototype),o.prototype.login=function(a,b){return"function"==typeof a?this._connection.authenticate({},a):this._connection.authenticate(a||{},b),this},o.prototype.close=function(){this._connection.close()},o.prototype.getConnectionState=function(){return this._connection.getState()},o.prototype.getUid=function(){return(new Date).getTime().toString(36)+"-"+(1e16*Math.random()).toString(36).replace(".","")},o.prototype._$getAckTimeoutRegistry=function(){return this._ackTimeoutRegistry},o.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))},o.prototype._$onError=function(a,b,c){var d=void 0;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)},o.prototype._onErrorMessage=function(a){this._$onError(a.topic,a.data[0],a.data[1])},o.prototype._getOptions=function(a){var b={};for(var c in m)void 0===a[c]?b[c]=m[c]:b[c]=a[c];return b},o.prototype.CONSTANTS=e,d.CONSTANTS=e,o.prototype.MERGE_STRATEGIES=f,d.MERGE_STRATEGIES=f,b.exports=d},{"./constants/constants":11,"./constants/merge-strategies":12,"./default-options":13,"./event/event-handler":14,"./message/connection":15,"./presence/presence-handler":18,"./record/record-handler":22,"./rpc/rpc-handler":24,"./utils/ack-timeout-registry":27,"component-emitter2":2}],11:[function(a,b,c){"use strict";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.PRESENCE="U",c.TOPIC.PRIVATE="PRIVATE/",c.EVENT={},c.EVENT.CONNECTION_ERROR="connectionError",c.EVENT.CONNECTION_STATE_CHANGED="connectionStateChanged",c.EVENT.MAX_RECONNECTION_ATTEMPTS_REACHED="MAX_RECONNECTION_ATTEMPTS_REACHED",c.EVENT.CONNECTION_AUTHENTICATION_TIMEOUT="CONNECTION_AUTHENTICATION_TIMEOUT",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.INVALID_AUTH_MSG="INVALID_AUTH_MSG",c.EVENT.IS_CLOSED="IS_CLOSED",c.EVENT.RECORD_NOT_FOUND="RECORD_NOT_FOUND",c.EVENT.NOT_SUBSCRIBED="NOT_SUBSCRIBED",c.ACTIONS={},c.ACTIONS.PING="PI",c.ACTIONS.PONG="PO",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.SUBSCRIPTION_HAS_PROVIDER="SH",c.ACTIONS.LISTEN="L",c.ACTIONS.UNLISTEN="UL",c.ACTIONS.LISTEN_ACCEPT="LA",c.ACTIONS.LISTEN_REJECT="LR",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.PRESENCE_JOIN="PNJ",c.ACTIONS.PRESENCE_LEAVE="PNL",c.ACTIONS.QUERY="Q",c.ACTIONS.WRITE_ACKNOWLEDGEMENT="WA",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"},{}],12:[function(a,b,c){"use strict";b.exports={REMOTE_WINS:function(a,b,c,d){d(null,b)},LOCAL_WINS:function(a,b,c,d){d(null,a.get())}}},{}],13:[function(a,b,c){"use strict";var d=a("./constants/merge-strategies");b.exports={heartbeatInterval:3e4,reconnectIntervalIncrement:4e3,maxReconnectInterval:18e4,maxReconnectAttempts:5,rpcAckTimeout:6e3,rpcResponseTimeout:1e4,subscriptionTimeout:2e3,maxMessagesPerPacket:100,timeBetweenSendingQueuedPackages:16,recordReadAckTimeout:15e3,recordReadTimeout:15e3,recordDeleteTimeout:15e3,path:"/deepstream",mergeStrategy:d.REMOTE_WINS,recordDeepCopy:!0,nodeSocketOptions:null}},{"./constants/merge-strategies":12}],14:[function(a,b,c){"use strict";var d=a("../message/message-builder"),e=a("../message/message-parser"),f=a("../utils/resubscribe-notifier"),g=a("../constants/constants"),h=a("../utils/listener"),i=a("component-emitter2"),j=function(a,b,c){this._options=a,this._connection=b,this._client=c,this._emitter=new i,this._listener={},this._ackTimeoutRegistry=c._$getAckTimeoutRegistry(),this._resubscribeNotifier=new f(this._client,this._resubscribe.bind(this))};j.prototype.subscribe=function(a,b){if("string"!=typeof a||0===a.length)throw new Error("invalid argument name");if("function"!=typeof b)throw new Error("invalid argument callback");this._emitter.hasListeners(a)||(this._ackTimeoutRegistry.add({topic:g.TOPIC.EVENT,action:g.ACTIONS.SUBSCRIBE,name:a}),this._connection.sendMsg(g.TOPIC.EVENT,g.ACTIONS.SUBSCRIBE,[a])),this._emitter.on(a,b)},j.prototype.unsubscribe=function(a,b){if("string"!=typeof a||0===a.length)throw new Error("invalid argument name");if(void 0!==b&&"function"!=typeof b)throw new Error("invalid argument callback");this._emitter.off(a,b),this._emitter.hasListeners(a)||(this._ackTimeoutRegistry.add({topic:g.TOPIC.EVENT,action:g.ACTIONS.UNSUBSCRIBE,name:a}),this._connection.sendMsg(g.TOPIC.EVENT,g.ACTIONS.UNSUBSCRIBE,[a]))},j.prototype.emit=function(a,b){if("string"!=typeof a||0===a.length)throw new Error("invalid argument name");this._connection.sendMsg(g.TOPIC.EVENT,g.ACTIONS.EVENT,[a,d.typed(b)]),this._emitter.emit(a,b)},j.prototype.listen=function(a,b){if("string"!=typeof a||0===a.length)throw new Error("invalid argument pattern");if("function"!=typeof b)throw new Error("invalid argument callback");if(this._listener[a]&&!this._listener[a].destroyPending)return void this._client._$onError(g.TOPIC.EVENT,g.EVENT.LISTENER_EXISTS,a);this._listener[a]&&this._listener[a].destroy(),this._listener[a]=new h(g.TOPIC.EVENT,a,b,this._options,this._client,this._connection)},j.prototype.unlisten=function(a){if("string"!=typeof a||0===a.length)throw new Error("invalid argument pattern");var b=this._listener[a];b&&!b.destroyPending?b.sendDestroy():this._listener[a]?(this._ackTimeoutRegistry.add({topic:g.TOPIC.EVENT,action:g.EVENT.UNLISTEN,name:a}),this._listener[a].destroy(),delete this._listener[a]):this._client._$onError(g.TOPIC.RECORD,g.EVENT.NOT_LISTENING,a)},j.prototype._$handle=function(a){var b=a.data[a.action===g.ACTIONS.ACK?1:0];if(a.action===g.ACTIONS.EVENT)return void(a.data&&2===a.data.length?this._emitter.emit(b,e.convertTyped(a.data[1],this._client)):this._emitter.emit(b));if(a.action===g.ACTIONS.ACK&&a.data[0]===g.ACTIONS.UNLISTEN&&this._listener[b]&&this._listener[b].destroyPending)return this._listener[b].destroy(),void delete this._listener[b];if(this._listener[b])return void this._listener[b]._$onMessage(a);if(a.action!==g.ACTIONS.SUBSCRIPTION_FOR_PATTERN_REMOVED&&a.action!==g.ACTIONS.SUBSCRIPTION_HAS_PROVIDER)return a.action===g.ACTIONS.ACK?void this._ackTimeoutRegistry.clear(a):a.action===g.ACTIONS.ERROR?(a.data[0]===g.EVENT.MESSAGE_DENIED?this._ackTimeoutRegistry.remove({topic:g.TOPIC.EVENT,name:a.data[1],action:a.data[2]}):a.data[0]===g.EVENT.NOT_SUBSCRIBED&&this._ackTimeoutRegistry.remove({topic:g.TOPIC.EVENT,name:a.data[1],action:g.ACTIONS.UNSUBSCRIBE}),a.processedError=!0,void this._client._$onError(g.TOPIC.EVENT,a.data[0],a.data[1])):void this._client._$onError(g.TOPIC.EVENT,g.EVENT.UNSOLICITED_MESSAGE,b)},j.prototype._resubscribe=function(){var a=this._emitter._callbacks;for(var b in a)this._connection.sendMsg(g.TOPIC.EVENT,g.ACTIONS.SUBSCRIBE,[b])},b.exports=j},{"../constants/constants":11,"../message/message-builder":16,"../message/message-parser":17,"../utils/listener":28,"../utils/resubscribe-notifier":29,"component-emitter2":2}],15:[function(a,b,c){(function(c){"use strict";var d="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},e=c.WebSocket||c.MozWebSocket,f=a("ws"),g=a("./message-parser"),h=a("./message-builder"),i=a("../utils/utils"),j=a("../constants/constants"),k=function(a,b,c){this._client=a,this._options=c,this._authParams=null,this._authCallback=null,this._deliberateClose=!1,this._redirecting=!1,this._tooManyAuthAttempts=!1,this._connectionAuthenticationTimeout=!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._lastHeartBeat=null,this._heartbeatInterval=null,this._originalUrl=i.parseUrl(b,this._options.path),this._url=this._originalUrl,this._state=j.CONNECTION_STATE.CLOSED,this._createEndpoint()};k.prototype.getState=function(){return this._state},k.prototype.authenticate=function(a,b){return"object"!==(void 0===a?"undefined":d(a))?void this._client._$onError(j.TOPIC.ERROR,j.EVENT.INVALID_AUTH_MSG,"authParams is not an object"):(this._authParams=a,this._authCallback=b,this._tooManyAuthAttempts||this._challengeDenied||this._connectionAuthenticationTimeout?void this._client._$onError(j.TOPIC.ERROR,j.EVENT.IS_CLOSED,"this client's connection was closed"):!0===this._deliberateClose&&this._state===j.CONNECTION_STATE.CLOSED?(this._createEndpoint(),void(this._deliberateClose=!1)):void(this._state===j.CONNECTION_STATE.AWAITING_AUTHENTICATION&&this._sendAuthParams()))},k.prototype.sendMsg=function(a,b,c){this.send(h.getMsg(a,b,c))},k.prototype.send=function(a){this._queuedMessages.push(a),this._currentPacketMessageCount++,null===this._currentMessageResetTimeout&&(this._currentMessageResetTimeout=i.nextTick(this._resetCurrentMessageCount.bind(this))),this._state===j.CONNECTION_STATE.OPEN&&this._queuedMessages.lengtha&&(clearInterval(this._heartbeatInterval),this._client._$onError(j.TOPIC.CONNECTION,j.EVENT.CONNECTION_ERROR,"heartbeat not received in the last "+a+" milliseconds"),this._endpoint.close())},k.prototype._onOpen=function(){this._clearReconnect(),this._lastHeartBeat=Date.now(),this._heartbeatInterval=i.setInterval(this._checkHeartBeat.bind(this),this._options.heartbeatInterval),this._setState(j.CONNECTION_STATE.AWAITING_CONNECTION)},k.prototype._onError=function(a){var b=this;clearInterval(this._heartbeatInterval),this._setState(j.CONNECTION_STATE.ERROR),setTimeout(function(){var c=void 0;c="ECONNRESET"===a.code||"ECONNREFUSED"===a.code?"Can't connect! Deepstream server unreachable on "+b._originalUrl:a.toString(),b._client._$onError(j.TOPIC.CONNECTION,j.EVENT.CONNECTION_ERROR,c)},1)},k.prototype._onClose=function(){clearInterval(this._heartbeatInterval),!0===this._redirecting?(this._redirecting=!1,this._createEndpoint()):!0===this._deliberateClose?this._setState(j.CONNECTION_STATE.CLOSED):this._tryReconnect()},k.prototype._onMessage=function(a){for(var b=g.parse(a.data,this._client),c=0;c2&&c.push(this._parseMessage(e[f],b));return c},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(c){return void b._$onError(d.TOPIC.ERROR,d.EVENT.MESSAGE_PARSE_ERROR,c.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={};for(var b in d.ACTIONS)a[d.ACTIONS[b]]=b;return a},e.prototype._parseMessage=function(a,b){var c=a.split(d.MESSAGE_PART_SEPERATOR),e={};return c.length<2?(b._$onError(d.TOPIC.ERROR,d.EVENT.MESSAGE_PARSE_ERROR,"Insufficiant message parts"),null):void 0===this._actions[c[1]]?(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":11}],18:[function(a,b,c){"use strict";var d=a("component-emitter2"),e=a("../constants/constants"),f=a("../utils/resubscribe-notifier"),g=function(a,b,c){this._options=a,this._connection=b,this._client=c,this._emitter=new d,this._ackTimeoutRegistry=c._$getAckTimeoutRegistry(),this._resubscribeNotifier=new f(this._client,this._resubscribe.bind(this))};g.prototype.getAll=function(a){this._emitter.hasListeners(e.ACTIONS.QUERY)||this._connection.sendMsg(e.TOPIC.PRESENCE,e.ACTIONS.QUERY,[e.ACTIONS.QUERY]),this._emitter.once(e.ACTIONS.QUERY,a)},g.prototype.subscribe=function(a){if(void 0!==a&&"function"!=typeof a)throw new Error("invalid argument callback");this._emitter.hasListeners(e.TOPIC.PRESENCE)||(this._ackTimeoutRegistry.add({topic:e.TOPIC.PRESENCE,action:e.ACTIONS.SUBSCRIBE,name:e.TOPIC.PRESENCE}),this._connection.sendMsg(e.TOPIC.PRESENCE,e.ACTIONS.SUBSCRIBE,[e.ACTIONS.SUBSCRIBE])),this._emitter.on(e.TOPIC.PRESENCE,a)},g.prototype.unsubscribe=function(a){if(void 0!==a&&"function"!=typeof a)throw new Error("invalid argument callback");this._emitter.off(e.TOPIC.PRESENCE,a),this._emitter.hasListeners(e.TOPIC.PRESENCE)||(this._ackTimeoutRegistry.add({topic:e.TOPIC.PRESENCE,action:e.ACTIONS.UNSUBSCRIBE,name:e.TOPIC.PRESENCE}),this._connection.sendMsg(e.TOPIC.PRESENCE,e.ACTIONS.UNSUBSCRIBE,[e.ACTIONS.UNSUBSCRIBE]))},g.prototype._$handle=function(a){a.action===e.ACTIONS.ERROR&&a.data[0]===e.EVENT.MESSAGE_DENIED?(this._ackTimeoutRegistry.remove(e.TOPIC.PRESENCE,a.data[1]),a.processedError=!0,this._client._$onError(e.TOPIC.PRESENCE,e.EVENT.MESSAGE_DENIED,a.data[1])):a.action===e.ACTIONS.ACK?this._ackTimeoutRegistry.clear(a):a.action===e.ACTIONS.PRESENCE_JOIN?this._emitter.emit(e.TOPIC.PRESENCE,a.data[0],!0):a.action===e.ACTIONS.PRESENCE_LEAVE?this._emitter.emit(e.TOPIC.PRESENCE,a.data[0],!1):a.action===e.ACTIONS.QUERY?this._emitter.emit(e.ACTIONS.QUERY,a.data):this._client._$onError(e.TOPIC.PRESENCE,e.EVENT.UNSOLICITED_MESSAGE,a.action)},g.prototype._resubscribe=function(){var a=this._emitter._callbacks;a&&a[e.TOPIC.PRESENCE]&&this._connection.sendMsg(e.TOPIC.PRESENCE,e.ACTIONS.SUBSCRIBE,[e.ACTIONS.SUBSCRIBE])},b.exports=g},{"../constants/constants":11,"../utils/resubscribe-notifier":29,"component-emitter2":2}],19:[function(a,b,c){"use strict";var d=a("./record"),e=a("component-emitter2"),f=function(a){this.name=null,this._recordHandler=a,this._record=null,this._subscriptions=[],this._proxyMethod("delete"),this._proxyMethod("set"),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=d.prototype._normalizeArguments(arguments),b=[],c=void 0;for(c=0;c=c.length||a<0))throw new Error("Index must be within current entries");b=!0}return b},g.prototype._beforeChange=function(){this._hasAddListener=this.listeners("entry-added").length>0,this._hasRemoveListener=this.listeners("entry-removed").length>0,this._hasMoveListener=this.listeners("entry-moved").length>0,this._hasAddListener||this._hasRemoveListener||this._hasMoveListener?this._beforeStructure=this._getStructure():this._beforeStructure=null},g.prototype._afterChange=function(){if(null!==this._beforeStructure){var a=this._getStructure(),b=this._beforeStructure,c=void 0,d=void 0;if(this._hasRemoveListener)for(c in b)for(d=0;d1?a.topic+a.data[0]+(a.data[1]?a.data[1]:""):a.topic+a.action+a.data[0],this._register[b]&&clearTimeout(this._register[b].__timeout),delete this._register[b]},f.prototype._onTimeout=function(a){if(delete this._register[this._getUniqueName(a)],a.callback)delete a.__timeout,delete a.timeout,a.callback(a);else{var b="No ACK message received in time"+(a.name?" for "+a.name:"");this._client._$onError(a.topic,a.event,b)}},f.prototype._getUniqueName=function(a){return a.topic+a.action+(a.name?a.name:"")},f.prototype._onConnectionStateChanged=function(a){if(a!==d.CONNECTION_STATE.OPEN)for(var b in this._register)clearTimeout(this._register[b].__timeout)},b.exports=f},{"../constants/constants":11,"component-emitter2":2}],28:[function(a,b,c){"use strict";var d=a("../constants/constants"),e=a("./resubscribe-notifier"),f=function(a,b,c,f,g,h){this._topic=a,this._callback=c,this._pattern=b,this._options=f,this._client=g,this._connection=h,this._ackTimeoutRegistry=g._$getAckTimeoutRegistry(),this._ackTimeoutRegistry.add({topic:this._topic,name:b,action:d.ACTIONS.LISTEN}),this._resubscribeNotifier=new e(g,this._sendListen.bind(this)),this._sendListen(),this.destroyPending=!1};f.prototype.sendDestroy=function(){this.destroyPending=!0,this._connection.sendMsg(this._topic,d.ACTIONS.UNLISTEN,[this._pattern]),this._resubscribeNotifier.destroy()},f.prototype.destroy=function(){this._callback=null,this._pattern=null,this._client=null,this._connection=null},f.prototype.accept=function(a){this._connection.sendMsg(this._topic,d.ACTIONS.LISTEN_ACCEPT,[this._pattern,a])},f.prototype.reject=function(a){this._connection.sendMsg(this._topic,d.ACTIONS.LISTEN_REJECT,[this._pattern,a])},f.prototype._createCallbackResponse=function(a){return{accept:this.accept.bind(this,a.data[1]),reject:this.reject.bind(this,a.data[1])}},f.prototype._$onMessage=function(a){a.action===d.ACTIONS.ACK?this._ackTimeoutRegistry.clear(a):a.action===d.ACTIONS.SUBSCRIPTION_FOR_PATTERN_FOUND?this._callback(a.data[1],!0,this._createCallbackResponse(a)):a.action===d.ACTIONS.SUBSCRIPTION_FOR_PATTERN_REMOVED?this._callback(a.data[1],!1):this._client._$onError(this._topic,d.EVENT.UNSOLICITED_MESSAGE,a.data[0]+"|"+a.data[1])},f.prototype._sendListen=function(){this._connection.sendMsg(this._topic,d.ACTIONS.LISTEN,[this._pattern])},b.exports=f},{"../constants/constants":11,"./resubscribe-notifier":29}],29:[function(a,b,c){"use strict";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&&!1===this._isReconnecting&&(this._isReconnecting=!0),a===d.CONNECTION_STATE.OPEN&&!0===this._isReconnecting&&(this._isReconnecting=!1,this._resubscribe())},b.exports=e},{"../constants/constants":11}],30:[function(a,b,c){"use strict";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._ackTimeoutRegistry=a._$getAckTimeoutRegistry(),this._resubscribeNotifier=new e(this._client,this._resendRequests.bind(this)),this._onResponseTimeout=this._onResponseTimeout.bind(this)};f.prototype.hasRequest=function(a){return!!this._requests[a]},f.prototype.request=function(a,b){this._requests[a]||(this._requests[a]=[],this._connection.sendMsg(this._topic,this._action,[a]));var c=this._ackTimeoutRegistry.add({topic:this._topic,event:d.EVENT.RESPONSE_TIMEOUT,name:a,action:this._action,timeout:this._timeoutDuration,callback:this._onResponseTimeout});this._requests[a].push({callback:b,ackId:c})},f.prototype.recieve=function(a,b,c){var e=this._requests[a];if(!e)return void this._client._$onError(this._topic,d.EVENT.UNSOLICITED_MESSAGE,"no entry for "+a);for(var f=0;f