Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

centrifuge

Package Overview
Dependencies
Maintainers
1
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

centrifuge - npm Package Compare versions

Comparing version 2.1.6 to 2.2.0

dist/centrifuge.d.ts

8

CHANGELOG.md

@@ -0,1 +1,9 @@

2.2.0
=====
* fix wrong case of fields in Publication info and in result of `presence()` and `presenceStats()` responses in Protobuf format case. Those fields were not compliant with JSON format due to the fact that Protobuf compiler does not keep original case defined in proto schema by default. **If you are using Protobuf this can be a breaking change** - see [this commit](https://github.com/centrifugal/centrifuge-js/commit/0b8e65df0ef6ed3f959233f99ae0cf1463560a6a) for fix details and all fields that now use snake_case instead of camelCase in Protobuf case. If you are using JSON you are not affected with these changes
* fix unhandled promise exceptions on NodeJS when calling subscription methods
* add TypeScript [type definitions](https://github.com/centrifugal/centrifuge-js/blob/master/dist/centrifuge.d.ts), thanks to @jekaspekas for contribution
* add `websocket` option to explicitly provide custom WebSocket implementation to use
2.1.6

@@ -2,0 +10,0 @@ =====

2

dist/centrifuge.min.js

@@ -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({error: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._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 s=this._callbacks[n];clearTimeout(this._callbacks[n].timeout),delete this._callbacks[n];(0,s.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");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.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",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)},function(e){return e.next&&e.next(),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),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.error),t.next&&t.next()})}}};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()},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,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.error),n.next&&n.next()})}}},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)},this._getTTLMilliseconds(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.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){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()},this._getTTLMilliseconds(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)},this._getTTLMilliseconds(t.ttl));this._subRefreshTimeouts[e]=u}}}},{key:"_handleReply",value:function(e,t){var n=e.id,s=e.result;if(!(n in this._callbacks))return void t();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 void t();i({error:e.error,next:t})}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&&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 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({error: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.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 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.error),e.next&&e.next()})},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(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._websocket=null,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,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},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 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(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({error: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._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 s=this._callbacks[n];clearTimeout(this._callbacks[n].timeout),delete this._callbacks[n];(0,s.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),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.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",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)},function(e){return e.next&&e.next(),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),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.error),t.next&&t.next()})}}};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()},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,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.error),n.next&&n.next()})}}},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)},this._getTTLMilliseconds(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.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){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()},this._getTTLMilliseconds(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)},this._getTTLMilliseconds(t.ttl));this._subRefreshTimeouts[e]=u}}}},{key:"_handleReply",value:function(e,t){var n=e.id,s=e.result;if(!(n in this._callbacks))return void t();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 void t();i({error:e.error,next:t})}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",{info:t.info})}},{key:"_handleLeave",value:function(e,t){var n=this._getSub(e);n&&n.emit("leave",{info:t.info})}},{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&&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 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({error: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.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 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._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,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(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(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[n._nextPromiseId()]={timeout: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.error),e.next&&e.next()})},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))}})});
//# sourceMappingURL=centrifuge.min.js.map
{
"name": "centrifuge",
"version": "2.1.6",
"version": "2.2.0",
"description": "Centrifuge and Centrifugo client for NodeJS and browser",
"main": "dist/centrifuge.js",
"types": "dist/centrifuge.d.ts",
"scripts": {

@@ -7,0 +8,0 @@ "build": "webpack --env dev && webpack --env build --optimize-minimize && npm run test",

@@ -102,2 +102,21 @@ # Centrifuge client for NodeJS and browser

#### websocket
`websocket` option allows to explicitly provide custom WebSocket client to use. By default centrifuge-js will try to use global WebSocket object, so if you are in web browser – it will just use native WebSocket implementation.
#### sockjs
`sockjs` option allows to explicitly provide SockJS client object to Centrifuge client.
For example this can be useful if you develop in ES6 with imports:
```javascript
import Centrifuge from 'centrifuge'
import SockJS from 'sockjs-client'
var centrifuge = new Centrifuge('https://centrifuge.example.com/connection/sockjs', {
sockjs: SockJS
});
```
#### sockjsTransports

@@ -139,17 +158,2 @@

#### sockjs
`sockjs` option allows to explicitly provide SockJS client object to Centrifuge client.
For example this can be useful if you develop in ES6 with imports:
```javascript
import Centrifuge from 'centrifuge'
import SockJS from 'sockjs-client'
var centrifuge = new Centrifuge('https://centrifuge.example.com/connection/sockjs', {
sockjs: SockJS
});
```
#### sockjsServer

@@ -166,11 +170,2 @@

#### insecure
`insecure` is a boolean option which is `false` by default. When enabled client will connect
to server in insecure mode - read about this mode in [special docs chapter](../mixed/insecure_modes.md).
This option nice if you want to use Centrifugo for quick real-time ideas prototyping, demos as
it allows to connect to Centrifugo without `sign`, `exp` and `user`. And moreover without
application backend! Please, [read separate chapter about insecure modes](../mixed/insecure_modes.md).
#### minRetry

@@ -447,3 +442,2 @@

{
"uid":"6778c79fccb2",
"data":{"input":"hello"},

@@ -459,8 +453,7 @@ "client":"7080fd2a-bd69-4f1f-6648-5f3ceba4b643"

{
"uid":"6778c79f-ccb2-4a1b-5768-2e7381bc5410",
"info":{
"user":"2694",
"client":"7080fd2a-bd69-4f1f-6648-5f3ceba4b643",
"default_info":{"name":"Alexandr"},
"channel_info":{"extra":"extra JSON data when authorizing private channel"}
"conn_info":{"name":"Alexandr"},
"chan_info":{"extra":"extra JSON data when authorizing private channel"}
},

@@ -554,4 +547,3 @@ "data":{"input":"hello"},

{
"channel":"$public:chat",
"data":{
"presence":{
"2724adea-6e9b-460b-4430-a9f999e94c36": {

@@ -607,10 +599,7 @@ "user":"2694",

{
"channel": "$public:chat",
"data": [
"publications": [
{
"uid": "87219102-a31d-44ed-489d-52b1a7fa520c",
"data": {"input": "hello2"}
},
{
"uid": "71617557-7466-4cbb-760e-639042a5cade",
"data": {"input": "hello1"}

@@ -622,3 +611,3 @@ }

Where `data` is an array of messages published into channel.
Where `publications` is an array of messages published into channel.

@@ -798,2 +787,4 @@ Note that also additional fields can be included in messages - `client`, `info` if those

As we just described when client subscribes on private channel by default AJAX request will be sent to `subscribeEndpoint` automatically if channel starts with `$`. In this case developer only needs to return proper response from server. But there is a way to override default behaviour and take full control on authorizing private channels. To do this it's possible to provide custom `onPrivateSubscribe` function in configuration options. This function will be called with all data required to authorize private channels client subscribes to and should call callback (will be provided by centrifuge-js as second argument) with authorization data when done. See our type declarations in `dist` folder to find out data format.
## Connection expiration

@@ -800,0 +791,0 @@

@@ -27,2 +27,3 @@ import EventEmitter from 'events';

this._url = url;
this._websocket = null;
this._sockjs = null;

@@ -67,2 +68,3 @@ this._isSockjs = false;

debug: false,
websocket: null,
sockjs: null,

@@ -190,2 +192,5 @@ promise: null,

_websocketSupported() {
if (this._config.websocket !== null) {
return true;
}
return !(typeof WebSocket !== 'function' && typeof WebSocket !== 'object');

@@ -404,3 +409,8 @@ };

}
this._transport = new WebSocket(this._url);
if (this._config.websocket !== null) {
this._websocket = this._config.websocket;
} else {
this._websocket = WebSocket;
}
this._transport = new this._websocket(this._url);
if (this._binary === true) {

@@ -1178,3 +1188,3 @@ this._transport.binaryType = 'arraybuffer';

}
sub.emit('join', join);
sub.emit('join', {'info': join.info});
};

@@ -1187,3 +1197,3 @@

}
sub.emit('leave', leave);
sub.emit('leave', {'info': leave.info});
};

@@ -1190,0 +1200,0 @@

@@ -100,7 +100,7 @@ {

},
"connInfo": {
"conn_info": {
"type": "bytes",
"id": 3
},
"chanInfo": {
"chan_info": {
"type": "bytes",

@@ -373,7 +373,7 @@ "id": 4

"fields": {
"numClients": {
"num_clients": {
"type": "uint32",
"id": 1
},
"numUsers": {
"num_users": {
"type": "uint32",

@@ -380,0 +380,0 @@ "id": 2

@@ -29,2 +29,3 @@ import EventEmitter from 'events';

this._promises = {};
this._promiseId = 0;
this.on('error', function (errContext) {

@@ -35,2 +36,6 @@ this._centrifuge._debug('subscription error', errContext);

_nextPromiseId() {
return ++this._promiseId;
}
_initializePromise() {

@@ -123,6 +128,6 @@ // this helps us to wait until subscription will successfully

this._resolve(successContext);
for (const to in this._promises) {
clearTimeout(to);
this._promises[to].resolve();
delete this._promises[to];
for (const id in this._promises) {
clearTimeout(this._promises[id].timeout);
this._promises[id].resolve();
delete this._promises[id];
}

@@ -140,6 +145,6 @@ };

this._reject(errContext);
for (const to in this._promises) {
clearTimeout(to);
this._promises[to].reject(err);
delete this._promises[to];
for (const id in this._promises) {
clearTimeout(this._promises[id].timeout);
this._promises[id].reject(err);
delete this._promises[id];
}

@@ -227,3 +232,4 @@ };

}, this._centrifuge._config.timeout);
this._promises[timeout] = {
this._promises[this._nextPromiseId()] = {
timeout: timeout,
resolve: res,

@@ -230,0 +236,0 @@ reject: rej

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc