UNPKG

@jayzyaj/centrifuge-js-cyy

Version:

Centrifuge and Centrifugo client for NodeJS and browser

1 lines 115 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("Centrifuge",[],t):"object"==typeof exports?exports.Centrifuge=t():e.Centrifuge=t()}("undefined"!=typeof self?self:this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=32)}([function(e,t,r){"use strict";var n,i,s=e.exports=r(1),o=r(20);s.codegen=r(46),s.fetch=r(47),s.path=r(48),s.fs=s.inquire("fs"),s.toArray=function(e){if(e){for(var t=Object.keys(e),r=new Array(t.length),n=0;n<t.length;)r[n]=e[t[n++]];return r}return[]},s.toObject=function(e){for(var t={},r=0;r<e.length;){var n=e[r++],i=e[r++];void 0!==i&&(t[n]=i)}return t};var u=/\\/g,a=/"/g;s.isReserved=function(e){return/^(?:do|if|in|for|let|new|try|var|case|else|enum|eval|false|null|this|true|void|with|break|catch|class|const|super|throw|while|yield|delete|export|import|public|return|static|switch|typeof|default|extends|finally|package|private|continue|debugger|function|arguments|interface|protected|implements|instanceof)$/.test(e)},s.safeProp=function(e){return!/^[$\w_]+$/.test(e)||s.isReserved(e)?'["'+e.replace(u,"\\\\").replace(a,'\\"')+'"]':"."+e},s.ucFirst=function(e){return e.charAt(0).toUpperCase()+e.substring(1)};var c=/_([a-z])/g;s.camelCase=function(e){return e.substring(0,1)+e.substring(1).replace(c,function(e,t){return t.toUpperCase()})},s.compareFieldsById=function(e,t){return e.id-t.id},s.decorateType=function(e,t){if(e.$type)return t&&e.$type.name!==t&&(s.decorateRoot.remove(e.$type),e.$type.name=t,s.decorateRoot.add(e.$type)),e.$type;n||(n=r(22));var i=new n(t||e.name);return s.decorateRoot.add(i),i.ctor=e,Object.defineProperty(e,"$type",{value:i,enumerable:!1}),Object.defineProperty(e.prototype,"$type",{value:i,enumerable:!1}),i};var f=0;s.decorateEnum=function(e){if(e.$type)return e.$type;i||(i=r(2));var t=new i("Enum"+f++,e);return s.decorateRoot.add(t),Object.defineProperty(e,"$type",{value:t,enumerable:!1}),t},Object.defineProperty(s,"decorateRoot",{get:function(){return o.decorated||(o.decorated=new(r(30)))}})},function(e,t,r){"use strict";(function(e){function n(e,t,r){for(var n=Object.keys(t),i=0;i<n.length;++i)void 0!==e[n[i]]&&r||(e[n[i]]=t[n[i]]);return e}function i(e){function t(e,r){if(!(this instanceof t))return new t(e,r);Object.defineProperty(this,"message",{get:function(){return e}}),Error.captureStackTrace?Error.captureStackTrace(this,t):Object.defineProperty(this,"stack",{value:(new Error).stack||""}),r&&n(this,r)}return(t.prototype=Object.create(Error.prototype)).constructor=t,Object.defineProperty(t.prototype,"name",{get:function(){return e}}),t.prototype.toString=function(){return this.name+": "+this.message},t}var s=t;s.asPromise=r(17),s.base64=r(37),s.EventEmitter=r(38),s.float=r(39),s.inquire=r(18),s.utf8=r(40),s.pool=r(41),s.LongBits=r(42),s.global="undefined"!=typeof window&&window||void 0!==e&&e||"undefined"!=typeof self&&self||this,s.emptyArray=Object.freeze?Object.freeze([]):[],s.emptyObject=Object.freeze?Object.freeze({}):{},s.isNode=Boolean(s.global.process&&s.global.process.versions&&s.global.process.versions.node),s.isInteger=Number.isInteger||function(e){return"number"==typeof e&&isFinite(e)&&Math.floor(e)===e},s.isString=function(e){return"string"==typeof e||e instanceof String},s.isObject=function(e){return e&&"object"==typeof e},s.isset=s.isSet=function(e,t){var r=e[t];return!(null==r||!e.hasOwnProperty(t))&&("object"!=typeof r||(Array.isArray(r)?r.length:Object.keys(r).length)>0)},s.Buffer=function(){try{var e=s.inquire("buffer").Buffer;return e.prototype.utf8Write?e:null}catch(e){return null}}(),s._Buffer_from=null,s._Buffer_allocUnsafe=null,s.newBuffer=function(e){return"number"==typeof e?s.Buffer?s._Buffer_allocUnsafe(e):new s.Array(e):s.Buffer?s._Buffer_from(e):"undefined"==typeof Uint8Array?e:new Uint8Array(e)},s.Array="undefined"!=typeof Uint8Array?Uint8Array:Array,s.Long=s.global.dcodeIO&&s.global.dcodeIO.Long||s.global.Long||s.inquire("long"),s.key2Re=/^true|false|0|1$/,s.key32Re=/^-?(?:0|[1-9][0-9]*)$/,s.key64Re=/^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/,s.longToHash=function(e){return e?s.LongBits.from(e).toHash():s.LongBits.zeroHash},s.longFromHash=function(e,t){var r=s.LongBits.fromHash(e);return s.Long?s.Long.fromBits(r.lo,r.hi,t):r.toNumber(Boolean(t))},s.merge=n,s.lcFirst=function(e){return e.charAt(0).toLowerCase()+e.substring(1)},s.newError=i,s.ProtocolError=i("ProtocolError"),s.oneOfGetter=function(e){for(var t={},r=0;r<e.length;++r)t[e[r]]=1;return function(){for(var e=Object.keys(this),r=e.length-1;r>-1;--r)if(1===t[e[r]]&&void 0!==this[e[r]]&&null!==this[e[r]])return e[r]}},s.oneOfSetter=function(e){return function(t){for(var r=0;r<e.length;++r)e[r]!==t&&delete this[e[r]]}},s.toJSONOptions={longs:String,enums:String,bytes:String,json:!0},s._configure=function(){var e=s.Buffer;if(!e)return void(s._Buffer_from=s._Buffer_allocUnsafe=null);s._Buffer_from=e.from!==Uint8Array.from&&e.from||function(t,r){return new e(t,r)},s._Buffer_allocUnsafe=e.allocUnsafe||function(t){return new e(t)}}}).call(t,r(3))},function(e,t,r){"use strict";function n(e,t,r,n,s){if(i.call(this,e,r),t&&"object"!=typeof t)throw TypeError("values must be an object");if(this.valuesById={},this.values=Object.create(this.valuesById),this.comment=n,this.comments=s||{},this.reserved=void 0,t)for(var o=Object.keys(t),u=0;u<o.length;++u)"number"==typeof t[o[u]]&&(this.valuesById[this.values[o[u]]=t[o[u]]]=o[u])}e.exports=n;var i=r(4);((n.prototype=Object.create(i.prototype)).constructor=n).className="Enum";var s=r(8),o=r(0);n.fromJSON=function(e,t){var r=new n(e,t.values,t.options,t.comment,t.comments);return r.reserved=t.reserved,r},n.prototype.toJSON=function(e){var t=!!e&&Boolean(e.keepComments);return o.toObject(["options",this.options,"values",this.values,"reserved",this.reserved&&this.reserved.length?this.reserved:void 0,"comment",t?this.comment:void 0,"comments",t?this.comments:void 0])},n.prototype.add=function(e,t,r){if(!o.isString(e))throw TypeError("name must be a string");if(!o.isInteger(t))throw TypeError("id must be an integer");if(void 0!==this.values[e])throw Error("duplicate name '"+e+"' in "+this);if(this.isReservedId(t))throw Error("id "+t+" is reserved in "+this);if(this.isReservedName(e))throw Error("name '"+e+"' is reserved in "+this);if(void 0!==this.valuesById[t]){if(!this.options||!this.options.allow_alias)throw Error("duplicate id "+t+" in "+this);this.values[e]=t}else this.valuesById[this.values[e]=t]=e;return this.comments[e]=r||null,this},n.prototype.remove=function(e){if(!o.isString(e))throw TypeError("name must be a string");var t=this.values[e];if(null==t)throw Error("name '"+e+"' does not exist in "+this);return delete this.valuesById[t],delete this.values[e],delete this.comments[e],this},n.prototype.isReservedId=function(e){return s.isReservedId(this.reserved,e)},n.prototype.isReservedName=function(e){return s.isReservedName(this.reserved,e)}},function(e,t){var r;r=function(){return this}();try{r=r||Function("return this")()||(0,eval)("this")}catch(e){"object"==typeof window&&(r=window)}e.exports=r},function(e,t,r){"use strict";function n(e,t){if(!s.isString(e))throw TypeError("name must be a string");if(t&&!s.isObject(t))throw TypeError("options must be an object");this.options=t,this.name=e,this.parent=null,this.resolved=!1,this.comment=null,this.filename=null}e.exports=n,n.className="ReflectionObject";var i,s=r(0);Object.defineProperties(n.prototype,{root:{get:function(){for(var e=this;null!==e.parent;)e=e.parent;return e}},fullName:{get:function(){for(var e=[this.name],t=this.parent;t;)e.unshift(t.name),t=t.parent;return e.join(".")}}}),n.prototype.toJSON=function(){throw Error()},n.prototype.onAdd=function(e){this.parent&&this.parent!==e&&this.parent.remove(this),this.parent=e,this.resolved=!1;var t=e.root;t instanceof i&&t._handleAdd(this)},n.prototype.onRemove=function(e){var t=e.root;t instanceof i&&t._handleRemove(this),this.parent=null,this.resolved=!1},n.prototype.resolve=function(){return this.resolved?this:(this.root instanceof i&&(this.resolved=!0),this)},n.prototype.getOption=function(e){if(this.options)return this.options[e]},n.prototype.setOption=function(e,t,r){return r&&this.options&&void 0!==this.options[e]||((this.options||(this.options={}))[e]=t),this},n.prototype.setOptions=function(e,t){if(e)for(var r=Object.keys(e),n=0;n<r.length;++n)this.setOption(r[n],e[r[n]],t);return this},n.prototype.toString=function(){var e=this.constructor.className,t=this.fullName;return t.length?e+" "+t:e},n._configure=function(e){i=e}},function(e,t,r){"use strict";function n(e,t,r,n,s,o,f){if(a.isObject(n)?(f=s,o=n,n=s=void 0):a.isObject(s)&&(f=o,o=s,s=void 0),i.call(this,e,o),!a.isInteger(t)||t<0)throw TypeError("id must be a non-negative integer");if(!a.isString(r))throw TypeError("type must be a string");if(void 0!==n&&!c.test(n=n.toString().toLowerCase()))throw TypeError("rule must be a string rule");if(void 0!==s&&!a.isString(s))throw TypeError("extend must be a string");this.rule=n&&"optional"!==n?n:void 0,this.type=r,this.id=t,this.extend=s||void 0,this.required="required"===n,this.optional=!this.required,this.repeated="repeated"===n,this.map=!1,this.message=null,this.partOf=null,this.typeDefault=null,this.defaultValue=null,this.long=!!a.Long&&void 0!==u.long[r],this.bytes="bytes"===r,this.resolvedType=null,this.extensionField=null,this.declaringField=null,this._packed=null,this.comment=f}e.exports=n;var i=r(4);((n.prototype=Object.create(i.prototype)).constructor=n).className="Field";var s,o=r(2),u=r(9),a=r(0),c=/^required|optional|repeated$/;n.fromJSON=function(e,t){return new n(e,t.id,t.type,t.rule,t.extend,t.options,t.comment)},Object.defineProperty(n.prototype,"packed",{get:function(){return null===this._packed&&(this._packed=!1!==this.getOption("packed")),this._packed}}),n.prototype.setOption=function(e,t,r){return"packed"===e&&(this._packed=null),i.prototype.setOption.call(this,e,t,r)},n.prototype.toJSON=function(e){var t=!!e&&Boolean(e.keepComments);return a.toObject(["rule","optional"!==this.rule&&this.rule||void 0,"type",this.type,"id",this.id,"extend",this.extend,"options",this.options,"comment",t?this.comment:void 0])},n.prototype.resolve=function(){if(this.resolved)return this;if(void 0===(this.typeDefault=u.defaults[this.type])&&(this.resolvedType=(this.declaringField?this.declaringField.parent:this.parent).lookupTypeOrEnum(this.type),this.resolvedType instanceof s?this.typeDefault=null:this.typeDefault=this.resolvedType.values[Object.keys(this.resolvedType.values)[0]]),this.options&&null!=this.options.default&&(this.typeDefault=this.options.default,this.resolvedType instanceof o&&"string"==typeof this.typeDefault&&(this.typeDefault=this.resolvedType.values[this.typeDefault])),this.options&&(!0!==this.options.packed&&(void 0===this.options.packed||!this.resolvedType||this.resolvedType instanceof o)||delete this.options.packed,Object.keys(this.options).length||(this.options=void 0)),this.long)this.typeDefault=a.Long.fromNumber(this.typeDefault,"u"===this.type.charAt(0)),Object.freeze&&Object.freeze(this.typeDefault);else if(this.bytes&&"string"==typeof this.typeDefault){var e;a.base64.test(this.typeDefault)?a.base64.decode(this.typeDefault,e=a.newBuffer(a.base64.length(this.typeDefault)),0):a.utf8.write(this.typeDefault,e=a.newBuffer(a.utf8.length(this.typeDefault)),0),this.typeDefault=e}return this.map?this.defaultValue=a.emptyObject:this.repeated?this.defaultValue=a.emptyArray:this.defaultValue=this.typeDefault,this.parent instanceof s&&(this.parent.ctor.prototype[this.name]=this.defaultValue),i.prototype.resolve.call(this)},n.d=function(e,t,r,i){return"function"==typeof t?t=a.decorateType(t).name:t&&"object"==typeof t&&(t=a.decorateEnum(t).name),function(s,o){a.decorateType(s.constructor).add(new n(o,e,t,r,{default:i}))}},n._configure=function(e){s=e}},function(e,t,r){"use strict";function n(e){console&&console.warn&&console.warn(e)}function i(){i.init.call(this)}function s(e){return void 0===e._maxListeners?i.defaultMaxListeners:e._maxListeners}function o(e,t,r,i){var o,u,a;if("function"!=typeof r)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof r);if(u=e._events,void 0===u?(u=e._events=Object.create(null),e._eventsCount=0):(void 0!==u.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),u=e._events),a=u[t]),void 0===a)a=u[t]=r,++e._eventsCount;else if("function"==typeof a?a=u[t]=i?[r,a]:[a,r]:i?a.unshift(r):a.push(r),(o=s(e))>0&&a.length>o&&!a.warned){a.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=a.length,n(c)}return e}function u(){for(var e=[],t=0;t<arguments.length;t++)e.push(arguments[t]);this.fired||(this.target.removeListener(this.type,this.wrapFn),this.fired=!0,v(this.listener,this.target,e))}function a(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=u.bind(n);return i.listener=r,n.wrapFn=i,i}function c(e,t,r){var n=e._events;if(void 0===n)return[];var i=n[t];return void 0===i?[]:"function"==typeof i?r?[i.listener||i]:[i]:r?p(i):l(i,i.length)}function f(e){var t=this._events;if(void 0!==t){var r=t[e];if("function"==typeof r)return 1;if(void 0!==r)return r.length}return 0}function l(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function h(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function p(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}var d,y="object"==typeof Reflect?Reflect:null,v=y&&"function"==typeof y.apply?y.apply:function(e,t,r){return Function.prototype.apply.call(e,t,r)};d=y&&"function"==typeof y.ownKeys?y.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var _=Number.isNaN||function(e){return e!==e};e.exports=i,i.EventEmitter=i,i.prototype._events=void 0,i.prototype._eventsCount=0,i.prototype._maxListeners=void 0;var b=10;Object.defineProperty(i,"defaultMaxListeners",{enumerable:!0,get:function(){return b},set:function(e){if("number"!=typeof e||e<0||_(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");b=e}}),i.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},i.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||_(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},i.prototype.getMaxListeners=function(){return s(this)},i.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t.push(arguments[r]);var n="error"===e,i=this._events;if(void 0!==i)n=n&&void 0===i.error;else if(!n)return!1;if(n){var s;if(t.length>0&&(s=t[0]),s instanceof Error)throw s;var o=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw o.context=s,o}var u=i[e];if(void 0===u)return!1;if("function"==typeof u)v(u,this,t);else for(var a=u.length,c=l(u,a),r=0;r<a;++r)v(c[r],this,t);return!0},i.prototype.addListener=function(e,t){return o(this,e,t,!1)},i.prototype.on=i.prototype.addListener,i.prototype.prependListener=function(e,t){return o(this,e,t,!0)},i.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t);return this.on(e,a(this,e,t)),this},i.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t);return this.prependListener(e,a(this,e,t)),this},i.prototype.removeListener=function(e,t){var r,n,i,s,o;if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t);if(void 0===(n=this._events))return this;if(void 0===(r=n[e]))return this;if(r===t||r.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete n[e],n.removeListener&&this.emit("removeListener",e,r.listener||t));else if("function"!=typeof r){for(i=-1,s=r.length-1;s>=0;s--)if(r[s]===t||r[s].listener===t){o=r[s].listener,i=s;break}if(i<0)return this;0===i?r.shift():h(r,i),1===r.length&&(n[e]=r[0]),void 0!==n.removeListener&&this.emit("removeListener",e,o||t)}return this},i.prototype.off=i.prototype.removeListener,i.prototype.removeAllListeners=function(e){var t,r,n;if(void 0===(r=this._events))return this;if(void 0===r.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==r[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete r[e]),this;if(0===arguments.length){var i,s=Object.keys(r);for(n=0;n<s.length;++n)"removeListener"!==(i=s[n])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=r[e]))this.removeListener(e,t);else if(void 0!==t)for(n=t.length-1;n>=0;n--)this.removeListener(e,t[n]);return this},i.prototype.listeners=function(e){return c(this,e,!0)},i.prototype.rawListeners=function(e){return c(this,e,!1)},i.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):f.call(e,t)},i.prototype.listenerCount=f,i.prototype.eventNames=function(){return this._eventsCount>0?d(this._events):[]}},function(e,t,r){"use strict";(function(e){function r(e,t){return 0===e.lastIndexOf(t,0)}function n(e){return void 0!==e&&null!==e&&"function"==typeof e}function i(t,r){if(e.console){var i=e.console[t];n(i)&&i.apply(e.console,r)}}function s(e,t,r){var n=.5*Math.random(),i=Math.min(r,t*Math.pow(2,e+1));return Math.floor((1-n)*i)}function o(e){return"error"in e&&null!==e.error}function u(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r]);return e}Object.defineProperty(t,"__esModule",{value:!0}),t.startsWith=r,t.isFunction=n,t.log=i,t.backoff=s,t.errorExists=o,t.extend=u}).call(t,r(3))},function(e,t,r){"use strict";function n(e,t){if(e&&e.length){for(var r={},n=0;n<e.length;++n)r[e[n].name]=e[n].toJSON(t);return r}}function i(e,t){o.call(this,e,t),this.nested=void 0,this._nestedArray=null}function s(e){return e._nestedArray=null,e}e.exports=i;var o=r(4);((i.prototype=Object.create(o.prototype)).constructor=i).className="Namespace";var u,a,c,f=r(5),l=r(0);i.fromJSON=function(e,t){return new i(e,t.options).addJSON(t.nested)},i.arrayToJSON=n,i.isReservedId=function(e,t){if(e)for(var r=0;r<e.length;++r)if("string"!=typeof e[r]&&e[r][0]<=t&&e[r][1]>t)return!0;return!1},i.isReservedName=function(e,t){if(e)for(var r=0;r<e.length;++r)if(e[r]===t)return!0;return!1},Object.defineProperty(i.prototype,"nestedArray",{get:function(){return this._nestedArray||(this._nestedArray=l.toArray(this.nested))}}),i.prototype.toJSON=function(e){return l.toObject(["options",this.options,"nested",n(this.nestedArray,e)])},i.prototype.addJSON=function(e){var t=this;if(e)for(var r,n=Object.keys(e),s=0;s<n.length;++s)r=e[n[s]],t.add((void 0!==r.fields?u.fromJSON:void 0!==r.values?c.fromJSON:void 0!==r.methods?a.fromJSON:void 0!==r.id?f.fromJSON:i.fromJSON)(n[s],r));return this},i.prototype.get=function(e){return this.nested&&this.nested[e]||null},i.prototype.getEnum=function(e){if(this.nested&&this.nested[e]instanceof c)return this.nested[e].values;throw Error("no such enum: "+e)},i.prototype.add=function(e){if(!(e instanceof f&&void 0!==e.extend||e instanceof u||e instanceof c||e instanceof a||e instanceof i))throw TypeError("object must be a valid nested object");if(this.nested){var t=this.get(e.name);if(t){if(!(t instanceof i&&e instanceof i)||t instanceof u||t instanceof a)throw Error("duplicate name '"+e.name+"' in "+this);for(var r=t.nestedArray,n=0;n<r.length;++n)e.add(r[n]);this.remove(t),this.nested||(this.nested={}),e.setOptions(t.options,!0)}}else this.nested={};return this.nested[e.name]=e,e.onAdd(this),s(this)},i.prototype.remove=function(e){if(!(e instanceof o))throw TypeError("object must be a ReflectionObject");if(e.parent!==this)throw Error(e+" is not a member of "+this);return delete this.nested[e.name],Object.keys(this.nested).length||(this.nested=void 0),e.onRemove(this),s(this)},i.prototype.define=function(e,t){if(l.isString(e))e=e.split(".");else if(!Array.isArray(e))throw TypeError("illegal path");if(e&&e.length&&""===e[0])throw Error("path must be relative");for(var r=this;e.length>0;){var n=e.shift();if(r.nested&&r.nested[n]){if(!((r=r.nested[n])instanceof i))throw Error("path conflicts with non-namespace objects")}else r.add(r=new i(n))}return t&&r.addJSON(t),r},i.prototype.resolveAll=function(){for(var e=this.nestedArray,t=0;t<e.length;)e[t]instanceof i?e[t++].resolveAll():e[t++].resolve();return this.resolve()},i.prototype.lookup=function(e,t,r){if("boolean"==typeof t?(r=t,t=void 0):t&&!Array.isArray(t)&&(t=[t]),l.isString(e)&&e.length){if("."===e)return this.root;e=e.split(".")}else if(!e.length)return this;if(""===e[0])return this.root.lookup(e.slice(1),t);var n=this.get(e[0]);if(n){if(1===e.length){if(!t||t.indexOf(n.constructor)>-1)return n}else if(n instanceof i&&(n=n.lookup(e.slice(1),t,!0)))return n}else for(var s=0;s<this.nestedArray.length;++s)if(this._nestedArray[s]instanceof i&&(n=this._nestedArray[s].lookup(e,t,!0)))return n;return null===this.parent||r?null:this.parent.lookup(e,t)},i.prototype.lookupType=function(e){var t=this.lookup(e,[u]);if(!t)throw Error("no such type: "+e);return t},i.prototype.lookupEnum=function(e){var t=this.lookup(e,[c]);if(!t)throw Error("no such Enum '"+e+"' in "+this);return t},i.prototype.lookupTypeOrEnum=function(e){var t=this.lookup(e,[u,c]);if(!t)throw Error("no such Type or Enum '"+e+"' in "+this);return t},i.prototype.lookupService=function(e){var t=this.lookup(e,[a]);if(!t)throw Error("no such Service '"+e+"' in "+this);return t},i._configure=function(e,t,r){u=e,a=t,c=r}},function(e,t,r){"use strict";function n(e,t){var r=0,n={};for(t|=0;r<e.length;)n[o[r+t]]=e[r++];return n}var i=t,s=r(0),o=["double","float","int32","uint32","sint32","fixed32","sfixed32","int64","uint64","sint64","fixed64","sfixed64","bool","string","bytes"];i.basic=n([1,5,0,0,0,5,5,0,0,0,1,1,0,2,2]),i.defaults=n([0,0,0,0,0,0,0,0,0,0,0,0,!1,"",s.emptyArray,null]),i.long=n([0,0,0,1,1],7),i.mapKey=n([0,0,0,5,5,0,0,0,1,1,0,2],2),i.packed=n([1,5,0,0,0,5,5,0,0,0,1,1,0])},function(e,t,r){"use strict";(function(e){function n(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function o(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0}),t.Centrifuge=void 0;var u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),c=r(6),f=n(c),l=r(11),h=n(l),p=r(12),d=r(7);t.Centrifuge=function(t){function r(e,t){i(this,r);var n=s(this,(r.__proto__||Object.getPrototypeOf(r)).call(this));return n._url=e,n._websocket=null,n._sockjs=null,n._isSockjs=!1,n._binary=!1,n._methodType=null,n._pushType=null,n._encoder=null,n._decoder=null,n._status="disconnected",n._reconnect=!0,n._reconnecting=!1,n._transport=null,n._transportName=null,n._transportClosed=!0,n._messageId=0,n._clientID=null,n._refreshRequired=!1,n._subs={},n._serverSubs={},n._lastSeq={},n._lastGen={},n._lastOffset={},n._lastEpoch={},n._messages=[],n._isBatching=!1,n._isSubscribeBatching=!1,n._privateChannels={},n._numRefreshFailed=0,n._refreshTimeout=null,n._pingTimeout=null,n._pongTimeout=null,n._subRefreshTimeouts={},n._retries=0,n._callbacks={},n._latency=null,n._latencyStart=null,n._connectData=null,n._token=null,n._xhrID=0,n._xhrs={},n._dispatchPromise=Promise.resolve(),n._config={debug:!1,websocket:null,sockjs:null,promise:null,minRetry:1e3,maxRetry:2e4,timeout:5e3,ping:!0,pingInterval:25e3,pongWaitTimeout:5e3,privateChannelPrefix:"$",onTransportClose:null,sockjsServer:null,sockjsTransports:["websocket","xdr-streaming","xhr-streaming","eventsource","iframe-eventsource","iframe-htmlfile","xdr-polling","xhr-polling","iframe-xhr-polling","jsonp-polling"],refreshEndpoint:"/centrifuge/refresh",refreshHeaders:{},refreshParams:{},refreshData:{},refreshAttempts:null,refreshInterval:1e3,onRefreshFailed:null,onRefresh:null,subscribeEndpoint:"/centrifuge/subscribe",subscribeHeaders:{},subscribeParams:{},subRefreshInterval:1e3,onPrivateSubscribe:null},n._configure(t),n}return o(r,t),a(r,[{key:"setToken",value:function(e){this._token=e}},{key:"setConnectData",value:function(e){this._connectData=e}},{key:"setRefreshHeaders",value:function(e){this._config.refreshHeaders=e}},{key:"setRefreshParams",value:function(e){this._config.refreshParams=e}},{key:"setRefreshData",value:function(e){this._config.refreshData=e}},{key:"setSubscribeHeaders",value:function(e){this._config.subscribeHeaders=e}},{key:"setSubscribeParams",value:function(e){this._config.subscribeParams=e}},{key:"_ajax",value:function(t,r,n,i,s){var o=this,u="";this._debug("sending AJAX request to",t,"with data",JSON.stringify(i));var a=e.XMLHttpRequest?new e.XMLHttpRequest:new e.ActiveXObject("Microsoft.XMLHTTP");for(var c in r)r.hasOwnProperty(c)&&(u.length>0&&(u+="&"),u+=encodeURIComponent(c)+"="+encodeURIComponent(r[c]));u.length>0&&(u="?"+u),a.open("POST",t+u,!0),"withCredentials"in a&&(a.withCredentials=!0),a.setRequestHeader("X-Requested-With","XMLHttpRequest"),a.setRequestHeader("Content-Type","application/json");for(var f in n)n.hasOwnProperty(f)&&a.setRequestHeader(f,n[f]);return a.onreadystatechange=function(){if(4===a.readyState)if(200===a.status){var e=void 0,t=!1;try{e=JSON.parse(a.responseText),t=!0}catch(e){s({error:"Invalid JSON. Data was: "+a.responseText,status:200,data:null})}t&&s({data:e,status:200})}else o._log("wrong status code in AJAX response",a.status),s({status:a.status,data:null})},setTimeout(function(){return a.send(JSON.stringify(i))},20),a}},{key:"_log",value:function(){(0,d.log)("info",arguments)}},{key:"_debug",value:function(){!0===this._config.debug&&(0,d.log)("debug",arguments)}},{key:"_websocketSupported",value:function(){return null!==this._config.websocket||!("function"!=typeof WebSocket&&"object"!==("undefined"==typeof WebSocket?"undefined":u(WebSocket)))}},{key:"_setFormat",value:function(e){if(!this._formatOverride(e)){if("protobuf"===e)throw new Error("not implemented by JSON only Centrifuge client – use client with Protobuf");this._binary=!1,this._methodType=p.JsonMethodType,this._pushType=p.JsonPushType,this._encoder=new p.JsonEncoder,this._decoder=new p.JsonDecoder}}},{key:"_formatOverride",value:function(e){return!1}},{key:"_configure",value:function(t){if(!("Promise"in e))throw new Error("Promise polyfill required");if((0,d.extend)(this._config,t||{}),this._debug("centrifuge config",this._config),!this._url)throw new Error("url required");if((0,d.startsWith)(this._url,"ws")&&this._url.indexOf("format=protobuf")>-1?this._setFormat("protobuf"):this._setFormat("json"),(0,d.startsWith)(this._url,"http"))if(this._debug("client will try to connect to SockJS endpoint"),null!==this._config.sockjs)this._debug("SockJS explicitly provided in options"),this._sockjs=this._config.sockjs;else{if(void 0===e.SockJS)throw new Error("SockJS not found, use ws:// in url or include SockJS");this._debug("use globally defined SockJS"),this._sockjs=e.SockJS}else this._debug("client will connect to websocket endpoint")}},{key:"_setStatus",value:function(e){this._status!==e&&(this._debug("Status",this._status,"->",e),this._status=e)}},{key:"_isDisconnected",value:function(){return"disconnected"===this._status}},{key:"_isConnecting",value:function(){return"connecting"===this._status}},{key:"_isConnected",value:function(){return"connected"===this._status}},{key:"_nextMessageId",value:function(){return++this._messageId}},{key:"_resetRetry",value:function(){this._debug("reset retries count to 0"),this._retries=0}},{key:"_getRetryInterval",value:function(){var e=(0,d.backoff)(this._retries,this._config.minRetry,this._config.maxRetry);return this._retries+=1,e}},{key:"_abortInflightXHRs",value:function(){for(var e in this._xhrs){try{this._xhrs[e].abort()}catch(e){this._debug("error aborting xhr",e)}delete this._xhrs[e]}}},{key:"_clearConnectedState",value:function(e){this._clientID=null,this._stopPing();for(var t in this._callbacks)if(this._callbacks.hasOwnProperty(t)){var r=this._callbacks[t];clearTimeout(r.timeout);var n=r.errback;if(!n)continue;n({error:this._createErrorObject("disconnected")})}this._callbacks={};for(var i in this._subs)if(this._subs.hasOwnProperty(i)){var s=this._subs[i];e?(s._isSuccess()&&(s._triggerUnsubscribe(),s._recover=!0),s._shouldResubscribe()&&s._setSubscribing()):s._setUnsubscribed()}this._abortInflightXHRs(),null!==this._refreshTimeout&&(clearTimeout(this._refreshTimeout),this._refreshTimeout=null);for(var o in this._subRefreshTimeouts)this._subRefreshTimeouts.hasOwnProperty(o)&&this._subRefreshTimeouts[o]&&this._clearSubRefreshTimeout(o);this._subRefreshTimeouts={},this._reconnect||(this._subs={})}},{key:"_isTransportOpen",value:function(){return this._isSockjs?this._transport&&this._transport.transport&&this._transport.transport.readyState===this._transport.transport.OPEN:this._transport&&this._transport.readyState===this._transport.OPEN}},{key:"_transportSend",value:function(e){if(!e.length)return!0;if(!this._isTransportOpen()){for(var t in e){var r=t.id;if(r in this._callbacks){var n=this._callbacks[r];clearTimeout(this._callbacks[r].timeout),delete this._callbacks[r];(0,n.errback)({error:this._createErrorObject("connection closed",0)})}}return!1}return this._transport.send(this._encoder.encodeCommands(e)),!0}},{key:"_setupTransport",value:function(){var e=this;if(this._isSockjs=!1,null!==this._sockjs){var t={transports:this._config.sockjsTransports};null!==this._config.sockjsServer&&(t.server=this._config.sockjsServer),this._isSockjs=!0,this._transport=new this._sockjs(this._url,null,t)}else{if(!this._websocketSupported())return void this._debug("No Websocket support and no SockJS configured, can not connect");null!==this._config.websocket?this._websocket=this._config.websocket:this._websocket=WebSocket,this._transport=new this._websocket(this._url),!0===this._binary&&(this._transport.binaryType="arraybuffer")}this._transport.onopen=function(){e._transportClosed=!1,e._isSockjs?(e._transportName="sockjs-"+e._transport.transport,e._transport.onheartbeat=function(){return e._restartPing()}):e._transportName="websocket";var t={};(e._token||e._connectData)&&(t.params={}),e._token&&(t.params.token=e._token),e._connectData&&(t.params.data=e._connectData);var r={},n=!1;for(var i in e._serverSubs)if(e._serverSubs.hasOwnProperty(i)&&e._serverSubs[i].recoverable){n=!0;var s={recover:!0};e._serverSubs[i].seq||e._serverSubs[i].gen?(e._serverSubs[i].seq&&(s.seq=e._serverSubs[i].seq),e._serverSubs[i].gen&&(s.gen=e._serverSubs[i].gen)):e._serverSubs[i].offset&&(s.offset=e._serverSubs[i].offset),e._serverSubs[i].epoch&&(s.epoch=e._serverSubs[i].epoch),r[i]=s}n&&(t.params||(t.params={}),t.params.subs=r),e._latencyStart=new Date,e._call(t).then(function(t){e._connectResponse(e._decoder.decodeCommandResult(e._methodType.CONNECT,t.result),n),t.next&&t.next()},function(t){109===t.error.code&&(e._refreshRequired=!0),e._disconnect("connect error",!0),t.next&&t.next()})},this._transport.onerror=function(t){e._debug("transport level error",t)},this._transport.onclose=function(t){e._transportClosed=!0;var r="connection closed",n=!0;if(t&&"reason"in t&&t.reason)try{var i=JSON.parse(t.reason);e._debug("reason is an advice object",i),r=i.reason,n=i.reconnect}catch(n){r=t.reason,e._debug("reason is a plain string",r)}if(null!==e._config.onTransportClose&&e._config.onTransportClose({event:t,reason:r,reconnect:n}),e._disconnect(r,n),!0===e._reconnect){e._reconnecting=!0;var s=e._getRetryInterval();e._debug("reconnect after "+s+" milliseconds"),setTimeout(function(){!0===e._reconnect&&(e._refreshRequired?e._refresh():e._connect())},s)}},this._transport.onmessage=function(t){e._dataReceived(t.data)}}},{key:"rpc",value:function(e){return this._rpc("",e)}},{key:"namedRPC",value:function(e,t){return this._rpc(e,t)}},{key:"_rpc",value:function(e,t){var r=this,n={data:t};""!==e&&(n.method=e);var i={method:this._methodType.RPC,params:n};return this.isConnected()?this._call(i).then(function(e){return e.next&&e.next(),r._decoder.decodeCommandResult(r._methodType.RPC,e.result)},function(e){return e.next&&e.next(),Promise.reject(e.error)}):Promise.reject(this._createErrorObject("connection closed",0))}},{key:"send",value:function(e){var t={method:this._methodType.SEND,params:{data:e}};return this.isConnected()&&this._transportSend([t])?Promise.resolve({}):Promise.reject(this._createErrorObject("connection closed",0))}},{key:"publish",value:function(e,t){var r={method:this._methodType.PUBLISH,params:{channel:e,data:t}};return this.isConnected()?this._call(r).then(function(e){return e.next&&e.next(),{}}):Promise.reject(this._createErrorObject("connection closed",0))}},{key:"_dataReceived",value:function(e){var t=this,r=this._decoder.decodeReplies(e);this._dispatchPromise=this._dispatchPromise.then(function(){var e=void 0;t._dispatchPromise=new Promise(function(t){e=t}),t._dispatchSynchronized(r,e)}),this._restartPing()}},{key:"_dispatchSynchronized",value:function(e,t){var r=this,n=Promise.resolve();for(var i in e)!function(t){e.hasOwnProperty(t)&&(n=n.then(function(){return r._dispatchReply(e[t])}))}(i);n=n.then(function(){t()})}},{key:"_dispatchReply",value:function(e){var t,r=new Promise(function(e){t=e});if(void 0===e||null===e)return this._debug("dispatch: got undefined or null reply"),t(),r;var n=e.id;return n&&n>0?this._handleReply(e,t):this._handlePush(e.result,t),r}},{key:"_call",value:function(e){var t=this;return new Promise(function(r,n){var i=t._addMessage(e);t._registerCall(i,r,n)})}},{key:"_connect",value:function(){if(this.isConnected())return void this._debug("connect called when already connected");"connecting"!==this._status&&(this._debug("start connecting"),this._setStatus("connecting"),this._clientID=null,this._reconnect=!0,this._setupTransport())}},{key:"_disconnect",value:function(e,t){var r=t||!1;if(!1===r&&(this._reconnect=!1),this._isDisconnected())return void(r||this._clearConnectedState(r));if(this._clearConnectedState(r),this._debug("disconnected:",e,t),this._setStatus("disconnected"),this._refreshTimeout&&(clearTimeout(this._refreshTimeout),this._refreshTimeout=null),!1===this._reconnecting){for(var n in this._serverSubs)this._serverSubs.hasOwnProperty(n)&&this.emit("unsubscribe",{channel:n});this.emit("disconnect",{reason:e,reconnect:r})}!1===r&&(this._subs={},this._serverSubs={}),this._transportClosed||this._transport.close()}},{key:"_refreshFailed",value:function(){this._numRefreshFailed=0,this._isDisconnected()||this._disconnect("refresh failed",!1),null!==this._config.onRefreshFailed&&this._config.onRefreshFailed()}},{key:"_refresh",value:function(){var e=this;if(this._debug("refresh token"),0===this._config.refreshAttempts)return this._debug("refresh attempts set to 0, do not send refresh request at all"),void this._refreshFailed();null!==this._refreshTimeout&&(clearTimeout(this._refreshTimeout),this._refreshTimeout=null);var t=this._clientID,r=this._newXHRID(),n=function(n){if(r in e._xhrs&&delete e._xhrs[r],e._clientID===t){if(n.error||200!==n.status){if(n.error?e._debug("error refreshing connection token",n.error):e._debug("error refreshing connection token: wrong status code",n.status),e._numRefreshFailed++,null!==e._refreshTimeout&&(clearTimeout(e._refreshTimeout),e._refreshTimeout=null),null!==e._config.refreshAttempts&&e._numRefreshFailed>=e._config.refreshAttempts)return void e._refreshFailed();var i=Math.round(1e3*Math.random()*Math.max(e._numRefreshFailed,20)),s=e._config.refreshInterval+i;return void(e._refreshTimeout=setTimeout(function(){return e._refresh()},s))}if(e._numRefreshFailed=0,e._token=n.data.token,!e._token)return void e._refreshFailed();if(e._isDisconnected()&&e._reconnect)e._debug("token refreshed, connect from scratch"),e._connect();else{e._debug("send refreshed token");var o={method:e._methodType.REFRESH,params:{token:e._token}};e._call(o).then(function(t){e._refreshResponse(e._decoder.decodeCommandResult(e._methodType.REFRESH,t.result)),t.next&&t.next()},function(t){e._refreshError(t.error),t.next&&t.next()})}}};if(null!==this._config.onRefresh){var i={};this._config.onRefresh(i,n)}else{var s=this._ajax(this._config.refreshEndpoint,this._config.refreshParams,this._config.refreshHeaders,this._config.refreshData,n);this._xhrs[r]=s}}},{key:"_refreshError",value:function(e){var t=this;this._debug("refresh error",e),this._refreshTimeout&&(clearTimeout(this._refreshTimeout),this._refreshTimeout=null);var r=this._config.refreshInterval+Math.round(1e3*Math.random());this._refreshTimeout=setTimeout(function(){return t._refresh()},r)}},{key:"_refreshResponse",value:function(e){var t=this;this._refreshTimeout&&(clearTimeout(this._refreshTimeout),this._refreshTimeout=null),e.expires&&(this._clientID=e.client,this._refreshTimeout=setTimeout(function(){return t._refresh()},this._getTTLMilliseconds(e.ttl)))}},{key:"_newXHRID",value:function(){return++this._xhrID}},{key:"_subRefresh",value:function(e){var t=this;if(this._debug("refresh subscription token for channel",e),void 0!==this._subRefreshTimeouts[e]){this._clearSubRefreshTimeout(e);var r=this._clientID,n=this._newXHRID(),i=function(i){if(n in t._xhrs&&delete t._xhrs[n],!i.error&&200===i.status&&t._clientID===r){var s={};if(i.data.channels)for(var o in i.data.channels){var u=i.data.channels[o];u.channel&&(s[u.channel]=u.token)}var a=s[e];if(a){var c={method:t._methodType.SUB_REFRESH,params:{channel:e,token:a}};null!==t._getSub(e)&&t._call(c).then(function(r){t._subRefreshResponse(e,t._decoder.decodeCommandResult(t._methodType.SUB_REFRESH,r.result)),r.next&&r.next()},function(r){t._subRefreshError(e,r.error),r.next&&r.next()})}}},s={client:this._clientID,channels:[e]};if(null!==this._config.onPrivateSubscribe)this._config.onPrivateSubscribe({data:s},i);else{var o=this._ajax(this._config.subscribeEndpoint,this._config.subscribeParams,this._config.subscribeHeaders,s,i);this._xhrs[n]=o}}}},{key:"_clearSubRefreshTimeout",value:function(e){void 0!==this._subRefreshTimeouts[e]&&(clearTimeout(this._subRefreshTimeouts[e]),delete this._subRefreshTimeouts[e])}},{key:"_subRefreshError",value:function(e,t){var r=this;if(this._debug("subscription refresh error",e,t),this._clearSubRefreshTimeout(e),null!==this._getSub(e)){var n=Math.round(1e3*Math.random()),i=setTimeout(function(){return r._subRefresh(e)},this._config.subRefreshInterval+n);this._subRefreshTimeouts[e]=i}}},{key:"_subRefreshResponse",value:function(e,t){var r=this;if(this._debug("subscription refresh success",e),this._clearSubRefreshTimeout(e),null!==this._getSub(e)&&!0===t.expires){var n=setTimeout(function(){return r._subRefresh(e)},this._getTTLMilliseconds(t.ttl));this._subRefreshTimeouts[e]=n}}},{key:"_subscribe",value:function(e,t){var r=this;this._debug("subscribing on",e.channel);var n=e.channel;if(n in this._subs||(this._subs[n]=e),!this.isConnected())return void e._setNew();e._setSubscribing(t);var i={method:this._methodType.SUBSCRIBE,params:{channel:n}};if((0,d.startsWith)(n,this._config.privateChannelPrefix))this._isSubscribeBatching?this._privateChannels[n]=!0:(this.startSubscribeBatching(),this._subscribe(e),this.stopSubscribeBatching());else{var s=e._needRecover();if(!0===s){i.params.recover=!0;var o=this._getLastSeq(n),u=this._getLastGen(n);if(o||u)o&&(i.params.seq=o),u&&(i.params.gen=u);else{var a=this._getLastOffset(n);a&&(i.params.offset=a)}var c=this._getLastEpoch(n);c&&(i.params.epoch=c)}this._call(i).then(function(e){r._subscribeResponse(n,s,r._decoder.decodeCommandResult(r._methodType.SUBSCRIBE,e.result)),e.next&&e.next()},function(e){r._subscribeError(n,e.error),e.next&&e.next()})}}},{key:"_unsubscribe",value:function(e){delete this._subs[e.channel],delete this._lastOffset[e.channel],delete this._lastSeq[e.channel],delete this._lastGen[e.channel],this.isConnected()&&this._addMessage({method:this._methodType.UNSUBSCRIBE,params:{channel:e.channel}})}},{key:"_getTTLMilliseconds",value:function(e){return Math.min(1e3*e,2147483647)}},{key:"getSub",value:function(e){return this._getSub(e)}},{key:"_getSub",value:function(e){var t=this._subs[e];return t||null}},{key:"_isServerSub",value:function(e){return void 0!==this._serverSubs[e]}},{key:"_connectResponse",value:function(e,t){var r=this,n=this._reconnecting;if(this._reconnecting=!1,this._resetRetry(),this._refreshRequired=!1,!this.isConnected()){null!==this._latencyStart&&(this._latency=(new Date).getTime()-this._latencyStart.getTime(),this._latencyStart=null),this._clientID=e.client,this._setStatus("connected"),this._refreshTimeout&&clearTimeout(this._refreshTimeout),e.expires&&(this._refreshTimeout=setTimeout(function(){return r._refresh()},this._getTTLMilliseconds(e.ttl))),this.startBatching(),this.startSubscribeBatching();for(var i in this._subs)if(this._subs.hasOwnProperty(i)){var s=this._subs[i];s._shouldResubscribe()&&this._subscribe(s,n)}this.stopSubscribeBatching(),this.stopBatching(),this._startPing();var o={client:e.client,transport:this._transportName,latency:this._latency};e.data&&(o.data=e.data),this.emit("connect",o),e.subs&&this._processServerSubs(e.subs,t)}}},{key:"_processServerSubs",value:function(e,t){for(var r in e)if(e.hasOwnProperty(r)){var n=e[r],i=!0===n.recovered,s={channel:r,isResubscribe:t,recovered:i};this.emit("subscribe",s)}for(var o in e)if(e.hasOwnProperty(o)){var u=e[o];if(u.recovered){var a=u.publications;if(a&&a.length>0){a.length>1&&(!a[0].offset||a[0].offset>a[1].offset)&&(a=a.reverse());for(var c in a)a.hasOwnProperty(c)&&this._handlePublication(o,a[c])}}this._serverSubs[o]={seq:u.seq,gen:u.gen,offset:u.offset,epoch:u.epoch,recoverable:u.recoverable}}}},{key:"_stopPing",value:function(){null!==this._pongTimeout&&(clearTimeout(this._pongTimeout),this._pongTimeout=null),null!==this._pingTimeout&&(clearTimeout(this._pingTimeout),this._pingTimeout=null)}},{key:"_startPing",value:function(){var e=this;!0!==this._config.ping||this._config.pingInterval<=0||this.isConnected()&&(this._pingTimeout=setTimeout(function(){if(!e.isConnected())return void e._stopPing();e.ping(),e._pongTimeout=setTimeout(function(){e._disconnect("no ping",!0)},e._config.pongWaitTimeout)},this._config.pingInterval))}},{key:"_restartPing",value:function(){this._stopPing(),this._startPing()}},{key:"_subscribeError",value:function(e,t){var r=this._getSub(e);if(r&&r._isSubscribing())return 0===t.code&&"timeout"===t.message?void this._disconnect("timeout",!0):void r._setSubscribeError(t)}},{key:"_subscribeResponse",value:function(e,t,r){var n=this,i=this._getSub(e);if(i&&i._isSubscribing()){var s=!1;"recovered"in r&&(s=r.recovered),i._setSubscribeSuccess(s);var o=r.publications;if(o&&o.length>0){o.length>=2&&!o[0].offset&&!o[1].offset&&(o=o.reverse());for(var u in o)o.hasOwnProperty(u)&&this._handlePublication(e,o[u])}if(!r.recoverable||t&&s||(this._lastSeq[e]=r.seq||0,this._lastGen[e]=r.gen||0,this._lastOffset[e]=r.offset||0),this._lastEpoch[e]=r.epoch||"",r.recoverable&&(i._recoverable=!0),!0===r.expires){var a=setTimeout(function(){return n._subRefresh(e)},this._getTTLMilliseconds(r.ttl));this._subRefreshTimeouts[e]=a}}}},{key:"_handleReply",value:function(e,t){var r=e.id,n=e.result;if(!(r in this._callbacks))return void t();var i=this._callbacks[r];if(clearTimeout(this._callbacks[r].timeout),delete this._callbacks[r],(0,d.errorExists)(e)){var s=i.errback;if(!s)return void t();s({error:e.error,next:t})}else{var o=i.callback;if(!o)return;o({result:n,next:t})}}},{key:"_handleJoin",value:function(e,t){var r={info:t.info},n=this._getSub(e);if(!n)return void(this._isServerSub(e)&&(r.channel=e,this.emit("join",r)));n.emit("join",r)}},{key:"_handleLeave",value:function(e,t){var r={info:t.info},n=this._getSub(e);if(!n)return void(this._isServerSub(e)&&(r.channel=e,this.emit("leave",r)));n.emit("leave",r)}},{key:"_handleUnsub",value:function(e,t){var r={},n=this._getSub(e);if(!n)return void(this._isServerSub(e)&&(delete this._serverSubs[e],r.channel=e,this.emit("unsubscribe",r)));n.unsubscribe(),!0===t.resubscribe&&n.subscribe()}},{key:"_handleSub",value:function(e,t){this._serverSubs[e]={seq:t.seq,gen:t.gen,offset:t.offset,epoch:t.epoch,recoverable:t.recoverable};var r={channel:e,isResubscribe:!1,recovered:!1};this.emit("subscribe",r)}},{key:"_handlePublication",value:function(e,t){var r=this._getSub(e),n={data:t.data,seq:t.seq,gen:t.gen,offset:t.offset};if(t.info&&(n.info=t.info),!r)return void(this._isServerSub(e)&&(void 0!==t.seq&&(this._serverSubs[e].seq=t.seq),void 0!==t.gen&&(this._serverSubs[e].gen=t.gen),void 0!==t.offset&&(this._serverSubs[e].offset=t.offset),n.channel=e,this.emit("publish",n)));void 0!==t.seq&&(this._lastSeq[e]=t.seq),void 0!==t.gen&&(this._lastGen[e]=t.gen),void 0!==t.offset&&(this._lastOffset[e]=t.offset),r.emit("publish",n)}},{key:"_handleMessage",value:function(e){this.emit("message",e.data)}},{key:"_handlePush",value:function(e,t){var r=this._decoder.decodePush(e),n=0;"type"in r&&(n=r.type);var i=r.channel;if(n===this._pushType.PUBLICATION){var s=this._decoder.decodePushData(this._pushType.PUBLICATION,r.data);this._handlePublication(i,s)}else if(n===this._pushType.MESSAGE){var o=this._decoder.decodePushData(this._pushType.MESSAGE,r.data);this._handleMessage(o)}else if(n===this._pushType.JOIN){var u=this._decoder.decodePushData(this._pushType.JOIN,r.data);this._handleJoin(i,u)}else if(n===this._pushType.LEAVE){var a=this._decoder.decodePushData(this._pushType.LEAVE,r.data);this._handleLeave(i,a)}else if(n===this._pushType.UNSUB){var c=this._decoder.decodePushData(this._pushType.UNSUB,r.data);this._handleUnsub(i,c)}else if(n===this._pushType.SUB){var f=this._decoder.decodePushData(this._pushType.SUB,r.data);this._handleSub(i,f)}t()}},{key:"_flush",value:function(){var e=this._messages.slice(0);this._messages=[],this._transportSend(e)}},{key:"_ping",value:function(){var e=this,t={method:this._methodType.PING};this._call(t).then(function(t){e._pingResponse(e._decoder.decodeCommandResult(e._methodType.PING,t.result)),t.next&&t.next()},function(t){e._debug("ping error",t.error),t.next&&t.next()})}},{key:"_pingResponse",value:function(e){this.isConnected()&&(this._stopPing(),this._startPing())}},{key:"_getLastSeq",value:function(e){var t=this._lastSeq[e];return t||0}},{key:"_getLastOffset",value:function(e){var t=this._lastOffset[e];return t||0}},{key:"_getLastGen",value:function(e){var t=this._lastGen[e];return t||0}},{key:"_getLastEpoch",value:function(e){var t=this._lastEpoch[e];return t||""}},{key:"_createErrorObject",value:function(e,t){return{message:e,code:t||0}}},{key:"_registerCall",value:function(e,t,r){var n=this;this._callbacks[e]={callback:t,errback:r,timeout:null},this._callbacks[e].timeout=setTimeout(function(){delete n._callbacks[e],(0,d.isFunction)(r)&&r({error:n._createErrorObject("timeout")})},this._config.timeout)}},{key:"_addMessage",value:function(e){var t=this._nextMessageId();return e.id=t,!0===this._isBatching?this._messages.push(e):this._transportSend([e]),t}},{key:"isConnected",value:function(){return this._isConnected()}},{key:"connect",value:function(){this._connect()}},{key:"disconnect",value:function(){this._disconnect("client",!1)}},{key:"ping",value:function(){return this._ping()}},{key:"startBatching",value:function(){this._isBatching=!0}},{key:"stopBatching",value:function(){this._isBatching=!1,this._flush()}},{key:"startSubscribeBatching",value:function(){this._isSubscribeBatching=!0}},{key:"stopSubscribeBatching",value:function(){var e=this;this._isSubscribeBatching=!1;var t=this._privateChannels;this._privateChannels={};var r=[];for(var n in t)if(t.hasOwnProperty(n)){var i=this._getSub(n);if(!i)continue;r.push(n)}if(0===r.length)return void this._debug("no private channels found, no need to make request");var s={client:this._clientID,channels:r},o=this._clientID,u=this._newXHRID(),a=function(t){if(u in e._xhrs&&delete e._xhrs[u],e._clientID===o)if(t.error||200!==t.status){e._debug("authorization request failed");for(var n in r)if(r.hasOwnProperty(n)){var i=r[n];e._subscribeError(i,e._createErrorObject("authorization request failed"))}}else{var s={};if(t.data.channels)for(var a in t.data.channels){var c=t.data.channels[a];c.channel&&(s[c.channel]=c.token)}var f=!1;e._isBatching||(e.startBatching(),f=!0);for(var l in r)if(r.hasOwnProperty(l)){var h=f