/
deepstream.min.js
5 lines (4 loc) · 73.7 KB
/
deepstream.min.js
1
2
3
4
5
/*! deepstream.io-client-js 2.2.1 (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;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){function d(a){if(a)return e(a)}function e(a){for(var b in d.prototype)a[b]=d.prototype[b];return a}void 0!==b&&(b.exports=d),d.prototype.on=d.prototype.addEventListener=function(a,b){return this._callbacks=this._callbacks||Object.create(null),(this._callbacks[a]=this._callbacks[a]||[]).push(b),this},d.prototype.once=function(a,b){function c(){this.off(a,c),b.apply(this,arguments)}return c.fn=b,this.on(a,c),this},d.prototype.off=d.prototype.removeListener=d.prototype.removeAllListeners=d.prototype.removeEventListener=function(a,b){if(this._callbacks=this._callbacks||Object.create(null),0==arguments.length)return this._callbacks=Object.create(null),this;var c=this._callbacks[a];if(!c)return this;if(1==arguments.length)return delete this._callbacks[a],this;for(var d,e=0;e<c.length;e++)if((d=c[e])===b||d.fn===b){c.splice(e,1);break}return 0===c.length&&delete this._callbacks[a],this},d.prototype.emit=function(a){this._callbacks=this._callbacks||Object.create(null);for(var b=new Array(arguments.length-1),c=this._callbacks[a],d=1;d<arguments.length;d++)b[d-1]=arguments[d];if(c){c=c.slice(0);for(var d=0,e=c.length;d<e;++d)c[d].apply(this,b)}return this},d.prototype.listeners=function(a){return this._callbacks=this._callbacks||Object.create(null),this._callbacks[a]||[]},d.prototype.hasListeners=function(a){return!!this.listeners(a).length},d.prototype.eventNames=function(){return this._callbacks?Object.keys(this._callbacks):[]}},{}],2:[function(a,b,c){},{}],3:[function(a,b,c){function d(){throw new Error("setTimeout has not been defined")}function e(){throw new Error("clearTimeout has not been defined")}function f(a){if(l===setTimeout)return setTimeout(a,0);if((l===d||!l)&&setTimeout)return l=setTimeout,setTimeout(a,0);try{return l(a,0)}catch(b){try{return l.call(null,a,0)}catch(b){return l.call(this,a,0)}}}function g(a){if(m===clearTimeout)return clearTimeout(a);if((m===e||!m)&&clearTimeout)return m=clearTimeout,clearTimeout(a);try{return m(a)}catch(b){try{return m.call(null,a)}catch(b){return m.call(this,a)}}}function h(){q&&o&&(q=!1,o.length?p=o.concat(p):r=-1,p.length&&i())}function i(){if(!q){var a=f(h);q=!0;for(var b=p.length;b;){for(o=p,p=[];++r<b;)o&&o[r].run();r=-1,b=p.length}o=null,q=!1,g(a)}}function j(a,b){this.fun=a,this.array=b}function k(){}var l,m,n=b.exports={};!function(){try{l="function"==typeof setTimeout?setTimeout:d}catch(a){l=d}try{m="function"==typeof clearTimeout?clearTimeout:e}catch(a){m=e}}();var o,p=[],q=!1,r=-1;n.nextTick=function(a){var b=new Array(arguments.length-1);if(arguments.length>1)for(var c=1;c<arguments.length;c++)b[c-1]=arguments[c];p.push(new j(a,b)),1!==p.length||q||f(i)},j.prototype.run=function(){this.fun.apply(null,this.array)},n.title="browser",n.browser=!0,n.env={},n.argv=[],n.version="",n.versions={},n.on=k,n.addListener=k,n.once=k,n.off=k,n.removeListener=k,n.removeAllListeners=k,n.emit=k,n.binding=function(a){throw new Error("process.binding is not supported")},n.cwd=function(){return"/"},n.chdir=function(a){throw new Error("process.chdir is not supported")},n.umask=function(){return 0}},{}],4:[function(b,c,d){(function(b){!function(e){function f(a){throw new RangeError(I[a])}function g(a,b){for(var c=a.length,d=[];c--;)d[c]=b(a[c]);return d}function h(a,b){var c=a.split("@"),d="";return c.length>1&&(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<f;)b=a.charCodeAt(e++),b>=55296&&b<=56319&&e<f?(c=a.charCodeAt(e++),56320==(64512&c)?d.push(((1023&b)<<10)+(1023&c)+65536):(d.push(b),e--)):d.push(b);return d}function j(a){return g(a,function(a){var b="";return a>65535&&(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<c;++d)a.charCodeAt(d)>=128&&f("not-basic"),p.push(a.charCodeAt(d));for(e=c>0?c+1:0;e<q;){for(g=r,h=1,i=x;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,!(l<n);i+=x)o=x-n,h>K(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<q;++h)(p=a[h])<128&&u.push(L(p));for(d=e=u.length,e&&u.push(E);d<q;){for(j=w,h=0;h<q;++h)(p=a[h])>=b&&p<j&&(j=p);for(r=d+1,j-b>K((w-c)/r)&&f("overflow"),c+=(j-b)*r,b=j,h=0;h<q;++h)if(p=a[h],p<b&&++c>w&&f("overflow"),p==b){for(k=c,n=x;o=n<=g?y:n>=g+z?z:n-g,!(k<o);n+=x)t=k-o,s=x-o,u.push(L(l(o+t%s,0))),k=K(t/s);u.push(L(l(k,0))),g=m(c,r,d==e),c=0,++d}++c,++b}return u.join("")}function p(a){return h(a,function(a){return F.test(a)?n(a.slice(4).toLowerCase()):a})}function q(a){return h(a,function(a){return G.test(a)?"xn--"+o(a):a})}var r="object"==typeof d&&d&&!d.nodeType&&d,s="object"==typeof c&&c&&!c.nodeType&&c,t="object"==typeof b&&b;t.global!==t&&t.window!==t&&t.self!==t||(e=t);var u,v,w=2147483647,x=36,y=1,z=26,A=38,B=700,C=72,D=128,E="-",F=/^xn--/,G=/[^\x20-\x7E]/,H=/[\x2E\u3002\uFF0E\uFF61]/g,I={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 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<i;++j){var k,l,m,n,o=a[j].replace(/\+/g,"%20"),p=o.indexOf(c);p>=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<a.length;d++)c.push(b(a[d],d));return c}var e=function(a){switch(typeof a){case"string":return a;case"boolean":return a?"true":"false";case"number":return isFinite(a)?a:"";default:return""}};b.exports=function(a,b,c,h){return b=b||"&",c=c||"=",null===a&&(a=void 0),"object"==typeof a?d(g(a),function(g){var h=encodeURIComponent(e(g))+c;return f(a[g])?d(a[g],function(a){return h+encodeURIComponent(e(a))}).join(b):h+encodeURIComponent(e(a[g]))}).join(b):h?encodeURIComponent(e(h))+c+encodeURIComponent(e(a)):""};var f=Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)},g=Object.keys||function(a){var b=[];for(var c in a)Object.prototype.hasOwnProperty.call(a,c)&&b.push(c);return b}},{}],7:[function(a,b,c){"use strict";c.decode=c.parse=a("./decode"),c.encode=c.stringify=a("./encode")},{"./decode":5,"./encode":6}],8:[function(a,b,c){"use strict";function d(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}function e(a,b,c){if(a&&j.isObject(a)&&a instanceof d)return a;var e=new d;return e.parse(a,b,c),e}function f(a){return j.isString(a)&&(a=e(a)),a instanceof d?a.format():d.prototype.format.call(a)}function g(a,b){return e(a,!1,!0).resolve(b)}function h(a,b){return a?e(a,!1,!0).resolveObject(b):b}var i=a("punycode"),j=a("./util");c.parse=e,c.resolve=g,c.resolveObject=h,c.format=f,c.Url=d;var k=/^([a-z0-9.+-]+:)/i,l=/:[0-9]*$/,m=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,n=["<",">",'"',"`"," ","\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&&d<a.indexOf("#")?"?":"#",f=a.split(e);f[0]=f[0].replace(/\\/g,"/"),a=f.join(e);var g=a;if(g=g.trim(),!c&&1===a.split("#").length){var h=m.exec(g);if(h)return this.path=g,this.href=g,this.pathname=h[1],h[2]?(this.search=h[2],this.query=b?v.parse(this.search.substr(1)):this.search.substr(1)):b&&(this.search="",this.query={}),this}var l=k.exec(g);if(l){l=l[0];var n=l.toLowerCase();this.protocol=n,g=g.substr(l.length)}if(c||l||g.match(/^\/\/[^@\/]+@[^@\/]+/)){var o="//"===g.substr(0,2);!o||l&&t[l]||(g=g.substr(2),this.slashes=!0)}if(!t[l]&&(o||l&&!u[l])){for(var w=-1,x=0;x<r.length;x++){var y=g.indexOf(r[x]);-1!==y&&(-1===w||y<w)&&(w=y)}var z,A;A=-1===w?g.lastIndexOf("@"):g.lastIndexOf("@",w),-1!==A&&(z=g.slice(0,A),g=g.slice(A+1),this.auth=decodeURIComponent(z)),w=-1;for(var x=0;x<q.length;x++){var y=g.indexOf(q[x]);-1!==y&&(-1===w||y<w)&&(w=y)}-1===w&&(w=g.length),this.host=g.slice(0,w),g=g.slice(w),this.parseHost(),this.hostname=this.hostname||"";var B="["===this.hostname[0]&&"]"===this.hostname[this.hostname.length-1];if(!B)for(var C=this.hostname.split(/\./),x=0,D=C.length;x<D;x++){var E=C[x];if(E&&!E.match(/^[+a-z0-9A-Z_-]{0,63}$/)){for(var F="",G=0,H=E.length;G<H;G++)E.charCodeAt(G)>127?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;x<D;x++){var N=p[x];if(-1!==g.indexOf(N)){var O=encodeURIComponent(N);O===N&&(O=escape(N)),g=g.split(N).join(O)}}var P=g.indexOf("#");-1!==P&&(this.hash=g.substr(P),g=g.slice(0,P));var Q=g.indexOf("?");if(-1!==Q?(this.search=g.substr(Q),this.query=g.substr(Q+1),b&&(this.query=v.parse(this.query)),g=g.slice(0,Q)):b&&(this.search="",this.query={}),g&&(this.pathname=g),u[n]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){var L=this.pathname||"",R=this.search||"";this.path=L+R}return this.href=this.format(),this},d.prototype.format=function(){var a=this.auth||"";a&&(a=encodeURIComponent(a),a=a.replace(/%3A/i,":"),a+="@");var b=this.protocol||"",c=this.pathname||"",d=this.hash||"",e=!1,f="";this.host?e=a+this.host:this.hostname&&(e=a+(-1===this.hostname.indexOf(":")?this.hostname:"["+this.hostname+"]"),this.port&&(e+=":"+this.port)),this.query&&j.isObject(this.query)&&Object.keys(this.query).length&&(f=v.stringify(this.query));var g=this.search||f&&"?"+f||"";return b&&":"!==b.substr(-1)&&(b+=":"),this.slashes||(!b||u[b])&&!1!==e?(e="//"+(e||""),c&&"/"!==c.charAt(0)&&(c="/"+c)):e||(e=""),d&&"#"!==d.charAt(0)&&(d="#"+d),g&&"?"!==g.charAt(0)&&(g="?"+g),c=c.replace(/[?#]/g,function(a){return encodeURIComponent(a)}),g=g.replace("#","%23"),b+e+c+g+d},d.prototype.resolve=function(a){return this.resolveObject(e(a,!1,!0)).format()},d.prototype.resolveObject=function(a){if(j.isString(a)){var b=new d;b.parse(a,!1,!0),a=b}for(var c=new d,e=Object.keys(this),f=0;f<e.length;f++){var g=e[f];c[g]=this[g]}if(c.hash=a.hash,""===a.href)return c.href=c.format(),c;if(a.slashes&&!a.protocol){for(var h=Object.keys(a),i=0;i<h.length;i++){var k=h[i];"protocol"!==k&&(c[k]=a[k])}return u[c.protocol]&&c.hostname&&!c.pathname&&(c.path=c.pathname="/"),c.href=c.format(),c}if(a.protocol&&a.protocol!==c.protocol){if(!u[a.protocol]){for(var l=Object.keys(a),m=0;m<l.length;m++){var n=l[m];c[n]=a[n]}return c.href=c.format(),c}if(c.protocol=a.protocol,a.host||t[a.protocol])c.pathname=a.pathname;else{for(var o=(a.pathname||"").split("/");o.length&&!(a.host=o.shift()););a.host||(a.host=""),a.hostname||(a.hostname=""),""!==o[0]&&o.unshift(""),o.length<2&&o.unshift(""),c.pathname=o.join("/")}if(c.search=a.search,c.query=a.query,c.host=a.host||"",c.auth=a.auth,c.hostname=a.hostname||a.host,c.port=a.port,c.pathname||c.search){var p=c.pathname||"",q=c.search||"";c.path=p+q}return c.slashes=c.slashes||a.slashes,c.href=c.format(),c}var r=c.pathname&&"/"===c.pathname.charAt(0),s=a.host||a.pathname&&"/"===a.pathname.charAt(0),v=s||r||c.host&&a.pathname,w=v,x=c.pathname&&c.pathname.split("/")||[],o=a.pathname&&a.pathname.split("/")||[],y=c.protocol&&!u[c.protocol];if(y&&(c.hostname="",c.port=null,c.host&&(""===x[0]?x[0]=c.host:x.unshift(c.host)),c.host="",a.protocol&&(a.hostname=null,a.port=null,a.host&&(""===o[0]?o[0]=a.host:o.unshift(a.host)),a.host=null),v=v&&(""===o[0]||""===x[0])),s)c.host=a.host||""===a.host?a.host:c.host,c.hostname=a.hostname||""===a.hostname?a.hostname:c.hostname,c.search=a.search,c.query=a.query,x=o;else if(o.length)x||(x=[]),x.pop(),x=x.concat(o),c.search=a.search,c.query=a.query;else if(!j.isNullOrUndefined(a.search)){if(y){c.hostname=c.host=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 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":1}],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.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":1}],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.length<this._options.maxMessagesPerPacket&&this._currentPacketMessageCount<this._options.maxMessagesPerPacket?this._sendQueuedMessages():null===this._sendNextPacketTimeout&&this._queueNextPacket()},k.prototype.close=function(){clearInterval(this._heartbeatInterval),this._deliberateClose=!0,this._endpoint.close()},k.prototype._createEndpoint=function(){this._endpoint=e?new e(this._url):new f(this._url,this._options.nodeSocketOptions),this._endpoint.onopen=this._onOpen.bind(this),this._endpoint.onerror=this._onError.bind(this),this._endpoint.onclose=this._onClose.bind(this),this._endpoint.onmessage=this._onMessage.bind(this)},k.prototype._resetCurrentMessageCount=function(){this._currentPacketMessageCount=0,this._currentMessageResetTimeout=null},k.prototype._sendQueuedMessages=function(){if(this._state===j.CONNECTION_STATE.OPEN&&this._endpoint.readyState===this._endpoint.OPEN){if(0===this._queuedMessages.length)return void(this._sendNextPacketTimeout=null);var a=this._queuedMessages.splice(0,this._options.maxMessagesPerPacket).join("");0!==this._queuedMessages.length?this._queueNextPacket():this._sendNextPacketTimeout=null,this._submit(a)}},k.prototype._submit=function(a){this._endpoint.readyState===this._endpoint.OPEN?this._endpoint.send(a):this._onError("Tried to send message on a closed websocket connection")},k.prototype._queueNextPacket=function(){var a=this._sendQueuedMessages.bind(this),b=this._options.timeBetweenSendingQueuedPackages;this._sendNextPacketTimeout=setTimeout(a,b)},k.prototype._sendAuthParams=function(){this._setState(j.CONNECTION_STATE.AUTHENTICATING);var a=h.getMsg(j.TOPIC.AUTH,j.ACTIONS.REQUEST,[this._authParams]);this._submit(a)},k.prototype._checkHeartBeat=function(){var a=2*this._options.heartbeatInterval;Date.now()-this._lastHeartBeat>a&&(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;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;c<b.length;c++)null!==b[c]&&(b[c].topic===j.TOPIC.CONNECTION?this._handleConnectionResponse(b[c]):b[c].topic===j.TOPIC.AUTH?this._handleAuthResponse(b[c]):this._client._$onMessage(b[c]))},k.prototype._handleConnectionResponse=function(a){a.action===j.ACTIONS.PING?(this._lastHeartBeat=Date.now(),this._submit(h.getMsg(j.TOPIC.CONNECTION,j.ACTIONS.PONG))):a.action===j.ACTIONS.ACK?(this._setState(j.CONNECTION_STATE.AWAITING_AUTHENTICATION),
this._authParams&&this._sendAuthParams()):a.action===j.ACTIONS.CHALLENGE?(this._setState(j.CONNECTION_STATE.CHALLENGING),this._submit(h.getMsg(j.TOPIC.CONNECTION,j.ACTIONS.CHALLENGE_RESPONSE,[this._originalUrl]))):a.action===j.ACTIONS.REJECTION?(this._challengeDenied=!0,this.close()):a.action===j.ACTIONS.REDIRECT?(this._url=a.data[0],this._redirecting=!0,this._endpoint.close()):a.action===j.ACTIONS.ERROR&&a.data[0]===j.EVENT.CONNECTION_AUTHENTICATION_TIMEOUT&&(this._deliberateClose=!0,this._connectionAuthenticationTimeout=!0,this._client._$onError(j.TOPIC.CONNECTION,a.data[0],a.data[1]))},k.prototype._handleAuthResponse=function(a){if(a.action===j.ACTIONS.ERROR){if(a.data[0]===j.EVENT.TOO_MANY_AUTH_ATTEMPTS)this._deliberateClose=!0,this._tooManyAuthAttempts=!0;else{if(a.data[0]===j.EVENT.INVALID_AUTH_MSG)return this._deliberateClose=!0,void(this._authCallback&&this._authCallback(!1,"invalid authentication message"));this._setState(j.CONNECTION_STATE.AWAITING_AUTHENTICATION)}this._authCallback&&this._authCallback(!1,this._getAuthData(a.data[1]))}else a.action===j.ACTIONS.ACK&&(this._setState(j.CONNECTION_STATE.OPEN),this._authCallback&&this._authCallback(!0,this._getAuthData(a.data[0])),this._sendQueuedMessages())},k.prototype._getAuthData=function(a){return void 0===a?null:g.convertTyped(a,this._client)},k.prototype._setState=function(a){this._state=a,this._client.emit(j.EVENT.CONNECTION_STATE_CHANGED,a)},k.prototype._tryReconnect=function(){null===this._reconnectTimeout&&(this._reconnectionAttempt<this._options.maxReconnectAttempts?(this._setState(j.CONNECTION_STATE.RECONNECTING),this._reconnectTimeout=setTimeout(this._tryOpen.bind(this),Math.min(this._options.maxReconnectInterval,this._options.reconnectIntervalIncrement*this._reconnectionAttempt)),this._reconnectionAttempt++):(this._clearReconnect(),this.close(),this._client.emit(j.EVENT.MAX_RECONNECTION_ATTEMPTS_REACHED,this._reconnectionAttempt)))},k.prototype._tryOpen=function(){this._originalUrl!==this._url&&(this._url=this._originalUrl),this._createEndpoint(),this._reconnectTimeout=null},k.prototype._clearReconnect=function(){clearTimeout(this._reconnectTimeout),this._reconnectTimeout=null,this._reconnectionAttempt=0},b.exports=k}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../constants/constants":11,"../utils/utils":31,"./message-builder":16,"./message-parser":17,ws:2}],16:[function(a,b,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=a("../constants/constants"),f=e.MESSAGE_PART_SEPERATOR;c.getMsg=function(a,b,c){if(c&&!(c instanceof Array))throw new Error("data must be an array");var g=[a,b];if(c)for(var h=0;h<c.length;h++)"object"===d(c[h])?g.push(JSON.stringify(c[h])):g.push(c[h]);return g.join(f)+e.MESSAGE_SEPERATOR},c.typed=function(a){var b=void 0===a?"undefined":d(a);if("string"===b)return e.TYPES.STRING+a;if(null===a)return e.TYPES.NULL;if("object"===b)return e.TYPES.OBJECT+JSON.stringify(a);if("number"===b)return e.TYPES.NUMBER+a.toString();if(!0===a)return e.TYPES.TRUE;if(!1===a)return e.TYPES.FALSE;if(void 0===a)return e.TYPES.UNDEFINED;throw new Error("Can't serialize type "+a)}},{"../constants/constants":11}],17:[function(a,b,c){"use strict";var d=a("../constants/constants"),e=function(){this._actions=this._getActions()};e.prototype.parse=function(a,b){for(var c=[],e=a.split(d.MESSAGE_SEPERATOR),f=0;f<e.length;f++)e[f].length>2&&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":1}],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<this._subscriptions.length;c++)this._subscriptions[c].path===a.path&&this._subscriptions[c].callback===a.callback||b.push(this._subscriptions[c]);this._subscriptions=b,null!==this._record&&this._record.unsubscribe(a)},f.prototype.setName=function(a){if(this.name!==a){this.name=a;var b=void 0;if(null!==this._record&&!this._record.isDestroyed){for(b=0;b<this._subscriptions.length;b++)this._record.unsubscribe(this._subscriptions[b]);this._record.discard()}for(this._record=this._recordHandler.getRecord(a),b=0;b<this._subscriptions.length;b++)this._record.subscribe(this._subscriptions[b]);this._record.whenReady(this.emit.bind(this,"ready")),this.emit("nameChanged",a)}},f.prototype._proxyMethod=function(a){this[a]=this._callMethodOnRecord.bind(this,a)},f.prototype._callMethodOnRecord=function(a){if(null===this._record)throw new Error("Can`t invoke "+a+". AnonymousRecord not initialised. Call setName first");if("function"!=typeof this._record[a])throw new Error(a+" is not a method on the record");var b=Array.prototype.slice.call(arguments,1);return this._record[a].apply(this._record,b)},b.exports=f},{"./record":23,"component-emitter2":1}],20:[function(a,b,c){"use strict";function d(a,b,c){var e=void 0,h=void 0;if(null===a||null===b)return b;if(Array.isArray(a)&&Array.isArray(b)){var i=void 0;for(e=0;e<b.length;e++){var j=d(a[e],b[e],!1);if(!i){if(j===a[e])continue;for(i=[],h=0;h<e;++h)i[h]=a[h]}i[e]=j}return i=i&&!1!==c?g.deepCopy(i):i,i=i||(a.length===b.length?a:b)}if(!Array.isArray(b)&&"object"===(void 0===a?"undefined":f(a))&&"object"===(void 0===b?"undefined":f(b))){var k=void 0,l=Object.keys(b);for(e=0;e<l.length;e++){var m=d(a[l[e]],b[l[e]],!1);if(!k){if(m===a[l[e]])continue;for(k=Object.create(null),h=0;h<e;++h)k[l[h]]=a[l[h]]}k[l[e]]=b[l[e]]}return k=k&&!1!==c?g.deepCopy(k):k,k=k||(Object.keys(a).length===l.length?a:b)}return b!==a?!1!==c?g.deepCopy(b):b:a}function e(a){if(i[a])return i[a];var b="undefined"!==String(a)?String(a).match(h):[];if(!b)throw new Error("invalid path "+a);return i[a]=b,i[a]}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=a("../utils/utils"),h=/([^.[\]\s]+)/g,i=Object.create(null);b.exports.get=function(a,b,c){for(var d=e(b),h=a,i=0;i<d.length;i++){if(void 0===h)return;if("object"!==(void 0===h?"undefined":f(h)))throw new Error("invalid data or path");h=h[d[i]]}return!1!==c?g.deepCopy(h):h},b.exports.set=function(a,c,f,h){var i=e(c);if(0===i.length)return d(a,f,h);var j=b.exports.get(a,c,!1),k=d(j,f,h);if(k===j)return a;for(var l=g.shallowCopy(a),m=l,n=0;n<i.length;n++)n===i.length-1?m[i[n]]=k:m=void 0!==m[i[n]]?m[i[n]]=g.shallowCopy(m[i[n]]):i[n+1]&&!isNaN(i[n+1])?m[i[n]]=[]:m[i[n]]=Object.create(null);return l}},{"../utils/utils":31}],21:[function(a,b,c){"use strict";var d=a("component-emitter2"),e=a("./record"),f=a("../constants/constants"),g=function(a,b,c){if("string"!=typeof b||0===b.length)throw new Error("invalid argument name");this._recordHandler=a,this._record=this._recordHandler.getRecord(b,c),this._record._applyUpdate=this._applyUpdate.bind(this),this._record.on("delete",this.emit.bind(this,"delete")),this._record.on("discard",this._onDiscard.bind(this)),this._record.on("ready",this._onReady.bind(this)),this.isDestroyed=this._record.isDestroyed,this.isReady=this._record.isReady,this.name=b,this._queuedMethods=[],this._beforeStructure=null,this._hasAddListener=null,this._hasRemoveListener=null,this._hasMoveListener=null,this.delete=this._record.delete.bind(this._record),this.discard=this._record.discard.bind(this._record),this.whenReady=this._record.whenReady.bind(this)};d(g.prototype),g.prototype.getEntries=function(){var a=this._record.get();return a instanceof Array?a:[]},g.prototype.isEmpty=function(){return 0===this.getEntries().length},g.prototype.setEntries=function(a){var b="entries must be an array of record names",c=void 0;if(!(a instanceof Array))throw new Error(b);for(c=0;c<a.length;c++)if("string"!=typeof a[c])throw new Error(b);!1===this._record.isReady?this._queuedMethods.push(this.setEntries.bind(this,a)):(this._beforeChange(),this._record.set(a),this._afterChange())},g.prototype.removeEntry=function(a,b){if(!1===this._record.isReady)return void this._queuedMethods.push(this.removeEntry.bind(this,a,b));var c=this._record.get(),d=this._hasIndex(b),e=[],f=void 0;for(f=0;f<c.length;f++)(c[f]!==a||d&&b!==f)&&e.push(c[f]);this._beforeChange(),this._record.set(e),this._afterChange()},g.prototype.addEntry=function(a,b){if("string"!=typeof a)throw new Error("Entry must be a recordName");if(!1===this._record.isReady)return void this._queuedMethods.push(this.addEntry.bind(this,a,b));var c=this._hasIndex(b),d=this.getEntries();c?d.splice(b,0,a):d.push(a),this._beforeChange(),this._record.set(d),this._afterChange()},g.prototype.subscribe=function(){var a=e.prototype._normalizeArguments(arguments);if(a.path)throw new Error("path is not supported for List.subscribe");var b=function(a){a(this.getEntries())}.bind(this,a.callback);a.callback.wrappedCallback=b,a.callback=b,this._record.subscribe(a)},g.prototype.unsubscribe=function(){var a=e.prototype._normalizeArguments(arguments);if(a.path)throw new Error("path is not supported for List.unsubscribe");a.callback=a.callback.wrappedCallback,this._record.unsubscribe(a)},g.prototype._onReady=function(){this.isReady=!0;for(var a=0;a<this._queuedMethods.length;a++)this._queuedMethods[a]();this._queuedMethods=[],this.emit("ready")},g.prototype._onDiscard=function(){this.isDestroyed=!0,this.emit("discard")},g.prototype._applyUpdate=function(a){if(a.action===f.ACTIONS.PATCH)throw new Error("PATCH is not supported for Lists");"["!==a.data[2].charAt(0)&&(a.data[2]="[]"),this._beforeChange(),e.prototype._applyUpdate.call(this._record,a),this._afterChange()},g.prototype._hasIndex=function(a){var b=!1,c=this.getEntries();if(void 0!==a){if(isNaN(a))throw new Error("Index must be a number");if(a!==c.length&&(a>=c.length||a<0))throw new Error("Index must be within current entries");b=!0}return b},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;d<b[c].length;d++)void 0!==a[c]&&void 0!==a[c][d]||this.emit("entry-removed",c,b[c][d]);if(this._hasAddListener||this._hasMoveListener)for(c in a)if(void 0===b[c])for(d=0;d<a[c].length;d++)this.emit("entry-added",c,a[c][d]);else for(d=0;d<a[c].length;d++)b[c][d]!==a[c][d]&&(void 0===b[c][d]?this.emit("entry-added",c,a[c][d]):this.emit("entry-moved",c,a[c][d]))}},g.prototype._getStructure=function(){var a={},b=void 0,c=this._record.get();for(b=0;b<c.length;b++)void 0===a[c[b]]?a[c[b]]=[b]:a[c[b]].push(b);return a},b.exports=g},{"../constants/constants":11,"./record":23,"component-emitter2":1}],22:[function(a,b,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=a("./record"),f=a("./anonymous-record"),g=a("./list"),h=a("../utils/listener"),i=a("../utils/single-notifier"),j=a("../constants/constants"),k=a("../message/message-parser"),l=a("../message/message-builder"),m=a("component-emitter2"),n=function(a,b,c){this._options=a,this._connection=b,this._client=c,this._records={},this._lists={},this._listener={},this._writeCallbacks={},this._destroyEventEmitter=new m,this._hasRegistry=new i(c,b,j.TOPIC.RECORD,j.ACTIONS.HAS,this._options.recordReadTimeout),this._snapshotRegistry=new i(c,b,j.TOPIC.RECORD,j.ACTIONS.SNAPSHOT,this._options.recordReadTimeout)};n.prototype.getRecord=function(a,b){return this._records[a]||(this._records[a]=new e(a,b||{},this._connection,this._options,this._client),this._records[a].on("error",this._onRecordError.bind(this,a)),this._records[a].on("destroyPending",this._onDestroyPending.bind(this,a)),this._records[a].on("delete",this._removeRecord.bind(this,a)),this._records[a].on("discard",this._removeRecord.bind(this,a))),this._records[a].usages++,this._records[a]},n.prototype.getList=function(a,b){return this._lists[a]?this._records[a].usages++:this._lists[a]=new g(this,a,b),this._lists[a]},n.prototype.getAnonymousRecord=function(){return new f(this)},n.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(j.TOPIC.RECORD,j.EVENT.LISTENER_EXISTS,a);this._listener[a]&&this._listener[a].destroy(),this._listener[a]=new h(j.TOPIC.RECORD,a,b,this._options,this._client,this._connection)},n.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._listener[a].destroy(),delete this._listener[a]):this._client._$onError(j.TOPIC.RECORD,j.EVENT.NOT_LISTENING,a)},n.prototype.snapshot=function(a,b){if("string"!=typeof a||0===a.length)throw new Error("invalid argument name");this._records[a]&&this._records[a].isReady?b(null,this._records[a].get()):this._snapshotRegistry.request(a,b)},n.prototype.has=function(a,b){if("string"!=typeof a||0===a.length)throw new Error("invalid argument name");this._records[a]?b(null,!0):this._hasRegistry.request(a,b)},n.prototype.setData=function(a,b,c,e){var f=void 0,g=void 0,h=void 0,i=!1;if(4===arguments.length?(f=b,g=c,h=e,i=!0):3===arguments.length?"string"==typeof b&&"function"!=typeof c?(f=b,g=c,i=!0):"object"===(void 0===b?"undefined":d(b))&&"function"==typeof c&&(f=null,g=b,h=c,i=!0):2===arguments.length&&"object"===(void 0===b?"undefined":d(b))&&(g=b,i=!0),!i)throw new Error("incorrect arguments used: records must exist as objects at the root level");var k=this._records[a];if(k)f&&h?k.set(f,g,h):f?k.set(f,g):h?k.set(g,h):k.set(g);else{var m=f?[a,-1,f,l.typed(g)]:[a,-1,g],n={};h&&(n.writeSuccess=!0,this._writeCallbacks[a]={},this._writeCallbacks[a][-1]=h),m.push(n),this._connection.sendMsg(j.TOPIC.RECORD,j.ACTIONS.CREATEANDUPDATE,m)}},n.prototype._$handle=function(a){var b=void 0;if(a.action===j.ACTIONS.ERROR&&a.data[0]!==j.EVENT.VERSION_EXISTS&&a.data[0]!==j.ACTIONS.SNAPSHOT&&a.data[0]!==j.ACTIONS.HAS&&a.data[0]!==j.EVENT.MESSAGE_DENIED)return a.processedError=!0,void this._client._$onError(j.TOPIC.RECORD,a.data[0],a.data[1]);if(a.action===j.ACTIONS.ACK||a.action===j.ACTIONS.ERROR){if(b=a.data[1],a.data[0]===j.ACTIONS.DELETE||a.data[0]===j.ACTIONS.UNSUBSCRIBE||a.data[0]===j.EVENT.MESSAGE_DENIED&&a.data[2]===j.ACTIONS.DELETE)return this._destroyEventEmitter.emit("destroy_ack_"+b,a),void(a.data[0]===j.ACTIONS.DELETE&&this._records[b]&&this._records[b]._$onMessage(a));if(a.data[0]===j.ACTIONS.SNAPSHOT)return a.processedError=!0,void this._snapshotRegistry.recieve(b,a.data[2]);if(a.data[0]===j.ACTIONS.HAS)return a.processedError=!0,void this._snapshotRegistry.recieve(b,a.data[2])}else b=a.data[0];var c=!1,d=this._records[b];d&&(c=!0,d._$onMessage(a)),a.action===j.ACTIONS.READ&&this._snapshotRegistry.hasRequest(b)?(c=!0,this._snapshotRegistry.recieve(b,null,JSON.parse(a.data[2]))):a.action===j.ACTIONS.HAS&&this._hasRegistry.hasRequest(b)?(c=!0,this._hasRegistry.recieve(b,null,k.convertTyped(a.data[1]))):a.action!==j.ACTIONS.WRITE_ACKNOWLEDGEMENT||d?a.action===j.ACTIONS.ACK&&a.data[0]===j.ACTIONS.UNLISTEN&&this._listener[b]&&this._listener[b].destroyPending?(c=!0,this._listener[b].destroy(),delete this._listener[b]):this._listener[b]?(c=!0,this._listener[b]._$onMessage(a)):a.action===j.ACTIONS.SUBSCRIPTION_FOR_PATTERN_REMOVED?c=!0:a.action===j.ACTIONS.SUBSCRIPTION_HAS_PROVIDER&&(c=!0):(c=!0,e._handleWriteAcknowledgements(a,this._writeCallbacks[b],this._client)),c||(a.processedError=!0,this._client._$onError(j.TOPIC.RECORD,j.EVENT.UNSOLICITED_MESSAGE,b))},n.prototype._onRecordError=function(a,b){this._client._$onError(j.TOPIC.RECORD,b,a)},n.prototype._onDestroyPending=function(a){if(!this._records[a])return void this._client._$onError(j.TOPIC.RECORD,"Record attempted to be destroyed but does not exists",a);var b=this._records[a]._$onMessage.bind(this._records[a]);this._destroyEventEmitter.once("destroy_ack_"+a,b),this._removeRecord(a)},n.prototype._removeRecord=function(a){delete this._records[a],delete this._lists[a]},b.exports=n},{"../constants/constants":11,"../message/message-builder":16,"../message/message-parser":17,"../utils/listener":28,"../utils/single-notifier":30,"./anonymous-record":19,"./list":21,"./record":23,"component-emitter2":1}],23:[function(a,b,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=a("./json-path"),f=a("../utils/resubscribe-notifier"),g=a("component-emitter2"),h=a("../constants/constants"),i=a("../message/message-builder"),j=a("../message/message-parser"),k=a("../utils/utils"),l=function(a,b,c,d,e){if("string"!=typeof a||0===a.length)throw new Error("invalid argument name");this.name=a,this.usages=0,this._recordOptions=b,this._connection=c,this._client=e,this._options=d,this.isReady=!1,this.isDestroyed=!1,this.hasProvider=!1,this._$data=Object.create(null),this.version=null,this._eventEmitter=new g,this._queuedMethodCalls=[],this._writeCallbacks={},this._mergeStrategy=null,d.mergeStrategy&&this.setMergeStrategy(d.mergeStrategy),this._ackTimeoutRegistry=e._$getAckTimeoutRegistry(),this._resubscribeNotifier=new f(this._client,this._sendRead.bind(this)),this._readAckTimeout=this._ackTimeoutRegistry.add({topic:h.TOPIC.RECORD,name:a,action:h.ACTIONS.SUBSCRIBE,timeout:this._options.recordReadAckTimeout}),this._responseTimeout=this._ackTimeoutRegistry.add({topic:h.TOPIC.RECORD,name:a,action:h.ACTIONS.READ,event:h.EVENT.RESPONSE_TIMEOUT,timeout:this._options.recordReadTimeout}),this._sendRead()};g(l.prototype),l.prototype.setMergeStrategy=function(a){if("function"!=typeof a)throw new Error("Invalid merge strategy: Must be a Function");this._mergeStrategy=a},l.prototype.get=function(a){return e.get(this._$data,a,this._options.recordDeepCopy)},l.prototype.set=function(a,b,c){var f=void 0,g=void 0;if(1===arguments.length){if("object"!==(void 0===a?"undefined":d(a)))throw new Error("invalid argument data");g=a}else if(2===arguments.length)if("string"==typeof a&&0!==a.length&&"function"!=typeof b)f=a,g=b;else{if("object"!==(void 0===a?"undefined":d(a))||"function"!=typeof b)throw new Error("invalid argument path");g=a,c=b}else if(3===arguments.length){if("string"!=typeof a||0===a.length||"function"!=typeof c)throw new Error("invalid arguments, must pass in a string, a value and a function");f=a,g=b}if(!f&&(null===g||"object"!==(void 0===g?"undefined":d(g))))throw new Error("invalid arguments, scalar values cannot be set without path");if(this._checkDestroyed("set"))return this;if(!this.isReady)return this._queuedMethodCalls.push({method:"set",args:arguments}),this;var h=this._$data,i=e.set(h,f,g,this._options.recordDeepCopy);if(h===i){if("function"==typeof c){var j=null;k.isConnected(this._client)||(j="Connection error: error updating record as connection was closed"),k.requestIdleCallback(function(){return c(j)})}return this}var l=void 0;return"function"==typeof c&&(l={},l.writeSuccess=!0,k.isConnected(this._client)?this._setUpCallback(this.version,c):k.requestIdleCallback(function(){return c("Connection error: error updating record as connection was closed")})),this._sendUpdate(f,g,l),this._applyChange(i),this},l.prototype.subscribe=function(a,b,c){var d=this,e=this._normalizeArguments(arguments);if(void 0!==e.path&&("string"!=typeof e.path||0===e.path.length))throw new Error("invalid argument path");if("function"!=typeof e.callback)throw new Error("invalid argument callback");this._checkDestroyed("subscribe")||(e.triggerNow?this.whenReady(function(){d._eventEmitter.on(e.path,e.callback),e.callback(d.get(e.path))}):this._eventEmitter.on(e.path,e.callback))},l.prototype.unsubscribe=function(a,b){var c=this._normalizeArguments(arguments);if(void 0!==c.path&&("string"!=typeof c.path||0===c.path.length))throw new Error("invalid argument path");if(void 0!==c.callback&&"function"!=typeof c.callback)throw new Error("invalid argument callback");this._checkDestroyed("unsubscribe")||this._eventEmitter.off(c.path,c.callback)},l.prototype.discard=function(){var a=this;this._checkDestroyed("discard")||this.whenReady(function(){--a.usages<=0&&(a.emit("destroyPending"),a._discardTimeout=a._ackTimeoutRegistry.add({topic:h.TOPIC.RECORD,name:a.name,action:h.ACTIONS.UNSUBSCRIBE}),a._connection.sendMsg(h.TOPIC.RECORD,h.ACTIONS.UNSUBSCRIBE,[a.name]))})},l.prototype.delete=function(){var a=this;this._checkDestroyed("delete")||this.whenReady(function(){a.emit("destroyPending"),a._deleteAckTimeout=a._ackTimeoutRegistry.add({topic:h.TOPIC.RECORD,name:a.name,action:h.ACTIONS.DELETE,event:h.EVENT.DELETE_TIMEOUT,timeout:a._options.recordDeleteTimeout}),a._connection.sendMsg(h.TOPIC.RECORD,h.ACTIONS.DELETE,[a.name])})},l.prototype.whenReady=function(a){!0===this.isReady?a(this):this.once("ready",a.bind(this,this))},l.prototype._$onMessage=function(a){if(a.action===h.ACTIONS.READ)null===this.version?(this._ackTimeoutRegistry.clear(a),this._onRead(a)):this._applyUpdate(a,this._client);else if(a.action===h.ACTIONS.ACK)this._processAckMessage(a);else if(a.action===h.ACTIONS.UPDATE||a.action===h.ACTIONS.PATCH)this._applyUpdate(a,this._client);else if(a.action===h.ACTIONS.WRITE_ACKNOWLEDGEMENT)l._handleWriteAcknowledgements(a,this._writeCallbacks,this._client);else if(a.data[0]===h.EVENT.VERSION_EXISTS)this._recoverRecord(a.data[2],JSON.parse(a.data[3]),a);else if(a.data[0]===h.EVENT.MESSAGE_DENIED)this._clearTimeouts();else if(a.action===h.ACTIONS.SUBSCRIPTION_HAS_PROVIDER){var b=j.convertTyped(a.data[1],this._client);this.hasProvider=b,this.emit("hasProviderChanged",b)}},l._handleWriteAcknowledgements=function(a,b,c){for(var d=JSON.parse(a.data[1]),e=0;e<d.length;e++){var f=b[d[e]];void 0!==f&&(f(j.convertTyped(a.data[2],c)),delete b[d[e]])}},l.prototype._recoverRecord=function(a,b,c){c.processedError=!0,this._mergeStrategy?this._mergeStrategy(this,b,a,this._onRecordRecovered.bind(this,a,b,c)):this.emit("error",h.EVENT.VERSION_EXISTS,"received update for "+a+" but version is "+this.version)},l.prototype._sendUpdate=function(a,b,c){this.version++;var d=void 0;a?(d=void 0===c?[this.name,this.version,a,i.typed(b)]:[this.name,this.version,a,i.typed(b),c],this._connection.sendMsg(h.TOPIC.RECORD,h.ACTIONS.PATCH,d)):(d=void 0===c?[this.name,this.version,b]:[this.name,this.version,b,c],this._connection.sendMsg(h.TOPIC.RECORD,h.ACTIONS.UPDATE,d))},l.prototype._onRecordRecovered=function(a,b,c,d,f){if(d)this.emit("error",h.EVENT.VERSION_EXISTS,"received update for "+a+" but version is "+this.version);else{var g=this.version;this.version=a;var i=this._$data;if(k.deepEquals(i,b))return;var j=e.set(i,void 0,f,!1);if(k.deepEquals(f,b)){this._applyChange(f);var l=this._writeCallbacks[a];return void(void 0!==l&&(l(null),delete this._writeCallbacks[a]))}var m=c.data[4];if(m&&JSON.parse(m).writeSuccess){var n=this._writeCallbacks[g];delete this._writeCallbacks[g],this._setUpCallback(this.version,n)}this._sendUpdate(void 0,f,m),this._applyChange(j)}},l.prototype._processAckMessage=function(a){var b=a.data[0];b===h.ACTIONS.SUBSCRIBE?this._ackTimeoutRegistry.clear(a):b===h.ACTIONS.DELETE?(this.emit("delete"),this._destroy()):b===h.ACTIONS.UNSUBSCRIBE&&(this.emit("discard"),this._destroy())},l.prototype._applyUpdate=function(a){var b=parseInt(a.data[1],10),c=void 0;if(c=a.action===h.ACTIONS.PATCH?j.convertTyped(a.data[3],this._client):JSON.parse(a.data[2]),null===this.version)this.version=b;else if(this.version+1!==b)return void(a.action===h.ACTIONS.PATCH?this._connection.sendMsg(h.TOPIC.RECORD,h.ACTIONS.SNAPSHOT,[this.name]):this._recoverRecord(b,c,a));this.version=b,this._applyChange(e.set(this._$data,a.action===h.ACTIONS.PATCH?a.data[2]:void 0,c))},l.prototype._onRead=function(a){this.version=parseInt(a.data[1],10),this._applyChange(e.set(this._$data,void 0,JSON.parse(a.data[2]))),this._setReady()},l.prototype._setReady=function(){this.isReady=!0;for(var a=0;a<this._queuedMethodCalls.length;a++)this[this._queuedMethodCalls[a].method].apply(this,this._queuedMethodCalls[a].args);this._queuedMethodCalls=[],this.emit("ready")},l.prototype._setUpCallback=function(a,b){var c=Number(this.version)+1;this._writeCallbacks[c]=b},l.prototype._sendRead=function(){this._connection.sendMsg(h.TOPIC.RECORD,h.ACTIONS.CREATEORREAD,[this.name])},l.prototype._applyChange=function(a){if(!this.isDestroyed){var b=this._$data;this._$data=a;for(var c=this._eventEmitter.eventNames(),d=0;d<c.length;d++){e.get(a,c[d],!1)!==e.get(b,c[d],!1)&&this._eventEmitter.emit(c[d],this.get(c[d]))}}},l.prototype._normalizeArguments=function(a){if(1===a.length&&"object"===d(a[0]))return a[0];for(var b=Object.create(null),c=0;c<a.length;c++)"string"==typeof a[c]?b.path=a[c]:"function"==typeof a[c]?b.callback=a[c]:"boolean"==typeof a[c]&&(b.triggerNow=a[c]);return b},l.prototype._clearTimeouts=function(){this._ackTimeoutRegistry.remove({ackId:this._readAckTimeout,silent:!0}),this._ackTimeoutRegistry.remove({ackId:this._responseTimeout,silent:!0}),this._ackTimeoutRegistry.remove({ackId:this._deleteAckTimeout,silent:!0}),this._ackTimeoutRegistry.remove({ackId:this._discardTimeout,silent:!0})},l.prototype._checkDestroyed=function(a){return!!this.isDestroyed&&(this.emit("error","Can't invoke '"+a+"'. Record '"+this.name+"' is already destroyed"),!0)},l.prototype._destroy=function(){this._clearTimeouts(),this._eventEmitter.off(),this._resubscribeNotifier.destroy(),this.isDestroyed=!0,this.isReady=!1,this._client=null,this._eventEmitter=null,this._connection=null},b.exports=l},{"../constants/constants":11,"../message/message-builder":16,"../message/message-parser":17,"../utils/resubscribe-notifier":29,"../utils/utils":31,"./json-path":20,"component-emitter2":1}],24:[function(a,b,c){"use strict";var d=a("../constants/constants"),e=a("../utils/resubscribe-notifier"),f=a("./rpc-response"),g=a("./rpc"),h=a("../message/message-parser"),i=a("../message/message-builder"),j=function(a,b,c){this._options=a,this._connection=b,this._client=c,this._rpcs={},this._providers={},this._ackTimeoutRegistry=c._$getAckTimeoutRegistry(),this._resubscribeNotifier=new e(this._client,this._reprovide.bind(this))};j.prototype.provide=function(a,b){if("string"!=typeof a||0===a.length)throw new Error("invalid argument name");if(this._providers[a])throw new Error("RPC "+a+" already registered");if("function"!=typeof b)throw new Error("invalid argument callback");this._ackTimeoutRegistry.add({topic:d.TOPIC.RPC,name:a,action:d.ACTIONS.SUBSCRIBE}),this._providers[a]=b,this._connection.sendMsg(d.TOPIC.RPC,d.ACTIONS.SUBSCRIBE,[a])},j.prototype.unprovide=function(a){if("string"!=typeof a||0===a.length)throw new Error("invalid argument name");this._providers[a]&&(delete this._providers[a],this._ackTimeoutRegistry.add({topic:d.TOPIC.RPC,name:a,action:d.ACTIONS.UNSUBSCRIBE}),this._connection.sendMsg(d.TOPIC.RPC,d.ACTIONS.UNSUBSCRIBE,[a]))},j.prototype.make=function(a,b,c){if("string"!=typeof a||0===a.length)throw new Error("invalid argument name");if("function"!=typeof c)throw new Error("invalid argument callback");var e=this._client.getUid(),f=i.typed(b);this._rpcs[e]=new g(a,c,this._options,this._client),this._connection.sendMsg(d.TOPIC.RPC,d.ACTIONS.REQUEST,[a,e,f])},j.prototype._getRpc=function(a,b,c){var e=this._rpcs[a];return e||(this._client._$onError(d.TOPIC.RPC,d.EVENT.UNSOLICITED_MESSAGE,c),null)},j.prototype._respondToRpc=function(a){var b=a.data[0],c=a.data[1],e=null,g=void 0;a.data[2]&&(e=h.convertTyped(a.data[2],this._client)),this._providers[b]?(g=new f(this._connection,b,c),
this._providers[b](e,g)):this._connection.sendMsg(d.TOPIC.RPC,d.ACTIONS.REJECTION,[b,c])},j.prototype._$handle=function(a){var b=void 0,c=void 0;if(a.action===d.ACTIONS.REQUEST)return void this._respondToRpc(a);if(a.action===d.ACTIONS.ACK&&(a.data[0]===d.ACTIONS.SUBSCRIBE||a.data[0]===d.ACTIONS.UNSUBSCRIBE))return void this._ackTimeoutRegistry.clear(a);if(a.action===d.ACTIONS.ERROR){if(a.data[0]===d.EVENT.MESSAGE_PERMISSION_ERROR)return;if(a.data[0]===d.EVENT.MESSAGE_DENIED&&a.data[2]===d.ACTIONS.SUBSCRIBE)return void this._ackTimeoutRegistry.remove({topic:d.TOPIC.RPC,action:d.ACTIONS.SUBSCRIBE,name:a.data[1]})}a.action===d.ACTIONS.ERROR||a.action===d.ACTIONS.ACK?(c=a.data[0]===d.EVENT.MESSAGE_DENIED&&a.data[2]===d.ACTIONS.REQUEST?a.data[3]:a.data[2],b=a.data[1]):(b=a.data[0],c=a.data[1]);var e=this._getRpc(c,b,a.raw);null!==e&&(a.action===d.ACTIONS.ACK?e.ack():a.action===d.ACTIONS.RESPONSE?(e.respond(a.data[2]),delete this._rpcs[c]):a.action===d.ACTIONS.ERROR&&(a.processedError=!0,e.error(a.data[0]),delete this._rpcs[c]))},j.prototype._reprovide=function(){for(var a in this._providers)this._connection.sendMsg(d.TOPIC.RPC,d.ACTIONS.SUBSCRIBE,[a])},b.exports=j},{"../constants/constants":11,"../message/message-builder":16,"../message/message-parser":17,"../utils/resubscribe-notifier":29,"./rpc":26,"./rpc-response":25}],25:[function(a,b,c){"use strict";var d=a("../constants/constants"),e=a("../utils/utils"),f=a("../message/message-builder"),g=function(a,b,c){this._connection=a,this._name=b,this._correlationId=c,this._isAcknowledged=!1,this._isComplete=!1,this.autoAck=!0,e.nextTick(this._performAutoAck.bind(this))};g.prototype.ack=function(){!1===this._isAcknowledged&&(this._connection.sendMsg(d.TOPIC.RPC,d.ACTIONS.ACK,[d.ACTIONS.REQUEST,this._name,this._correlationId]),this._isAcknowledged=!0)},g.prototype.reject=function(){this.autoAck=!1,this._isComplete=!0,this._isAcknowledged=!0,this._connection.sendMsg(d.TOPIC.RPC,d.ACTIONS.REJECTION,[this._name,this._correlationId])},g.prototype.error=function(a){this.autoAck=!1,this._isComplete=!0,this._isAcknowledged=!0,this._connection.sendMsg(d.TOPIC.RPC,d.ACTIONS.ERROR,[a,this._name,this._correlationId])},g.prototype.send=function(a){if(!0===this._isComplete)throw new Error("Rpc "+this._name+" already completed");this.ack();var b=f.typed(a);this._connection.sendMsg(d.TOPIC.RPC,d.ACTIONS.RESPONSE,[this._name,this._correlationId,b]),this._isComplete=!0},g.prototype._performAutoAck=function(){!0===this.autoAck&&this.ack()},b.exports=g},{"../constants/constants":11,"../message/message-builder":16,"../utils/utils":31}],26:[function(a,b,c){"use strict";var d=a("../constants/constants"),e=a("../message/message-parser"),f=function(a,b,c,e){this._options=c,this._callback=b,this._client=e,this._ackTimeoutRegistry=e._$getAckTimeoutRegistry(),this._ackTimeout=this._ackTimeoutRegistry.add({topic:d.TOPIC.RPC,action:d.ACTIONS.ACK,name:a,timeout:this._options.rpcAckTimeout,callback:this.error.bind(this)}),this._responseTimeout=this._ackTimeoutRegistry.add({topic:d.TOPIC.RPC,action:d.ACTIONS.REQUEST,name:a,event:d.EVENT.RESPONSE_TIMEOUT,timeout:this._options.rpcResponseTimeout,callback:this.error.bind(this)})};f.prototype.ack=function(){this._ackTimeoutRegistry.remove({ackId:this._ackTimeout})},f.prototype.respond=function(a){var b=e.convertTyped(a,this._client);this._callback(null,b),this._complete()},f.prototype.error=function(a){this._callback(a.event||a),this._complete()},f.prototype._complete=function(){this._ackTimeoutRegistry.remove({ackId:this._ackTimeout}),this._ackTimeoutRegistry.remove({ackId:this._responseTimeout})},b.exports=f},{"../constants/constants":11,"../message/message-parser":17}],27:[function(a,b,c){"use strict";var d=a("../constants/constants"),e=a("component-emitter2"),f=function(a,b){this._options=b,this._client=a,this._register={},this._counter=1,a.on("connectionStateChanged",this._onConnectionStateChanged.bind(this))};e(f.prototype),f.prototype.add=function(a){var b=a.timeout||this._options.subscriptionTimeout;return this._client.getConnectionState()!==d.CONNECTION_STATE.OPEN||b<1?-1:(this.remove(a),a.ackId=this._counter++,a.event=a.event||d.EVENT.ACK_TIMEOUT,a.__timeout=setTimeout(this._onTimeout.bind(this,a),b),this._register[this._getUniqueName(a)]=a,a.ackId)},f.prototype.remove=function(a){if(a.ackId)for(var b in this._register)a.ackId===this._register[b].ackId&&this.clear({topic:this._register[b].topic,action:this._register[b].action,data:[this._register[b].name]});this._register[this._getUniqueName(a)]&&this.clear({topic:a.topic,action:a.action,data:[a.name]})},f.prototype.clear=function(a){var b=void 0;b=a.action===d.ACTIONS.ACK&&a.data.length>1?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":1}],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<e.length;f++){var g=e[f];this._ackTimeoutRegistry.remove({ackId:g.ackId}),g.callback(b,c)}delete this._requests[a]},f.prototype._onResponseTimeout=function(a){var b="No response received in time for "+this._topic+"|"+this._action+"|"+a.name;this._client._$onError(this._topic,d.EVENT.RESPONSE_TIMEOUT,b)},f.prototype._resendRequests=function(){for(var a in this._requests)this._connection.sendMsg(this._topic,this._action,[a])},b.exports=f},{"../constants/constants":11,"./resubscribe-notifier":29}],31:[function(a,b,c){(function(b){"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=a("../constants/constants");c.isNode=void 0!==b&&"[object process]"===b.toString(),c.nextTick=function(a){c.isNode?b.nextTick(a):setTimeout(a,0)},c.trim=function(a){return a.trim?a.trim():a.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")},c.deepEquals=function(a,b){return a===b||"object"===(void 0===a?"undefined":d(a))&&"object"===(void 0===b?"undefined":d(b))&&JSON.stringify(a)===JSON.stringify(b)},c.deepCopy=function(a){return"object"===(void 0===a?"undefined":d(a))?JSON.parse(JSON.stringify(a)):a},c.shallowCopy=function(a){if(Array.isArray(a))return a.slice(0);if("object"===(void 0===a?"undefined":d(a))){for(var b=Object.create(null),c=Object.keys(a),e=0;e<c.length;e++)b[c[e]]=a[c[e]];return b}return a},c.setTimeout=function(a,b){return null!==b?setTimeout(a,b):-1},c.setInterval=function(a,b){return null!==b?setInterval(a,b):-1},c.requestIdleCallback=!c.isNode&&window.requestIdleCallback&&window.requestIdleCallback.bind(window)||function(a){var b=Date.now();return setTimeout(function(){a({didTimeout:!1,timeRemaining:function(){return Math.max(0,50-(Date.now()-b))}})},1)},c.cancelIdleCallback=!c.isNode&&window.cancelIdleCallback&&window.cancelIdleCallback.bind(window)||function(a){clearTimeout(a)};var f=/^wss:|^ws:|^\/\//,g=/^http:|^https:/,h=a("url");c.parseUrl=function(a,b){var c=a;if(g.test(c))throw new Error("Only ws and wss are supported");f.test(c)?0===c.indexOf("//")&&(c="ws:"+c):c="ws://"+c;var d=h.parse(c);if(!d.host)throw new Error("invalid url, missing host");return d.protocol=d.protocol?d.protocol:"ws:",d.pathname=d.pathname?d.pathname:b,h.format(d)},c.isConnected=function(a){return a.getConnectionState()===e.CONNECTION_STATE.OPEN}}).call(this,a("_process"))},{"../constants/constants":11,_process:3,url:8}]},{},[10])(10)});