!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;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),c=n(6),h=r(c),l=n(11),_=r(l),f=n(12),d=n(7);t.Centrifuge=function(t){function n(e,t){s(this,n);var r=i(this,(n.__proto__||Object.getPrototypeOf(n)).call(this));return r._url=e,r._websocket=null,r._sockjs=null,r._isSockjs=!1,r._binary=!1,r._methodType=null,r._pushType=null,r._encoder=null,r._decoder=null,r._status="disconnected",r._reconnect=!0,r._reconnecting=!1,r._transport=null,r._transportName=null,r._transportClosed=!0,r._messageId=0,r._clientID=null,r._refreshRequired=!1,r._subs={},r._serverSubs={},r._lastSeq={},r._lastGen={},r._lastEpoch={},r._messages=[],r._isBatching=!1,r._isSubscribeBatching=!1,r._privateChannels={},r._numRefreshFailed=0,r._refreshTimeout=null,r._pingTimeout=null,r._pongTimeout=null,r._subRefreshTimeouts={},r._retries=0,r._callbacks={},r._latency=null,r._latencyStart=null,r._connectData=null,r._token=null,r._xhrID=0,r._xhrs={},r._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},r._configure(t),r}return o(n,t),a(n,[{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,n,r,s,i){var o=this,u="";this._debug("sending AJAX request to",t,"with data",JSON.stringify(s));var a=e.XMLHttpRequest?new e.XMLHttpRequest:new e.ActiveXObject("Microsoft.XMLHTTP");for(var c in n)n.hasOwnProperty(c)&&(u.length>0&&(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;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),u=n(6),a=function(e){return e&&e.__esModule?e:{default:e}}(u),c=n(7),h=0,l=function(e){function t(e,n,i){r(this,t);var o=s(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return o.channel=n,o._centrifuge=e,o._status=h,o._error=null,o._isResubscribe=!1,o._ready=!1,o._subscriptionPromise=null,o._noResubscribe=!1,o._recoverable=!1,o._recover=!1,o._setEvents(i),o._initializePromise(),o._promises={},o._promiseId=0,o.on("error",function(e){this._centrifuge._debug("subscription error",e)}),o}return i(t,e),o(t,[{key:"_nextPromiseId",value:function(){return++this._promiseId}},{key:"_initializePromise",value:function(){var e=this;this._ready=!1,this._subscriptionPromise=new Promise(function(t,n){e._resolve=function(n){e._ready=!0,t(n)},e._reject=function(t){e._ready=!0,n(t)}}).then(function(){},function(){})}},{key:"_needRecover",value:function(){return!0===this._recoverable&&!0===this._recover}},{key:"_setEvents",value:function(e){if(e)if((0,c.isFunction)(e))this.on("publish",e);else if(Object.prototype.toString.call(e)===Object.prototype.toString.call({}))for(var t=["publish","join","leave","unsubscribe","subscribe","error"],n=0,r=t.length;n<r;n++){var s=t[n];s in e&&this.on(s,e[s])}}},{key:"_isNew",value:function(){return this._status===h}},{key:"_isUnsubscribed",value:function(){return 4===this._status}},{key:"_isSubscribing",value:function(){return 1===this._status}},{key:"_isReady",value:function(){return 2===this._status||3===this._status}},{key:"_isSuccess",value:function(){return 2===this._status}},{key:"_isError",value:function(){return 3===this._status}},{key:"_setNew",value:function(){this._status=h}},{key:"_setSubscribing",value:function(e){this._isResubscribe=e||!1,!0===this._ready&&this._initializePromise(),this._status=1}},{key:"_setSubscribeSuccess",value:function(e){if(2!==this._status){this._status=2;var t=this._getSubscribeSuccessContext(e);this._recover=!1,this.emit("subscribe",t),this._resolve(t);for(var n in this._promises)clearTimeout(this._promises[n].timeout),this._promises[n].resolve(),delete this._promises[n]}}},{key:"_setSubscribeError",value:function(e){if(3!==this._status){this._status=3,this._error=e;var t=this._getSubscribeErrorContext();this.emit("error",t),this._reject(t);for(var n in this._promises)clearTimeout(this._promises[n].timeout),this._promises[n].reject(e),delete this._promises[n]}}},{key:"_triggerUnsubscribe",value:function(){this.emit("unsubscribe",{channel:this.channel})}},{key:"_setUnsubscribed",value:function(e){if(this._centrifuge._clearSubRefreshTimeout(this.channel),4!==this._status){var t=2===this._status;this._status=4,!0===e&&(this._recover=!1,this._noResubscribe=!0,delete this._centrifuge._lastSeq[this.channel],delete this._centrifuge._lastGen[this.channel],delete this._centrifuge._lastEpoch[this.channel]),t&&this._triggerUnsubscribe()}}},{key:"_shouldResubscribe",value:function(){return!this._noResubscribe}},{key:"_getSubscribeSuccessContext",value:function(e){return{channel:this.channel,isResubscribe:this._isResubscribe,recovered:e}}},{key:"_getSubscribeErrorContext",value:function(){var e=this._error;return e.channel=this.channel,e.isResubscribe=this._isResubscribe,e}},{key:"ready",value:function(e,t){this._ready&&(this._isSuccess()?e(this._getSubscribeSuccessContext()):t(this._getSubscribeErrorContext()))}},{key:"subscribe",value:function(){2!==this._status&&(this._noResubscribe=!1,this._centrifuge._subscribe(this))}},{key:"unsubscribe",value:function(){this._setUnsubscribed(!0),this._centrifuge._unsubscribe(this)}},{key:"_methodCall",value:function(e,t){var n=this;return new Promise(function(r,s){var i=void 0;i=n._isSuccess()?Promise.resolve():n._isError()?Promise.reject(n._error):new Promise(function(e,t){var r=setTimeout(function(){t({code:0,message:"timeout"})},n._centrifuge._config.timeout);n._promises[n._nextPromiseId()]={timeout:r,resolve:e,reject:t}}),i.then(function(){return n._centrifuge._call(e).then(function(e){r(n._centrifuge._decoder.decodeCommandResult(t,e.result)),e.next&&e.next()},function(e){s(e.error),e.next&&e.next()})},function(e){s(e)})})}},{key:"publish",value:function(e){return this._methodCall({method:this._centrifuge._methodType.PUBLISH,params:{channel:this.channel,data:e}},this._centrifuge._methodType.PUBLISH)}},{key:"presence",value:function(){return this._methodCall({method:this._centrifuge._methodType.PRESENCE,params:{channel:this.channel}},this._centrifuge._methodType.PRESENCE)}},{key:"presenceStats",value:function(){return this._methodCall({method:this._centrifuge._methodType.PRESENCE_STATS,params:{channel:this.channel}},this._centrifuge._methodType.PRESENCE_STATS)}},{key:"history",value:function(){return this._methodCall({method:this._centrifuge._methodType.HISTORY,params:{channel:this.channel}},this._centrifuge._methodType.HISTORY)}}]),t}(a.default);t.default=l,e.exports=t.default},12:function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var s=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();t.JsonMethodType={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},t.JsonPushType={PUBLICATION:0,JOIN:1,LEAVE:2,UNSUB:3,MESSAGE:4,SUB:5},t.JsonEncoder=function(){function e(){r(this,e)}return s(e,[{key:"encodeCommands",value:function(e){var t=[];for(var n in e)e.hasOwnProperty(n)&&t.push(JSON.stringify(e[n]));return t.join("\n")}}]),e}(),t.JsonDecoder=function(){function e(){r(this,e)}return s(e,[{key:"decodeReplies",value:function(e){var t=[],n=e.split("\n");for(var r in n)if(n.hasOwnProperty(r)){if(!n[r])continue;var s=JSON.parse(n[r]);t.push(s)}return t}},{key:"decodeCommandResult",value:function(e,t){return t}},{key:"decodePush",value:function(e){return e}},{key:"decodePushData",value:function(e,t){return t}}]),e}()},3:function(e,t){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(e){"object"==typeof window&&(n=window)}e.exports=n},31:function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(10);t.default=r.Centrifuge,e.exports=t.default},6:function(e,t,n){"use strict";function r(e){console&&console.warn&&console.warn(e)}function s(){s.init.call(this)}function i(e){return void 0===e._maxListeners?s.defaultMaxListeners:e._maxListeners}function o(e,t,n,s){var o,u,a;if("function"!=typeof n)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof n);if(u=e._events,void 0===u?(u=e._events=Object.create(null),e._eventsCount=0):(void 0!==u.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),u=e._events),a=u[t]),void 0===a)a=u[t]=n,++e._eventsCount;else if("function"==typeof a?a=u[t]=s?[n,a]:[a,n]:s?a.unshift(n):a.push(n),(o=i(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,r(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,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},s=u.bind(r);return s.listener=n,r.wrapFn=s,s}function c(e,t,n){var r=e._events;if(void 0===r)return[];var s=r[t];return void 0===s?[]:"function"==typeof s?n?[s.listener||s]:[s]:n?f(s):l(s,s.length)}function h(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function l(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e[r];return n}function _(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function f(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}var d,p="object"==typeof Reflect?Reflect:null,v=p&&"function"==typeof p.apply?p.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};d=p&&"function"==typeof p.ownKeys?p.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var b=Number.isNaN||function(e){return e!==e};e.exports=s,s.EventEmitter=s,s.prototype._events=void 0,s.prototype._eventsCount=0,s.prototype._maxListeners=void 0;var m=10;Object.defineProperty(s,"defaultMaxListeners",{enumerable:!0,get:function(){return m},set:function(e){if("number"!=typeof e||e<0||b(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");m=e}}),s.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},s.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||b(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},s.prototype.getMaxListeners=function(){return i(this)},s.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var r="error"===e,s=this._events;if(void 0!==s)r=r&&void 0===s.error;else if(!r)return!1;if(r){var i;if(t.length>0&&(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<a;++n)v(c[n],this,t);return!0},s.prototype.addListener=function(e,t){return o(this,e,t,!1)},s.prototype.on=s.prototype.addListener,s.prototype.prependListener=function(e,t){return o(this,e,t,!0)},s.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},s.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},s.prototype.removeListener=function(e,t){var n,r,s,i,o;if("function"!=typeof t)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t);if(void 0===(r=this._events))return this;if(void 0===(n=r[e]))return this;if(n===t||n.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(s=-1,i=n.length-1;i>=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<i.length;++r)"removeListener"!==(s=i[r])&&this.removeAllListeners(s);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(void 0!==t)for(r=t.length-1;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))}})});
|