!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;n0)},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-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;r0&&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;t0&&(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=f(u,a),r=0;r=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=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):l.call(e,t)},i.prototype.listenerCount=l,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=t)return!0;return!1},i.isReservedName=function(e,t){if(e)for(var r=0;r0;){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-1)return n}else if(n instanceof i&&(n=n.lookup(e.slice(1),t,!0)))return n}else for(var s=0;s0&&(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 l in n)n.hasOwnProperty(l)&&a.setRequestHeader(l,n[l]);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&&(s.seq=e._serverSubs[i].seq),e._serverSubs[i].gen&&(s.gen=e._serverSubs[i].gen),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){var t=this,r={method:this._methodType.RPC,params:{data:e}};return this.isConnected()?this._call(r).then(function(e){return e.next&&e.next(),t._decoder.decodeCommandResult(t._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),n=Promise.resolve();for(var i in r)!function(e){r.hasOwnProperty(e)&&(n=n.then(function(){return t._dispatchReply(r[e])}))}(i);this._restartPing()}},{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 o={};if(i.data.channels)for(var u in s.channels){var a=i.data.channels[u];a.channel&&(o[a.channel]=a.token)}var c=o[e];if(c){var l={method:t._methodType.SUB_REFRESH,params:{channel:e,token:c}};null!==t._getSub(e)&&t._call(l).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);o&&(i.params.seq=o);var u=this._getLastGen(n);u&&(i.params.gen=u);var a=this._getLastEpoch(n);a&&(i.params.epoch=a)}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){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:"_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=a.reverse();for(var c in a)a.hasOwnProperty(c)&&this._handlePublication(o,a[c])}}this._serverSubs[o]={seq:u.seq,gen:u.gen,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=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._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 r.channel=e,void 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 r.channel=e,void this.emit("leave",r);n.emit("leave",r)}},{key:"_handleUnsub",value:function(e,t){var r={},n=this._getSub(e);if(!n)return delete this._serverSubs[e],r.channel=e,void 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,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};if(!r)return void 0!==this._serverSubs[e]&&(void 0!==t.seq&&(this._serverSubs[e].seq=t.seq),void 0!==t.gen&&(this._serverSubs[e].gen=t.gen)),n.channel=e,void this.emit("publish",n);void 0!==t.seq&&(this._lastSeq[e]=t.seq),void 0!==t.gen&&(this._lastGen[e]=t.gen),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 l=this._decoder.decodePushData(this._pushType.SUB,r.data);this._handleSub(i,l)}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:"_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:"_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 l=!1;e._isBatching||(e.startBatching(),l=!0);for(var f in r)if(r.hasOwnProperty(f)){var h=function(){var t=r[f],n=s[t];if(!n)return e._subscribeError(t,e._createErrorObject("permission denied",103)),"continue";var i={method:e._methodType.SUBSCRIBE,params:{channel:t,token:n}},o=e._getSub(t);if(null===o)return"continue";var u=o._needRecover();if(!0===u){i.params.recover=!0;var a=e._getLastSeq(t);a&&(i.params.seq=a);var c=e._getLastGen(t);c&&(i.params.gen=c);var l=e._getLastEpoch(t);l&&(i.params.epoch=l)}e._call(i).then(function(r){e._subscribeResponse(t,u,e._decoder.decodeCommandResult(e._methodType.SUBSCRIBE,r.result)),r.next&&r.next()},function(r){e._subscribeError(t,r.error),r.next&&r.next()})}();if("continue"===h)continue}l&&e.stopBatching()}};if(null!==this._config.onPrivateSubscribe)this._config.onPrivateSubscribe({data:s},a);else{var c=this._ajax(this._config.subscribeEndpoint,this._config.subscribeParams,this._config.subscribeHeaders,s,a);this._xhrs[u]=c}}},{key:"subscribe",value:function(e,t){var r=this._getSub(e);if(null!==r)return r._setEvents(t),r._isUnsubscribed()&&r.subscribe(),r;var n=new h.default(this,e,t);return this._subs[e]=n,n.subscribe(),n}}]),r}(l.default)}).call(t,r(3))},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(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 s(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});var o=function(){function e(e,t){for(var r=0;r127;)t[r++]=127&e|128,e>>>=7;t[r]=e}function c(e,t){this.len=e,this.next=void 0,this.val=t}function l(e,t,r){for(;e.hi;)t[r++]=127&e.lo|128,e.lo=(e.lo>>>7|e.hi<<25)>>>0,e.hi>>>=7;for(;e.lo>127;)t[r++]=127&e.lo|128,e.lo=e.lo>>>7;t[r++]=e.lo}function f(e,t,r){t[r]=255&e,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}e.exports=o;var h,p=r(1),d=p.LongBits,y=p.base64,v=p.utf8;o.create=p.Buffer?function(){return(o.create=function(){return new h})()}:function(){return new o},o.alloc=function(e){return new p.Array(e)},p.Array!==Array&&(o.alloc=p.pool(o.alloc,p.Array.prototype.subarray)),o.prototype._push=function(e,t,r){return this.tail=this.tail.next=new n(e,t,r),this.len+=t,this},c.prototype=Object.create(n.prototype),c.prototype.fn=a,o.prototype.uint32=function(e){return this.len+=(this.tail=this.tail.next=new c((e>>>=0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this},o.prototype.int32=function(e){return e<0?this._push(l,10,d.fromNumber(e)):this.uint32(e)},o.prototype.sint32=function(e){return this.uint32((e<<1^e>>31)>>>0)},o.prototype.uint64=function(e){var t=d.from(e);return this._push(l,t.length(),t)},o.prototype.int64=o.prototype.uint64,o.prototype.sint64=function(e){var t=d.from(e).zzEncode();return this._push(l,t.length(),t)},o.prototype.bool=function(e){return this._push(u,1,e?1:0)},o.prototype.fixed32=function(e){return this._push(f,4,e>>>0)},o.prototype.sfixed32=o.prototype.fixed32,o.prototype.fixed64=function(e){var t=d.from(e);return this._push(f,4,t.lo)._push(f,4,t.hi)},o.prototype.sfixed64=o.prototype.fixed64,o.prototype.float=function(e){return this._push(p.float.writeFloatLE,4,e)},o.prototype.double=function(e){return this._push(p.float.writeDoubleLE,8,e)};var b=p.Array.prototype.set?function(e,t,r){t.set(e,r)}:function(e,t,r){for(var n=0;n>>0;if(!t)return this._push(u,1,0);if(p.isString(e)){var r=o.alloc(t=y.length(e));y.decode(e,r,0),e=r}return this.uint32(t)._push(b,t,e)},o.prototype.string=function(e){var t=v.length(e);return t?this.uint32(t)._push(v.write,t,e):this._push(u,1,0)},o.prototype.fork=function(){return this.states=new s(this),this.head=this.tail=new n(i,0,0),this.len=0,this},o.prototype.reset=function(){return this.states?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new n(i,0,0),this.len=0),this},o.prototype.ldelim=function(){var e=this.head,t=this.tail,r=this.len;return this.reset().uint32(r),r&&(this.tail.next=e.next,this.tail=t,this.len+=r),this},o.prototype.finish=function(){for(var e=this.head.next,t=this.constructor.alloc(this.len),r=0;e;)e.fn(e.val,t,r),r+=e.len,e=e.next;return t},o._configure=function(e){h=e}},function(e,t,r){"use strict";function n(e,t){return RangeError("index out of range: "+e.pos+" + "+(t||1)+" > "+e.len)}function i(e){this.buf=e,this.pos=0,this.len=e.length}function s(){var e=new l(0,0),t=0;if(!(this.len-this.pos>4)){for(;t<3;++t){if(this.pos>=this.len)throw n(this);if(e.lo=(e.lo|(127&this.buf[this.pos])<<7*t)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(127&this.buf[this.pos++])<<7*t)>>>0,e}for(;t<4;++t)if(e.lo=(e.lo|(127&this.buf[this.pos])<<7*t)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(127&this.buf[this.pos])<<28)>>>0,e.hi=(e.hi|(127&this.buf[this.pos])>>4)>>>0,this.buf[this.pos++]<128)return e;if(t=0,this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(127&this.buf[this.pos])<<7*t+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw n(this);if(e.hi=(e.hi|(127&this.buf[this.pos])<<7*t+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}function o(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}function u(){if(this.pos+8>this.len)throw n(this,8);return new l(o(this.buf,this.pos+=4),o(this.buf,this.pos+=4))}e.exports=i;var a,c=r(1),l=c.LongBits,f=c.utf8,h="undefined"!=typeof Uint8Array?function(e){if(e instanceof Uint8Array||Array.isArray(e))return new i(e);throw Error("illegal buffer")}:function(e){if(Array.isArray(e))return new i(e);throw Error("illegal buffer")};i.create=c.Buffer?function(e){return(i.create=function(e){return c.Buffer.isBuffer(e)?new a(e):h(e)})(e)}:h,i.prototype._slice=c.Array.prototype.subarray||c.Array.prototype.slice,i.prototype.uint32=function(){var e=4294967295;return function(){if(e=(127&this.buf[this.pos])>>>0,this.buf[this.pos++]<128)return e;if(e=(e|(127&this.buf[this.pos])<<7)>>>0,this.buf[this.pos++]<128)return e;if(e=(e|(127&this.buf[this.pos])<<14)>>>0,this.buf[this.pos++]<128)return e;if(e=(e|(127&this.buf[this.pos])<<21)>>>0,this.buf[this.pos++]<128)return e;if(e=(e|(15&this.buf[this.pos])<<28)>>>0,this.buf[this.pos++]<128)return e;if((this.pos+=5)>this.len)throw this.pos=this.len,n(this,10);return e}}(),i.prototype.int32=function(){return 0|this.uint32()},i.prototype.sint32=function(){var e=this.uint32();return e>>>1^-(1&e)|0},i.prototype.bool=function(){return 0!==this.uint32()},i.prototype.fixed32=function(){if(this.pos+4>this.len)throw n(this,4);return o(this.buf,this.pos+=4)},i.prototype.sfixed32=function(){if(this.pos+4>this.len)throw n(this,4);return 0|o(this.buf,this.pos+=4)},i.prototype.float=function(){if(this.pos+4>this.len)throw n(this,4);var e=c.float.readFloatLE(this.buf,this.pos);return this.pos+=4,e},i.prototype.double=function(){if(this.pos+8>this.len)throw n(this,4);var e=c.float.readDoubleLE(this.buf,this.pos);return this.pos+=8,e},i.prototype.bytes=function(){var e=this.uint32(),t=this.pos,r=this.pos+e;if(r>this.len)throw n(this,e);return this.pos+=e,Array.isArray(this.buf)?this.buf.slice(t,r):t===r?new this.buf.constructor(0):this._slice.call(this.buf,t,r)},i.prototype.string=function(){var e=this.bytes();return f.read(e,0,e.length)},i.prototype.skip=function(e){if("number"==typeof e){if(this.pos+e>this.len)throw n(this,e);this.pos+=e}else do{if(this.pos>=this.len)throw n(this)}while(128&this.buf[this.pos++]);return this},i.prototype.skipType=function(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;4!=(e=7&this.uint32());)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error("invalid wire type "+e+" at offset "+this.pos)}return this},i._configure=function(e){a=e;var t=c.Long?"toLong":"toNumber";c.merge(i.prototype,{int64:function(){return s.call(this)[t](!1)},uint64:function(){return s.call(this)[t](!0)},sint64:function(){return s.call(this).zzDecode()[t](!1)},fixed64:function(){return u.call(this)[t](!0)},sfixed64:function(){return u.call(this)[t](!1)}})}},function(e,t,r){"use strict";function n(e,t,r,n){if(Array.isArray(t)||(r=t,t=void 0),s.call(this,e,r),void 0!==t&&!Array.isArray(t))throw TypeError("fieldNames must be an Array");this.oneof=t||[],this.fieldsArray=[],this.comment=n}function i(e){if(e.parent)for(var t=0;t-1&&this.oneof.splice(t,1),e.partOf=null,this},n.prototype.onAdd=function(e){s.prototype.onAdd.call(this,e);for(var t=this,r=0;r>>0,(t.id<<3|4)>>>0):e("types[%i].encode(%s,w.uint32(%i).fork()).ldelim()",r,n,(t.id<<3|2)>>>0)}function i(e){for(var t,r,i=u.codegen(["m","w"],e.name+"$encode")("if(!w)")("w=Writer.create()"),a=e.fieldsArray.slice().sort(u.compareFieldsById),t=0;t>>0,8|o.mapKey[c.keyType],c.keyType),void 0===h?i("types[%i].encode(%s[ks[i]],w.uint32(18).fork()).ldelim().ldelim()",l,r):i(".uint32(%i).%s(%s[ks[i]]).ldelim()",16|h,f,r),i("}")("}")):c.repeated?(i("if(%s!=null&&%s.length){",r,r),c.packed&&void 0!==o.packed[f]?i("w.uint32(%i).fork()",(c.id<<3|2)>>>0)("for(var i=0;i<%s.length;++i)",r)("w.%s(%s[i])",f,r)("w.ldelim()"):(i("for(var i=0;i<%s.length;++i)",r),void 0===h?n(i,c,l,r+"[i]"):i("w.uint32(%i).%s(%s[i])",(c.id<<3|h)>>>0,f,r)),i("}")):(c.optional&&i("if(%s!=null&&m.hasOwnProperty(%j))",r,c.name),void 0===h?n(i,c,l,r):i("w.uint32(%i).%s(%s)",(c.id<<3|h)>>>0,f,r))}return i("return w")}e.exports=i;var s=r(2),o=r(9),u=r(0)},function(e,t,r){"use strict";function n(e,t){s.call(this,e,t),this.fields={},this.oneofs=void 0,this.extensions=void 0,this.reserved=void 0,this.group=void 0,this._fieldsById=null,this._fieldsArray=null,this._oneofsArray=null,this._ctor=null}function i(e){return e._fieldsById=e._fieldsArray=e._oneofsArray=null,delete e.encode,delete e.decode,delete e.verify,e}e.exports=n;var s=r(8);((n.prototype=Object.create(s.prototype)).constructor=n).className="Type";var o=r(2),u=r(15),a=r(5),c=r(23),l=r(24),f=r(16),h=r(14),p=r(13),d=r(0),y=r(21),v=r(26),b=r(27),m=r(28),_=r(29);Object.defineProperties(n.prototype,{fieldsById:{get:function(){if(this._fieldsById)return this._fieldsById;this._fieldsById={};for(var e=Object.keys(this.fields),t=0;t>>3){");for(var r=0;r>>0",n,n);break;case"int32":case"sint32":case"sfixed32":e("m%s=d%s|0",n,n);break;case"uint64":a=!0;case"int64":case"sint64":case"fixed64":case"sfixed64":e("if(util.Long)")("(m%s=util.Long.fromValue(d%s)).unsigned=%j",n,n,a)('else if(typeof d%s==="string")',n)("m%s=parseInt(d%s,10)",n,n)('else if(typeof d%s==="number")',n)("m%s=d%s",n,n)('else if(typeof d%s==="object")',n)("m%s=new util.LongBits(d%s.low>>>0,d%s.high>>>0).toNumber(%s)",n,n,n,a?"true":"");break;case"bytes":e('if(typeof d%s==="string")',n)("util.base64.decode(d%s,m%s=util.newBuffer(util.base64.length(d%s)),0)",n,n,n)("else if(d%s.length)",n)("m%s=d%s",n,n);break;case"string":e("m%s=String(d%s)",n,n);break;case"bool":e("m%s=Boolean(d%s)",n,n)}}return e}function i(e,t,r,n){if(t.resolvedType)t.resolvedType instanceof o?e("d%s=o.enums===String?types[%i].values[m%s]:m%s",n,r,n,n):e("d%s=types[%i].toObject(m%s,o)",n,r,n);else{var i=!1;switch(t.type){case"double":case"float":e("d%s=o.json&&!isFinite(m%s)?String(m%s):m%s",n,n,n,n);break;case"uint64":i=!0;case"int64":case"sint64":case"fixed64":case"sfixed64":e('if(typeof m%s==="number")',n)("d%s=o.longs===String?String(m%s):m%s",n,n,n)("else")("d%s=o.longs===String?util.Long.prototype.toString.call(m%s):o.longs===Number?new util.LongBits(m%s.low>>>0,m%s.high>>>0).toNumber(%s):m%s",n,n,n,n,i?"true":"",n);break;case"bytes":e("d%s=o.bytes===String?util.base64.encode(m%s,0,m%s.length):o.bytes===Array?Array.prototype.slice.call(m%s):m%s",n,n,n,n,n);break;default:e("d%s=m%s",n,n)}}return e}var s=t,o=r(2),u=r(0);s.fromObject=function(e){var t=e.fieldsArray,r=u.codegen(["d"],e.name+"$fromObject")("if(d instanceof this.ctor)")("return d");if(!t.length)return r("return new this.ctor");r("var m=new this.ctor");for(var i=0;i-1){var i=e.substring(r);i in c&&(e=i)}if(!(l.files.indexOf(e)>-1)){if(l.files.push(e),e in c)return void(f?o(e,c[e]):(++h,setTimeout(function(){--h,o(e,c[e])})));if(f){var u;try{u=p.fs.readFileSync(e).toString("utf8")}catch(e){return void(t||s(e))}o(e,u)}else++h,p.fetch(e,function(r,i){if(--h,n)return r?void(t?h||s(null,l):s(r)):void o(e,i)})}}"function"==typeof r&&(n=r,r=void 0);var l=this;if(!n)return p.asPromise(e,l,t,r);var f=n===i,h=0;p.isString(t)&&(t=[t]);for(var d,y=0;y-1&&this.deferred.splice(t,1)}}else if(e instanceof f)d.test(e.name)&&delete e.parent[e.name];else if(e instanceof o){for(var r=0;r1&&"="===e.charAt(t);)++r;return Math.ceil(3*e.length)/4-r};for(var i=new Array(64),s=new Array(123),o=0;o<64;)s[i[o]=o<26?o+65:o<52?o+71:o<62?o-4:o-59|43]=o++;n.encode=function(e,t,r){for(var n,s=null,o=[],u=0,a=0;t>2],n=(3&c)<<4,a=1;break;case 1:o[u++]=i[n|c>>4],n=(15&c)<<2,a=2;break;case 2:o[u++]=i[n|c>>6],o[u++]=i[63&c],a=0}u>8191&&((s||(s=[])).push(String.fromCharCode.apply(String,o)),u=0)}return a&&(o[u++]=i[n],o[u++]=61,1===a&&(o[u++]=61)),s?(u&&s.push(String.fromCharCode.apply(String,o.slice(0,u))),s.join("")):String.fromCharCode.apply(String,o.slice(0,u))};n.decode=function(e,t,r){for(var n,i=r,o=0,u=0;u1)break;if(void 0===(a=s[a]))throw Error("invalid encoding");switch(o){case 0:n=a,o=1;break;case 1:t[r++]=n<<2|(48&a)>>4,n=a,o=2;break;case 2:t[r++]=(15&n)<<4|(60&a)>>2,n=a,o=3;break;case 3:t[r++]=(3&n)<<6|a,o=0}}if(1===o)throw Error("invalid encoding");return r-i},n.test=function(e){return/^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/.test(e)}},function(e,t,r){"use strict";function n(){this._listeners={}}e.exports=n,n.prototype.on=function(e,t,r){return(this._listeners[e]||(this._listeners[e]=[])).push({fn:t,ctx:r||this}),this},n.prototype.off=function(e,t){if(void 0===e)this._listeners={};else if(void 0===t)this._listeners[e]=[];else for(var r=this._listeners[e],n=0;n0?0:2147483648,r,n);else if(isNaN(t))e(2143289344,r,n);else if(t>3.4028234663852886e38)e((i<<31|2139095040)>>>0,r,n);else if(t<1.1754943508222875e-38)e((i<<31|Math.round(t/1.401298464324817e-45))>>>0,r,n);else{var s=Math.floor(Math.log(t)/Math.LN2),o=8388607&Math.round(t*Math.pow(2,-s)*8388608);e((i<<31|s+127<<23|o)>>>0,r,n)}}function r(e,t,r){var n=e(t,r),i=2*(n>>31)+1,s=n>>>23&255,o=8388607&n;return 255===s?o?NaN:i*(1/0):0===s?1.401298464324817e-45*i*o:i*Math.pow(2,s-150)*(o+8388608)}e.writeFloatLE=t.bind(null,i),e.writeFloatBE=t.bind(null,s),e.readFloatLE=r.bind(null,o),e.readFloatBE=r.bind(null,u)}(),"undefined"!=typeof Float64Array?function(){function t(e,t,r){s[0]=e,t[r]=o[0],t[r+1]=o[1],t[r+2]=o[2],t[r+3]=o[3],t[r+4]=o[4],t[r+5]=o[5],t[r+6]=o[6],t[r+7]=o[7]}function r(e,t,r){s[0]=e,t[r]=o[7],t[r+1]=o[6],t[r+2]=o[5],t[r+3]=o[4],t[r+4]=o[3],t[r+5]=o[2],t[r+6]=o[1],t[r+7]=o[0]}function n(e,t){return o[0]=e[t],o[1]=e[t+1],o[2]=e[t+2],o[3]=e[t+3],o[4]=e[t+4],o[5]=e[t+5],o[6]=e[t+6],o[7]=e[t+7],s[0]}function i(e,t){return o[7]=e[t],o[6]=e[t+1],o[5]=e[t+2],o[4]=e[t+3],o[3]=e[t+4],o[2]=e[t+5],o[1]=e[t+6],o[0]=e[t+7],s[0]}var s=new Float64Array([-0]),o=new Uint8Array(s.buffer),u=128===o[7];e.writeDoubleLE=u?t:r,e.writeDoubleBE=u?r:t,e.readDoubleLE=u?n:i,e.readDoubleBE=u?i:n}():function(){function t(e,t,r,n,i,s){var o=n<0?1:0;if(o&&(n=-n),0===n)e(0,i,s+t),e(1/n>0?0:2147483648,i,s+r);else if(isNaN(n))e(0,i,s+t),e(2146959360,i,s+r);else if(n>1.7976931348623157e308)e(0,i,s+t),e((o<<31|2146435072)>>>0,i,s+r);else{var u;if(n<2.2250738585072014e-308)u=n/5e-324,e(u>>>0,i,s+t),e((o<<31|u/4294967296)>>>0,i,s+r);else{var a=Math.floor(Math.log(n)/Math.LN2);1024===a&&(a=1023),u=n*Math.pow(2,-a),e(4503599627370496*u>>>0,i,s+t),e((o<<31|a+1023<<20|1048576*u&1048575)>>>0,i,s+r)}}}function r(e,t,r,n,i){var s=e(n,i+t),o=e(n,i+r),u=2*(o>>31)+1,a=o>>>20&2047,c=4294967296*(1048575&o)+s;return 2047===a?c?NaN:u*(1/0):0===a?5e-324*u*c:u*Math.pow(2,a-1075)*(c+4503599627370496)}e.writeDoubleLE=t.bind(null,i,0,4),e.writeDoubleBE=t.bind(null,s,4,0),e.readDoubleLE=r.bind(null,o,0,4),e.readDoubleBE=r.bind(null,u,4,0)}(),e}function i(e,t,r){t[r]=255&e,t[r+1]=e>>>8&255,t[r+2]=e>>>16&255,t[r+3]=e>>>24}function s(e,t,r){t[r]=e>>>24,t[r+1]=e>>>16&255,t[r+2]=e>>>8&255,t[r+3]=255&e}function o(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0}function u(e,t){return(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0}e.exports=n(n)},function(e,t,r){"use strict";var n=t;n.length=function(e){for(var t=0,r=0,n=0;n191&&n<224?s[o++]=(31&n)<<6|63&e[t++]:n>239&&n<365?(n=((7&n)<<18|(63&e[t++])<<12|(63&e[t++])<<6|63&e[t++])-65536,s[o++]=55296+(n>>10),s[o++]=56320+(1023&n)):s[o++]=(15&n)<<12|(63&e[t++])<<6|63&e[t++],o>8191&&((i||(i=[])).push(String.fromCharCode.apply(String,s)),o=0);return i?(o&&i.push(String.fromCharCode.apply(String,s.slice(0,o))),i.join("")):String.fromCharCode.apply(String,s.slice(0,o))},n.write=function(e,t,r){for(var n,i,s=r,o=0;o>6|192,t[r++]=63&n|128):55296==(64512&n)&&56320==(64512&(i=e.charCodeAt(o+1)))?(n=65536+((1023&n)<<10)+(1023&i),++o,t[r++]=n>>18|240,t[r++]=n>>12&63|128,t[r++]=n>>6&63|128,t[r++]=63&n|128):(t[r++]=n>>12|224,t[r++]=n>>6&63|128,t[r++]=63&n|128);return r-s}},function(e,t,r){"use strict";function n(e,t,r){var n=r||8192,i=n>>>1,s=null,o=n;return function(r){if(r<1||r>i)return e(r);o+r>n&&(s=e(n),o=0);var u=t.call(s,o,o+=r);return 7&o&&(o=1+(7|o)),u}}e.exports=n},function(e,t,r){"use strict";function n(e,t){this.lo=e>>>0,this.hi=t>>>0}e.exports=n;var i=r(1),s=n.zero=new n(0,0);s.toNumber=function(){return 0},s.zzEncode=s.zzDecode=function(){return this},s.length=function(){return 1};var o=n.zeroHash="\0\0\0\0\0\0\0\0";n.fromNumber=function(e){if(0===e)return s;var t=e<0;t&&(e=-e);var r=e>>>0,i=(e-r)/4294967296>>>0;return t&&(i=~i>>>0,r=~r>>>0,++r>4294967295&&(r=0,++i>4294967295&&(i=0))),new n(r,i)},n.from=function(e){if("number"==typeof e)return n.fromNumber(e);if(i.isString(e)){if(!i.Long)return n.fromNumber(parseInt(e,10));e=i.Long.fromString(e)}return e.low||e.high?new n(e.low>>>0,e.high>>>0):s},n.prototype.toNumber=function(e){if(!e&&this.hi>>>31){var t=1+~this.lo>>>0,r=~this.hi>>>0;return t||(r=r+1>>>0),-(t+4294967296*r)}return this.lo+4294967296*this.hi},n.prototype.toLong=function(e){return i.Long?new i.Long(0|this.lo,0|this.hi,Boolean(e)):{low:0|this.lo,high:0|this.hi,unsigned:Boolean(e)}};var u=String.prototype.charCodeAt;n.fromHash=function(e){return e===o?s:new n((u.call(e,0)|u.call(e,1)<<8|u.call(e,2)<<16|u.call(e,3)<<24)>>>0,(u.call(e,4)|u.call(e,5)<<8|u.call(e,6)<<16|u.call(e,7)<<24)>>>0)},n.prototype.toHash=function(){return String.fromCharCode(255&this.lo,this.lo>>>8&255,this.lo>>>16&255,this.lo>>>24,255&this.hi,this.hi>>>8&255,this.hi>>>16&255,this.hi>>>24)},n.prototype.zzEncode=function(){var e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this},n.prototype.zzDecode=function(){var e=-(1&this.lo);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this},n.prototype.length=function(){var e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,r=this.hi>>>24;return 0===r?0===t?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:r<128?9:10}},function(e,t,r){"use strict";function n(){s.call(this)}function i(e,t,r){e.length<40?o.utf8.write(e,t,r):t.utf8Write(e,r)}e.exports=n;var s=r(13);(n.prototype=Object.create(s.prototype)).constructor=n;var o=r(1),u=o.Buffer;n.alloc=function(e){return(n.alloc=o._Buffer_allocUnsafe)(e)};var a=u&&u.prototype instanceof Uint8Array&&"set"===u.prototype.set.name?function(e,t,r){t.set(e,r)}:function(e,t,r){if(e.copy)e.copy(t,r,0,e.length);else for(var n=0;n>>0;return this.uint32(t),t&&this._push(a,t,e),this},n.prototype.string=function(e){var t=u.byteLength(e);return this.uint32(t),t&&this._push(i,t,e),this}},function(e,t,r){"use strict";function n(e){i.call(this,e)}e.exports=n;var i=r(14);(n.prototype=Object.create(i.prototype)).constructor=n;var s=r(1);s.Buffer&&(n.prototype._slice=s.Buffer.prototype.slice),n.prototype.string=function(){var e=this.uint32();return this.buf.utf8Slice(this.pos,this.pos=Math.min(this.pos+e,this.len))}},function(e,t,r){"use strict";function n(e,t,r){if("function"!=typeof e)throw TypeError("rpcImpl must be a function");i.EventEmitter.call(this),this.rpcImpl=e,this.requestDelimited=Boolean(t),this.responseDelimited=Boolean(r)}e.exports=n;var i=r(1);(n.prototype=Object.create(i.EventEmitter.prototype)).constructor=n,n.prototype.rpcCall=function e(t,r,n,s,o){if(!s)throw TypeError("request must be specified");var u=this;if(!o)return i.asPromise(e,u,t,r,n,s);if(!u.rpcImpl)return void setTimeout(function(){o(Error("already ended"))},0);try{return u.rpcImpl(t,r[u.requestDelimited?"encodeDelimited":"encode"](s).finish(),function(e,r){if(e)return u.emit("error",e,t),o(e);if(null===r)return void u.end(!0);if(!(r instanceof n))try{r=n[u.responseDelimited?"decodeDelimited":"decode"](r)}catch(e){return u.emit("error",e,t),o(e)}return u.emit("data",r,t),o(null,r)})}catch(e){return u.emit("error",e,t),void setTimeout(function(){o(e)},0)}},n.prototype.end=function(e){return this.rpcImpl&&(e||this.rpcImpl(null,null,null),this.rpcImpl=null,this.emit("end").off()),this}},function(e,t,r){"use strict";function n(e,t){function r(e){if("string"!=typeof e){var t=i();if(n.verbose&&console.log("codegen: "+t),t="return "+t,e){for(var o=Object.keys(e),u=new Array(o.length+1),a=new Array(o.length),c=0;c0&&".."!==t[s-1]?t.splice(--s,2):r?t.splice(s,1):++s:"."===t[s]?t.splice(s,1):++s;return n+t.join("/")};n.resolve=function(e,t,r){return r||(t=s(t)),i(t)?t:(r||(e=s(e)),(e=e.replace(/(?:\/|^)[^\/]+$/,"")).length?s(e+"/"+t):t)}},function(e,t){e.exports={nested:{protocol:{nested:{Error:{fields:{code:{type:"uint32",id:1},message:{type:"string",id:2}}},MethodType:{values:{CONNECT:0,SUBSCRIBE:1,UNSUBSCRIBE:2,PUBLISH:3,PRESENCE:4,PRESENCE_STATS:5,HISTORY:6,PING:7,SEND:8,RPC:9,REFRESH:10,SUB_REFRESH:11}},Command:{fields:{id:{type:"uint32",id:1},method:{type:"MethodType",id:2},params:{type:"bytes",id:3}}},Reply:{fields:{id:{type:"uint32",id:1},error:{type:"Error",id:2},result:{type:"bytes",id:3}}},PushType:{values:{PUBLICATION:0,JOIN:1,LEAVE:2,UNSUB:3,MESSAGE:4,SUB:5}},Push:{fields:{type:{type:"PushType",id:1},channel:{type:"string",id:2},data:{type:"bytes",id:3}}},ClientInfo:{fields:{user:{type:"string",id:1},client:{type:"string",id:2},conn_info:{type:"bytes",id:3},chan_info:{type:"bytes",id:4}}},Publication:{fields:{seq:{type:"uint32",id:1},gen:{type:"uint32",id:2},uid:{type:"string",id:3},data:{type:"bytes",id:4},info:{type:"ClientInfo",id:5}}},Join:{fields:{info:{type:"ClientInfo",id:1}}},Leave:{fields:{info:{type:"ClientInfo",id:1}}},Unsub:{fields:{resubscribe:{type:"bool",id:1}}},Sub:{fields:{recoverable:{type:"bool",id:1},seq:{type:"uint32",id:2},gen:{type:"uint32",id:3},epoch:{type:"string",id:4},publications:{rule:"repeated",type:"Publication",id:5}}},Message:{fields:{data:{type:"bytes",id:1}}},ConnectRequest:{fields:{token:{type:"string",id:1},data:{type:"bytes",id:2},subs:{keyType:"string",type:"SubscribeRequest",id:3}}},ConnectResult:{fields:{client:{type:"string",id:1},version:{type:"string",id:2},expires:{type:"bool",id:3},ttl:{type:"uint32",id:4},data:{type:"bytes",id:5},subs:{keyType:"string",type:"SubscribeResult",id:6}}},RefreshRequest:{fields:{token:{type:"string",id:1}}},RefreshResult:{fields:{client:{type:"string",id:1},version:{type:"string",id:2},expires:{type:"bool",id:3},ttl:{type:"uint32",id:4}}},SubscribeRequest:{fields:{channel:{type:"string",id:1},token:{type:"string",id:2},recover:{type:"bool",id:3},seq:{type:"uint32",id:4},gen:{type:"uint32",id:5},epoch:{type:"string",id:6}}},SubscribeResult:{fields:{expires:{type:"bool",id:1},ttl:{type:"uint32",id:2},recoverable:{type:"bool",id:3},seq:{type:"uint32",id:4},gen:{type:"uint32",id:5},epoch:{type:"string",id:6},publications:{rule:"repeated",type:"Publication",id:7},recovered:{type:"bool",id:8}}},SubRefreshRequest:{fields:{channel:{type:"string",id:1},token:{type:"string",id:2}}},SubRefreshResult:{fields:{expires:{type:"bool",id:1},ttl:{type:"uint32",id:2}}},UnsubscribeRequest:{fields:{channel:{type:"string",id:1}}},UnsubscribeResult:{fields:{}},PublishRequest:{fields:{channel:{type:"string",id:1},data:{type:"bytes",id:2}}},PublishResult:{fields:{}},PresenceRequest:{fields:{channel:{type:"string",id:1}}},PresenceResult:{fields:{presence:{keyType:"string",type:"ClientInfo",id:1}}},PresenceStatsRequest:{fields:{channel:{type:"string",id:1}}},PresenceStatsResult:{fields:{num_clients:{type:"uint32",id:1},num_users:{type:"uint32",id:2}}},HistoryRequest:{fields:{channel:{type:"string",id:1}}},HistoryResult:{fields:{publications:{rule:"repeated",type:"Publication",id:1}}},PingRequest:{fields:{}},PingResult:{fields:{}},RPCRequest:{fields:{data:{type:"bytes",id:1},method:{type:"string",id:2}}},RPCResult:{fields:{data:{type:"bytes",id:1}}},SendRequest:{fields:{data:{type:"bytes",id:1}}}}}}}}])}); //# sourceMappingURL=centrifuge.protobuf.min.js.map