New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

centrifuge-ts

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

centrifuge-ts - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

tslint.json

59

dist/centrifuge.js

@@ -197,4 +197,4 @@ (function webpackUniversalModuleDefinition(root, factory) {

}
var cb = function (error, data) {
if (error === true) {
var cb = function (err, _data) {
if (err === true) {
_this._debug('Authorization request failed');

@@ -223,3 +223,3 @@ for (i in channels) {

channel = channels[i];
var channelResponse = data[channel];
var channelResponse = _data[channel];
if (!channelResponse) {

@@ -286,3 +286,3 @@ _this._subscribeError({

else {
throw 'Unknown private channel auth transport ' + transport;
throw new Error('Unknown private channel auth transport ' + transport);
}

@@ -293,6 +293,6 @@ }

if (!Object(__WEBPACK_IMPORTED_MODULE_0__Functions__["d" /* isString */])(channel)) {
throw 'Illegal argument type: channel must be a string';
throw new Error('Illegal argument type: channel must be a string');
}
if (!this._config.resubscribe && !this.isConnected()) {
throw 'Can not only subscribe in connected state when resubscribe option is off';
throw new Error('Can not only subscribe in connected state when resubscribe option is off');
}

@@ -356,6 +356,8 @@ var currentSub = this._getSub(channel);

if (this.isConnected()) {
var channel = sub.channel;
delete this._subs[channel];
this.addMessage({
method: 'unsubscribe',
params: {
channel: sub.channel
channel: channel
}

@@ -470,5 +472,5 @@ }).then(function (response) {

if (xhr.status === 200) {
var data_1, parsed = false;
var callbackData = void 0, parsed = false;
try {
data_1 = JSON.parse(xhr.responseText);
callbackData = JSON.parse(xhr.responseText);
parsed = true;

@@ -480,3 +482,3 @@ }

if (parsed) {
callback(false, data_1);
callback(false, callbackData);
}

@@ -522,3 +524,3 @@ }

if (!config.url) {
throw 'Missing required configuration parameter \'url\' specifying server URL';
throw new Error('Missing required configuration parameter \'url\' specifying server URL');
}

@@ -528,3 +530,3 @@ config.url = Object(__WEBPACK_IMPORTED_MODULE_0__Functions__["h" /* stripSlash */])(config.url);

if (!config.insecure) {
throw 'Missing required configuration parameter \'user\' specifying user\'s unique ID in your application';
throw new Error('Missing required configuration parameter \'user\' specifying user\'s unique ID in your application');
}

@@ -542,3 +544,3 @@ else {

if (!config.insecure) {
throw 'Missing required configuration parameter \'timestamp\'';
throw new Error('Missing required configuration parameter \'timestamp\'');
}

@@ -556,3 +558,3 @@ else {

if (!config.insecure) {
throw 'Missing required configuration parameter \'token\' specifying the sign of authorization request';
throw new Error('Missing required configuration parameter \'token\' specifying the sign of authorization request');
}

@@ -679,8 +681,5 @@ else {

}
var encodedMessages = [];
for (var i in messages) {
encodedMessages.push(JSON.stringify(messages[i]));
}
this._transport.send(encodedMessages.join("\n"));
this._debug('Send', messages.length === 1 ? messages[0] : messages);
var _messages = messages.length === 1 ? messages[0] : messages;
this._transport.send(JSON.stringify(_messages));
this._debug('Send', _messages);
};

@@ -751,4 +750,4 @@ Centrifuge.prototype._getNextMessageId = function () {

}
var cb = function (error, data) {
if (error === true) {
var cb = function (err, data) {
if (err === true) {
_this._debug('Error getting connection credentials from refresh endpoint', data);

@@ -805,3 +804,3 @@ _this._numRefreshFailed++;

else {
throw 'Unknown refresh transport ' + transport;
throw new Error('Unknown refresh transport ' + transport);
}

@@ -853,2 +852,3 @@ }

this.trigger('connect', [{
version: response.version,
client: response.client,

@@ -1028,3 +1028,3 @@ transport: this._transportName,

if (!Object(__WEBPACK_IMPORTED_MODULE_0__Functions__["c" /* isFunction */])(WebSocket)) {
throw 'No Websocket support and no SockJS configured, can not connect';
throw new Error('No Websocket support and no SockJS configured, can not connect');
}

@@ -1103,10 +1103,5 @@ this._transport = new WebSocket(this._getWebsocketEndpoint());

this._transport.onmessage = function (event) {
var replies = event.data.split("\n");
for (var i in replies) {
if (replies.hasOwnProperty(i) && replies[i]) {
var data = JSON.parse(replies[i]);
_this._debug('Received', data);
_this._receive(data);
}
}
var data = JSON.parse(event.data);
_this._debug('Received', data);
_this._receive(data);
_this._restartPing();

@@ -1113,0 +1108,0 @@ };

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

(function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n=e();for(var s in n)("object"==typeof exports?exports:t)[s]=n[s]}})("undefined"!=typeof self?self:this,function(){return function(t){function e(s){if(n[s])return n[s].exports;var r=n[s]={i:s,l:!1,exports:{}};return t[s].call(r.exports,r,r.exports,e),r.l=!0,r.exports}var n={};return e.m=t,e.c=n,e.d=function(t,n,s){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:s})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),n.d(e,"Centrifuge",function(){return c});var s=n(1),r=n(2),i=n(3),o=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function s(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(s.prototype=n.prototype,new s)}}(),c=function(t){function e(e){var n=t.call(this)||this;return n._config={},n._status="disconnected",n._isSockJS=!1,n._transport=null,n._transportName=null,n._transportClosed=!0,n._reconnect=!0,n._reconnecting=!1,n._numRefreshFailed=0,n._refreshTimeout=null,n._pongTimeout=null,n._pingInterval=null,n._messageId=0,n._messages=[],n._isBatching=!1,n._isAuthBatching=!1,n._authChannels={},n._clientID=null,n._callbacks={},n._subs={},n._retries=0,n._latency=null,n._latencyStart=null,n._lastMessageID={},n._configure(e),n}return o(e,t),e.prototype.connect=function(){if(this.isConnected())return void this._debug("Connect called when already connected");"connecting"!==this._status&&(this._debug("Start connecting"),this._clientID=null,this._reconnect=!0,this._setStatus("connecting"),this._setTransport())},e.prototype.disconnect=function(){this._disconnect("client")},e.prototype.isConnected=function(){return"connected"===this._status},e.prototype.isDisconnected=function(){return"disconnected"===this._status},e.prototype.ping=function(){this.addMessage({method:"ping"}).then(function(t){},function(t){})},e.prototype.startBatching=function(){this._isBatching=!0},e.prototype.stopBatching=function(t){void 0===t&&(t=!1),this._isBatching=!1,!0===t&&this.flush()},e.prototype.flush=function(){var t=this._messages.slice(0);this._messages=[],this._send(t)},e.prototype.startAuthBatching=function(){this._isAuthBatching=!0},e.prototype.stopAuthBatching=function(){var t,e,n=this;this._isAuthBatching=!1;var r=this._authChannels;this._authChannels={};var i=[];for(e in r)if(r.hasOwnProperty(e)){if(!this._getSub(e))continue;i.push(e)}if(0!==i.length){var o=function(s,r){if(!0!==s){var o=!1;n._isBatching||(n.startBatching(),o=!0);for(t in i)if(i.hasOwnProperty(t)){e=i[t];var c=r[e];if(!c){n._subscribeError({error:"channel not found in authorization response",advice:"fix",body:{channel:e}});continue}if(c.status&&200!==c.status)n._subscribeError({error:c.status,body:{channel:e}});else{var a={method:"subscribe",params:{channel:e,client:n.getClientId(),info:c.info,sign:c.sign}};!0===n._recover(e)&&(a.params.recover=!0,a.params.last=n._getLastID(e)),n.addMessage(a).then(function(t){n._subscribeResponse(t)},function(t){})}}o&&n.stopBatching(!0)}else{n._debug("Authorization request failed");for(t in i)i.hasOwnProperty(t)&&(e=i[t],n._subscribeError({error:"authorization request failed",advice:"fix",body:{channel:e}}))}},c={client:this.getClientId(),channels:i};if(Object(s.c)(this._config.onPrivateChannelAuth))this._config.onPrivateChannelAuth({data:c},o);else{var a=this._config.authTransport.toLowerCase();if("ajax"===a)this._ajax(this._config.authEndpoint,this._config.authParams,this._config.authHeaders,c,o);else{if("jsonp"!==a)throw"Unknown private channel auth transport "+a;this._jsonp(this._config.authEndpoint,this._config.authParams,this._config.authHeaders,c,o)}}}},e.prototype.subscribe=function(t,e){if(!Object(s.d)(t))throw"Illegal argument type: channel must be a string";if(!this._config.resubscribe&&!this.isConnected())throw"Can not only subscribe in connected state when resubscribe option is off";var n=this._getSub(t);if(null!==n)return n.setEvents(e),n.isUnsubscribed()&&n.subscribe(),n;var r=new i.a(this,t,e);return this._subs[t]=r,r.subscribe(),r},e.prototype.subscribeSub=function(t){var e=this,n=t.channel;if(n in this._subs||(this._subs[n]=t),!this.isConnected())return void t.setNew();if(t.setSubscribing(),Object(s.g)(n,this._config.privateChannelPrefix))this._isAuthBatching?this._authChannels[n]=!0:(this.startAuthBatching(),this.subscribeSub(t),this.stopAuthBatching());else{var r={method:"subscribe",params:{channel:n}};!0===this._recover(n)&&(r.params.recover=!0,r.params.last=this._getLastID(n)),this.addMessage(r).then(function(t){e._subscribeResponse(t)},function(t){e._subscribeError(t)})}},e.prototype.unsubscribeSub=function(t){var e=this;this.isConnected()&&this.addMessage({method:"unsubscribe",params:{channel:t.channel}}).then(function(t){e._unsubscribeResponse(t)},function(t){})},e.prototype.getClientId=function(){return this._clientID},e.prototype.registerCall=function(t,n,r){var i=this;this._callbacks[t]={callback:n,errback:r},setTimeout(function(){delete i._callbacks[t],Object(s.c)(r)&&r(e.createErrorObject("timeout","retry"))},this._config.timeout)},e.prototype.addMessage=function(t){var e=this;return new Promise(function(n,s){var r=e._getNextMessageId()+"";t.uid=r,!0===e._isBatching?e._messages.push(t):e._send([t]),e.registerCall(r,n,s)})},e.createErrorObject=function(t,e){var n={error:t};return e&&(n.advice=e),n},e.log=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];Object(s.e)("info",t)},e.prototype._debug=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];!0===this._config.debug&&Object(s.e)("debug",t)},e.prototype._jsonp=function(t,n,r,i,o){Object.keys(r).length>0&&e.log("Only AJAX request allows to send custom headers, it is not possible with JSONP."),this._debug("Sending JSONP request to",t);var c="centrifuge_jsonp_"+e.nextJSONPCallbackID.toString();e.nextJSONPCallbackID++;var a=document.createElement("script"),u=setTimeout(function(){e.jsonpCallbacks[c]=function(){},o(!0,"timeout")},3e3);e.jsonpCallbacks[c]=function(t){clearTimeout(u),o(!1,t),delete e.jsonpCallbacks[c]};var h="Centrifuge._jsonpCallbacks['"+c+"']";a.src=this._config.authEndpoint+"?callback="+encodeURIComponent(h)+"&data="+encodeURIComponent(JSON.stringify(i))+"&"+Object(s.f)(n);var f=document.getElementsByTagName("head")[0]||document.documentElement;f.insertBefore(a,f.firstChild)},e.prototype._ajax=function(t,n,r,i,o){this._debug("Sending AJAX request to",t);var c=XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),a=Object(s.f)(n);a.length>0&&(a="?"+a),c.open("POST",t+a,!0),"withCredentials"in c&&(c.withCredentials=!0),c.setRequestHeader("X-Requested-With","XMLHttpRequest"),c.setRequestHeader("Content-Type","application/json");for(var u in r)r.hasOwnProperty(u)&&c.setRequestHeader(u,r[u]);return c.onreadystatechange=function(){if(4===c.readyState)if(200===c.status){var t,n=!1;try{t=JSON.parse(c.responseText),n=!0}catch(t){o(!0,"JSON returned was invalid, yet status code was 200. Data was: "+c.responseText)}n&&o(!1,t)}else e.log("Could not get auth info from application",c.status),o(!0,c.status)},setTimeout(function(){c.send(JSON.stringify(i))},20),c},e.prototype._configure=function(t){if(this._debug("Configuring Centrifuge with",t),t=Object.assign({retry:1e3,maxRetry:2e4,timeout:5e3,info:"",resubscribe:!0,ping:!0,pingInterval:3e4,pongWaitTimeout:5e3,debug:!1,insecure:!1,privateChannelPrefix:"$",refreshEndpoint:"/centrifuge/refresh/",refreshHeaders:{},refreshParams:{},refreshData:{},refreshTransport:"ajax",refreshAttempts:0,refreshInterval:3e3,authEndpoint:"/centrifuge/auth/",authHeaders:{},authParams:{},authTransport:"ajax"},t),!t.url)throw"Missing required configuration parameter 'url' specifying server URL";if(t.url=Object(s.h)(t.url),t.user)Object(s.d)(t.user)||e.log("Configuration parameter 'user' expected to be string");else{if(!t.insecure)throw"Missing required configuration parameter 'user' specifying user's unique ID in your application";this._debug("Configuration parameter 'user' not found but this is OK for insecure mode - anonymous access will be used")}if(t.timestamp)Object(s.d)(t.timestamp)||e.log("Configuration parameter 'timestamp' expected to be string");else{if(!t.insecure)throw"Missing required configuration parameter 'timestamp'";this._debug("Configuration parameter 'timestamp' not found but this is OK for insecure mode")}if(t.token)Object(s.d)(t.token)||e.log("Configuration parameter 'token' expected to be string");else{if(!t.insecure)throw"Missing required configuration parameter 'token' specifying the sign of authorization request";this._debug("Configuration parameter 'token' not found but this is OK for insecure mode")}t.info&&!Object(s.d)(t.info)&&e.log("Configuration parameter 'info' expected to be string"),this._config=t},e.prototype._getSockjsEndpoint=function(){var t=this._config.url;return t=t.replace("ws://","http://").replace("wss://","https://"),t=Object(s.h)(t),Object(s.a)(this._config.url,"connection")||(t+="/connection"),t},e.prototype._getWebsocketEndpoint=function(){var t=this._config.url;return t=t.replace("http://","ws://").replace("https://","wss://"),t=Object(s.h)(t),Object(s.a)(this._config.url,"connection/websocket")||(t+="/connection/websocket"),t},e.prototype._recover=function(t){return t in this._lastMessageID},e.prototype._getLastID=function(t){var e=this._lastMessageID[t];return e?(this._debug("Last uid found and sent for channel",t),e):(this._debug("No last uid found for channel",t),"")},e.prototype._getSub=function(t){return this._subs[t]||null},e.prototype._clearConnectedState=function(t){this._clientID=null;for(var n in this._callbacks)if(this._callbacks.hasOwnProperty(n)){var s=this._callbacks[n],r=s.errback;if(!r)continue;r(e.createErrorObject("disconnected","retry"))}this._callbacks={};for(var i in this._subs)if(this._subs.hasOwnProperty(i)){var o=this._getSub(i);t?(o.isSuccess()&&o.triggerUnsubscribe(),o.setSubscribing()):o.setUnsubscribed()}this._config.resubscribe&&this._reconnect||(this._subs={})},e.prototype._setStatus=function(t){this._status!==t&&(this._debug("Status:",this._status,"->",t),this._status=t)},e.prototype._disconnect=function(t,e){void 0===e&&(e=!1),this.isDisconnected()||(this._debug("Disconnected:",t+".","shouldReconnect:",e),!1===e&&(this._reconnect=!1),this._clearConnectedState(e),this.isDisconnected()||(this._setStatus("disconnected"),this._refreshTimeout&&clearTimeout(this._refreshTimeout),!1===this._reconnecting&&this.trigger("disconnect",[{reason:t,reconnect:e}])),this._transportClosed||this._transport.close())},e.prototype._send=function(t){if(t.length){var e=[];for(var n in t)e.push(JSON.stringify(t[n]));this._transport.send(e.join("\n")),this._debug("Send",1===t.length?t[0]:t)}},e.prototype._getNextMessageId=function(){return++this._messageId},e.prototype._stopPing=function(){null!==this._pongTimeout&&clearTimeout(this._pongTimeout),null!==this._pingInterval&&clearInterval(this._pingInterval)},e.prototype._startPing=function(){var t=this;!0!==this._config.ping||this._config.pingInterval<=0||!this.isConnected()||(this._pingInterval=setInterval(function(){if(!t.isConnected())return void t._stopPing();t.ping(),t._pongTimeout=setTimeout(function(){this._disconnect("no ping",!0)},t._config.pongWaitTimeout)},this._config.pingInterval))},e.prototype._restartPing=function(){this._stopPing(),this._startPing()},e.prototype._resetRetry=function(){this._debug("Reset retries count to 0"),this._retries=0},e.prototype._getRetryInterval=function(){this._retries+=1;var t=.5*Math.random(),e=this._config.retry*Math.pow(2,this._retries+1);return e>this._config.maxRetry&&(e=this._config.maxRetry),Math.floor((1-t)*e)},e.prototype._refreshFailed=function(){this._numRefreshFailed=0,this.isDisconnected()||this._disconnect("refresh failed"),this._config.refreshFailed&&this._config.refreshFailed()},e.prototype._refresh=function(){var t=this;if(this._debug("Refresh credentials"),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);var e=function(e,n){if(!0===e)return t._debug("Error getting connection credentials from refresh endpoint",n),t._numRefreshFailed++,t._refreshTimeout&&clearTimeout(t._refreshTimeout),null!==t._config.refreshAttempts&&t._numRefreshFailed>=t._config.refreshAttempts?void t._refreshFailed():void(t._refreshTimeout=setTimeout(function(){t._refresh()},t._config.refreshInterval+Math.round(1e3*Math.random())));t._numRefreshFailed=0,t._config.user=n.user,t._config.timestamp=n.timestamp,t._config.token=n.token,"info"in n?t._config.info=n.info:n.info="",t.isDisconnected()?(t._debug("Credentials refreshed, connect from scratch"),t.connect()):(t._debug("Send refreshed credentials"),t.addMessage({method:"refresh",params:n}).then(function(e){t._refreshResponse(e)},function(t){}))};if(null!==this._config.onRefresh)this._config.onRefresh({},e);else{var n=this._config.refreshTransport.toLowerCase();if("ajax"===n)this._ajax(this._config.refreshEndpoint,this._config.refreshParams,this._config.refreshHeaders,this._config.refreshData,e);else{if("jsonp"!==n)throw"Unknown refresh transport "+n;this._jsonp(this._config.refreshEndpoint,this._config.refreshParams,this._config.refreshHeaders,this._config.refreshData,e)}}},e.prototype._connectResponse=function(t){var e=this;if(!this.isConnected()){if(null!==this._latencyStart&&(this._latency=(new Date).getTime()-this._latencyStart.getTime(),this._latencyStart=null),t.expires&&t.expired)return this._reconnecting=!0,this._disconnect("expired",!0),void this._refresh();if(this._clientID=t.client,this._setStatus("connected"),this._refreshTimeout&&clearTimeout(this._refreshTimeout),t.expires&&(this._refreshTimeout=setTimeout(function(){e._refresh()},1e3*t.ttl)),this._config.resubscribe){this.startBatching(),this.startAuthBatching();for(var n in this._subs)if(this._subs.hasOwnProperty(n)){var s=this._getSub(n);s.shouldResubscribe()&&this.subscribeSub(s)}this.stopAuthBatching(),this.stopBatching(!0)}this._restartPing(),this.trigger("connect",[{client:t.client,transport:this._transportName,latency:this._latency}])}},e.prototype._subscribeResponse=function(t){var e=t.channel,n=this._getSub(e);if(n&&n.isSubscribing()){var s=t.messages;if(s&&s.length>0){s=s.reverse();for(var r in s)s.hasOwnProperty(r)&&this._messageResponse({body:s[r]})}else"last"in t&&(this._lastMessageID[e]=t.last);var i=!1;"recovered"in t&&(i=t.recovered),n.setSubscribeSuccess(i)}},e.prototype._subscribeError=function(t){var e=t.channel,n=this._getSub(e);n&&n.isSubscribing()&&(this.trigger("error",[{error:t}]),n.setSubscribeError(t))},e.prototype._unsubscribeResponse=function(t){var e=this._getSub(t.channel);e&&e.setUnsubscribed()},e.prototype._joinResponse=function(t){var e=this._getSub(t.channel);e&&e.trigger("join",[t])},e.prototype._leaveResponse=function(t){var e=this._getSub(t.channel);e&&e.trigger("leave",[t])},e.prototype._refreshResponse=function(t){var e=this;if(this._refreshTimeout&&clearTimeout(this._refreshTimeout),t.expires){if(t.expired)return void(this._refreshTimeout=setTimeout(function(){e._refresh()},this._config.refreshInterval+Math.round(1e3*Math.random())));this._clientID=t.client,this._refreshTimeout=setTimeout(function(){e._refresh()},1e3*t.ttl)}},e.prototype._messageResponse=function(t){var e=t.body,n=e.channel;this._lastMessageID[n]=e.uid;var s=this._getSub(n);s&&s.trigger("message",[e])},e.prototype._handleResponse=function(t){var n=t.uid;if(n in this._callbacks){var r=this._callbacks[n];if(delete this._callbacks[n],Object(s.b)(t)){var i=r.errback;if(!i)return;i(e.createErrorObject(t.error,t.advice)),this.trigger("error",[{message:t}])}else{var o=r.callback;if(!o)return;o(t.body)}}},e.prototype._dispatchMessage=function(t){if(void 0===t||null===t)return void this._debug("Dispatch: got undefined or null message");switch(t.method){case"join":this._joinResponse(t);break;case"leave":this._leaveResponse(t);break;case"message":this._messageResponse(t);break;default:this._handleResponse(t)}},e.prototype._receive=function(t){if(Object.prototype.toString.call(t)===Object.prototype.toString.call([]))for(var e in t)t.hasOwnProperty(e)&&this._dispatchMessage(t[e]);else Object.prototype.toString.call(t)===Object.prototype.toString.call({})&&this._dispatchMessage(t)},e.prototype._setTransport=function(){var t=this;if(Object(s.c)(this._config.sockJS)){var e={transports:this._config.transports||["websocket","xdr-streaming","xhr-streaming","eventsource","iframe-eventsource","iframe-htmlfile","xdr-polling","xhr-polling","iframe-xhr-polling","jsonp-polling"]};this._config.server&&(e.server=this._config.server),this._transport=new this._config.sockJS(this._getSockjsEndpoint(),null,e),this._isSockJS=!0}else{if(!Object(s.c)(WebSocket))throw"No Websocket support and no SockJS configured, can not connect";this._transport=new WebSocket(this._getWebsocketEndpoint())}this._transport.onopen=function(){t._transportClosed=!1,t._reconnecting=!1,t._isSockJS?(t._transportName=t._transport.transport,t._transport.onheartbeat=function(){this._restartPing()}):t._transportName="raw-websocket",t._resetRetry();var e={method:"connect",params:{user:t._config.user,info:t._config.info}};t._config.insecure||(e.params.timestamp=t._config.timestamp,e.params.token=t._config.token),t._latencyStart=new Date,t.addMessage(e).then(function(e){t._connectResponse(e)},function(t){})},this._transport.onerror=function(e){t._debug("Transport level error",e)},this._transport.onclose=function(e){t._transportClosed=!0;var n="Connection closed",s=!0;if(e&&"reason"in e&&e.reason)try{var r=JSON.parse(e.reason);t._debug(n+". Reason is an advice object:",r),n=r.reason,s=r.reconnect}catch(r){n=e.reason,t._debug(n+". Reason is a plain string:",n),s="disconnect"!==n}if(t._config.onTransportClose&&t._config.onTransportClose({event:e,reason:n,reconnect:s}),t._disconnect(n,s),!0===t._reconnect){t._reconnecting=!0;var i=t._getRetryInterval();t._debug("Reconnect after "+i+" milliseconds"),setTimeout(function(){!0===t._reconnect&&t.connect()},i)}},this._transport.onmessage=function(e){var n=e.data.split("\n");for(var s in n)if(n.hasOwnProperty(s)&&n[s]){var r=JSON.parse(n[s]);t._debug("Received",r),t._receive(r)}t._restartPing()}},e.jsonpCallbacks={},e.nextJSONPCallbackID=1,e}(r.a)},function(t,e,n){"use strict";n.d(e,"c",function(){return s}),n.d(e,"d",function(){return r}),n.d(e,"e",function(){return i}),n.d(e,"h",function(){return o}),n.d(e,"g",function(){return c}),n.d(e,"a",function(){return a}),n.d(e,"b",function(){return u}),n.d(e,"f",function(){return h});var s=function(t){return"function"==typeof t},r=function(t){return"string"==typeof t},i=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];if(console){1===e.length&&(e=e[0]);var r=console[t];s(r)&&r.apply(r,e)}},o=function(t){return t.replace(/\/$/,"")},c=function(t,e){return 0===t.lastIndexOf(e,0)},a=function(t,e){return-1!==t.indexOf(e,t.length-e.length)},u=function(t){return"error"in t&&null!==t.error&&""!==t.error},h=function(t){var e=[];for(var n in t)t.hasOwnProperty(n)&&e.push(encodeURIComponent(n)+(t[n]?"="+encodeURIComponent(t[n]):""));return e.join("&")}},function(t,e,n){"use strict";n.d(e,"a",function(){return s});var s=function(){function t(){this.__callbacks={}}return t.prototype.on=function(t,e){var n=this;return t.replace(/[^\s]+/g,function(t){return(n.__callbacks[t]=n.__callbacks[t]||[]).push(e),""}),this},t.prototype.one=function(t,e){return e.one=!0,this.on(t,e)},t.prototype.off=function(t,e){var n=this;if("*"===t)this.__callbacks={};else if(e)for(var s=this.__callbacks[t],r=0,i=void 0;i=s&&s[r];++r)i===e&&s.splice(r,1);else t.replace(/[^\s]+/g,function(t){return n.__callbacks[t]=[],""});return this},t.prototype.trigger=function(t,e){for(var n=this.__callbacks[t]||[],s=0,r=void 0;r=n[s];++s)r.busy||(r.busy=!0,r.apply(this,e),r.one&&(n.splice(s,1),s--),r.busy=!1);return this},t}()},function(t,e,n){"use strict";n.d(e,"a",function(){return c});var s=n(1),r=n(2),i=n(0),o=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function s(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(s.prototype=n.prototype,new s)}}(),c=function(t){function e(n,s,r){var i=t.call(this)||this;return i.channel=null,i._status=e.STATE_NEW,i._error=null,i._centrifuge=null,i._isResubscribe=!1,i._recovered=!1,i._ready=!1,i._promise=null,i._noResubscribe=!1,i._centrifuge=n,i.channel=s,i.setEvents(r),i._initializePromise(),i}return o(e,t),e.prototype.setEvents=function(t){if(t)if(Object(s.c)(t))this.on("message",t);else if(Object.prototype.toString.call(t)===Object.prototype.toString.call({}))for(var e=["message","join","leave","unsubscribe","subscribe","error"],n=0,r=e.length;n<r;n++){var i=e[n];i in t&&this.on(i,t[i])}},e.prototype.setNew=function(){this._status=e.STATE_NEW},e.prototype.setSubscribing=function(){!0===this._ready&&(this._initializePromise(),this._isResubscribe=!0),this._status=e.STATE_SUBSCRIBING},e.prototype.setUnsubscribed=function(t){this._status!==e.STATE_UNSUBSCRIBED&&(this._status=e.STATE_UNSUBSCRIBED,!0===t&&(this._noResubscribe=!0),this.triggerUnsubscribe())},e.prototype.setSubscribeSuccess=function(t){if(this._status!==e.STATE_SUCCESS){this._recovered=t,this._status=e.STATE_SUCCESS;var n=this._getSubscribeSuccess();this.trigger("subscribe",[n]),this._resolve(n)}},e.prototype.setSubscribeError=function(t){if(this._status!==e.STATE_ERROR){this._status=e.STATE_ERROR,this._error=t;var n=this._getSubscribeError();this.trigger("error",[n]),this._reject(n)}},e.prototype.triggerUnsubscribe=function(){this.trigger("unsubscribe",[{channel:this.channel}])},e.prototype.isUnsubscribed=function(){return this._status===e.STATE_UNSUBSCRIBED},e.prototype.isSuccess=function(){return this._status===e.STATE_SUCCESS},e.prototype.isSubscribing=function(){return this._status===e.STATE_SUBSCRIBING},e.prototype.shouldResubscribe=function(){return!this._noResubscribe},e.prototype.ready=function(t,e){this._ready&&(this.isSuccess()?t(this._getSubscribeSuccess()):e(this._getSubscribeError()))},e.prototype.subscribe=function(){if(this._status!==e.STATE_SUCCESS)return this._centrifuge.subscribeSub(this),this},e.prototype.unsubscribe=function(){this.setUnsubscribed(!0),this._centrifuge.unsubscribeSub(this)},e.prototype.publish=function(t){return this._request("publish",t)},e.prototype.presence=function(){return this._request("presence")},e.prototype.history=function(){return this._request("history")},e.prototype._initializePromise=function(){var t=this;this._ready=!1,this._promise=new Promise(function(e,n){t._resolve=function(n){t._ready=!0,e(n)},t._reject=function(e){t._ready=!0,n(e)}})},e.prototype._getSubscribeSuccess=function(){return{channel:this.channel,isResubscribe:this._isResubscribe,recovered:this._recovered}},e.prototype._getSubscribeError=function(){var t=this._error;return t.channel=this.channel,t.isResubscribe=this._isResubscribe,t},e.prototype._request=function(t,e){var n=this;return new Promise(function(s,r){if(n.isUnsubscribed())return void r(i.Centrifuge.createErrorObject("subscription unsubscribed","fix"));n._promise.then(function(){if(!n._centrifuge.isConnected())return void r(i.Centrifuge.createErrorObject("disconnected","retry"));var o={channel:n.channel};e&&(o.data=e),n._centrifuge.addMessage({method:t,params:o}).then(function(t){s(t)},function(t){r(t)})},function(t){r(t)})})},e.STATE_NEW=0,e.STATE_SUBSCRIBING=1,e.STATE_SUCCESS=2,e.STATE_ERROR=3,e.STATE_UNSUBSCRIBED=4,e}(r.a)}])});
(function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n=e();for(var r in n)("object"==typeof exports?exports:t)[r]=n[r]}})("undefined"!=typeof self?self:this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var s=n[r]={i:r,l:!1,exports:{}};return t[r].call(s.exports,s,s.exports,e),s.l=!0,s.exports}var n={};return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),n.d(e,"Centrifuge",function(){return c});var r=n(1),s=n(2),i=n(3),o=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),c=function(t){function e(e){var n=t.call(this)||this;return n._config={},n._status="disconnected",n._isSockJS=!1,n._transport=null,n._transportName=null,n._transportClosed=!0,n._reconnect=!0,n._reconnecting=!1,n._numRefreshFailed=0,n._refreshTimeout=null,n._pongTimeout=null,n._pingInterval=null,n._messageId=0,n._messages=[],n._isBatching=!1,n._isAuthBatching=!1,n._authChannels={},n._clientID=null,n._callbacks={},n._subs={},n._retries=0,n._latency=null,n._latencyStart=null,n._lastMessageID={},n._configure(e),n}return o(e,t),e.prototype.connect=function(){if(this.isConnected())return void this._debug("Connect called when already connected");"connecting"!==this._status&&(this._debug("Start connecting"),this._clientID=null,this._reconnect=!0,this._setStatus("connecting"),this._setTransport())},e.prototype.disconnect=function(){this._disconnect("client")},e.prototype.isConnected=function(){return"connected"===this._status},e.prototype.isDisconnected=function(){return"disconnected"===this._status},e.prototype.ping=function(){this.addMessage({method:"ping"}).then(function(t){},function(t){})},e.prototype.startBatching=function(){this._isBatching=!0},e.prototype.stopBatching=function(t){void 0===t&&(t=!1),this._isBatching=!1,!0===t&&this.flush()},e.prototype.flush=function(){var t=this._messages.slice(0);this._messages=[],this._send(t)},e.prototype.startAuthBatching=function(){this._isAuthBatching=!0},e.prototype.stopAuthBatching=function(){var t,e,n=this;this._isAuthBatching=!1;var s=this._authChannels;this._authChannels={};var i=[];for(e in s)if(s.hasOwnProperty(e)){if(!this._getSub(e))continue;i.push(e)}if(0!==i.length){var o=function(r,s){if(!0!==r){var o=!1;n._isBatching||(n.startBatching(),o=!0);for(t in i)if(i.hasOwnProperty(t)){e=i[t];var c=s[e];if(!c){n._subscribeError({error:"channel not found in authorization response",advice:"fix",body:{channel:e}});continue}if(c.status&&200!==c.status)n._subscribeError({error:c.status,body:{channel:e}});else{var a={method:"subscribe",params:{channel:e,client:n.getClientId(),info:c.info,sign:c.sign}};!0===n._recover(e)&&(a.params.recover=!0,a.params.last=n._getLastID(e)),n.addMessage(a).then(function(t){n._subscribeResponse(t)},function(t){})}}o&&n.stopBatching(!0)}else{n._debug("Authorization request failed");for(t in i)i.hasOwnProperty(t)&&(e=i[t],n._subscribeError({error:"authorization request failed",advice:"fix",body:{channel:e}}))}},c={client:this.getClientId(),channels:i};if(Object(r.c)(this._config.onPrivateChannelAuth))this._config.onPrivateChannelAuth({data:c},o);else{var a=this._config.authTransport.toLowerCase();if("ajax"===a)this._ajax(this._config.authEndpoint,this._config.authParams,this._config.authHeaders,c,o);else{if("jsonp"!==a)throw new Error("Unknown private channel auth transport "+a);this._jsonp(this._config.authEndpoint,this._config.authParams,this._config.authHeaders,c,o)}}}},e.prototype.subscribe=function(t,e){if(!Object(r.d)(t))throw new Error("Illegal argument type: channel must be a string");if(!this._config.resubscribe&&!this.isConnected())throw new Error("Can not only subscribe in connected state when resubscribe option is off");var n=this._getSub(t);if(null!==n)return n.setEvents(e),n.isUnsubscribed()&&n.subscribe(),n;var s=new i.a(this,t,e);return this._subs[t]=s,s.subscribe(),s},e.prototype.subscribeSub=function(t){var e=this,n=t.channel;if(n in this._subs||(this._subs[n]=t),!this.isConnected())return void t.setNew();if(t.setSubscribing(),Object(r.g)(n,this._config.privateChannelPrefix))this._isAuthBatching?this._authChannels[n]=!0:(this.startAuthBatching(),this.subscribeSub(t),this.stopAuthBatching());else{var s={method:"subscribe",params:{channel:n}};!0===this._recover(n)&&(s.params.recover=!0,s.params.last=this._getLastID(n)),this.addMessage(s).then(function(t){e._subscribeResponse(t)},function(t){e._subscribeError(t)})}},e.prototype.unsubscribeSub=function(t){var e=this;if(this.isConnected()){var n=t.channel;delete this._subs[n],this.addMessage({method:"unsubscribe",params:{channel:n}}).then(function(t){e._unsubscribeResponse(t)},function(t){})}},e.prototype.getClientId=function(){return this._clientID},e.prototype.registerCall=function(t,n,s){var i=this;this._callbacks[t]={callback:n,errback:s},setTimeout(function(){delete i._callbacks[t],Object(r.c)(s)&&s(e.createErrorObject("timeout","retry"))},this._config.timeout)},e.prototype.addMessage=function(t){var e=this;return new Promise(function(n,r){var s=e._getNextMessageId()+"";t.uid=s,!0===e._isBatching?e._messages.push(t):e._send([t]),e.registerCall(s,n,r)})},e.createErrorObject=function(t,e){var n={error:t};return e&&(n.advice=e),n},e.log=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];Object(r.e)("info",t)},e.prototype._debug=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];!0===this._config.debug&&Object(r.e)("debug",t)},e.prototype._jsonp=function(t,n,s,i,o){Object.keys(s).length>0&&e.log("Only AJAX request allows to send custom headers, it is not possible with JSONP."),this._debug("Sending JSONP request to",t);var c="centrifuge_jsonp_"+e.nextJSONPCallbackID.toString();e.nextJSONPCallbackID++;var a=document.createElement("script"),u=setTimeout(function(){e.jsonpCallbacks[c]=function(){},o(!0,"timeout")},3e3);e.jsonpCallbacks[c]=function(t){clearTimeout(u),o(!1,t),delete e.jsonpCallbacks[c]};var h="Centrifuge._jsonpCallbacks['"+c+"']";a.src=this._config.authEndpoint+"?callback="+encodeURIComponent(h)+"&data="+encodeURIComponent(JSON.stringify(i))+"&"+Object(r.f)(n);var f=document.getElementsByTagName("head")[0]||document.documentElement;f.insertBefore(a,f.firstChild)},e.prototype._ajax=function(t,n,s,i,o){this._debug("Sending AJAX request to",t);var c=XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),a=Object(r.f)(n);a.length>0&&(a="?"+a),c.open("POST",t+a,!0),"withCredentials"in c&&(c.withCredentials=!0),c.setRequestHeader("X-Requested-With","XMLHttpRequest"),c.setRequestHeader("Content-Type","application/json");for(var u in s)s.hasOwnProperty(u)&&c.setRequestHeader(u,s[u]);return c.onreadystatechange=function(){if(4===c.readyState)if(200===c.status){var t=void 0,n=!1;try{t=JSON.parse(c.responseText),n=!0}catch(t){o(!0,"JSON returned was invalid, yet status code was 200. Data was: "+c.responseText)}n&&o(!1,t)}else e.log("Could not get auth info from application",c.status),o(!0,c.status)},setTimeout(function(){c.send(JSON.stringify(i))},20),c},e.prototype._configure=function(t){if(this._debug("Configuring Centrifuge with",t),t=Object.assign({retry:1e3,maxRetry:2e4,timeout:5e3,info:"",resubscribe:!0,ping:!0,pingInterval:3e4,pongWaitTimeout:5e3,debug:!1,insecure:!1,privateChannelPrefix:"$",refreshEndpoint:"/centrifuge/refresh/",refreshHeaders:{},refreshParams:{},refreshData:{},refreshTransport:"ajax",refreshAttempts:0,refreshInterval:3e3,authEndpoint:"/centrifuge/auth/",authHeaders:{},authParams:{},authTransport:"ajax"},t),!t.url)throw new Error("Missing required configuration parameter 'url' specifying server URL");if(t.url=Object(r.h)(t.url),t.user)Object(r.d)(t.user)||e.log("Configuration parameter 'user' expected to be string");else{if(!t.insecure)throw new Error("Missing required configuration parameter 'user' specifying user's unique ID in your application");this._debug("Configuration parameter 'user' not found but this is OK for insecure mode - anonymous access will be used")}if(t.timestamp)Object(r.d)(t.timestamp)||e.log("Configuration parameter 'timestamp' expected to be string");else{if(!t.insecure)throw new Error("Missing required configuration parameter 'timestamp'");this._debug("Configuration parameter 'timestamp' not found but this is OK for insecure mode")}if(t.token)Object(r.d)(t.token)||e.log("Configuration parameter 'token' expected to be string");else{if(!t.insecure)throw new Error("Missing required configuration parameter 'token' specifying the sign of authorization request");this._debug("Configuration parameter 'token' not found but this is OK for insecure mode")}t.info&&!Object(r.d)(t.info)&&e.log("Configuration parameter 'info' expected to be string"),this._config=t},e.prototype._getSockjsEndpoint=function(){var t=this._config.url;return t=t.replace("ws://","http://").replace("wss://","https://"),t=Object(r.h)(t),Object(r.a)(this._config.url,"connection")||(t+="/connection"),t},e.prototype._getWebsocketEndpoint=function(){var t=this._config.url;return t=t.replace("http://","ws://").replace("https://","wss://"),t=Object(r.h)(t),Object(r.a)(this._config.url,"connection/websocket")||(t+="/connection/websocket"),t},e.prototype._recover=function(t){return t in this._lastMessageID},e.prototype._getLastID=function(t){var e=this._lastMessageID[t];return e?(this._debug("Last uid found and sent for channel",t),e):(this._debug("No last uid found for channel",t),"")},e.prototype._getSub=function(t){return this._subs[t]||null},e.prototype._clearConnectedState=function(t){this._clientID=null;for(var n in this._callbacks)if(this._callbacks.hasOwnProperty(n)){var r=this._callbacks[n],s=r.errback;if(!s)continue;s(e.createErrorObject("disconnected","retry"))}this._callbacks={};for(var i in this._subs)if(this._subs.hasOwnProperty(i)){var o=this._getSub(i);t?(o.isSuccess()&&o.triggerUnsubscribe(),o.setSubscribing()):o.setUnsubscribed()}this._config.resubscribe&&this._reconnect||(this._subs={})},e.prototype._setStatus=function(t){this._status!==t&&(this._debug("Status:",this._status,"->",t),this._status=t)},e.prototype._disconnect=function(t,e){void 0===e&&(e=!1),this.isDisconnected()||(this._debug("Disconnected:",t+".","shouldReconnect:",e),!1===e&&(this._reconnect=!1),this._clearConnectedState(e),this.isDisconnected()||(this._setStatus("disconnected"),this._refreshTimeout&&clearTimeout(this._refreshTimeout),!1===this._reconnecting&&this.trigger("disconnect",[{reason:t,reconnect:e}])),this._transportClosed||this._transport.close())},e.prototype._send=function(t){if(t.length){var e=1===t.length?t[0]:t;this._transport.send(JSON.stringify(e)),this._debug("Send",e)}},e.prototype._getNextMessageId=function(){return++this._messageId},e.prototype._stopPing=function(){null!==this._pongTimeout&&clearTimeout(this._pongTimeout),null!==this._pingInterval&&clearInterval(this._pingInterval)},e.prototype._startPing=function(){var t=this;!0!==this._config.ping||this._config.pingInterval<=0||!this.isConnected()||(this._pingInterval=setInterval(function(){if(!t.isConnected())return void t._stopPing();t.ping(),t._pongTimeout=setTimeout(function(){this._disconnect("no ping",!0)},t._config.pongWaitTimeout)},this._config.pingInterval))},e.prototype._restartPing=function(){this._stopPing(),this._startPing()},e.prototype._resetRetry=function(){this._debug("Reset retries count to 0"),this._retries=0},e.prototype._getRetryInterval=function(){this._retries+=1;var t=.5*Math.random(),e=this._config.retry*Math.pow(2,this._retries+1);return e>this._config.maxRetry&&(e=this._config.maxRetry),Math.floor((1-t)*e)},e.prototype._refreshFailed=function(){this._numRefreshFailed=0,this.isDisconnected()||this._disconnect("refresh failed"),this._config.refreshFailed&&this._config.refreshFailed()},e.prototype._refresh=function(){var t=this;if(this._debug("Refresh credentials"),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);var e=function(e,n){if(!0===e)return t._debug("Error getting connection credentials from refresh endpoint",n),t._numRefreshFailed++,t._refreshTimeout&&clearTimeout(t._refreshTimeout),null!==t._config.refreshAttempts&&t._numRefreshFailed>=t._config.refreshAttempts?void t._refreshFailed():void(t._refreshTimeout=setTimeout(function(){t._refresh()},t._config.refreshInterval+Math.round(1e3*Math.random())));t._numRefreshFailed=0,t._config.user=n.user,t._config.timestamp=n.timestamp,t._config.token=n.token,"info"in n?t._config.info=n.info:n.info="",t.isDisconnected()?(t._debug("Credentials refreshed, connect from scratch"),t.connect()):(t._debug("Send refreshed credentials"),t.addMessage({method:"refresh",params:n}).then(function(e){t._refreshResponse(e)},function(t){}))};if(null!==this._config.onRefresh)this._config.onRefresh({},e);else{var n=this._config.refreshTransport.toLowerCase();if("ajax"===n)this._ajax(this._config.refreshEndpoint,this._config.refreshParams,this._config.refreshHeaders,this._config.refreshData,e);else{if("jsonp"!==n)throw new Error("Unknown refresh transport "+n);this._jsonp(this._config.refreshEndpoint,this._config.refreshParams,this._config.refreshHeaders,this._config.refreshData,e)}}},e.prototype._connectResponse=function(t){var e=this;if(!this.isConnected()){if(null!==this._latencyStart&&(this._latency=(new Date).getTime()-this._latencyStart.getTime(),this._latencyStart=null),t.expires&&t.expired)return this._reconnecting=!0,this._disconnect("expired",!0),void this._refresh();if(this._clientID=t.client,this._setStatus("connected"),this._refreshTimeout&&clearTimeout(this._refreshTimeout),t.expires&&(this._refreshTimeout=setTimeout(function(){e._refresh()},1e3*t.ttl)),this._config.resubscribe){this.startBatching(),this.startAuthBatching();for(var n in this._subs)if(this._subs.hasOwnProperty(n)){var r=this._getSub(n);r.shouldResubscribe()&&this.subscribeSub(r)}this.stopAuthBatching(),this.stopBatching(!0)}this._restartPing(),this.trigger("connect",[{version:t.version,client:t.client,transport:this._transportName,latency:this._latency}])}},e.prototype._subscribeResponse=function(t){var e=t.channel,n=this._getSub(e);if(n&&n.isSubscribing()){var r=t.messages;if(r&&r.length>0){r=r.reverse();for(var s in r)r.hasOwnProperty(s)&&this._messageResponse({body:r[s]})}else"last"in t&&(this._lastMessageID[e]=t.last);var i=!1;"recovered"in t&&(i=t.recovered),n.setSubscribeSuccess(i)}},e.prototype._subscribeError=function(t){var e=t.channel,n=this._getSub(e);n&&n.isSubscribing()&&(this.trigger("error",[{error:t}]),n.setSubscribeError(t))},e.prototype._unsubscribeResponse=function(t){var e=this._getSub(t.channel);e&&e.setUnsubscribed()},e.prototype._joinResponse=function(t){var e=this._getSub(t.channel);e&&e.trigger("join",[t])},e.prototype._leaveResponse=function(t){var e=this._getSub(t.channel);e&&e.trigger("leave",[t])},e.prototype._refreshResponse=function(t){var e=this;if(this._refreshTimeout&&clearTimeout(this._refreshTimeout),t.expires){if(t.expired)return void(this._refreshTimeout=setTimeout(function(){e._refresh()},this._config.refreshInterval+Math.round(1e3*Math.random())));this._clientID=t.client,this._refreshTimeout=setTimeout(function(){e._refresh()},1e3*t.ttl)}},e.prototype._messageResponse=function(t){var e=t.body,n=e.channel;this._lastMessageID[n]=e.uid;var r=this._getSub(n);r&&r.trigger("message",[e])},e.prototype._handleResponse=function(t){var n=t.uid;if(n in this._callbacks){var s=this._callbacks[n];if(delete this._callbacks[n],Object(r.b)(t)){var i=s.errback;if(!i)return;i(e.createErrorObject(t.error,t.advice)),this.trigger("error",[{message:t}])}else{var o=s.callback;if(!o)return;o(t.body)}}},e.prototype._dispatchMessage=function(t){if(void 0===t||null===t)return void this._debug("Dispatch: got undefined or null message");switch(t.method){case"join":this._joinResponse(t);break;case"leave":this._leaveResponse(t);break;case"message":this._messageResponse(t);break;default:this._handleResponse(t)}},e.prototype._receive=function(t){if(Object.prototype.toString.call(t)===Object.prototype.toString.call([]))for(var e in t)t.hasOwnProperty(e)&&this._dispatchMessage(t[e]);else Object.prototype.toString.call(t)===Object.prototype.toString.call({})&&this._dispatchMessage(t)},e.prototype._setTransport=function(){var t=this;if(Object(r.c)(this._config.sockJS)){var e={transports:this._config.transports||["websocket","xdr-streaming","xhr-streaming","eventsource","iframe-eventsource","iframe-htmlfile","xdr-polling","xhr-polling","iframe-xhr-polling","jsonp-polling"]};this._config.server&&(e.server=this._config.server),this._transport=new this._config.sockJS(this._getSockjsEndpoint(),null,e),this._isSockJS=!0}else{if(!Object(r.c)(WebSocket))throw new Error("No Websocket support and no SockJS configured, can not connect");this._transport=new WebSocket(this._getWebsocketEndpoint())}this._transport.onopen=function(){t._transportClosed=!1,t._reconnecting=!1,t._isSockJS?(t._transportName=t._transport.transport,t._transport.onheartbeat=function(){this._restartPing()}):t._transportName="raw-websocket",t._resetRetry();var e={method:"connect",params:{user:t._config.user,info:t._config.info}};t._config.insecure||(e.params.timestamp=t._config.timestamp,e.params.token=t._config.token),t._latencyStart=new Date,t.addMessage(e).then(function(e){t._connectResponse(e)},function(t){})},this._transport.onerror=function(e){t._debug("Transport level error",e)},this._transport.onclose=function(e){t._transportClosed=!0;var n="Connection closed",r=!0;if(e&&"reason"in e&&e.reason)try{var s=JSON.parse(e.reason);t._debug(n+". Reason is an advice object:",s),n=s.reason,r=s.reconnect}catch(s){n=e.reason,t._debug(n+". Reason is a plain string:",n),r="disconnect"!==n}if(t._config.onTransportClose&&t._config.onTransportClose({event:e,reason:n,reconnect:r}),t._disconnect(n,r),!0===t._reconnect){t._reconnecting=!0;var i=t._getRetryInterval();t._debug("Reconnect after "+i+" milliseconds"),setTimeout(function(){!0===t._reconnect&&t.connect()},i)}},this._transport.onmessage=function(e){var n=JSON.parse(e.data);t._debug("Received",n),t._receive(n),t._restartPing()}},e.jsonpCallbacks={},e.nextJSONPCallbackID=1,e}(s.a)},function(t,e,n){"use strict";n.d(e,"c",function(){return r}),n.d(e,"d",function(){return s}),n.d(e,"e",function(){return i}),n.d(e,"h",function(){return o}),n.d(e,"g",function(){return c}),n.d(e,"a",function(){return a}),n.d(e,"b",function(){return u}),n.d(e,"f",function(){return h});var r=function(t){return"function"==typeof t},s=function(t){return"string"==typeof t},i=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];if(console){1===e.length&&(e=e[0]);var s=console[t];r(s)&&s.apply(s,e)}},o=function(t){return t.replace(/\/$/,"")},c=function(t,e){return 0===t.lastIndexOf(e,0)},a=function(t,e){return-1!==t.indexOf(e,t.length-e.length)},u=function(t){return"error"in t&&null!==t.error&&""!==t.error},h=function(t){var e=[];for(var n in t)t.hasOwnProperty(n)&&e.push(encodeURIComponent(n)+(t[n]?"="+encodeURIComponent(t[n]):""));return e.join("&")}},function(t,e,n){"use strict";n.d(e,"a",function(){return r});var r=function(){function t(){this.__callbacks={}}return t.prototype.on=function(t,e){var n=this;return t.replace(/[^\s]+/g,function(t){return(n.__callbacks[t]=n.__callbacks[t]||[]).push(e),""}),this},t.prototype.one=function(t,e){return e.one=!0,this.on(t,e)},t.prototype.off=function(t,e){var n=this;if("*"===t)this.__callbacks={};else if(e)for(var r=this.__callbacks[t],s=0,i=void 0;i=r&&r[s];++s)i===e&&r.splice(s,1);else t.replace(/[^\s]+/g,function(t){return n.__callbacks[t]=[],""});return this},t.prototype.trigger=function(t,e){for(var n=this.__callbacks[t]||[],r=0,s=void 0;s=n[r];++r)s.busy||(s.busy=!0,s.apply(this,e),s.one&&(n.splice(r,1),r--),s.busy=!1);return this},t}()},function(t,e,n){"use strict";n.d(e,"a",function(){return c});var r=n(1),s=n(2),i=n(0),o=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),c=function(t){function e(n,r,s){var i=t.call(this)||this;return i.channel=null,i._status=e.STATE_NEW,i._error=null,i._centrifuge=null,i._isResubscribe=!1,i._recovered=!1,i._ready=!1,i._promise=null,i._noResubscribe=!1,i._centrifuge=n,i.channel=r,i.setEvents(s),i._initializePromise(),i}return o(e,t),e.prototype.setEvents=function(t){if(t)if(Object(r.c)(t))this.on("message",t);else if(Object.prototype.toString.call(t)===Object.prototype.toString.call({}))for(var e=["message","join","leave","unsubscribe","subscribe","error"],n=0,s=e.length;n<s;n++){var i=e[n];i in t&&this.on(i,t[i])}},e.prototype.setNew=function(){this._status=e.STATE_NEW},e.prototype.setSubscribing=function(){!0===this._ready&&(this._initializePromise(),this._isResubscribe=!0),this._status=e.STATE_SUBSCRIBING},e.prototype.setUnsubscribed=function(t){this._status!==e.STATE_UNSUBSCRIBED&&(this._status=e.STATE_UNSUBSCRIBED,!0===t&&(this._noResubscribe=!0),this.triggerUnsubscribe())},e.prototype.setSubscribeSuccess=function(t){if(this._status!==e.STATE_SUCCESS){this._recovered=t,this._status=e.STATE_SUCCESS;var n=this._getSubscribeSuccess();this.trigger("subscribe",[n]),this._resolve(n)}},e.prototype.setSubscribeError=function(t){if(this._status!==e.STATE_ERROR){this._status=e.STATE_ERROR,this._error=t;var n=this._getSubscribeError();this.trigger("error",[n]),this._reject(n)}},e.prototype.triggerUnsubscribe=function(){this.trigger("unsubscribe",[{channel:this.channel}])},e.prototype.isUnsubscribed=function(){return this._status===e.STATE_UNSUBSCRIBED},e.prototype.isSuccess=function(){return this._status===e.STATE_SUCCESS},e.prototype.isSubscribing=function(){return this._status===e.STATE_SUBSCRIBING},e.prototype.shouldResubscribe=function(){return!this._noResubscribe},e.prototype.ready=function(t,e){this._ready&&(this.isSuccess()?t(this._getSubscribeSuccess()):e(this._getSubscribeError()))},e.prototype.subscribe=function(){if(this._status!==e.STATE_SUCCESS)return this._centrifuge.subscribeSub(this),this},e.prototype.unsubscribe=function(){this.setUnsubscribed(!0),this._centrifuge.unsubscribeSub(this)},e.prototype.publish=function(t){return this._request("publish",t)},e.prototype.presence=function(){return this._request("presence")},e.prototype.history=function(){return this._request("history")},e.prototype._initializePromise=function(){var t=this;this._ready=!1,this._promise=new Promise(function(e,n){t._resolve=function(n){t._ready=!0,e(n)},t._reject=function(e){t._ready=!0,n(e)}})},e.prototype._getSubscribeSuccess=function(){return{channel:this.channel,isResubscribe:this._isResubscribe,recovered:this._recovered}},e.prototype._getSubscribeError=function(){var t=this._error;return t.channel=this.channel,t.isResubscribe=this._isResubscribe,t},e.prototype._request=function(t,e){var n=this;return new Promise(function(r,s){if(n.isUnsubscribed())return void s(i.Centrifuge.createErrorObject("subscription unsubscribed","fix"));n._promise.then(function(){if(!n._centrifuge.isConnected())return void s(i.Centrifuge.createErrorObject("disconnected","retry"));var o={channel:n.channel};e&&(o.data=e),n._centrifuge.addMessage({method:t,params:o}).then(function(t){r(t)},function(t){s(t)})},function(t){s(t)})})},e.STATE_NEW=0,e.STATE_SUBSCRIBING=1,e.STATE_SUCCESS=2,e.STATE_ERROR=3,e.STATE_UNSUBSCRIBED=4,e}(s.a)}])});
{
"name": "centrifuge-ts",
"version": "1.0.2",
"version": "1.0.3",
"description": "Centrifuge javascript client",

@@ -8,7 +8,8 @@ "main": "dist/centrifuge.js",

"devDependencies": {
"@types/node": "^9.3.0",
"@types/node": "^9.4.0",
"protobufjs": "^6.8.4",
"ts-loader": "^3.3.1",
"tslint": "^5.9.1",
"typescript": "^2.6.2",
"uglifyjs-webpack-plugin": "^1.1.6",
"uglifyjs-webpack-plugin": "^1.1.8",
"webpack": "^3.10.0"

@@ -15,0 +16,0 @@ },

@@ -41,20 +41,20 @@ declare var ActiveXObject: ActiveXObject;

public static jsonpCallbacks: any = {};
public static nextJSONPCallbackID: number = 1;
public static nextJSONPCallbackID = 1;
private _config: ICentrifugeConfig = {};
private _status: string = 'disconnected';
private _isSockJS: boolean = false;
private _status = 'disconnected';
private _isSockJS = false;
private _transport: any = null;
private _transportName: string = null;
private _transportClosed: boolean = true;
private _reconnect: boolean = true;
private _reconnecting: boolean = false;
private _numRefreshFailed: number = 0;
private _transportClosed = true;
private _reconnect = true;
private _reconnecting = false;
private _numRefreshFailed = 0;
private _refreshTimeout: any = null;
private _pongTimeout: any = null;
private _pingInterval: any = null;
private _messageId: number = 0;
private _messageId = 0;
private _messages: ICentrifugeMessage[] = [];
private _isBatching: boolean = false;
private _isAuthBatching: boolean = false;
private _isBatching = false;
private _isAuthBatching = false;
private _authChannels: any = {};

@@ -64,3 +64,3 @@ private _clientID: string = null;

private _subs: any = {};
private _retries: number = 0;
private _retries = 0;
private _latency: number = null;

@@ -147,3 +147,3 @@ private _latencyStart: Date = null;

this._authChannels = {};
let channels = [];
const channels = [];

@@ -163,4 +163,4 @@ for (channel in authChannels) {

const cb = (error: boolean, data: any) => {
if (error === true) {
const cb = (err: boolean, _data: any) => {
if (err === true) {
this._debug('Authorization request failed');

@@ -192,3 +192,3 @@ for (i in channels) {

channel = channels[i];
const channelResponse = data[channel];
const channelResponse = _data[channel];
if (!channelResponse) {

@@ -252,7 +252,19 @@ // subscription:error

if (transport === 'ajax') {
this._ajax(this._config.authEndpoint, this._config.authParams, this._config.authHeaders, data, cb);
this._ajax(
this._config.authEndpoint,
this._config.authParams,
this._config.authHeaders,
data,
cb
);
} else if (transport === 'jsonp') {
this._jsonp(this._config.authEndpoint, this._config.authParams, this._config.authHeaders, data, cb);
this._jsonp(
this._config.authEndpoint,
this._config.authParams,
this._config.authHeaders,
data,
cb
);
} else {
throw 'Unknown private channel auth transport ' + transport;
throw new Error('Unknown private channel auth transport ' + transport);
}

@@ -264,6 +276,6 @@ }

if (!isString(channel)) {
throw 'Illegal argument type: channel must be a string';
throw new Error('Illegal argument type: channel must be a string');
}
if (!this._config.resubscribe && !this.isConnected()) {
throw 'Can not only subscribe in connected state when resubscribe option is off';
throw new Error('Can not only subscribe in connected state when resubscribe option is off');
}

@@ -336,2 +348,5 @@

if (this.isConnected()) {
const channel = sub.channel;
// remove unsubscribed channel in _subs
delete this._subs[channel];
// No need to unsubscribe in disconnected state - i.e. client already unsubscribed.

@@ -341,3 +356,3 @@ this.addMessage(<ICentrifugeUnsubscribeMessage>{

params: {
channel: sub.channel
channel
}

@@ -452,3 +467,3 @@ }).then((response: ICentrifugeUnsubscribeResponse) => {

xhr.setRequestHeader('Content-Type', 'application/json');
for (let headerName in headers) {
for (const headerName in headers) {
if (headers.hasOwnProperty(headerName)) {

@@ -462,6 +477,6 @@ xhr.setRequestHeader(headerName, headers[headerName]);

if (xhr.status === 200) {
let data,
let callbackData,
parsed = false;
try {
data = JSON.parse(xhr.responseText);
callbackData = JSON.parse(xhr.responseText);
parsed = true;

@@ -472,3 +487,3 @@ } catch (e) {

if (parsed) { // prevents double execution.
callback(false, data);
callback(false, callbackData);
}

@@ -516,3 +531,3 @@ } else {

if (!config.url) {
throw 'Missing required configuration parameter \'url\' specifying server URL';
throw new Error('Missing required configuration parameter \'url\' specifying server URL');
}

@@ -523,3 +538,3 @@ config.url = stripSlash(config.url);

if (!config.insecure) {
throw 'Missing required configuration parameter \'user\' specifying user\'s unique ID in your application';
throw new Error('Missing required configuration parameter \'user\' specifying user\'s unique ID in your application');
} else {

@@ -536,3 +551,3 @@ this._debug('Configuration parameter \'user\' not found but this is OK for insecure mode - anonymous access will be used');

if (!config.insecure) {
throw 'Missing required configuration parameter \'timestamp\'';
throw new Error('Missing required configuration parameter \'timestamp\'');
} else {

@@ -549,3 +564,3 @@ this._debug('Configuration parameter \'timestamp\' not found but this is OK for insecure mode');

if (!config.insecure) {
throw 'Missing required configuration parameter \'token\' specifying the sign of authorization request';
throw new Error('Missing required configuration parameter \'token\' specifying the sign of authorization request');
} else {

@@ -614,3 +629,3 @@ this._debug('Configuration parameter \'token\' not found but this is OK for insecure mode');

// fire errbacks of registered calls.
for (let uid in this._callbacks) {
for (const uid in this._callbacks) {
if (this._callbacks.hasOwnProperty(uid)) {

@@ -628,3 +643,3 @@ const callbacks = this._callbacks[uid];

// fire unsubscribe events
for (let channel in this._subs) {
for (const channel in this._subs) {
if (this._subs.hasOwnProperty(channel)) {

@@ -690,8 +705,5 @@ const sub = this._getSub(channel);

}
let encodedMessages = [];
for (const i in messages) {
encodedMessages.push(JSON.stringify(messages[i]))
}
this._transport.send(encodedMessages.join("\n"));
this._debug('Send', messages.length === 1 ? messages[0] : messages);
const _messages = messages.length === 1 ? messages[0] : messages;
this._transport.send(JSON.stringify(_messages));
this._debug('Send', _messages);
}

@@ -773,4 +785,4 @@

const cb = (error: boolean, data: ICentrifugeCredentials) => {
if (error === true) {
const cb = (err: boolean, data: ICentrifugeCredentials) => {
if (err === true) {
// We don't perform any connection status related actions here as we are

@@ -821,7 +833,19 @@ // relying on Centrifugo that must close connection eventually.

if (transport === 'ajax') {
this._ajax(this._config.refreshEndpoint, this._config.refreshParams, this._config.refreshHeaders, this._config.refreshData, cb);
this._ajax(
this._config.refreshEndpoint,
this._config.refreshParams,
this._config.refreshHeaders,
this._config.refreshData,
cb
);
} else if (transport === 'jsonp') {
this._jsonp(this._config.refreshEndpoint, this._config.refreshParams, this._config.refreshHeaders, this._config.refreshData, cb);
this._jsonp(
this._config.refreshEndpoint,
this._config.refreshParams,
this._config.refreshHeaders,
this._config.refreshData,
cb
);
} else {
throw 'Unknown refresh transport ' + transport;
throw new Error('Unknown refresh transport ' + transport);
}

@@ -863,3 +887,3 @@ }

this.startAuthBatching();
for (let channel in this._subs) {
for (const channel in this._subs) {
if (this._subs.hasOwnProperty(channel)) {

@@ -878,2 +902,3 @@ const sub = this._getSub(channel);

this.trigger('connect', [{
version: response.version,
client: response.client,

@@ -895,3 +920,3 @@ transport: this._transportName,

messages = messages.reverse();
for (let i in messages) {
for (const i in messages) {
if (messages.hasOwnProperty(i)) {

@@ -1032,3 +1057,3 @@ this._messageResponse(<ICentrifugeMessage>{

// array of responses received
for (let i in data) {
for (const i in data) {
if (data.hasOwnProperty(i)) {

@@ -1067,3 +1092,3 @@ this._dispatchMessage(data[i]);

if (!isFunction(WebSocket)) {
throw 'No Websocket support and no SockJS configured, can not connect';
throw new Error('No Websocket support and no SockJS configured, can not connect');
}

@@ -1156,10 +1181,5 @@ this._transport = new WebSocket(this._getWebsocketEndpoint());

this._transport.onmessage = (event: any) => {
const replies = event.data.split("\n");
for (const i in replies) {
if (replies.hasOwnProperty(i) && replies[i]) {
const data = JSON.parse(replies[i]);
this._debug('Received', data);
this._receive(data);
}
}
const data = JSON.parse(event.data);
this._debug('Received', data);
this._receive(data);
this._restartPing();

@@ -1166,0 +1186,0 @@ };

export interface ICentrifugeConnectResponse {
version?: string;
expires: boolean;

@@ -3,0 +4,0 @@ expired: boolean;

@@ -1,4 +0,3 @@

import {ICentrifugeJoinResponse} from './ICentrifugeJoinResponse';
export interface ICentrifugeLeaveResponse extends ICentrifugeJoinResponse {
export interface ICentrifugeLeaveResponse {
channel: string;
}

@@ -1,4 +0,7 @@

import {ICentrifugeConnectMessage} from './ICentrifugeConnectMessage';
import {ICentrifugeCredentials} from './ICentrifugeCredentials';
export interface ICentrifugeRefreshMessage extends ICentrifugeConnectMessage {
export interface ICentrifugeRefreshMessage {
method?: string;
uid?: string;
params?: ICentrifugeCredentials;
}

@@ -1,4 +0,7 @@

import {ICentrifugeConnectResponse} from './ICentrifugeConnectResponse';
export interface ICentrifugeRefreshResponse extends ICentrifugeConnectResponse {
export interface ICentrifugeRefreshResponse {
version?: string;
expires: boolean;
expired: boolean;
client: string;
ttl: number;
}

@@ -1,4 +0,3 @@

import {ICentrifugeJoinResponse} from './ICentrifugeJoinResponse';
export interface ICentrifugeUnsubscribeResponse extends ICentrifugeJoinResponse {
export interface ICentrifugeUnsubscribeResponse {
channel: string;
}

@@ -22,3 +22,3 @@ export class Observable {

} else if (fn) {
let arr = this.__callbacks[events];
const arr = this.__callbacks[events];
for (let i = 0, cb; (cb = arr && arr[i]); ++i) {

@@ -39,3 +39,3 @@ if (cb === fn) {

public trigger(name: string, args: any[]): this {
let fns = this.__callbacks[name] || [];
const fns = this.__callbacks[name] || [];
for (let i = 0, fn; (fn = fns[i]); ++i) {

@@ -42,0 +42,0 @@ if (!fn['busy']) {

@@ -15,7 +15,7 @@ import {

public static STATE_NEW: number = 0;
public static STATE_SUBSCRIBING: number = 1;
public static STATE_SUCCESS: number = 2;
public static STATE_ERROR: number = 3;
public static STATE_UNSUBSCRIBED: number = 4;
public static STATE_NEW = 0;
public static STATE_SUBSCRIBING = 1;
public static STATE_SUCCESS = 2;
public static STATE_ERROR = 3;
public static STATE_UNSUBSCRIBED = 4;

@@ -27,7 +27,7 @@ public channel: string = null;

private _centrifuge: Centrifuge = null;
private _isResubscribe: boolean = false;
private _recovered: boolean = false;
private _ready: boolean = false;
private _isResubscribe = false;
private _recovered = false;
private _ready = false;
private _promise: Promise<any> = null;
private _noResubscribe: boolean = false;
private _noResubscribe = false;
private _resolve: Function;

@@ -34,0 +34,0 @@ private _reject: Function;

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