centrifuge
Advanced tools
Comparing version 2.1.2 to 2.1.3
@@ -0,1 +1,6 @@ | ||
2.1.3 | ||
===== | ||
* fix setting setInterval with value greater than `2,147,483,647` which resulted in immediate refresh callback firing | ||
2.1.2 | ||
@@ -2,0 +7,0 @@ ===== |
@@ -1,2 +0,2 @@ | ||
!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(s){if(n[s])return n[s].exports;var r=n[s]={i:s,l:!1,exports:{}};return e[s].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,s){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:s})},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 s(e){return e&&e.__esModule?e:{default:e}}function r(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 s=t[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}return function(t,n,s){return n&&e(t.prototype,n),s&&e(t,s),t}}(),c=n(6),h=s(c),l=n(11),_=s(l),f=n(12),d=n(7);t.Centrifuge=function(t){function n(e,t){r(this,n);var s=i(this,(n.__proto__||Object.getPrototypeOf(n)).call(this));return s._url=e,s._sockjs=null,s._isSockjs=!1,s._binary=!1,s._methodType=null,s._pushType=null,s._encoder=null,s._decoder=null,s._status="disconnected",s._reconnect=!0,s._reconnecting=!1,s._transport=null,s._transportName=null,s._transportClosed=!0,s._messageId=0,s._clientID=null,s._refreshRequired=!1,s._subs={},s._lastSeq={},s._lastGen={},s._lastEpoch={},s._messages=[],s._isBatching=!1,s._isSubscribeBatching=!1,s._privateChannels={},s._numRefreshFailed=0,s._refreshTimeout=null,s._pingTimeout=null,s._pongTimeout=null,s._subRefreshTimeouts={},s._retries=0,s._callbacks={},s._latency=null,s._latencyStart=null,s._connectData=null,s._token=null,s._xhrID=0,s._xhrs={},s._config={debug:!1,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},s._configure(t),s}return o(n,t),a(n,[{key:"setToken",value:function(e){this._token=e}},{key:"setConnectData",value:function(e){this._connectData=e}},{key:"_ajax",value:function(t,n,s,r,i){var o=this,u="";this._debug("sending AJAX request to",t,"with data",JSON.stringify(r));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 s)s.hasOwnProperty(h)&&a.setRequestHeader(h,s[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(r))},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!("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(Object.assign(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 s=n.errback;if(!s)continue;s(this._createErrorObject("disconnected"))}this._callbacks={};for(var r in this._subs)if(this._subs.hasOwnProperty(r)){var i=this._subs[r];e?(i._isSuccess()&&(i._triggerUnsubscribe(),i._recover=!0),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 s=this._callbacks[n];clearTimeout(this._callbacks[n].timeout),delete this._callbacks[n];(0,s.errback)(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");this._transport=new 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),e._latencyStart=new Date,e._call(t).then(function(t){e._connectResponse(e._decoder.decodeCommandResult(e._methodType.CONNECT,t.result)),t.next&&t.next()},function(t){109===t.code&&(e._refreshRequired=!0),e._disconnect("connect error",!0)})},this._transport.onerror=function(t){e._debug("transport level error",t)},this._transport.onclose=function(t){e._transportClosed=!0;var n="connection closed",s=!0;if(t&&"reason"in t&&t.reason)try{var r=JSON.parse(t.reason);e._debug("reason is an advice object",r),n=r.reason,s=r.reconnect}catch(s){n=t.reason,e._debug("reason is a plain string",n)}if(null!==e._config.onTransportClose&&e._config.onTransportClose({event:t,reason:n,reconnect:s}),e._disconnect(n,s),!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)}):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),s=Promise.resolve();for(var r in n)!function(e){n.hasOwnProperty(e)&&(s=s.then(function(){return t._dispatchReply(n[e])}))}(r);this._restartPing()}},{key:"_call",value:function(e){var t=this;return new Promise(function(n,s){var r=t._addMessage(e);t._registerCall(r,n,s)})}},{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){if(!this._isDisconnected()){this._debug("disconnected:",e,t);var n=t||!1;!1===n&&(this._reconnect=!1),this._clearConnectedState(n),this._isDisconnected()||(this._setStatus("disconnected"),this._refreshTimeout&&(clearTimeout(this._refreshTimeout),this._refreshTimeout=null),!1===this._reconnecting&&this.emit("disconnect",{reason:e,reconnect:n})),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(),s=function(s){if(n in e._xhrs&&delete e._xhrs[n],e._clientID===t){if(s.error||200!==s.status){if(s.error?e._debug("error refreshing connection token",s.error):e._debug("error refreshing connection token: wrong status code",s.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 r=Math.round(1e3*Math.random()*Math.max(e._numRefreshFailed,20)),i=e._config.refreshInterval+r;return void(e._refreshTimeout=setTimeout(function(){return e._refresh()},i))}if(e._numRefreshFailed=0,e._token=s.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)})}}};if(null!==this._config.onRefresh){var r={};this._config.onRefresh(r,s)}else{var i=this._ajax(this._config.refreshEndpoint,this._config.refreshParams,this._config.refreshHeaders,this._config.refreshData,s);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()},1e3*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,s=this._newXHRID(),r=function(r){if(s in t._xhrs&&delete t._xhrs[s],!r.error&&200===r.status&&t._clientID===n){var o={};if(r.data.channels)for(var u in i.channels){var a=r.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)})}}},i={client:this._clientID,channels:[e]};if(null!==this._config.onPrivateSubscribe)this._config.onPrivateSubscribe({data:i},r);else{var o=this._ajax(this._config.subscribeEndpoint,this._config.subscribeParams,this._config.subscribeHeaders,i,r);this._xhrs[s]=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 s=Math.round(1e3*Math.random()),r=setTimeout(function(){return n._subRefresh(e)},this._config.subRefreshInterval+s);this._subRefreshTimeouts[e]=r}}},{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 s=setTimeout(function(){return n._subRefresh(e)},1e3*t.ttl);this._subRefreshTimeouts[e]=s}}},{key:"_subscribe",value:function(e,t){var n=this;this._debug("subscribing on",e.channel);var s=e.channel;if(s in this._subs||(this._subs[s]=e),!this.isConnected())return void e._setNew();e._setSubscribing(t);var r={method:this._methodType.SUBSCRIBE,params:{channel:s}};if((0,d.startsWith)(s,this._config.privateChannelPrefix))this._isSubscribeBatching?this._privateChannels[s]=!0:(this.startSubscribeBatching(),this._subscribe(e),this.stopSubscribeBatching());else{if(!0===e._needRecover()){r.params.recover=!0;var i=this._getLastSeq(s);i&&(r.params.seq=i);var o=this._getLastGen(s);o&&(r.params.gen=o);var u=this._getLastEpoch(s);u&&(r.params.epoch=u)}this._call(r).then(function(e){n._subscribeResponse(s,n._decoder.decodeCommandResult(n._methodType.SUBSCRIBE,e.result)),e.next&&e.next()},function(e){n._subscribeError(s,e)})}}},{key:"_unsubscribe",value:function(e){this.isConnected()&&this._addMessage({method:this._methodType.UNSUBSCRIBE,params:{channel:e.channel}})}},{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){var t=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 t._refresh()},1e3*e.ttl)),this.startBatching(),this.startSubscribeBatching();for(var s in this._subs)if(this._subs.hasOwnProperty(s)){var r=this._subs[s];r._shouldResubscribe()&&this._subscribe(r,n)}this.stopSubscribeBatching(),this.stopBatching(),this._startPing();var i={client:e.client,transport:this._transportName,latency:this._latency};e.data&&(i.data=e.data),this.emit("connect",i)}}},{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){var n=this,s=this._getSub(e);if(s&&s._isSubscribing()){var r=!1;"recovered"in t&&(r=t.recovered),s._setSubscribeSuccess(r);var i=t.publications;if(i&&i.length>0){i=i.reverse();for(var o in i)i.hasOwnProperty(o)&&this._handlePublication(e,i[o])}else t.recoverable&&(this._lastSeq[e]=t.seq||0,this._lastGen[e]=t.gen||0);if(this._lastEpoch[e]=t.epoch||"",t.recoverable&&(s._recoverable=!0),!0===t.expires){var u=setTimeout(function(){return n._subRefresh(e)},1e3*t.ttl);this._subRefreshTimeouts[e]=u}}}},{key:"_handleReply",value:function(e,t){var n=e.id,s=e.result;if(n in this._callbacks){var r=this._callbacks[n];if(clearTimeout(this._callbacks[n].timeout),delete this._callbacks[n],(0,d.errorExists)(e)){var i=r.errback;if(!i)return;i(e.error)}else{var o=r.callback;if(!o)return;o({result:s,next:t})}}}},{key:"_handleJoin",value:function(e,t){var n=this._getSub(e);n&&n.emit("join",t)}},{key:"_handleLeave",value:function(e,t){var n=this._getSub(e);n&&n.emit("leave",t)}},{key:"_handleUnsub",value:function(e,t){var n=this._getSub(e);n&&(n.unsubscribe(),!0===t.resubscribe&&n.subscribe())}},{key:"_handlePublication",value:function(e,t){var n=this._getSub(e);n&&(void 0!==t.seq&&(this._lastSeq[e]=t.seq),void 0!==t.gen&&(this._lastGen[e]=t.gen),n.emit("publish",t))}},{key:"_handleMessage",value:function(e){this.emit("message",e.data)}},{key:"_handlePush",value:function(e,t){var n=this._decoder.decodePush(e),s=0;"type"in n&&(s=n.type);var r=n.channel;if(s===this._pushType.PUBLICATION){var i=this._decoder.decodePushData(this._pushType.PUBLICATION,n.data);this._handlePublication(r,i)}else if(s===this._pushType.MESSAGE){var o=this._decoder.decodePushData(this._pushType.MESSAGE,n.data);this._handleMessage(o)}else if(s===this._pushType.JOIN){var u=this._decoder.decodePushData(this._pushType.JOIN,n.data);this._handleJoin(r,u)}else if(s===this._pushType.LEAVE){var a=this._decoder.decodePushData(this._pushType.LEAVE,n.data);this._handleLeave(r,a)}else if(s===this._pushType.UNSUB){var c=this._decoder.decodePushData(this._pushType.UNSUB,n.data);this._handleUnsub(r,c)}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 s=e.id;return s&&s>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()},function(t){e._debug("ping error",t)})}},{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 s=this;this._callbacks[e]={callback:t,errback:n,timeout:null},this._callbacks[e].timeout=setTimeout(function(){delete s._callbacks[e],(0,d.isFunction)(n)&&n(s._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 s in t)if(t.hasOwnProperty(s)){var r=this._getSub(s);if(!r)continue;n.push(s)}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 s in n)if(n.hasOwnProperty(s)){var r=n[s];e._subscribeError(r,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],s=i[t];if(!s)return e._subscribeError(t,e._createErrorObject("permission denied",103)),"continue";var r={method:e._methodType.SUBSCRIBE,params:{channel:t,token:s}},o=e._getSub(t);if(null===o)return"continue";if(!0===o._needRecover()){r.params.recover=!0;var u=e._getLastSeq(t);u&&(r.params.seq=u);var a=e._getLastGen(t);a&&(r.params.gen=a);var c=e._getLastEpoch(t);c&&(r.params.epoch=c)}e._call(r).then(function(n){e._subscribeResponse(t,e._decoder.decodeCommandResult(e._methodType.SUBSCRIBE,n.result)),n.next&&n.next()},function(n){e._subscribeError(t,n)})}();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 s=new _.default(this,e,t);return this._subs[e]=s,s.subscribe(),s}}]),n}(h.default)}).call(t,n(3))},11:function(e,t,n){"use strict";function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(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 s=t[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}return function(t,n,s){return n&&e(t.prototype,n),s&&e(t,s),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){s(this,t);var o=r(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.on("error",function(e){this._centrifuge._debug("subscription error",e)}),o}return i(t,e),o(t,[{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,s=t.length;n<s;n++){var r=t[n];r in e&&this.on(r,e[r])}}},{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(n),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(n),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(s,r){var i=void 0;i=n._isSuccess()?Promise.resolve():n._isError()?Promise.reject(n._error):new Promise(function(e,t){var s=setTimeout(function(){t({code:0,message:"timeout"})},n._centrifuge._config.timeout);n._promises[s]={resolve:e,reject:t}}),i.then(function(){return n._centrifuge._call(e).then(function(e){s(n._centrifuge._decoder.decodeCommandResult(t,e.result)),e.next&&e.next()},function(e){r(e)})},function(e){r(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 s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var s=t[n];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,s.key,s)}}return function(t,n,s){return n&&e(t.prototype,n),s&&e(t,s),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},t.JsonEncoder=function(){function e(){s(this,e)}return r(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(){s(this,e)}return r(e,[{key:"decodeReplies",value:function(e){var t=[],n=e.split("\n");for(var s in n)if(n.hasOwnProperty(s)){if(!n[s])continue;var r=JSON.parse(n[s]);t.push(r)}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 s=n(10);t.default=s.Centrifuge,e.exports=t.default},6:function(e,t){function n(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function s(e){return"function"==typeof e}function r(e){return"number"==typeof e}function i(e){return"object"==typeof e&&null!==e}function o(e){return void 0===e}e.exports=n,n.EventEmitter=n,n.prototype._events=void 0,n.prototype._maxListeners=void 0,n.defaultMaxListeners=10,n.prototype.setMaxListeners=function(e){if(!r(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},n.prototype.emit=function(e){var t,n,r,u,a,c;if(this._events||(this._events={}),"error"===e&&(!this._events.error||i(this._events.error)&&!this._events.error.length)){if((t=arguments[1])instanceof Error)throw t;var h=new Error('Uncaught, unspecified "error" event. ('+t+")");throw h.context=t,h}if(n=this._events[e],o(n))return!1;if(s(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:u=Array.prototype.slice.call(arguments,1),n.apply(this,u)}else if(i(n))for(u=Array.prototype.slice.call(arguments,1),c=n.slice(),r=c.length,a=0;a<r;a++)c[a].apply(this,u);return!0},n.prototype.addListener=function(e,t){var r;if(!s(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,s(t.listener)?t.listener:t),this._events[e]?i(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,i(this._events[e])&&!this._events[e].warned&&(r=o(this._maxListeners)?n.defaultMaxListeners:this._maxListeners)&&r>0&&this._events[e].length>r&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace()),this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(e,t){function n(){this.removeListener(e,n),r||(r=!0,t.apply(this,arguments))}if(!s(t))throw TypeError("listener must be a function");var r=!1;return n.listener=t,this.on(e,n),this},n.prototype.removeListener=function(e,t){var n,r,o,u;if(!s(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(n=this._events[e],o=n.length,r=-1,n===t||s(n.listener)&&n.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(i(n)){for(u=o;u-- >0;)if(n[u]===t||n[u].listener&&n[u].listener===t){r=u;break}if(r<0)return this;1===n.length?(n.length=0,delete this._events[e]):n.splice(r,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},n.prototype.removeAllListeners=function(e){var t,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[e],s(n))this.removeListener(e,n);else if(n)for(;n.length;)this.removeListener(e,n[n.length-1]);return delete this._events[e],this},n.prototype.listeners=function(e){return this._events&&this._events[e]?s(this._events[e])?[this._events[e]]:this._events[e].slice():[]},n.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(s(t))return 1;if(t)return t.length}return 0},n.listenerCount=function(e,t){return e.listenerCount(t)}},7:function(e,t,n){"use strict";(function(e){function n(e,t){return 0===e.lastIndexOf(t,0)}function s(e){return void 0!==e&&null!==e&&"function"==typeof e}function r(t,n){if(e.console){var r=e.console[t];s(r)&&r.apply(e.console,n)}}function i(e,t,n){var s=.5*Math.random(),r=Math.min(n,t*Math.pow(2,e+1));return Math.floor((1-s)*r)}function o(e){return"error"in e&&null!==e.error}Object.defineProperty(t,"__esModule",{value:!0}),t.startsWith=n,t.isFunction=s,t.log=r,t.backoff=i,t.errorExists=o}).call(t,n(3))}})}); | ||
!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(s[n])return s[n].exports;var i=s[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var s={};return t.m=e,t.c=s,t.d=function(e,s,n){t.o(e,s)||Object.defineProperty(e,s,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var s=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(s,"a",s),s},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=31)}({10:function(e,t,s){"use strict";(function(e){function n(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(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 s=0;s<t.length;s++){var n=t[s];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,s,n){return s&&e(t.prototype,s),n&&e(t,n),t}}(),c=s(6),h=n(c),l=s(11),_=n(l),f=s(12),d=s(7);t.Centrifuge=function(t){function s(e,t){i(this,s);var n=r(this,(s.__proto__||Object.getPrototypeOf(s)).call(this));return n._url=e,n._sockjs=null,n._isSockjs=!1,n._binary=!1,n._methodType=null,n._pushType=null,n._encoder=null,n._decoder=null,n._status="disconnected",n._reconnect=!0,n._reconnecting=!1,n._transport=null,n._transportName=null,n._transportClosed=!0,n._messageId=0,n._clientID=null,n._refreshRequired=!1,n._subs={},n._lastSeq={},n._lastGen={},n._lastEpoch={},n._messages=[],n._isBatching=!1,n._isSubscribeBatching=!1,n._privateChannels={},n._numRefreshFailed=0,n._refreshTimeout=null,n._pingTimeout=null,n._pongTimeout=null,n._subRefreshTimeouts={},n._retries=0,n._callbacks={},n._latency=null,n._latencyStart=null,n._connectData=null,n._token=null,n._xhrID=0,n._xhrs={},n._config={debug:!1,sockjs:null,promise:null,minRetry:1e3,maxRetry:2e4,timeout:5e3,ping:!0,pingInterval:25e3,pongWaitTimeout:5e3,privateChannelPrefix:"$",onTransportClose:null,sockjsServer:null,sockjsTransports:["websocket","xdr-streaming","xhr-streaming","eventsource","iframe-eventsource","iframe-htmlfile","xdr-polling","xhr-polling","iframe-xhr-polling","jsonp-polling"],refreshEndpoint:"/centrifuge/refresh",refreshHeaders:{},refreshParams:{},refreshData:{},refreshAttempts:null,refreshInterval:1e3,onRefreshFailed:null,onRefresh:null,subscribeEndpoint:"/centrifuge/subscribe",subscribeHeaders:{},subscribeParams:{},subRefreshInterval:1e3,onPrivateSubscribe:null},n._configure(t),n}return o(s,t),a(s,[{key:"setToken",value:function(e){this._token=e}},{key:"setConnectData",value:function(e){this._connectData=e}},{key:"_ajax",value:function(t,s,n,i,r){var o=this,u="";this._debug("sending AJAX request to",t,"with data",JSON.stringify(i));var a=e.XMLHttpRequest?new e.XMLHttpRequest:new e.ActiveXObject("Microsoft.XMLHTTP");for(var c in s)s.hasOwnProperty(c)&&(u.length>0&&(u+="&"),u+=encodeURIComponent(c)+"="+encodeURIComponent(s[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 n)n.hasOwnProperty(h)&&a.setRequestHeader(h,n[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){r({error:"Invalid JSON. Data was: "+a.responseText,status:200,data:null})}t&&r({data:e,status:200})}else o._log("wrong status code in AJAX response",a.status),r({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!("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(Object.assign(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 s=this._callbacks[t];clearTimeout(s.timeout);var n=s.errback;if(!n)continue;n(this._createErrorObject("disconnected"))}this._callbacks={};for(var i in this._subs)if(this._subs.hasOwnProperty(i)){var r=this._subs[i];e?(r._isSuccess()&&(r._triggerUnsubscribe(),r._recover=!0),r._setSubscribing()):r._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 s=t.id;if(s in this._callbacks){var n=this._callbacks[s];clearTimeout(this._callbacks[s].timeout),delete this._callbacks[s];(0,n.errback)(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");this._transport=new 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),e._latencyStart=new Date,e._call(t).then(function(t){e._connectResponse(e._decoder.decodeCommandResult(e._methodType.CONNECT,t.result)),t.next&&t.next()},function(t){109===t.code&&(e._refreshRequired=!0),e._disconnect("connect error",!0)})},this._transport.onerror=function(t){e._debug("transport level error",t)},this._transport.onclose=function(t){e._transportClosed=!0;var s="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),s=i.reason,n=i.reconnect}catch(n){s=t.reason,e._debug("reason is a plain string",s)}if(null!==e._config.onTransportClose&&e._config.onTransportClose({event:t,reason:s,reconnect:n}),e._disconnect(s,n),!0===e._reconnect){e._reconnecting=!0;var r=e._getRetryInterval();e._debug("reconnect after "+r+" milliseconds"),setTimeout(function(){!0===e._reconnect&&(e._refreshRequired?e._refresh():e._connect())},r)}},this._transport.onmessage=function(t){e._dataReceived(t.data)}}},{key:"rpc",value:function(e){var t=this,s={method:this._methodType.RPC,params:{data:e}};return this.isConnected()?this._call(s).then(function(e){return e.next&&e.next(),t._decoder.decodeCommandResult(t._methodType.RPC,e.result)}):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 s={method:this._methodType.PUBLISH,params:{channel:e,data:t}};return this.isConnected()?this._call(s).then(function(e){return e.next&&e.next(),{}}):Promise.reject(this._createErrorObject("connection closed",0))}},{key:"_dataReceived",value:function(e){var t=this,s=this._decoder.decodeReplies(e),n=Promise.resolve();for(var i in s)!function(e){s.hasOwnProperty(e)&&(n=n.then(function(){return t._dispatchReply(s[e])}))}(i);this._restartPing()}},{key:"_call",value:function(e){var t=this;return new Promise(function(s,n){var i=t._addMessage(e);t._registerCall(i,s,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){if(!this._isDisconnected()){this._debug("disconnected:",e,t);var s=t||!1;!1===s&&(this._reconnect=!1),this._clearConnectedState(s),this._isDisconnected()||(this._setStatus("disconnected"),this._refreshTimeout&&(clearTimeout(this._refreshTimeout),this._refreshTimeout=null),!1===this._reconnecting&&this.emit("disconnect",{reason:e,reconnect:s})),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,s=this._newXHRID(),n=function(n){if(s in e._xhrs&&delete e._xhrs[s],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)),r=e._config.refreshInterval+i;return void(e._refreshTimeout=setTimeout(function(){return e._refresh()},r))}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)})}}};if(null!==this._config.onRefresh){var i={};this._config.onRefresh(i,n)}else{var r=this._ajax(this._config.refreshEndpoint,this._config.refreshParams,this._config.refreshHeaders,this._config.refreshData,n);this._xhrs[s]=r}}},{key:"_refreshError",value:function(e){var t=this;this._debug("refresh error",e),this._refreshTimeout&&(clearTimeout(this._refreshTimeout),this._refreshTimeout=null);var s=this._config.refreshInterval+Math.round(1e3*Math.random());this._refreshTimeout=setTimeout(function(){return t._refresh()},s)}},{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 s=this._clientID,n=this._newXHRID(),i=function(i){if(n in t._xhrs&&delete t._xhrs[n],!i.error&&200===i.status&&t._clientID===s){var o={};if(i.data.channels)for(var u in r.channels){var a=i.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(s){t._subRefreshResponse(e,t._decoder.decodeCommandResult(t._methodType.SUB_REFRESH,s.result)),s.next&&s.next()},function(s){t._subRefreshError(e,s)})}}},r={client:this._clientID,channels:[e]};if(null!==this._config.onPrivateSubscribe)this._config.onPrivateSubscribe({data:r},i);else{var o=this._ajax(this._config.subscribeEndpoint,this._config.subscribeParams,this._config.subscribeHeaders,r,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 s=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 s._subRefresh(e)},this._config.subRefreshInterval+n);this._subRefreshTimeouts[e]=i}}},{key:"_subRefreshResponse",value:function(e,t){var s=this;if(this._debug("subscription refresh success",e),this._clearSubRefreshTimeout(e),null!==this._getSub(e)&&!0===t.expires){var n=setTimeout(function(){return s._subRefresh(e)},this._getTTLMilliseconds(t.ttl));this._subRefreshTimeouts[e]=n}}},{key:"_subscribe",value:function(e,t){var s=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{if(!0===e._needRecover()){i.params.recover=!0;var r=this._getLastSeq(n);r&&(i.params.seq=r);var o=this._getLastGen(n);o&&(i.params.gen=o);var u=this._getLastEpoch(n);u&&(i.params.epoch=u)}this._call(i).then(function(e){s._subscribeResponse(n,s._decoder.decodeCommandResult(s._methodType.SUBSCRIBE,e.result)),e.next&&e.next()},function(e){s._subscribeError(n,e)})}}},{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){var t=this,s=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 t._refresh()},this._getTTLMilliseconds(e.ttl))),this.startBatching(),this.startSubscribeBatching();for(var n in this._subs)if(this._subs.hasOwnProperty(n)){var i=this._subs[n];i._shouldResubscribe()&&this._subscribe(i,s)}this.stopSubscribeBatching(),this.stopBatching(),this._startPing();var r={client:e.client,transport:this._transportName,latency:this._latency};e.data&&(r.data=e.data),this.emit("connect",r)}}},{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 s=this._getSub(e);if(s&&s._isSubscribing())return 0===t.code&&"timeout"===t.message?void this._disconnect("timeout",!0):void s._setSubscribeError(t)}},{key:"_subscribeResponse",value:function(e,t){var s=this,n=this._getSub(e);if(n&&n._isSubscribing()){var i=!1;"recovered"in t&&(i=t.recovered),n._setSubscribeSuccess(i);var r=t.publications;if(r&&r.length>0){r=r.reverse();for(var o in r)r.hasOwnProperty(o)&&this._handlePublication(e,r[o])}else t.recoverable&&(this._lastSeq[e]=t.seq||0,this._lastGen[e]=t.gen||0);if(this._lastEpoch[e]=t.epoch||"",t.recoverable&&(n._recoverable=!0),!0===t.expires){var u=setTimeout(function(){return s._subRefresh(e)},this._getTTLMilliseconds(t.ttl));this._subRefreshTimeouts[e]=u}}}},{key:"_handleReply",value:function(e,t){var s=e.id,n=e.result;if(s in this._callbacks){var i=this._callbacks[s];if(clearTimeout(this._callbacks[s].timeout),delete this._callbacks[s],(0,d.errorExists)(e)){var r=i.errback;if(!r)return;r(e.error)}else{var o=i.callback;if(!o)return;o({result:n,next:t})}}}},{key:"_handleJoin",value:function(e,t){var s=this._getSub(e);s&&s.emit("join",t)}},{key:"_handleLeave",value:function(e,t){var s=this._getSub(e);s&&s.emit("leave",t)}},{key:"_handleUnsub",value:function(e,t){var s=this._getSub(e);s&&(s.unsubscribe(),!0===t.resubscribe&&s.subscribe())}},{key:"_handlePublication",value:function(e,t){var s=this._getSub(e);s&&(void 0!==t.seq&&(this._lastSeq[e]=t.seq),void 0!==t.gen&&(this._lastGen[e]=t.gen),s.emit("publish",t))}},{key:"_handleMessage",value:function(e){this.emit("message",e.data)}},{key:"_handlePush",value:function(e,t){var s=this._decoder.decodePush(e),n=0;"type"in s&&(n=s.type);var i=s.channel;if(n===this._pushType.PUBLICATION){var r=this._decoder.decodePushData(this._pushType.PUBLICATION,s.data);this._handlePublication(i,r)}else if(n===this._pushType.MESSAGE){var o=this._decoder.decodePushData(this._pushType.MESSAGE,s.data);this._handleMessage(o)}else if(n===this._pushType.JOIN){var u=this._decoder.decodePushData(this._pushType.JOIN,s.data);this._handleJoin(i,u)}else if(n===this._pushType.LEAVE){var a=this._decoder.decodePushData(this._pushType.LEAVE,s.data);this._handleLeave(i,a)}else if(n===this._pushType.UNSUB){var c=this._decoder.decodePushData(this._pushType.UNSUB,s.data);this._handleUnsub(i,c)}t()}},{key:"_dispatchReply",value:function(e){var t,s=new Promise(function(e){t=e});if(void 0===e||null===e)return this._debug("dispatch: got undefined or null reply"),t(),s;var n=e.id;return n&&n>0?this._handleReply(e,t):this._handlePush(e.result,t),s}},{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()},function(t){e._debug("ping error",t)})}},{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,s){var n=this;this._callbacks[e]={callback:t,errback:s,timeout:null},this._callbacks[e].timeout=setTimeout(function(){delete n._callbacks[e],(0,d.isFunction)(s)&&s(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 s=[];for(var n in t)if(t.hasOwnProperty(n)){var i=this._getSub(n);if(!i)continue;s.push(n)}if(0===s.length)return void this._debug("no private channels found, no need to make request");var r={client:this._clientID,channels:s},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 s)if(s.hasOwnProperty(n)){var i=s[n];e._subscribeError(i,e._createErrorObject("authorization request failed"))}}else{var r={};if(t.data.channels)for(var a in t.data.channels){var c=t.data.channels[a];c.channel&&(r[c.channel]=c.token)}var h=!1;e._isBatching||(e.startBatching(),h=!0);for(var l in s)if(s.hasOwnProperty(l)){var _=function(){var t=s[l],n=r[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";if(!0===o._needRecover()){i.params.recover=!0;var u=e._getLastSeq(t);u&&(i.params.seq=u);var a=e._getLastGen(t);a&&(i.params.gen=a);var c=e._getLastEpoch(t);c&&(i.params.epoch=c)}e._call(i).then(function(s){e._subscribeResponse(t,e._decoder.decodeCommandResult(e._methodType.SUBSCRIBE,s.result)),s.next&&s.next()},function(s){e._subscribeError(t,s)})}();if("continue"===_)continue}h&&e.stopBatching()}};if(null!==this._config.onPrivateSubscribe)this._config.onPrivateSubscribe({data:r},a);else{var c=this._ajax(this._config.subscribeEndpoint,this._config.subscribeParams,this._config.subscribeHeaders,r,a);this._xhrs[u]=c}}},{key:"subscribe",value:function(e,t){var s=this._getSub(e);if(null!==s)return s._setEvents(t),s._isUnsubscribed()&&s.subscribe(),s;var n=new _.default(this,e,t);return this._subs[e]=n,n.subscribe(),n}}]),s}(h.default)}).call(t,s(3))},11:function(e,t,s){"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 r(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 s=0;s<t.length;s++){var n=t[s];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,s,n){return s&&e(t.prototype,s),n&&e(t,n),t}}(),u=s(6),a=function(e){return e&&e.__esModule?e:{default:e}}(u),c=s(7),h=0,l=function(e){function t(e,s,r){n(this,t);var o=i(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return o.channel=s,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(r),o._initializePromise(),o._promises={},o.on("error",function(e){this._centrifuge._debug("subscription error",e)}),o}return r(t,e),o(t,[{key:"_initializePromise",value:function(){var e=this;this._ready=!1,this._subscriptionPromise=new Promise(function(t,s){e._resolve=function(s){e._ready=!0,t(s)},e._reject=function(t){e._ready=!0,s(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"],s=0,n=t.length;s<n;s++){var i=t[s];i in e&&this.on(i,e[i])}}},{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 s in this._promises)clearTimeout(s),this._promises[s].resolve(),delete this._promises[s]}}},{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 s in this._promises)clearTimeout(s),this._promises[s].reject(e),delete this._promises[s]}}},{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 s=this;return new Promise(function(n,i){var r=void 0;r=s._isSuccess()?Promise.resolve():s._isError()?Promise.reject(s._error):new Promise(function(e,t){var n=setTimeout(function(){t({code:0,message:"timeout"})},s._centrifuge._config.timeout);s._promises[n]={resolve:e,reject:t}}),r.then(function(){return s._centrifuge._call(e).then(function(e){n(s._centrifuge._decoder.decodeCommandResult(t,e.result)),e.next&&e.next()},function(e){i(e)})},function(e){i(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,s){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var s=0;s<t.length;s++){var n=t[s];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,s,n){return s&&e(t.prototype,s),n&&e(t,n),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},t.JsonEncoder=function(){function e(){n(this,e)}return i(e,[{key:"encodeCommands",value:function(e){var t=[];for(var s in e)e.hasOwnProperty(s)&&t.push(JSON.stringify(e[s]));return t.join("\n")}}]),e}(),t.JsonDecoder=function(){function e(){n(this,e)}return i(e,[{key:"decodeReplies",value:function(e){var t=[],s=e.split("\n");for(var n in s)if(s.hasOwnProperty(n)){if(!s[n])continue;var i=JSON.parse(s[n]);t.push(i)}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 s;s=function(){return this}();try{s=s||Function("return this")()||(0,eval)("this")}catch(e){"object"==typeof window&&(s=window)}e.exports=s},31:function(e,t,s){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=s(10);t.default=n.Centrifuge,e.exports=t.default},6:function(e,t){function s(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function n(e){return"function"==typeof e}function i(e){return"number"==typeof e}function r(e){return"object"==typeof e&&null!==e}function o(e){return void 0===e}e.exports=s,s.EventEmitter=s,s.prototype._events=void 0,s.prototype._maxListeners=void 0,s.defaultMaxListeners=10,s.prototype.setMaxListeners=function(e){if(!i(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},s.prototype.emit=function(e){var t,s,i,u,a,c;if(this._events||(this._events={}),"error"===e&&(!this._events.error||r(this._events.error)&&!this._events.error.length)){if((t=arguments[1])instanceof Error)throw t;var h=new Error('Uncaught, unspecified "error" event. ('+t+")");throw h.context=t,h}if(s=this._events[e],o(s))return!1;if(n(s))switch(arguments.length){case 1:s.call(this);break;case 2:s.call(this,arguments[1]);break;case 3:s.call(this,arguments[1],arguments[2]);break;default:u=Array.prototype.slice.call(arguments,1),s.apply(this,u)}else if(r(s))for(u=Array.prototype.slice.call(arguments,1),c=s.slice(),i=c.length,a=0;a<i;a++)c[a].apply(this,u);return!0},s.prototype.addListener=function(e,t){var i;if(!n(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,n(t.listener)?t.listener:t),this._events[e]?r(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,r(this._events[e])&&!this._events[e].warned&&(i=o(this._maxListeners)?s.defaultMaxListeners:this._maxListeners)&&i>0&&this._events[e].length>i&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace()),this},s.prototype.on=s.prototype.addListener,s.prototype.once=function(e,t){function s(){this.removeListener(e,s),i||(i=!0,t.apply(this,arguments))}if(!n(t))throw TypeError("listener must be a function");var i=!1;return s.listener=t,this.on(e,s),this},s.prototype.removeListener=function(e,t){var s,i,o,u;if(!n(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(s=this._events[e],o=s.length,i=-1,s===t||n(s.listener)&&s.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(r(s)){for(u=o;u-- >0;)if(s[u]===t||s[u].listener&&s[u].listener===t){i=u;break}if(i<0)return this;1===s.length?(s.length=0,delete this._events[e]):s.splice(i,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},s.prototype.removeAllListeners=function(e){var t,s;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(s=this._events[e],n(s))this.removeListener(e,s);else if(s)for(;s.length;)this.removeListener(e,s[s.length-1]);return delete this._events[e],this},s.prototype.listeners=function(e){return this._events&&this._events[e]?n(this._events[e])?[this._events[e]]:this._events[e].slice():[]},s.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(n(t))return 1;if(t)return t.length}return 0},s.listenerCount=function(e,t){return e.listenerCount(t)}},7:function(e,t,s){"use strict";(function(e){function s(e,t){return 0===e.lastIndexOf(t,0)}function n(e){return void 0!==e&&null!==e&&"function"==typeof e}function i(t,s){if(e.console){var i=e.console[t];n(i)&&i.apply(e.console,s)}}function r(e,t,s){var n=.5*Math.random(),i=Math.min(s,t*Math.pow(2,e+1));return Math.floor((1-n)*i)}function o(e){return"error"in e&&null!==e.error}Object.defineProperty(t,"__esModule",{value:!0}),t.startsWith=s,t.isFunction=n,t.log=i,t.backoff=r,t.errorExists=o}).call(t,s(3))}})}); | ||
//# sourceMappingURL=centrifuge.min.js.map |
{ | ||
"name": "centrifuge", | ||
"version": "2.1.2", | ||
"version": "2.1.3", | ||
"description": "Centrifuge and Centrifugo client for NodeJS and browser", | ||
@@ -5,0 +5,0 @@ "main": "dist/centrifuge.js", |
@@ -61,3 +61,3 @@ # Centrifuge client for NodeJS and browser | ||
```html | ||
<script src="//cdn.jsdelivr.net/sockjs/1.1/sockjs.min.js" type="text/javascript"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/sockjs-client@1.3/dist/sockjs.min.js" type="text/javascript"></script> | ||
<script src="centrifuge.js" type="text/javascript"></script> | ||
@@ -174,7 +174,7 @@ ``` | ||
#### retry | ||
#### minRetry | ||
When client disconnected from server it will automatically try to reconnect using exponential | ||
backoff algorithm to get interval between reconnect attempts which value grows exponentially. | ||
`retry` option sets minimal interval value in milliseconds. Default is `1000` milliseconds. | ||
`minRetry` option sets minimal interval value in milliseconds. Default is `1000` milliseconds. | ||
@@ -181,0 +181,0 @@ #### maxRetry |
@@ -755,3 +755,3 @@ import EventEmitter from 'events'; | ||
this._clientID = result.client; | ||
this._refreshTimeout = setTimeout(() => this._refresh(), result.ttl * 1000); | ||
this._refreshTimeout = setTimeout(() => this._refresh(), this._getTTLMilliseconds(result.ttl)); | ||
} | ||
@@ -869,3 +869,3 @@ }; | ||
if (result.expires === true) { | ||
let subRefreshTimeout = setTimeout(() => this._subRefresh(channel), result.ttl * 1000); | ||
let subRefreshTimeout = setTimeout(() => this._subRefresh(channel), this._getTTLMilliseconds(result.ttl)); | ||
this._subRefreshTimeouts[channel] = subRefreshTimeout; | ||
@@ -954,2 +954,7 @@ } | ||
_getTTLMilliseconds(ttl) { | ||
// https://stackoverflow.com/questions/12633405/what-is-the-maximum-delay-for-setinterval | ||
return Math.min(ttl * 1000, 2147483647); | ||
} | ||
getSub(channel) { | ||
@@ -990,3 +995,3 @@ return this._getSub(channel); | ||
if (result.expires) { | ||
this._refreshTimeout = setTimeout(() => this._refresh(), result.ttl * 1000); | ||
this._refreshTimeout = setTimeout(() => this._refresh(), this._getTTLMilliseconds(result.ttl)); | ||
} | ||
@@ -1111,3 +1116,3 @@ | ||
if (result.expires === true) { | ||
let subRefreshTimeout = setTimeout(() => this._subRefresh(channel), result.ttl * 1000); | ||
let subRefreshTimeout = setTimeout(() => this._subRefresh(channel), this._getTTLMilliseconds(result.ttl)); | ||
this._subRefreshTimeouts[channel] = subRefreshTimeout; | ||
@@ -1114,0 +1119,0 @@ } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2304944
14202