!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(r){if(n[r])return n[r].exports;var s=n[r]={i:r,l:!1,exports:{}};return e[r].call(s.exports,s,s.exports,t),s.l=!0,s.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=31)}({10:function(e,t,n){"use strict";(function(e){function r(e){return e&&e.__esModule?e:{default:e}}function s(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 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 n=0;n0&&(u+="&"),u+=encodeURIComponent(c)+"="+encodeURIComponent(n[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 h in r)r.hasOwnProperty(h)&&a.setRequestHeader(h,r[h]);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){i({error:"Invalid JSON. Data was: "+a.responseText,status:200,data:null})}t&&i({data:e,status:200})}else o._log("wrong status code in AJAX response",a.status),i({status:a.status,data:null})},setTimeout(function(){return a.send(JSON.stringify(s))},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=f.JsonMethodType,this._pushType=f.JsonPushType,this._encoder=new f.JsonEncoder,this._decoder=new f.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 n=this._callbacks[t];clearTimeout(n.timeout);var r=n.errback;if(!r)continue;r({error:this._createErrorObject("disconnected")})}this._callbacks={};for(var s in this._subs)if(this._subs.hasOwnProperty(s)){var i=this._subs[s];e?(i._isSuccess()&&(i._triggerUnsubscribe(),i._recover=!0),i._shouldResubscribe()&&i._setSubscribing()):i._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 n=t.id;if(n in this._callbacks){var r=this._callbacks[n];clearTimeout(this._callbacks[n].timeout),delete this._callbacks[n];(0,r.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 n={},r=!1;for(var s in e._serverSubs)if(e._serverSubs.hasOwnProperty(s)&&e._serverSubs[s].recoverable){r=!0;var i={recover:!0};e._serverSubs[s].seq&&(i.seq=e._serverSubs[s].seq),e._serverSubs[s].gen&&(i.gen=e._serverSubs[s].gen),e._serverSubs[s].epoch&&(i.epoch=e._serverSubs[s].epoch),n[s]=i}r&&(t.params||(t.params={}),t.params.subs=n),e._latencyStart=new Date,e._call(t).then(function(t){e._connectResponse(e._decoder.decodeCommandResult(e._methodType.CONNECT,t.result),r),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 n="connection closed",r=!0;if(t&&"reason"in t&&t.reason)try{var s=JSON.parse(t.reason);e._debug("reason is an advice object",s),n=s.reason,r=s.reconnect}catch(r){n=t.reason,e._debug("reason is a plain string",n)}if(null!==e._config.onTransportClose&&e._config.onTransportClose({event:t,reason:n,reconnect:r}),e._disconnect(n,r),!0===e._reconnect){e._reconnecting=!0;var i=e._getRetryInterval();e._debug("reconnect after "+i+" milliseconds"),setTimeout(function(){!0===e._reconnect&&(e._refreshRequired?e._refresh():e._connect())},i)}},this._transport.onmessage=function(t){e._dataReceived(t.data)}}},{key:"rpc",value:function(e){var t=this,n={method:this._methodType.RPC,params:{data:e}};return this.isConnected()?this._call(n).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 n={method:this._methodType.PUBLISH,params:{channel:e,data:t}};return this.isConnected()?this._call(n).then(function(e){return e.next&&e.next(),{}}):Promise.reject(this._createErrorObject("connection closed",0))}},{key:"_dataReceived",value:function(e){var t=this,n=this._decoder.decodeReplies(e),r=Promise.resolve();for(var s in n)!function(e){n.hasOwnProperty(e)&&(r=r.then(function(){return t._dispatchReply(n[e])}))}(s);this._restartPing()}},{key:"_call",value:function(e){var t=this;return new Promise(function(n,r){var s=t._addMessage(e);t._registerCall(s,n,r)})}},{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 n=t||!1;if(!1===n&&(this._reconnect=!1),this._isDisconnected())return void(n||this._clearConnectedState(n));if(this._clearConnectedState(n),this._debug("disconnected:",e,t),this._setStatus("disconnected"),this._refreshTimeout&&(clearTimeout(this._refreshTimeout),this._refreshTimeout=null),!1===this._reconnecting){for(var r in this._serverSubs)this._serverSubs.hasOwnProperty(r)&&this.emit("unsubscribe",{channel:r});this.emit("disconnect",{reason:e,reconnect:n})}!1===n&&(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,n=this._newXHRID(),r=function(r){if(n in e._xhrs&&delete e._xhrs[n],e._clientID===t){if(r.error||200!==r.status){if(r.error?e._debug("error refreshing connection token",r.error):e._debug("error refreshing connection token: wrong status code",r.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 s=Math.round(1e3*Math.random()*Math.max(e._numRefreshFailed,20)),i=e._config.refreshInterval+s;return void(e._refreshTimeout=setTimeout(function(){return e._refresh()},i))}if(e._numRefreshFailed=0,e._token=r.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 s={};this._config.onRefresh(s,r)}else{var i=this._ajax(this._config.refreshEndpoint,this._config.refreshParams,this._config.refreshHeaders,this._config.refreshData,r);this._xhrs[n]=i}}},{key:"_refreshError",value:function(e){var t=this;this._debug("refresh error",e),this._refreshTimeout&&(clearTimeout(this._refreshTimeout),this._refreshTimeout=null);var n=this._config.refreshInterval+Math.round(1e3*Math.random());this._refreshTimeout=setTimeout(function(){return t._refresh()},n)}},{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 n=this._clientID,r=this._newXHRID(),s=function(s){if(r in t._xhrs&&delete t._xhrs[r],!s.error&&200===s.status&&t._clientID===n){var o={};if(s.data.channels)for(var u in i.channels){var a=s.data.channels[u];a.channel&&(o[a.channel]=a.token)}var c=o[e];if(c){var h={method:t._methodType.SUB_REFRESH,params:{channel:e,token:c}};null!==t._getSub(e)&&t._call(h).then(function(n){t._subRefreshResponse(e,t._decoder.decodeCommandResult(t._methodType.SUB_REFRESH,n.result)),n.next&&n.next()},function(n){t._subRefreshError(e,n.error),n.next&&n.next()})}}},i={client:this._clientID,channels:[e]};if(null!==this._config.onPrivateSubscribe)this._config.onPrivateSubscribe({data:i},s);else{var o=this._ajax(this._config.subscribeEndpoint,this._config.subscribeParams,this._config.subscribeHeaders,i,s);this._xhrs[r]=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 n=this;if(this._debug("subscription refresh error",e,t),this._clearSubRefreshTimeout(e),null!==this._getSub(e)){var r=Math.round(1e3*Math.random()),s=setTimeout(function(){return n._subRefresh(e)},this._config.subRefreshInterval+r);this._subRefreshTimeouts[e]=s}}},{key:"_subRefreshResponse",value:function(e,t){var n=this;if(this._debug("subscription refresh success",e),this._clearSubRefreshTimeout(e),null!==this._getSub(e)&&!0===t.expires){var r=setTimeout(function(){return n._subRefresh(e)},this._getTTLMilliseconds(t.ttl));this._subRefreshTimeouts[e]=r}}},{key:"_subscribe",value:function(e,t){var n=this;this._debug("subscribing on",e.channel);var r=e.channel;if(r in this._subs||(this._subs[r]=e),!this.isConnected())return void e._setNew();e._setSubscribing(t);var s={method:this._methodType.SUBSCRIBE,params:{channel:r}};if((0,d.startsWith)(r,this._config.privateChannelPrefix))this._isSubscribeBatching?this._privateChannels[r]=!0:(this.startSubscribeBatching(),this._subscribe(e),this.stopSubscribeBatching());else{var i=e._needRecover();if(!0===i){s.params.recover=!0;var o=this._getLastSeq(r);o&&(s.params.seq=o);var u=this._getLastGen(r);u&&(s.params.gen=u);var a=this._getLastEpoch(r);a&&(s.params.epoch=a)}this._call(s).then(function(e){n._subscribeResponse(r,i,n._decoder.decodeCommandResult(n._methodType.SUBSCRIBE,e.result)),e.next&&e.next()},function(e){n._subscribeError(r,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 n=this,r=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 n._refresh()},this._getTTLMilliseconds(e.ttl))),this.startBatching(),this.startSubscribeBatching();for(var s in this._subs)if(this._subs.hasOwnProperty(s)){var i=this._subs[s];i._shouldResubscribe()&&this._subscribe(i,r)}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 n in e)if(e.hasOwnProperty(n)){var r=e[n],s=!0===r.recovered,i={channel:n,isResubscribe:t,recovered:s};this.emit("subscribe",i)}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 n=this._getSub(e);if(n&&n._isSubscribing())return 0===t.code&&"timeout"===t.message?void this._disconnect("timeout",!0):void n._setSubscribeError(t)}},{key:"_subscribeResponse",value:function(e,t,n){var r=this,s=this._getSub(e);if(s&&s._isSubscribing()){var i=!1;"recovered"in n&&(i=n.recovered),s._setSubscribeSuccess(i);var o=n.publications;if(o&&o.length>0){o=o.reverse();for(var u in o)o.hasOwnProperty(u)&&this._handlePublication(e,o[u])}if(!n.recoverable||t&&i||(this._lastSeq[e]=n.seq||0,this._lastGen[e]=n.gen||0),this._lastEpoch[e]=n.epoch||"",n.recoverable&&(s._recoverable=!0),!0===n.expires){var a=setTimeout(function(){return r._subRefresh(e)},this._getTTLMilliseconds(n.ttl));this._subRefreshTimeouts[e]=a}}}},{key:"_handleReply",value:function(e,t){var n=e.id,r=e.result;if(!(n in this._callbacks))return void t();var s=this._callbacks[n];if(clearTimeout(this._callbacks[n].timeout),delete this._callbacks[n],(0,d.errorExists)(e)){var i=s.errback;if(!i)return void t();i({error:e.error,next:t})}else{var o=s.callback;if(!o)return;o({result:r,next:t})}}},{key:"_handleJoin",value:function(e,t){var n={info:t.info},r=this._getSub(e);if(!r)return n.channel=e,void this.emit("join",n);r.emit("join",n)}},{key:"_handleLeave",value:function(e,t){var n={info:t.info},r=this._getSub(e);if(!r)return n.channel=e,void this.emit("leave",n);r.emit("leave",n)}},{key:"_handleUnsub",value:function(e,t){var n={},r=this._getSub(e);if(!r)return delete this._serverSubs[e],n.channel=e,void this.emit("unsubscribe",n);r.unsubscribe(),!0===t.resubscribe&&r.subscribe()}},{key:"_handleSub",value:function(e,t){this._serverSubs[e]={seq:t.seq,gen:t.gen,epoch:t.epoch,recoverable:t.recoverable};var n={channel:e,isResubscribe:!1,recovered:!1};this.emit("subscribe",n)}},{key:"_handlePublication",value:function(e,t){var n=this._getSub(e),r={data:t.data,seq:t.seq,gen:t.gen};if(!n)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)),r.channel=e,void this.emit("publish",r);void 0!==t.seq&&(this._lastSeq[e]=t.seq),void 0!==t.gen&&(this._lastGen[e]=t.gen),n.emit("publish",r)}},{key:"_handleMessage",value:function(e){this.emit("message",e.data)}},{key:"_handlePush",value:function(e,t){var n=this._decoder.decodePush(e),r=0;"type"in n&&(r=n.type);var s=n.channel;if(r===this._pushType.PUBLICATION){var i=this._decoder.decodePushData(this._pushType.PUBLICATION,n.data);this._handlePublication(s,i)}else if(r===this._pushType.MESSAGE){var o=this._decoder.decodePushData(this._pushType.MESSAGE,n.data);this._handleMessage(o)}else if(r===this._pushType.JOIN){var u=this._decoder.decodePushData(this._pushType.JOIN,n.data);this._handleJoin(s,u)}else if(r===this._pushType.LEAVE){var a=this._decoder.decodePushData(this._pushType.LEAVE,n.data);this._handleLeave(s,a)}else if(r===this._pushType.UNSUB){var c=this._decoder.decodePushData(this._pushType.UNSUB,n.data);this._handleUnsub(s,c)}else if(r===this._pushType.SUB){var h=this._decoder.decodePushData(this._pushType.SUB,n.data);this._handleSub(s,h)}t()}},{key:"_dispatchReply",value:function(e){var t,n=new Promise(function(e){t=e});if(void 0===e||null===e)return this._debug("dispatch: got undefined or null reply"),t(),n;var r=e.id;return r&&r>0?this._handleReply(e,t):this._handlePush(e.result,t),n}},{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,n){var r=this;this._callbacks[e]={callback:t,errback:n,timeout:null},this._callbacks[e].timeout=setTimeout(function(){delete r._callbacks[e],(0,d.isFunction)(n)&&n({error:r._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 n=[];for(var r in t)if(t.hasOwnProperty(r)){var s=this._getSub(r);if(!s)continue;n.push(r)}if(0===n.length)return void this._debug("no private channels found, no need to make request");var i={client:this._clientID,channels:n},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 r in n)if(n.hasOwnProperty(r)){var s=n[r];e._subscribeError(s,e._createErrorObject("authorization request failed"))}}else{var i={};if(t.data.channels)for(var a in t.data.channels){var c=t.data.channels[a];c.channel&&(i[c.channel]=c.token)}var h=!1;e._isBatching||(e.startBatching(),h=!0);for(var l in n)if(n.hasOwnProperty(l)){var _=function(){var t=n[l],r=i[t];if(!r)return e._subscribeError(t,e._createErrorObject("permission denied",103)),"continue";var s={method:e._methodType.SUBSCRIBE,params:{channel:t,token:r}},o=e._getSub(t);if(null===o)return"continue";var u=o._needRecover();if(!0===u){s.params.recover=!0;var a=e._getLastSeq(t);a&&(s.params.seq=a);var c=e._getLastGen(t);c&&(s.params.gen=c);var h=e._getLastEpoch(t);h&&(s.params.epoch=h)}e._call(s).then(function(n){e._subscribeResponse(t,u,e._decoder.decodeCommandResult(e._methodType.SUBSCRIBE,n.result)),n.next&&n.next()},function(n){e._subscribeError(t,n.error),n.next&&n.next()})}();if("continue"===_)continue}h&&e.stopBatching()}};if(null!==this._config.onPrivateSubscribe)this._config.onPrivateSubscribe({data:i},a);else{var c=this._ajax(this._config.subscribeEndpoint,this._config.subscribeParams,this._config.subscribeHeaders,i,a);this._xhrs[u]=c}}},{key:"subscribe",value:function(e,t){var n=this._getSub(e);if(null!==n)return n._setEvents(t),n._isUnsubscribed()&&n.subscribe(),n;var r=new _.default(this,e,t);return this._subs[e]=r,r.subscribe(),r}}]),n}(h.default)}).call(t,n(3))},11:function(e,t,n){"use strict";function r(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 i(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 n=0;n0&&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,r(c)}return e}function u(){for(var e=[],t=0;t0&&(i=t[0]),i instanceof Error)throw i;var o=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw o.context=i,o}var u=s[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),n=0;n=0;i--)if(n[i]===t||n[i].listener===t){o=n[i].listener,s=i;break}if(s<0)return this;0===s?n.shift():_(n,s),1===n.length&&(r[e]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",e,o||t)}return this},s.prototype.off=s.prototype.removeListener,s.prototype.removeAllListeners=function(e){var t,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete n[e]),this;if(0===arguments.length){var s,i=Object.keys(n);for(r=0;r=0;r--)this.removeListener(e,t[r]);return this},s.prototype.listeners=function(e){return c(this,e,!0)},s.prototype.rawListeners=function(e){return c(this,e,!1)},s.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):h.call(e,t)},s.prototype.listenerCount=h,s.prototype.eventNames=function(){return this._eventsCount>0?d(this._events):[]}},7:function(e,t,n){"use strict";(function(e){function n(e,t){return 0===e.lastIndexOf(t,0)}function r(e){return void 0!==e&&null!==e&&"function"==typeof e}function s(t,n){if(e.console){var s=e.console[t];r(s)&&s.apply(e.console,n)}}function i(e,t,n){var r=.5*Math.random(),s=Math.min(n,t*Math.pow(2,e+1));return Math.floor((1-r)*s)}function o(e){return"error"in e&&null!==e.error}function u(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);return e}Object.defineProperty(t,"__esModule",{value:!0}),t.startsWith=n,t.isFunction=r,t.log=s,t.backoff=i,t.errorExists=o,t.extend=u}).call(t,n(3))}})}); //# sourceMappingURL=centrifuge.min.js.map