From 73809150d0fd6d8681c1fc4a700f6a70fb4908a6 Mon Sep 17 00:00:00 2001 From: Alex Harley Date: Mon, 25 Sep 2017 15:43:05 +0200 Subject: [PATCH] v2.3.0 --- dist/deepstream.min.js | 6 ++++-- package.json | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/dist/deepstream.min.js b/dist/deepstream.min.js index 3c8ed17a7..656709a7b 100644 --- a/dist/deepstream.min.js +++ b/dist/deepstream.min.js @@ -1,3 +1,5 @@ -/*! deepstream.io-client-js 2.2.1 (c)2017 deepstreamHub GmbH, with parts (c)2017 Joyent and contributers @licence Apache-2.0*/ +/*! deepstream.io-client-js 2.3.0 (c)2017 deepstreamHub GmbH, with parts (c)2017 Joyent and contributers @licence Apache-2.0*/ -!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).deepstream=t()}}(function(){return function t(e,i,n){function s(r,a){if(!i[r]){if(!e[r]){var c="function"==typeof require&&require;if(!a&&c)return c(r,!0);if(o)return o(r,!0);var h=new Error("Cannot find module '"+r+"'");throw h.code="MODULE_NOT_FOUND",h}var u=i[r]={exports:{}};e[r][0].call(u.exports,function(t){var i=e[r][1][t];return s(i||t)},u,u.exports,t,e,i,n)}return i[r].exports}for(var o="function"==typeof require&&require,r=0;r1)for(var i=1;i1&&(n=i[0]+"@",t=i[1]),n+o((t=t.replace(P,".")).split("."),e).join(".")}function a(t){for(var e,i,n=[],s=0,o=t.length;s=55296&&e<=56319&&s65535&&(e+=M((t-=65536)>>>10&1023|55296),t=56320|1023&t),e+=M(t)}).join("")}function h(t){return t-48<10?t-22:t-65<26?t-65:t-97<26?t-97:m}function u(t,e){return t+22+75*(t<26)-((0!=e)<<5)}function l(t,e,i){var n=0;for(t=i?U(t/I):t>>1,t+=U(t/e);t>w*O>>1;n+=m)t=U(t/w);return U(n+(w+1)*t/(t+y))}function _(t){var e,i,n,o,r,a,u,_,d,p,E=[],T=t.length,f=0,C=R,y=g;for((i=t.lastIndexOf(A))<0&&(i=0),n=0;n=128&&s("not-basic"),E.push(t.charCodeAt(n));for(o=i>0?i+1:0;o=T&&s("invalid-input"),((_=h(t.charCodeAt(o++)))>=m||_>U((N-f)/a))&&s("overflow"),f+=_*a,d=u<=y?S:u>=y+O?O:u-y,!(_U(N/(p=m-d))&&s("overflow"),a*=p;y=l(f-r,e=E.length+1,0==r),U(f/e)>N-C&&s("overflow"),C+=U(f/e),f%=e,E.splice(f++,0,C)}return c(E)}function d(t){var e,i,n,o,r,c,h,_,d,p,E,T,f,C,y,I=[];for(T=(t=a(t)).length,e=R,i=0,r=g,c=0;c=e&&EU((N-i)/(f=n+1))&&s("overflow"),i+=(h-e)*f,e=h,c=0;cN&&s("overflow"),E==e){for(_=i,d=m;p=d<=r?S:d>=r+O?O:d-r,!(_= 0x80 (not a basic code point)","invalid-input":"Invalid input"},w=m-S,U=Math.floor,M=String.fromCharCode;if(f={version:"1.4.1",ucs2:{decode:a,encode:c},decode:_,encode:d,toASCII:function(t){return r(t,function(t){return v.test(t)?"xn--"+d(t):t})},toUnicode:function(t){return r(t,function(t){return b.test(t)?_(t.slice(4).toLowerCase()):t})}},p&&E)if(e.exports==p)E.exports=f;else for(C in f)f.hasOwnProperty(C)&&(p[C]=f[C]);else n.punycode=f}(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],5:[function(t,e,i){"use strict";function n(t,e){return Object.prototype.hasOwnProperty.call(t,e)}e.exports=function(t,e,i,o){e=e||"&",i=i||"=";var r={};if("string"!=typeof t||0===t.length)return r;var a=/\+/g;t=t.split(e);var c=1e3;o&&"number"==typeof o.maxKeys&&(c=o.maxKeys);var h=t.length;c>0&&h>c&&(h=c);for(var u=0;u=0?(l=E.substr(0,T),_=E.substr(T+1)):(l=E,_=""),d=decodeURIComponent(l),p=decodeURIComponent(_),n(r,d)?s(r[d])?r[d].push(p):r[d]=[r[d],p]:r[d]=p}return r};var s=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)}},{}],6:[function(t,e,i){"use strict";function n(t,e){if(t.map)return t.map(e);for(var i=[],n=0;n",'"',"`"," ","\r","\n","\t"],l=["{","}","|","\\","^","`"].concat(u),_=["'"].concat(l),d=["%","/","?",";","#"].concat(_),p=["/","?","#"],E=/^[+a-z0-9A-Z_-]{0,63}$/,T=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,f={javascript:!0,"javascript:":!0},C={javascript:!0,"javascript:":!0},N={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},m=t("querystring");n.prototype.parse=function(t,e,i){if(!r.isString(t))throw new TypeError("Parameter 'url' must be a string, not "+typeof t);var n=t.indexOf("?"),s=-1!==n&&n127?M+="x":M+=U[D];if(!M.match(E)){var B=k.slice(0,R),V=k.slice(R+1),x=U.match(T);x&&(B.push(x[1]),V.unshift(x[2])),V.length&&(l="/"+V.join(".")+l),this.hostname=B.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),P||(this.hostname=o.toASCII(this.hostname));var G=this.port?":"+this.port:"",j=this.hostname||"";this.host=j+G,this.href+=this.host,P&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==l[0]&&(l="/"+l))}if(!f[y])for(var R=0,w=_.length;R0)&&i.host.split("@"))&&(i.auth=P.shift(),i.host=i.hostname=P.shift())),i.search=t.search,i.query=t.query,r.isNull(i.pathname)&&r.isNull(i.search)||(i.path=(i.pathname?i.pathname:"")+(i.search?i.search:"")),i.href=i.format(),i;if(!O.length)return i.pathname=null,i.search?i.path="/"+i.search:i.path=null,i.href=i.format(),i;for(var g=O.slice(-1)[0],R=(i.host||t.host||O.length>1)&&("."===g||".."===g)||""===g,A=0,b=O.length;b>=0;b--)"."===(g=O[b])?O.splice(b,1):".."===g?(O.splice(b,1),A++):A&&(O.splice(b,1),A--);if(!m&&!S)for(;A--;A)O.unshift("..");!m||""===O[0]||O[0]&&"/"===O[0].charAt(0)||O.unshift(""),R&&"/"!==O.join("/").substr(-1)&&O.push("");var v=""===O[0]||O[0]&&"/"===O[0].charAt(0);if(I){i.hostname=i.host=v?"":O.length?O.shift():"";var P=!!(i.host&&i.host.indexOf("@")>0)&&i.host.split("@");P&&(i.auth=P.shift(),i.host=i.hostname=P.shift())}return(m=m||i.host&&O.length)&&!v&&O.unshift(""),O.length?i.pathname=O.join("/"):(i.pathname=null,i.path=null),r.isNull(i.pathname)&&r.isNull(i.search)||(i.path=(i.pathname?i.pathname:"")+(i.search?i.search:"")),i.auth=t.auth||i.auth,i.slashes=i.slashes||t.slashes,i.href=i.format(),i},n.prototype.parseHost=function(){var t=this.host,e=c.exec(t);e&&(":"!==(e=e[0])&&(this.port=e.substr(1)),t=t.substr(0,t.length-e.length)),t&&(this.hostname=t)}},{"./util":9,punycode:4,querystring:7}],9:[function(t,e,i){"use strict";e.exports={isString:function(t){return"string"==typeof t},isObject:function(t){return"object"==typeof t&&null!==t},isNull:function(t){return null===t},isNullOrUndefined:function(t){return null==t}}},{}],10:[function(t,e,i){"use strict";function n(t,e){return new p(t,e)}var s=t("./constants/constants"),o=t("./constants/merge-strategies"),r=t("component-emitter2"),a=t("./message/connection"),c=t("./event/event-handler"),h=t("./rpc/rpc-handler"),u=t("./record/record-handler"),l=t("./presence/presence-handler"),_=t("./default-options"),d=t("./utils/ack-timeout-registry"),p=function(t,e){this._url=t,this._options=this._getOptions(e||{}),this._connection=new a(this,this._url,this._options),this._ackTimeoutRegistry=new d(this,this._options),this.event=new c(this._options,this._connection,this),this.rpc=new h(this._options,this._connection,this),this.record=new u(this._options,this._connection,this),this.presence=new l(this._options,this._connection,this),this._messageCallbacks={},this._messageCallbacks[s.TOPIC.EVENT]=this.event._$handle.bind(this.event),this._messageCallbacks[s.TOPIC.RPC]=this.rpc._$handle.bind(this.rpc),this._messageCallbacks[s.TOPIC.RECORD]=this.record._$handle.bind(this.record),this._messageCallbacks[s.TOPIC.PRESENCE]=this.presence._$handle.bind(this.presence),this._messageCallbacks[s.TOPIC.ERROR]=this._onErrorMessage.bind(this)};r(p.prototype),p.prototype.login=function(t,e){return"function"==typeof t?this._connection.authenticate({},t):this._connection.authenticate(t||{},e),this},p.prototype.close=function(){this._connection.close()},p.prototype.getConnectionState=function(){return this._connection.getState()},p.prototype.getUid=function(){return(new Date).getTime().toString(36)+"-"+(1e16*Math.random()).toString(36).replace(".","")},p.prototype._$getAckTimeoutRegistry=function(){return this._ackTimeoutRegistry},p.prototype._$onMessage=function(t){this._messageCallbacks[t.topic]?this._messageCallbacks[t.topic](t):(t.processedError=!0,this._$onError(t.topic,s.EVENT.MESSAGE_PARSE_ERROR,"Received message for unknown topic "+t.topic)),t.action!==s.ACTIONS.ERROR||t.processedError||this._$onError(t.topic,t.data[0],t.data.slice(0))},p.prototype._$onError=function(t,e,i){var n=void 0;if(e!==s.EVENT.ACK_TIMEOUT&&e!==s.EVENT.RESPONSE_TIMEOUT||this.getConnectionState()===s.CONNECTION_STATE.AWAITING_AUTHENTICATION&&(n="Your message timed out because you're not authenticated. Have you called login()?",setTimeout(this._$onError.bind(this,s.EVENT.NOT_AUTHENTICATED,s.TOPIC.ERROR,n),1)),!this.hasListeners("error"))throw console.log("--- You can catch all deepstream errors by subscribing to the error event ---"),n=e+": "+i,t&&(n+=" ("+t+")"),new Error(n);this.emit("error",i,e,t),this.emit(e,t,i)},p.prototype._onErrorMessage=function(t){this._$onError(t.topic,t.data[0],t.data[1])},p.prototype._getOptions=function(t){var e={};for(var i in _)void 0===t[i]?e[i]=_[i]:e[i]=t[i];return e},p.prototype.CONSTANTS=s,n.CONSTANTS=s,p.prototype.MERGE_STRATEGIES=o,n.MERGE_STRATEGIES=o,e.exports=n},{"./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(t,e,i){"use strict";i.CONNECTION_STATE={},i.CONNECTION_STATE.CLOSED="CLOSED",i.CONNECTION_STATE.AWAITING_CONNECTION="AWAITING_CONNECTION",i.CONNECTION_STATE.CHALLENGING="CHALLENGING",i.CONNECTION_STATE.AWAITING_AUTHENTICATION="AWAITING_AUTHENTICATION",i.CONNECTION_STATE.AUTHENTICATING="AUTHENTICATING",i.CONNECTION_STATE.OPEN="OPEN",i.CONNECTION_STATE.ERROR="ERROR",i.CONNECTION_STATE.RECONNECTING="RECONNECTING",i.MESSAGE_SEPERATOR=String.fromCharCode(30),i.MESSAGE_PART_SEPERATOR=String.fromCharCode(31),i.TYPES={},i.TYPES.STRING="S",i.TYPES.OBJECT="O",i.TYPES.NUMBER="N",i.TYPES.NULL="L",i.TYPES.TRUE="T",i.TYPES.FALSE="F",i.TYPES.UNDEFINED="U",i.TOPIC={},i.TOPIC.CONNECTION="C",i.TOPIC.AUTH="A",i.TOPIC.ERROR="X",i.TOPIC.EVENT="E",i.TOPIC.RECORD="R",i.TOPIC.RPC="P",i.TOPIC.PRESENCE="U",i.TOPIC.PRIVATE="PRIVATE/",i.EVENT={},i.EVENT.CONNECTION_ERROR="connectionError",i.EVENT.CONNECTION_STATE_CHANGED="connectionStateChanged",i.EVENT.MAX_RECONNECTION_ATTEMPTS_REACHED="MAX_RECONNECTION_ATTEMPTS_REACHED",i.EVENT.CONNECTION_AUTHENTICATION_TIMEOUT="CONNECTION_AUTHENTICATION_TIMEOUT",i.EVENT.ACK_TIMEOUT="ACK_TIMEOUT",i.EVENT.NO_RPC_PROVIDER="NO_RPC_PROVIDER",i.EVENT.RESPONSE_TIMEOUT="RESPONSE_TIMEOUT",i.EVENT.DELETE_TIMEOUT="DELETE_TIMEOUT",i.EVENT.UNSOLICITED_MESSAGE="UNSOLICITED_MESSAGE",i.EVENT.MESSAGE_DENIED="MESSAGE_DENIED",i.EVENT.MESSAGE_PARSE_ERROR="MESSAGE_PARSE_ERROR",i.EVENT.VERSION_EXISTS="VERSION_EXISTS",i.EVENT.NOT_AUTHENTICATED="NOT_AUTHENTICATED",i.EVENT.MESSAGE_PERMISSION_ERROR="MESSAGE_PERMISSION_ERROR",i.EVENT.LISTENER_EXISTS="LISTENER_EXISTS",i.EVENT.NOT_LISTENING="NOT_LISTENING",i.EVENT.TOO_MANY_AUTH_ATTEMPTS="TOO_MANY_AUTH_ATTEMPTS",i.EVENT.INVALID_AUTH_MSG="INVALID_AUTH_MSG",i.EVENT.IS_CLOSED="IS_CLOSED",i.EVENT.RECORD_NOT_FOUND="RECORD_NOT_FOUND",i.EVENT.NOT_SUBSCRIBED="NOT_SUBSCRIBED",i.ACTIONS={},i.ACTIONS.PING="PI",i.ACTIONS.PONG="PO",i.ACTIONS.ACK="A",i.ACTIONS.REDIRECT="RED",i.ACTIONS.CHALLENGE="CH",i.ACTIONS.CHALLENGE_RESPONSE="CHR",i.ACTIONS.READ="R",i.ACTIONS.CREATE="C",i.ACTIONS.UPDATE="U",i.ACTIONS.PATCH="P",i.ACTIONS.DELETE="D",i.ACTIONS.SUBSCRIBE="S",i.ACTIONS.UNSUBSCRIBE="US",i.ACTIONS.HAS="H",i.ACTIONS.SNAPSHOT="SN",i.ACTIONS.INVOKE="I",i.ACTIONS.SUBSCRIPTION_FOR_PATTERN_FOUND="SP",i.ACTIONS.SUBSCRIPTION_FOR_PATTERN_REMOVED="SR",i.ACTIONS.SUBSCRIPTION_HAS_PROVIDER="SH",i.ACTIONS.LISTEN="L",i.ACTIONS.UNLISTEN="UL",i.ACTIONS.LISTEN_ACCEPT="LA",i.ACTIONS.LISTEN_REJECT="LR",i.ACTIONS.PROVIDER_UPDATE="PU",i.ACTIONS.QUERY="Q",i.ACTIONS.CREATEORREAD="CR",i.ACTIONS.CREATEANDUPDATE="CU",i.ACTIONS.EVENT="EVT",i.ACTIONS.ERROR="E",i.ACTIONS.REQUEST="REQ",i.ACTIONS.RESPONSE="RES",i.ACTIONS.REJECTION="REJ",i.ACTIONS.PRESENCE_JOIN="PNJ",i.ACTIONS.PRESENCE_LEAVE="PNL",i.ACTIONS.WRITE_ACKNOWLEDGEMENT="WA",i.CALL_STATE={},i.CALL_STATE.INITIAL="INITIAL",i.CALL_STATE.CONNECTING="CONNECTING",i.CALL_STATE.ESTABLISHED="ESTABLISHED",i.CALL_STATE.ACCEPTED="ACCEPTED",i.CALL_STATE.DECLINED="DECLINED",i.CALL_STATE.ENDED="ENDED",i.CALL_STATE.ERROR="ERROR"},{}],12:[function(t,e,i){"use strict";e.exports={REMOTE_WINS:function(t,e,i,n){n(null,e)},LOCAL_WINS:function(t,e,i,n){n(null,t.get())}}},{}],13:[function(t,e,i){"use strict";var n=t("./constants/merge-strategies");e.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:n.REMOTE_WINS,recordDeepCopy:!0,nodeSocketOptions:null}},{"./constants/merge-strategies":12}],14:[function(t,e,i){"use strict";var n=t("../message/message-builder"),s=t("../message/message-parser"),o=t("../utils/resubscribe-notifier"),r=t("../constants/constants"),a=t("../utils/listener"),c=t("component-emitter2"),h=function(t,e,i){this._options=t,this._connection=e,this._client=i,this._emitter=new c,this._listener={},this._ackTimeoutRegistry=i._$getAckTimeoutRegistry(),this._resubscribeNotifier=new o(this._client,this._resubscribe.bind(this))};h.prototype.subscribe=function(t,e){if("string"!=typeof t||0===t.length)throw new Error("invalid argument name");if("function"!=typeof e)throw new Error("invalid argument callback");this._emitter.hasListeners(t)||(this._ackTimeoutRegistry.add({topic:r.TOPIC.EVENT,action:r.ACTIONS.SUBSCRIBE,name:t}),this._connection.sendMsg(r.TOPIC.EVENT,r.ACTIONS.SUBSCRIBE,[t])),this._emitter.on(t,e)},h.prototype.unsubscribe=function(t,e){if("string"!=typeof t||0===t.length)throw new Error("invalid argument name");if(void 0!==e&&"function"!=typeof e)throw new Error("invalid argument callback");this._emitter.off(t,e),this._emitter.hasListeners(t)||(this._ackTimeoutRegistry.add({topic:r.TOPIC.EVENT,action:r.ACTIONS.UNSUBSCRIBE,name:t}),this._connection.sendMsg(r.TOPIC.EVENT,r.ACTIONS.UNSUBSCRIBE,[t]))},h.prototype.emit=function(t,e){if("string"!=typeof t||0===t.length)throw new Error("invalid argument name");this._connection.sendMsg(r.TOPIC.EVENT,r.ACTIONS.EVENT,[t,n.typed(e)]),this._emitter.emit(t,e)},h.prototype.listen=function(t,e){if("string"!=typeof t||0===t.length)throw new Error("invalid argument pattern");if("function"!=typeof e)throw new Error("invalid argument callback");!this._listener[t]||this._listener[t].destroyPending?(this._listener[t]&&this._listener[t].destroy(),this._listener[t]=new a(r.TOPIC.EVENT,t,e,this._options,this._client,this._connection)):this._client._$onError(r.TOPIC.EVENT,r.EVENT.LISTENER_EXISTS,t)},h.prototype.unlisten=function(t){if("string"!=typeof t||0===t.length)throw new Error("invalid argument pattern");var e=this._listener[t];e&&!e.destroyPending?e.sendDestroy():this._listener[t]?(this._ackTimeoutRegistry.add({topic:r.TOPIC.EVENT,action:r.EVENT.UNLISTEN,name:t}),this._listener[t].destroy(),delete this._listener[t]):this._client._$onError(r.TOPIC.RECORD,r.EVENT.NOT_LISTENING,t)},h.prototype._$handle=function(t){var e=t.data[t.action===r.ACTIONS.ACK?1:0];if(t.action!==r.ACTIONS.EVENT){if(t.action===r.ACTIONS.ACK&&t.data[0]===r.ACTIONS.UNLISTEN&&this._listener[e]&&this._listener[e].destroyPending)return this._listener[e].destroy(),void delete this._listener[e];if(this._listener[e])this._listener[e]._$onMessage(t);else if(t.action!==r.ACTIONS.SUBSCRIPTION_FOR_PATTERN_REMOVED&&t.action!==r.ACTIONS.SUBSCRIPTION_HAS_PROVIDER){if(t.action!==r.ACTIONS.ACK)return t.action===r.ACTIONS.ERROR?(t.data[0]===r.EVENT.MESSAGE_DENIED?this._ackTimeoutRegistry.remove({topic:r.TOPIC.EVENT,name:t.data[1],action:t.data[2]}):t.data[0]===r.EVENT.NOT_SUBSCRIBED&&this._ackTimeoutRegistry.remove({topic:r.TOPIC.EVENT,name:t.data[1],action:r.ACTIONS.UNSUBSCRIBE}),t.processedError=!0,void this._client._$onError(r.TOPIC.EVENT,t.data[0],t.data[1])):void this._client._$onError(r.TOPIC.EVENT,r.EVENT.UNSOLICITED_MESSAGE,e);this._ackTimeoutRegistry.clear(t)}}else t.data&&2===t.data.length?this._emitter.emit(e,s.convertTyped(t.data[1],this._client)):this._emitter.emit(e)},h.prototype._resubscribe=function(){var t=this._emitter._callbacks;for(var e in t)this._connection.sendMsg(r.TOPIC.EVENT,r.ACTIONS.SUBSCRIBE,[e])},e.exports=h},{"../constants/constants":11,"../message/message-builder":16,"../message/message-parser":17,"../utils/listener":28,"../utils/resubscribe-notifier":29,"component-emitter2":2}],15:[function(t,e,i){(function(i){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},s=i.WebSocket||i.MozWebSocket,o=t("ws"),r=t("./message-parser"),a=t("./message-builder"),c=t("../utils/utils"),h=t("../constants/constants"),u=function(t,e,i){this._client=t,this._options=i,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=c.parseUrl(e,this._options.path),this._url=this._originalUrl,this._state=h.CONNECTION_STATE.CLOSED,this._createEndpoint()};u.prototype.getState=function(){return this._state},u.prototype.authenticate=function(t,e){if("object"===(void 0===t?"undefined":n(t))){if(this._authParams=t,this._authCallback=e,!(this._tooManyAuthAttempts||this._challengeDenied||this._connectionAuthenticationTimeout))return!0===this._deliberateClose&&this._state===h.CONNECTION_STATE.CLOSED?(this._createEndpoint(),void(this._deliberateClose=!1)):void(this._state===h.CONNECTION_STATE.AWAITING_AUTHENTICATION&&this._sendAuthParams());this._client._$onError(h.TOPIC.ERROR,h.EVENT.IS_CLOSED,"this client's connection was closed")}else this._client._$onError(h.TOPIC.ERROR,h.EVENT.INVALID_AUTH_MSG,"authParams is not an object")},u.prototype.sendMsg=function(t,e,i){this.send(a.getMsg(t,e,i))},u.prototype.send=function(t){this._queuedMessages.push(t),this._currentPacketMessageCount++,null===this._currentMessageResetTimeout&&(this._currentMessageResetTimeout=c.nextTick(this._resetCurrentMessageCount.bind(this))),this._state===h.CONNECTION_STATE.OPEN&&this._queuedMessages.lengtht&&(clearInterval(this._heartbeatInterval),this._endpoint.close(),this._client._$onError(h.TOPIC.CONNECTION,h.EVENT.CONNECTION_ERROR,"heartbeat not received in the last "+t+" milliseconds"))},u.prototype._onOpen=function(){this._clearReconnect(),this._lastHeartBeat=Date.now(),this._heartbeatInterval=c.setInterval(this._checkHeartBeat.bind(this),this._options.heartbeatInterval),this._setState(h.CONNECTION_STATE.AWAITING_CONNECTION)},u.prototype._onError=function(t){var e=this;clearInterval(this._heartbeatInterval),this._setState(h.CONNECTION_STATE.ERROR),setTimeout(function(){var i=void 0;if("ECONNRESET"===t.code||"ECONNREFUSED"===t.code)i="Can't connect! Deepstream server unreachable on "+e._originalUrl;else try{i=JSON.stringify(t)}catch(e){i=t.toString()}e._client._$onError(h.TOPIC.CONNECTION,h.EVENT.CONNECTION_ERROR,i)},1)},u.prototype._onClose=function(){clearInterval(this._heartbeatInterval),!0===this._redirecting?(this._redirecting=!1,this._createEndpoint()):!0===this._deliberateClose?this._setState(h.CONNECTION_STATE.CLOSED):this._tryReconnect()},u.prototype._onMessage=function(t){for(var e=r.parse(t.data,this._client),i=0;i2&&i.push(this._parseMessage(s[o],e));return i},s.prototype.convertTyped=function(t,e){var i=t.charAt(0);if(i===n.TYPES.STRING)return t.substr(1);if(i===n.TYPES.OBJECT)try{return JSON.parse(t.substr(1))}catch(i){return void e._$onError(n.TOPIC.ERROR,n.EVENT.MESSAGE_PARSE_ERROR,i.toString()+"("+t+")")}return i===n.TYPES.NUMBER?parseFloat(t.substr(1)):i===n.TYPES.NULL?null:i===n.TYPES.TRUE||i!==n.TYPES.FALSE&&void(i!==n.TYPES.UNDEFINED&&e._$onError(n.TOPIC.ERROR,n.EVENT.MESSAGE_PARSE_ERROR,"UNKNOWN_TYPE ("+t+")"))},s.prototype._getActions=function(){var t={};for(var e in n.ACTIONS)t[n.ACTIONS[e]]=e;return t},s.prototype._parseMessage=function(t,e){var i=t.split(n.MESSAGE_PART_SEPERATOR),s={};return i.length<2?(e._$onError(n.TOPIC.ERROR,n.EVENT.MESSAGE_PARSE_ERROR,"Insufficiant message parts"),null):void 0===this._actions[i[1]]?(e._$onError(n.TOPIC.ERROR,n.EVENT.MESSAGE_PARSE_ERROR,"Unknown action "+i[1]),null):(s.raw=t,s.topic=i[0],s.action=i[1],s.data=i.splice(2),s)},e.exports=new s},{"../constants/constants":11}],18:[function(t,e,i){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function s(t,e,i){if("function"==typeof t&&void 0===e?(e=t,t=i):t=[t],void 0!==e&&"function"!=typeof e)throw new Error("invalid argument callback");return{userId:t,callback:e}}var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r=function(){function t(t,e){for(var i=0;i-1&&(t.splice(t.indexOf(c.ACTIONS.SUBSCRIBE),1),this._sendGlobalSubscription(c.ACTIONS.SUBSCRIBE)),t.length>0&&this._sendSubscriptionBulk(c.ACTIONS.SUBSCRIBE,t)}},{key:"_flush",value:function(){var t=Object.keys(this._pendingSubscribes);t.length>0&&(this._sendSubscriptionBulk(c.ACTIONS.SUBSCRIBE,t),this._pendingSubscribes={});var e=Object.keys(this._pendingUnsubscribes);e.length>0&&(this._sendSubscriptionBulk(c.ACTIONS.UNSUBSCRIBE,e),this._pendingUnsubscribes={}),this._flushTimeout=null}},{key:"_sendSubscriptionBulk",value:function(t,e){var i=this._counter++;this._ackTimeoutRegistry.add({topic:c.TOPIC.PRESENCE,action:t,name:i}),this._connection.sendMsg(c.TOPIC.PRESENCE,t,[i,e])}},{key:"_sendGlobalSubscription",value:function(t){this._ackTimeoutRegistry.add({topic:c.TOPIC.PRESENCE,action:t,name:t}),this._connection.sendMsg(c.TOPIC.PRESENCE,t,[t])}}]),t}()},{"../constants/constants":11,"../utils/resubscribe-notifier":29,"component-emitter2":2}],19:[function(t,e,i){"use strict";var n=t("./record"),s=function(t){this.name=null,this._recordHandler=t,this._record=null,this._subscriptions=[],this._proxyMethod("delete"),this._proxyMethod("set"),this._proxyMethod("discard")};t("component-emitter2")(s.prototype),s.prototype.get=function(t){if(null!==this._record)return this._record.get(t)},s.prototype.subscribe=function(){var t=n.prototype._normalizeArguments(arguments);t.triggerNow=!0,this._subscriptions.push(t),null!==this._record&&this._record.subscribe(t)},s.prototype.unsubscribe=function(){var t=n.prototype._normalizeArguments(arguments),e=[],i=void 0;for(i=0;i=i.length||t<0))throw new Error("Index must be within current entries");e=!0}return e},r.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},r.prototype._afterChange=function(){if(null!==this._beforeStructure){var t=this._getStructure(),e=this._beforeStructure,i=void 0,n=void 0;if(this._hasRemoveListener)for(i in e)for(n=0;n1?t.topic+t.data[0]+(t.data[1]?t.data[1]:""):t.topic+t.action+t.data[0],this._register[e]&&clearTimeout(this._register[e].__timeout),delete this._register[e]},s.prototype._onTimeout=function(t){if(delete this._register[this._getUniqueName(t)],t.callback)delete t.__timeout,delete t.timeout,t.callback(t);else{var e="No ACK message received in time"+(t.name?" for "+t.name:"");this._client._$onError(t.topic,t.event,e)}},s.prototype._getUniqueName=function(t){return t.topic+t.action+(t.name?t.name:"")},s.prototype._onConnectionStateChanged=function(t){if(t!==n.CONNECTION_STATE.OPEN)for(var e in this._register)clearTimeout(this._register[e].__timeout)},e.exports=s},{"../constants/constants":11,"component-emitter2":2}],28:[function(t,e,i){"use strict";var n=t("../constants/constants"),s=t("./resubscribe-notifier"),o=function(t,e,i,o,r,a){this._topic=t,this._callback=i,this._pattern=e,this._options=o,this._client=r,this._connection=a,this._ackTimeoutRegistry=r._$getAckTimeoutRegistry(),this._ackTimeoutRegistry.add({topic:this._topic,name:e,action:n.ACTIONS.LISTEN}),this._resubscribeNotifier=new s(r,this._sendListen.bind(this)),this._sendListen(),this.destroyPending=!1};o.prototype.sendDestroy=function(){this.destroyPending=!0,this._connection.sendMsg(this._topic,n.ACTIONS.UNLISTEN,[this._pattern]),this._resubscribeNotifier.destroy()},o.prototype.destroy=function(){this._callback=null,this._pattern=null,this._client=null,this._connection=null},o.prototype.accept=function(t){this._connection.sendMsg(this._topic,n.ACTIONS.LISTEN_ACCEPT,[this._pattern,t])},o.prototype.reject=function(t){this._connection.sendMsg(this._topic,n.ACTIONS.LISTEN_REJECT,[this._pattern,t])},o.prototype._createCallbackResponse=function(t){return{accept:this.accept.bind(this,t.data[1]),reject:this.reject.bind(this,t.data[1])}},o.prototype._$onMessage=function(t){t.action===n.ACTIONS.ACK?this._ackTimeoutRegistry.clear(t):t.action===n.ACTIONS.SUBSCRIPTION_FOR_PATTERN_FOUND?this._callback(t.data[1],!0,this._createCallbackResponse(t)):t.action===n.ACTIONS.SUBSCRIPTION_FOR_PATTERN_REMOVED?this._callback(t.data[1],!1):this._client._$onError(this._topic,n.EVENT.UNSOLICITED_MESSAGE,t.data[0]+"|"+t.data[1])},o.prototype._sendListen=function(){this._connection.sendMsg(this._topic,n.ACTIONS.LISTEN,[this._pattern])},e.exports=o},{"../constants/constants":11,"./resubscribe-notifier":29}],29:[function(t,e,i){"use strict";var n=t("../constants/constants"),s=function(t,e){this._client=t,this._resubscribe=e,this._isReconnecting=!1,this._connectionStateChangeHandler=this._handleConnectionStateChanges.bind(this),this._client.on("connectionStateChanged",this._connectionStateChangeHandler)};s.prototype.destroy=function(){this._client.removeListener("connectionStateChanged",this._connectionStateChangeHandler),this._connectionStateChangeHandler=null,this._client=null},s.prototype._handleConnectionStateChanges=function(){var t=this._client.getConnectionState();t===n.CONNECTION_STATE.RECONNECTING&&!1===this._isReconnecting&&(this._isReconnecting=!0),t===n.CONNECTION_STATE.OPEN&&!0===this._isReconnecting&&(this._isReconnecting=!1,this._resubscribe())},e.exports=s},{"../constants/constants":11}],30:[function(t,e,i){"use strict";var n=t("../constants/constants"),s=t("./resubscribe-notifier"),o=function(t,e,i,n,o){this._client=t,this._connection=e,this._topic=i,this._action=n,this._timeoutDuration=o,this._requests={},this._ackTimeoutRegistry=t._$getAckTimeoutRegistry(),this._resubscribeNotifier=new s(this._client,this._resendRequests.bind(this)),this._onResponseTimeout=this._onResponseTimeout.bind(this)};o.prototype.hasRequest=function(t){return!!this._requests[t]},o.prototype.request=function(t,e){this._requests[t]||(this._requests[t]=[],this._connection.sendMsg(this._topic,this._action,[t]));var i=this._ackTimeoutRegistry.add({topic:this._topic,event:n.EVENT.RESPONSE_TIMEOUT,name:t,action:this._action,timeout:this._timeoutDuration,callback:this._onResponseTimeout});this._requests[t].push({callback:e,ackId:i})},o.prototype.recieve=function(t,e,i){var s=this._requests[t];if(s){for(var o=0;o1)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;var h=/\+/g;a=a.split(b);var i=1e3;f&&"number"==typeof f.maxKeys&&(i=f.maxKeys);var j=a.length;i>0&&j>i&&(j=i);for(var k=0;k=0?(l=p.substr(0,q),m=p.substr(q+1)):(l=p,m=""),n=decodeURIComponent(l),o=decodeURIComponent(m),d(g,n)?e(g[n])?g[n].push(o):g[n]=[g[n],o]:g[n]=o}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=/^[+a-z0-9A-Z_-]{0,63}$/,t=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,u={javascript:!0,"javascript:":!0},v={javascript:!0,"javascript:":!0},w={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},x=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?I+="x":I+=H[J];if(!I.match(s)){var L=F.slice(0,A),M=F.slice(A+1),N=H.match(t);N&&(L.push(N[1]),M.unshift(N[2])),M.length&&(h="/"+M.join(".")+h),this.hostname=L.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),E||(this.hostname=i.toASCII(this.hostname));var O=this.port?":"+this.port:"",P=this.hostname||"";this.host=P+O,this.href+=this.host,E&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==h[0]&&(h="/"+h))}if(!u[o])for(var A=0,G=p.length;A0)&&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(!t&&!u)for(;C--;C)x.unshift("..");!t||""===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 t=t||c.host&&x.length,t&&!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.CREATEANDUPDATE="CU",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.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._endpoint.close(),this._client._$onError(j.TOPIC.CONNECTION,j.EVENT.CONNECTION_ERROR,"heartbeat not received in the last "+a+" milliseconds"))},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;if("ECONNRESET"===a.code||"ECONNREFUSED"===a.code)c="Can't connect! Deepstream server unreachable on "+b._originalUrl;else try{c=JSON.stringify(a)}catch(b){c=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";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function e(a,b,c){if("function"==typeof a&&void 0===b?(b=a,a=c):a=[a],void 0!==b&&"function"!=typeof b)throw new Error("invalid argument callback");return{userId:a,callback:b}}var f="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},g=function(){function a(a,b){for(var c=0;c-1&&(a.splice(a.indexOf(i.ACTIONS.SUBSCRIBE),1),this._sendGlobalSubscription(i.ACTIONS.SUBSCRIBE)),a.length>0&&this._sendSubscriptionBulk(i.ACTIONS.SUBSCRIBE,a)}},{key:"_flush",value:function(){var a=Object.keys(this._pendingSubscribes);a.length>0&&(this._sendSubscriptionBulk(i.ACTIONS.SUBSCRIBE,a),this._pendingSubscribes={});var b=Object.keys(this._pendingUnsubscribes);b.length>0&&(this._sendSubscriptionBulk(i.ACTIONS.UNSUBSCRIBE,b),this._pendingUnsubscribes={}),this._flushTimeout=null}},{key:"_sendSubscriptionBulk",value:function(a,b){var c=this._counter++;this._ackTimeoutRegistry.add({topic:i.TOPIC.PRESENCE,action:a,name:c}),this._connection.sendMsg(i.TOPIC.PRESENCE,a,[c,b])}},{key:"_sendGlobalSubscription",value:function(a){this._ackTimeoutRegistry.add({topic:i.TOPIC.PRESENCE,action:a,name:a}),this._connection.sendMsg(i.TOPIC.PRESENCE,a,[a])}}]),a}()},{"../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