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.0 to 1.0.2

LICENSE

214

dist/centrifuge.js

@@ -82,6 +82,6 @@ (function webpackUniversalModuleDefinition(root, factory) {

Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* WEBPACK VAR INJECTION */(function(global) {/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Centrifuge", function() { return Centrifuge; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "Centrifuge", function() { return Centrifuge; });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__Functions__ = __webpack_require__(1);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__Observable__ = __webpack_require__(2);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__Subscription__ = __webpack_require__(4);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__Subscription__ = __webpack_require__(3);
var __extends = (this && this.__extends) || (function () {

@@ -131,5 +131,5 @@ var extendStatics = Object.setPrototypeOf ||

}
Centrifuge.prototype.connect = function (callback) {
Centrifuge.prototype.connect = function () {
if (this.isConnected()) {
this._debug('connect called when already connected');
this._debug('Connect called when already connected');
return;

@@ -140,13 +140,10 @@ }

}
this._debug('start connecting');
this._setStatus('connecting');
this._debug('Start connecting');
this._clientID = null;
this._reconnect = true;
if (callback) {
this.on('connect', callback);
}
this._setStatus('connecting');
this._setTransport();
};
Centrifuge.prototype.disconnect = function () {
this._disconnect('client', false);
this._disconnect('client');
};

@@ -162,3 +159,5 @@ Centrifuge.prototype.isConnected = function () {

method: 'ping'
}, false);
}).then(function (response) {
}, function (error) {
});
};

@@ -169,3 +168,3 @@ Centrifuge.prototype.startBatching = function () {

Centrifuge.prototype.stopBatching = function (flush) {
flush = flush || false;
if (flush === void 0) { flush = false; }
this._isBatching = false;

@@ -205,3 +204,3 @@ if (flush === true) {

if (error === true) {
_this._debug('authorization request failed');
_this._debug('Authorization request failed');
for (i in channels) {

@@ -328,3 +327,3 @@ if (channels.hasOwnProperty(i)) {

sub.setSubscribing();
if (Object(__WEBPACK_IMPORTED_MODULE_0__Functions__["h" /* startsWith */])(channel, this._config.privateChannelPrefix)) {
if (Object(__WEBPACK_IMPORTED_MODULE_0__Functions__["g" /* startsWith */])(channel, this._config.privateChannelPrefix)) {
if (this._isAuthBatching) {

@@ -387,3 +386,3 @@ this._authChannels[channel] = true;

};
Centrifuge.prototype.addMessage = function (message, registerCall) {
Centrifuge.prototype.addMessage = function (message) {
var _this = this;

@@ -399,5 +398,3 @@ return new Promise(function (resolve, reject) {

}
if (registerCall !== false) {
_this.registerCall(uid, resolve, reject);
}
_this.registerCall(uid, resolve, reject);
});

@@ -419,3 +416,3 @@ };

}
Object(__WEBPACK_IMPORTED_MODULE_0__Functions__["f" /* log */])('info', args);
Object(__WEBPACK_IMPORTED_MODULE_0__Functions__["e" /* log */])('info', args);
};

@@ -428,3 +425,3 @@ Centrifuge.prototype._debug = function () {

if (this._config.debug === true) {
Object(__WEBPACK_IMPORTED_MODULE_0__Functions__["f" /* log */])('debug', args);
Object(__WEBPACK_IMPORTED_MODULE_0__Functions__["e" /* log */])('debug', args);
}

@@ -436,3 +433,3 @@ };

}
this._debug('sending JSONP request to', url);
this._debug('Sending JSONP request to', url);
var callbackName = 'centrifuge_jsonp_' + Centrifuge.nextJSONPCallbackID.toString();

@@ -455,3 +452,3 @@ Centrifuge.nextJSONPCallbackID++;

'&data=' + encodeURIComponent(JSON.stringify(data)) +
'&' + Object(__WEBPACK_IMPORTED_MODULE_0__Functions__["g" /* objectToQuery */])(params);
'&' + Object(__WEBPACK_IMPORTED_MODULE_0__Functions__["f" /* objectToQuery */])(params);
var head = document.getElementsByTagName('head')[0] || document.documentElement;

@@ -461,5 +458,5 @@ head.insertBefore(script, head.firstChild);

Centrifuge.prototype._ajax = function (url, params, headers, data, callback) {
this._debug('sending AJAX request to', url);
this._debug('Sending AJAX request to', url);
var xhr = (XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'));
var query = Object(__WEBPACK_IMPORTED_MODULE_0__Functions__["g" /* objectToQuery */])(params);
var query = Object(__WEBPACK_IMPORTED_MODULE_0__Functions__["f" /* objectToQuery */])(params);
if (query.length > 0) {

@@ -506,3 +503,3 @@ query = '?' + query;

Centrifuge.prototype._configure = function (config) {
this._debug('Configuring centrifuge object with', config);
this._debug('Configuring Centrifuge with', config);
config = Object.assign({

@@ -535,26 +532,3 @@ retry: 1000,

}
config.url = Object(__WEBPACK_IMPORTED_MODULE_0__Functions__["i" /* stripSlash */])(config.url);
if (Object(__WEBPACK_IMPORTED_MODULE_0__Functions__["a" /* endsWith */])(config.url, 'connection/websocket')) {
this._debug('client will connect to raw Websocket endpoint');
}
else {
if (Object(__WEBPACK_IMPORTED_MODULE_0__Functions__["a" /* endsWith */])(config.url, 'connection')) {
this._debug('client will connect to SockJS endpoint');
}
else {
this._debug('client will detect connection endpoint itself');
}
if (config.sockJS !== null) {
this._debug('SockJS explicitly provided in options');
}
else {
if (Object(__WEBPACK_IMPORTED_MODULE_0__Functions__["e" /* isUndefined */])(global['SockJS'])) {
throw 'Include SockJS client library before Centrifuge javascript client library or provide SockJS object in options or use raw Websocket connection endpoint';
}
else {
this._debug('Use globally defined SockJS');
config.sockJS = global['SockJS'];
}
}
}
config.url = Object(__WEBPACK_IMPORTED_MODULE_0__Functions__["h" /* stripSlash */])(config.url);
if (!config.user) {

@@ -565,3 +539,3 @@ if (!config.insecure) {

else {
this._debug('user not found but this is OK for insecure mode - anonymous access will be used');
this._debug('Configuration parameter \'user\' not found but this is OK for insecure mode - anonymous access will be used');
}

@@ -579,3 +553,3 @@ }

else {
this._debug('Configuration parameter \'v\' not found but this is OK for insecure mode');
this._debug('Configuration parameter \'timestamp\' not found but this is OK for insecure mode');
}

@@ -611,3 +585,3 @@ }

.replace('wss://', 'https://');
url = Object(__WEBPACK_IMPORTED_MODULE_0__Functions__["i" /* stripSlash */])(url);
url = Object(__WEBPACK_IMPORTED_MODULE_0__Functions__["h" /* stripSlash */])(url);
if (!Object(__WEBPACK_IMPORTED_MODULE_0__Functions__["a" /* endsWith */])(this._config.url, 'connection')) {

@@ -623,3 +597,3 @@ url = url + '/connection';

.replace('https://', 'wss://');
url = Object(__WEBPACK_IMPORTED_MODULE_0__Functions__["i" /* stripSlash */])(url);
url = Object(__WEBPACK_IMPORTED_MODULE_0__Functions__["h" /* stripSlash */])(url);
if (!Object(__WEBPACK_IMPORTED_MODULE_0__Functions__["a" /* endsWith */])(this._config.url, 'connection/websocket')) {

@@ -678,18 +652,18 @@ url = url + '/connection/websocket';

};
Centrifuge.prototype._setStatus = function (newStatus) {
if (this._status !== newStatus) {
this._debug('Status', this._status, '->', newStatus);
this._status = newStatus;
Centrifuge.prototype._setStatus = function (status) {
if (this._status !== status) {
this._debug('Status:', this._status, '->', status);
this._status = status;
}
};
Centrifuge.prototype._disconnect = function (reason, shouldReconnect) {
if (shouldReconnect === void 0) { shouldReconnect = false; }
if (this.isDisconnected()) {
return;
}
this._debug('disconnected:', reason, shouldReconnect);
var reconnect = shouldReconnect || false;
if (reconnect === false) {
this._debug('Disconnected:', reason + '.', 'shouldReconnect:', shouldReconnect);
if (shouldReconnect === false) {
this._reconnect = false;
}
this._clearConnectedState(reconnect);
this._clearConnectedState(shouldReconnect);
if (!this.isDisconnected()) {

@@ -703,3 +677,3 @@ this._setStatus('disconnected');

reason: reason,
reconnect: reconnect,
reconnect: shouldReconnect,
}]);

@@ -716,3 +690,2 @@ }

}
this._debug('Send', messages);
var encodedMessages = [];

@@ -723,2 +696,3 @@ for (var i in messages) {

this._transport.send(encodedMessages.join("\n"));
this._debug('Send', messages.length === 1 ? messages[0] : messages);
};

@@ -757,3 +731,3 @@ Centrifuge.prototype._getNextMessageId = function () {

Centrifuge.prototype._resetRetry = function () {
this._debug('reset retries count to 0');
this._debug('Reset retries count to 0');
this._retries = 0;

@@ -781,5 +755,5 @@ };

var _this = this;
this._debug('refresh credentials');
this._debug('Refresh credentials');
if (this._config.refreshAttempts === 0) {
this._debug('refresh attempts set to 0, do not send refresh request at all');
this._debug('Refresh attempts set to 0, do not send refresh request at all');
this._refreshFailed();

@@ -793,3 +767,3 @@ return;

if (error === true) {
_this._debug('error getting connection credentials from refresh endpoint', data);
_this._debug('Error getting connection credentials from refresh endpoint', data);
_this._numRefreshFailed++;

@@ -819,7 +793,7 @@ if (_this._refreshTimeout) {

if (_this.isDisconnected()) {
_this._debug('credentials refreshed, connect from scratch');
_this._debug('Credentials refreshed, connect from scratch');
_this.connect();
}
else {
_this._debug('send refreshed credentials');
_this._debug('Send refreshed credentials');
_this.addMessage({

@@ -1013,3 +987,3 @@ method: 'refresh',

if (message === undefined || message === null) {
this._debug('dispatch: got undefined or null message');
this._debug('Dispatch: got undefined or null message');
return;

@@ -1085,8 +1059,2 @@ }

_this._resetRetry();
if (!Object(__WEBPACK_IMPORTED_MODULE_0__Functions__["d" /* isString */])(_this._config.user)) {
Centrifuge.log('user expected to be string');
}
if (!Object(__WEBPACK_IMPORTED_MODULE_0__Functions__["d" /* isString */])(_this._config.info)) {
Centrifuge.log('info expected to be string');
}
var msg = {

@@ -1110,7 +1078,7 @@ method: 'connect',

this._transport.onerror = function (error) {
_this._debug('transport level error', error);
_this._debug('Transport level error', error);
};
this._transport.onclose = function (event) {
_this._transportClosed = true;
var reason = 'connection closed';
var reason = 'Connection closed';
var reconnect = true;

@@ -1120,3 +1088,3 @@ if (event && 'reason' in event && event.reason) {

var advice = JSON.parse(event.reason);
_this._debug('reason is an advice object', advice);
_this._debug(reason + '. Reason is an advice object:', advice);
reason = advice.reason;

@@ -1127,3 +1095,3 @@ reconnect = advice.reconnect;

reason = event.reason;
_this._debug('reason is a plain string', reason);
_this._debug(reason + '. Reason is a plain string:', reason);
reconnect = reason !== 'disconnect';

@@ -1143,3 +1111,3 @@ }

var interval = _this._getRetryInterval();
_this._debug('reconnect after ' + interval + ' milliseconds');
_this._debug('Reconnect after ' + interval + ' milliseconds');
setTimeout(function () {

@@ -1170,3 +1138,2 @@ if (_this._reconnect === true) {

/* WEBPACK VAR INJECTION */}.call(__webpack_exports__, __webpack_require__(3)))

@@ -1178,21 +1145,17 @@ /***/ }),

"use strict";
/* harmony export (immutable) */ __webpack_exports__["e"] = isUndefined;
/* harmony export (immutable) */ __webpack_exports__["c"] = isFunction;
/* harmony export (immutable) */ __webpack_exports__["d"] = isString;
/* harmony export (immutable) */ __webpack_exports__["f"] = log;
/* harmony export (immutable) */ __webpack_exports__["i"] = stripSlash;
/* harmony export (immutable) */ __webpack_exports__["h"] = startsWith;
/* harmony export (immutable) */ __webpack_exports__["a"] = endsWith;
/* harmony export (immutable) */ __webpack_exports__["b"] = errorExists;
/* harmony export (immutable) */ __webpack_exports__["g"] = objectToQuery;
function isUndefined(value) {
return typeof value === 'undefined';
}
function isFunction(value) {
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "c", function() { return isFunction; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "d", function() { return isString; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "e", function() { return log; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "h", function() { return stripSlash; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "g", function() { return startsWith; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return endsWith; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return errorExists; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "f", function() { return objectToQuery; });
var isFunction = function (value) {
return typeof value === 'function';
}
function isString(value) {
};
var isString = function (value) {
return typeof value === 'string';
}
function log(level) {
};
var log = function (level) {
var args = [];

@@ -1211,16 +1174,16 @@ for (var _i = 1; _i < arguments.length; _i++) {

}
}
function stripSlash(value) {
};
var stripSlash = function (value) {
return value.replace(/\/$/, '');
}
function startsWith(value, prefix) {
};
var startsWith = function (value, prefix) {
return value.lastIndexOf(prefix, 0) === 0;
}
function endsWith(value, suffix) {
};
var endsWith = function (value, suffix) {
return value.indexOf(suffix, value.length - suffix.length) !== -1;
}
function errorExists(data) {
};
var errorExists = function (data) {
return 'error' in data && data.error !== null && data.error !== '';
}
function objectToQuery(object) {
};
var objectToQuery = function (object) {
var p = [];

@@ -1233,3 +1196,3 @@ for (var i in object) {

return p.join('&');
}
};

@@ -1302,29 +1265,2 @@

/* 3 */
/***/ (function(module, exports) {
var g;
// This works in non-strict mode
g = (function() {
return this;
})();
try {
// This works if eval is allowed (see CSP)
g = g || Function("return this")() || (1,eval)("this");
} catch(e) {
// This works if the window reference is available
if(typeof window === "object")
g = window;
}
// g can still be undefined, but nothing to do about it...
// We return undefined, instead of nothing here, so it's
// easier to handle this case. if(!global) { ...}
module.exports = g;
/***/ }),
/* 4 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

@@ -1416,3 +1352,3 @@

};
Subscription.prototype.setSubscribeError = function (err) {
Subscription.prototype.setSubscribeError = function (error) {
if (this._status === Subscription.STATE_ERROR) {

@@ -1422,3 +1358,3 @@ return;

this._status = Subscription.STATE_ERROR;
this._error = err;
this._error = error;
var errContext = this._getSubscribeError();

@@ -1425,0 +1361,0 @@ this.trigger('error', [errContext]);

@@ -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 i=n[s]={i:s,l:!1,exports:{}};return t[s].call(i.exports,i,i.exports,e),i.l=!0,i.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}),function(t){n.d(e,"Centrifuge",function(){return c});var s=n(1),i=n(2),r=n(4),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(e){function n(t){var n=e.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(t),n}return o(n,e),n.prototype.connect=function(t){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,t&&this.on("connect",t),this._setTransport())},n.prototype.disconnect=function(){this._disconnect("client",!1)},n.prototype.isConnected=function(){return"connected"===this._status},n.prototype.isDisconnected=function(){return"disconnected"===this._status},n.prototype.ping=function(){this.addMessage({method:"ping"},!1)},n.prototype.startBatching=function(){this._isBatching=!0},n.prototype.stopBatching=function(t){t=t||!1,this._isBatching=!1,!0===t&&this.flush()},n.prototype.flush=function(){var t=this._messages.slice(0);this._messages=[],this._send(t)},n.prototype.startAuthBatching=function(){this._isAuthBatching=!0},n.prototype.stopAuthBatching=function(){var t,e,n=this;this._isAuthBatching=!1;var i=this._authChannels;this._authChannels={};var r=[];for(e in i)if(i.hasOwnProperty(e)){if(!this._getSub(e))continue;r.push(e)}if(0!==r.length){var o=function(s,i){if(!0!==s){var o=!1;n._isBatching||(n.startBatching(),o=!0);for(t in r)if(r.hasOwnProperty(t)){e=r[t];var c=i[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 r)r.hasOwnProperty(t)&&(e=r[t],n._subscribeError({error:"authorization request failed",advice:"fix",body:{channel:e}}))}},c={client:this.getClientId(),channels:r};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)}}}},n.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 i=new r.a(this,t,e);return this._subs[t]=i,i.subscribe(),i},n.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.h)(n,this._config.privateChannelPrefix))this._isAuthBatching?this._authChannels[n]=!0:(this.startAuthBatching(),this.subscribeSub(t),this.stopAuthBatching());else{var i={method:"subscribe",params:{channel:n}};!0===this._recover(n)&&(i.params.recover=!0,i.params.last=this._getLastID(n)),this.addMessage(i).then(function(t){e._subscribeResponse(t)},function(t){e._subscribeError(t)})}},n.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){})},n.prototype.getClientId=function(){return this._clientID},n.prototype.registerCall=function(t,e,i){var r=this;this._callbacks[t]={callback:e,errback:i},setTimeout(function(){delete r._callbacks[t],Object(s.c)(i)&&i(n.createErrorObject("timeout","retry"))},this._config.timeout)},n.prototype.addMessage=function(t,e){var n=this;return new Promise(function(s,i){var r=n._getNextMessageId()+"";t.uid=r,!0===n._isBatching?n._messages.push(t):n._send([t]),!1!==e&&n.registerCall(r,s,i)})},n.createErrorObject=function(t,e){var n={error:t};return e&&(n.advice=e),n},n.log=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];Object(s.f)("info",t)},n.prototype._debug=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];!0===this._config.debug&&Object(s.f)("debug",t)},n.prototype._jsonp=function(t,e,i,r,o){Object.keys(i).length>0&&n.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_"+n.nextJSONPCallbackID.toString();n.nextJSONPCallbackID++;var a=document.createElement("script"),u=setTimeout(function(){n.jsonpCallbacks[c]=function(){},o(!0,"timeout")},3e3);n.jsonpCallbacks[c]=function(t){clearTimeout(u),o(!1,t),delete n.jsonpCallbacks[c]};var h="Centrifuge._jsonpCallbacks['"+c+"']";a.src=this._config.authEndpoint+"?callback="+encodeURIComponent(h)+"&data="+encodeURIComponent(JSON.stringify(r))+"&"+Object(s.g)(e);var f=document.getElementsByTagName("head")[0]||document.documentElement;f.insertBefore(a,f.firstChild)},n.prototype._ajax=function(t,e,i,r,o){this._debug("sending AJAX request to",t);var c=XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),a=Object(s.g)(e);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 i)i.hasOwnProperty(u)&&c.setRequestHeader(u,i[u]);return c.onreadystatechange=function(){if(4===c.readyState)if(200===c.status){var t,e=!1;try{t=JSON.parse(c.responseText),e=!0}catch(t){o(!0,"JSON returned was invalid, yet status code was 200. Data was: "+c.responseText)}e&&o(!1,t)}else n.log("Could not get auth info from application",c.status),o(!0,c.status)},setTimeout(function(){c.send(JSON.stringify(r))},20),c},n.prototype._configure=function(e){if(this._debug("Configuring centrifuge object with",e),e=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"},e),!e.url)throw"Missing required configuration parameter 'url' specifying server URL";if(e.url=Object(s.i)(e.url),Object(s.a)(e.url,"connection/websocket"))this._debug("client will connect to raw Websocket endpoint");else if(Object(s.a)(e.url,"connection")?this._debug("client will connect to SockJS endpoint"):this._debug("client will detect connection endpoint itself"),null!==e.sockJS)this._debug("SockJS explicitly provided in options");else{if(Object(s.e)(t.SockJS))throw"Include SockJS client library before Centrifuge javascript client library or provide SockJS object in options or use raw Websocket connection endpoint";this._debug("Use globally defined SockJS"),e.sockJS=t.SockJS}if(e.user)Object(s.d)(e.user)||n.log("Configuration parameter 'user' expected to be string");else{if(!e.insecure)throw"Missing required configuration parameter 'user' specifying user's unique ID in your application";this._debug("user not found but this is OK for insecure mode - anonymous access will be used")}if(e.timestamp)Object(s.d)(e.timestamp)||n.log("Configuration parameter 'timestamp' expected to be string");else{if(!e.insecure)throw"Missing required configuration parameter 'timestamp'";this._debug("Configuration parameter 'v' not found but this is OK for insecure mode")}if(e.token)Object(s.d)(e.token)||n.log("Configuration parameter 'token' expected to be string");else{if(!e.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")}e.info&&!Object(s.d)(e.info)&&n.log("Configuration parameter 'info' expected to be string"),this._config=e},n.prototype._getSockjsEndpoint=function(){var t=this._config.url;return t=t.replace("ws://","http://").replace("wss://","https://"),t=Object(s.i)(t),Object(s.a)(this._config.url,"connection")||(t+="/connection"),t},n.prototype._getWebsocketEndpoint=function(){var t=this._config.url;return t=t.replace("http://","ws://").replace("https://","wss://"),t=Object(s.i)(t),Object(s.a)(this._config.url,"connection/websocket")||(t+="/connection/websocket"),t},n.prototype._recover=function(t){return t in this._lastMessageID},n.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),"")},n.prototype._getSub=function(t){return this._subs[t]||null},n.prototype._clearConnectedState=function(t){this._clientID=null;for(var e in this._callbacks)if(this._callbacks.hasOwnProperty(e)){var s=this._callbacks[e],i=s.errback;if(!i)continue;i(n.createErrorObject("disconnected","retry"))}this._callbacks={};for(var r in this._subs)if(this._subs.hasOwnProperty(r)){var o=this._getSub(r);t?(o.isSuccess()&&o.triggerUnsubscribe(),o.setSubscribing()):o.setUnsubscribed()}this._config.resubscribe&&this._reconnect||(this._subs={})},n.prototype._setStatus=function(t){this._status!==t&&(this._debug("Status",this._status,"->",t),this._status=t)},n.prototype._disconnect=function(t,e){if(!this.isDisconnected()){this._debug("disconnected:",t,e);var n=e||!1;!1===n&&(this._reconnect=!1),this._clearConnectedState(n),this.isDisconnected()||(this._setStatus("disconnected"),this._refreshTimeout&&clearTimeout(this._refreshTimeout),!1===this._reconnecting&&this.trigger("disconnect",[{reason:t,reconnect:n}])),this._transportClosed||this._transport.close()}},n.prototype._send=function(t){if(t.length){this._debug("Send",t);var e=[];for(var n in t)e.push(JSON.stringify(t[n]));this._transport.send(e.join("\n"))}},n.prototype._getNextMessageId=function(){return++this._messageId},n.prototype._stopPing=function(){null!==this._pongTimeout&&clearTimeout(this._pongTimeout),null!==this._pingInterval&&clearInterval(this._pingInterval)},n.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))},n.prototype._restartPing=function(){this._stopPing(),this._startPing()},n.prototype._resetRetry=function(){this._debug("reset retries count to 0"),this._retries=0},n.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)},n.prototype._refreshFailed=function(){this._numRefreshFailed=0,this.isDisconnected()||this._disconnect("refresh failed"),this._config.refreshFailed&&this._config.refreshFailed()},n.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)}}},n.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}])}},n.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 i in s)s.hasOwnProperty(i)&&this._messageResponse({body:s[i]})}else"last"in t&&(this._lastMessageID[e]=t.last);var r=!1;"recovered"in t&&(r=t.recovered),n.setSubscribeSuccess(r)}},n.prototype._subscribeError=function(t){var e=t.channel,n=this._getSub(e);n&&n.isSubscribing()&&(this.trigger("error",[{error:t}]),n.setSubscribeError(t))},n.prototype._unsubscribeResponse=function(t){var e=this._getSub(t.channel);e&&e.setUnsubscribed()},n.prototype._joinResponse=function(t){var e=this._getSub(t.channel);e&&e.trigger("join",[t])},n.prototype._leaveResponse=function(t){var e=this._getSub(t.channel);e&&e.trigger("leave",[t])},n.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)}},n.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])},n.prototype._handleResponse=function(t){var e=t.uid;if(e in this._callbacks){var i=this._callbacks[e];if(delete this._callbacks[e],Object(s.b)(t)){var r=i.errback;if(!r)return;r(n.createErrorObject(t.error,t.advice)),this.trigger("error",[{message:t}])}else{var o=i.callback;if(!o)return;o(t.body)}}},n.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)}},n.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)},n.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(),Object(s.d)(t._config.user)||n.log("user expected to be string"),Object(s.d)(t._config.info)||n.log("info expected to be string");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 i=JSON.parse(e.reason);t._debug("reason is an advice object",i),n=i.reason,s=i.reconnect}catch(i){n=e.reason,t._debug("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 r=t._getRetryInterval();t._debug("reconnect after "+r+" milliseconds"),setTimeout(function(){!0===t._reconnect&&t.connect()},r)}},this._transport.onmessage=function(e){var n=e.data.split("\n");for(var s in n)if(n.hasOwnProperty(s)&&n[s]){var i=JSON.parse(n[s]);t._debug("Received",i),t._receive(i)}t._restartPing()}},n.jsonpCallbacks={},n.nextJSONPCallbackID=1,n}(i.a)}.call(e,n(3))},function(t,e,n){"use strict";function s(t){return void 0===t}function i(t){return"function"==typeof t}function r(t){return"string"==typeof t}function o(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];i(s)&&s.apply(s,e)}}function c(t){return t.replace(/\/$/,"")}function a(t,e){return 0===t.lastIndexOf(e,0)}function u(t,e){return-1!==t.indexOf(e,t.length-e.length)}function h(t){return"error"in t&&null!==t.error&&""!==t.error}function f(t){var e=[];for(var n in t)t.hasOwnProperty(n)&&e.push(encodeURIComponent(n)+(t[n]?"="+encodeURIComponent(t[n]):""));return e.join("&")}e.e=s,e.c=i,e.d=r,e.f=o,e.i=c,e.h=a,e.a=u,e.b=h,e.g=f},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],i=0,r=void 0;r=s&&s[i];++i)r===e&&s.splice(i,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,i=void 0;i=n[s];++s)i.busy||(i.busy=!0,i.apply(this,e),i.one&&(n.splice(s,1),s--),i.busy=!1);return this},t}()},function(t,e){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(t){"object"==typeof window&&(n=window)}t.exports=n},function(t,e,n){"use strict";n.d(e,"a",function(){return c});var s=n(1),i=n(2),r=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,i){var r=t.call(this)||this;return r.channel=null,r._status=e.STATE_NEW,r._error=null,r._centrifuge=null,r._isResubscribe=!1,r._recovered=!1,r._ready=!1,r._promise=null,r._noResubscribe=!1,r._centrifuge=n,r.channel=s,r.setEvents(i),r._initializePromise(),r}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,i=e.length;n<i;n++){var r=e[n];r in t&&this.on(r,t[r])}},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,i){if(n.isUnsubscribed())return void i(r.Centrifuge.createErrorObject("subscription unsubscribed","fix"));n._promise.then(function(){if(!n._centrifuge.isConnected())return void i(r.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){i(t)})},function(t){i(t)})})},e.STATE_NEW=0,e.STATE_SUBSCRIBING=1,e.STATE_SUCCESS=2,e.STATE_ERROR=3,e.STATE_UNSUBSCRIBED=4,e}(i.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 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)}])});

@@ -1,5 +0,2 @@

export * from './src/Functions';
export * from './src/Observable';
export * from './src';
export * from './src/interfaces';
export * from './src/Centrifuge';
export * from './src/Subscription';
{
"name": "centrifuge-ts",
"version": "1.0.0",
"version": "1.0.2",
"description": "Centrifuge javascript client",

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

"devDependencies": {
"@types/node": "^9.3.0",
"protobufjs": "^6.8.4",

@@ -20,3 +21,3 @@ "ts-loader": "^3.3.1",

"contributors": [
"Alexandr Emelin",
"Alexander Emelin",
"Oleg V. Kuzmin"

@@ -23,0 +24,0 @@ ],

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

Browser Javascript client for Centrifugo
========================================
# Browser Javascript client for Centrifugo
See client [documentation](https://fzambia.gitbooks.io/centrifugal/content/clients/javascript.html)
### Contribute
If you want to contribute, install dependencies and run `npm run build` command from root repo folder - this results
in creating unminified (`centrifuge.js`) and minified (`centrifuge.min.js`) bundles in `dist` directory.
## Install
You can clone the repository or use NPM package `centrifuge-ts`.
## Development
It is convenient to make changes to the `centrifuge-ts` code by running the command
`npm run watch`.
## Contribute
If you want to contribute, install dependencies and run `npm run build` command from
the root repo folder - this results in creating unminified (`centrifuge.js`) and
minified (`centrifuge.min.js`) bundles in `dist` directory.
## Example
~~~
import {
Centrifuge,
Subscription,
} from 'centrifuge-ts';
const centrifuge = new Centrifuge({
// centrifuge options
});
~~~

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

declare var ActiveXObject: ActiveXObject;
import {
isUndefined,
isFunction,

@@ -37,4 +38,2 @@ isString,

declare var ActiveXObject: ActiveXObject;
export class Centrifuge extends Observable {

@@ -75,8 +74,7 @@

public connect(callback?: Function): void {
public connect(): void {
if (this.isConnected()) {
this._debug('connect called when already connected');
this._debug('Connect called when already connected');
return;
}
if (this._status === 'connecting') {

@@ -86,13 +84,6 @@ return;

this._debug('start connecting');
this._setStatus('connecting');
this._debug('Start connecting');
this._clientID = null;
this._reconnect = true;
if (callback) {
this.on('connect', callback);
}
this._setStatus('connecting');
this._setTransport();

@@ -102,3 +93,3 @@ }

public disconnect(): void {
this._disconnect('client', false);
this._disconnect('client');
}

@@ -117,3 +108,5 @@

method: 'ping'
}, false);
}).then((response: any) => {
}, (error: ICentrifugeError) => {
});
}

@@ -127,5 +120,4 @@

public stopBatching(flush?: boolean): void {
public stopBatching(flush: boolean = false): void {
// stop collecting messages
flush = flush || false;
this._isBatching = false;

@@ -176,3 +168,3 @@ if (flush === true) {

if (error === true) {
this._debug('authorization request failed');
this._debug('Authorization request failed');
for (i in channels) {

@@ -374,3 +366,3 @@ if (channels.hasOwnProperty(i)) {

public addMessage(message: ICentrifugeMessage, registerCall?: boolean): Promise<any> {
public addMessage(message: ICentrifugeMessage): Promise<any> {
return new Promise((resolve: Function, reject: Function) => {

@@ -384,5 +376,3 @@ const uid = this._getNextMessageId() + '';

}
if (registerCall !== false) {
this.registerCall(uid, resolve, reject);
}
this.registerCall(uid, resolve, reject);
});

@@ -415,3 +405,3 @@ }

}
this._debug('sending JSONP request to', url);
this._debug('Sending JSONP request to', url);

@@ -446,3 +436,3 @@ const callbackName = 'centrifuge_jsonp_' + Centrifuge.nextJSONPCallbackID.toString();

private _ajax(url: string, params: any, headers: any, data: any, callback: Function) {
this._debug('sending AJAX request to', url);
this._debug('Sending AJAX request to', url);

@@ -498,3 +488,3 @@ const xhr = (XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'));

private _configure(config: ICentrifugeConfig): void {
this._debug('Configuring centrifuge object with', config);
this._debug('Configuring Centrifuge with', config);
config = Object.assign({

@@ -530,22 +520,2 @@ retry: 1000,

if (endsWith(config.url, 'connection/websocket')) {
this._debug('client will connect to raw Websocket endpoint');
} else {
if (endsWith(config.url, 'connection')) {
this._debug('client will connect to SockJS endpoint');
} else {
this._debug('client will detect connection endpoint itself');
}
if (config.sockJS !== null) {
this._debug('SockJS explicitly provided in options');
} else {
if (isUndefined(global['SockJS'])) {
throw 'Include SockJS client library before Centrifuge javascript client library or provide SockJS object in options or use raw Websocket connection endpoint';
} else {
this._debug('Use globally defined SockJS');
config.sockJS = global['SockJS'];
}
}
}
if (!config.user) {

@@ -555,3 +525,3 @@ if (!config.insecure) {

} else {
this._debug('user not found but this is OK for insecure mode - anonymous access will be used');
this._debug('Configuration parameter \'user\' not found but this is OK for insecure mode - anonymous access will be used');
}

@@ -568,3 +538,3 @@ } else {

} else {
this._debug('Configuration parameter \'v\' not found but this is OK for insecure mode');
this._debug('Configuration parameter \'timestamp\' not found but this is OK for insecure mode');
}

@@ -676,21 +646,20 @@ } else {

private _setStatus(newStatus: string): void {
if (this._status !== newStatus) {
this._debug('Status', this._status, '->', newStatus);
this._status = newStatus;
private _setStatus(status: string): void {
if (this._status !== status) {
this._debug('Status:', this._status, '->', status);
this._status = status;
}
}
private _disconnect(reason: string, shouldReconnect?: boolean): void {
private _disconnect(reason: string, shouldReconnect: boolean = false): void {
if (this.isDisconnected()) {
return;
}
this._debug('disconnected:', reason, shouldReconnect);
this._debug('Disconnected:', reason + '.', 'shouldReconnect:', shouldReconnect);
const reconnect = shouldReconnect || false;
if (reconnect === false) {
if (shouldReconnect === false) {
this._reconnect = false;
}
this._clearConnectedState(reconnect);
this._clearConnectedState(shouldReconnect);

@@ -705,3 +674,3 @@ if (!this.isDisconnected()) {

reason,
reconnect,
reconnect: shouldReconnect,
}]);

@@ -720,3 +689,2 @@ }

}
this._debug('Send', messages);
let encodedMessages = [];

@@ -727,2 +695,3 @@ for (const i in messages) {

this._transport.send(encodedMessages.join("\n"));
this._debug('Send', messages.length === 1 ? messages[0] : messages);
}

@@ -765,3 +734,3 @@

private _resetRetry(): void {
this._debug('reset retries count to 0');
this._debug('Reset retries count to 0');
this._retries = 0;

@@ -793,6 +762,6 @@ }

// timestamp, info and token
this._debug('refresh credentials');
this._debug('Refresh credentials');
if (this._config.refreshAttempts === 0) {
this._debug('refresh attempts set to 0, do not send refresh request at all');
this._debug('Refresh attempts set to 0, do not send refresh request at all');
this._refreshFailed();

@@ -810,3 +779,3 @@ return;

// relying on Centrifugo that must close connection eventually.
this._debug('error getting connection credentials from refresh endpoint', data);
this._debug('Error getting connection credentials from refresh endpoint', data);
this._numRefreshFailed++;

@@ -835,6 +804,6 @@ if (this._refreshTimeout) {

if (this.isDisconnected()) {
this._debug('credentials refreshed, connect from scratch');
this._debug('Credentials refreshed, connect from scratch');
this.connect();
} else {
this._debug('send refreshed credentials');
this._debug('Send refreshed credentials');
this.addMessage(<ICentrifugeRefreshMessage>{

@@ -1041,3 +1010,3 @@ method: 'refresh',

if (message === undefined || message === null) {
this._debug('dispatch: got undefined or null message');
this._debug('Dispatch: got undefined or null message');
return;

@@ -1117,9 +1086,2 @@ }

if (!isString(this._config.user)) {
Centrifuge.log('user expected to be string');
}
if (!isString(this._config.info)) {
Centrifuge.log('info expected to be string');
}
const msg: ICentrifugeConnectMessage = {

@@ -1146,3 +1108,3 @@ method: 'connect',

this._transport.onerror = (error: any) => {
this._debug('transport level error', error);
this._debug('Transport level error', error);
};

@@ -1152,3 +1114,3 @@

this._transportClosed = true;
let reason = 'connection closed';
let reason = 'Connection closed';
let reconnect = true;

@@ -1158,3 +1120,3 @@ if (event && 'reason' in event && event.reason) {

const advice = JSON.parse(event.reason);
this._debug('reason is an advice object', advice);
this._debug(reason + '. Reason is an advice object:', advice);
reason = advice.reason;

@@ -1164,3 +1126,3 @@ reconnect = advice.reconnect;

reason = event.reason;
this._debug('reason is a plain string', reason);
this._debug(reason + '. Reason is a plain string:', reason);
reconnect = reason !== 'disconnect';

@@ -1187,3 +1149,3 @@ }

const interval = this._getRetryInterval();
this._debug('reconnect after ' + interval + ' milliseconds');
this._debug('Reconnect after ' + interval + ' milliseconds');
setTimeout(() => {

@@ -1190,0 +1152,0 @@ if (this._reconnect === true) {

@@ -1,14 +0,10 @@

export function isUndefined(value: any): boolean {
return typeof value === 'undefined';
}
export function isFunction(value: any): boolean {
export const isFunction = (value: any): boolean => {
return typeof value === 'function';
}
};
export function isString(value: any): boolean {
export const isString = (value: any): boolean => {
return typeof value === 'string';
}
};
export function log(level: string, ...args: any[]) {
export const log = (level: string, ...args: any[]) => {
if (console) {

@@ -23,23 +19,23 @@ if (args.length === 1) {

}
}
};
export function stripSlash(value: string): string {
export const stripSlash = (value: string): string => {
return value.replace(/\/$/, '');
}
};
export function startsWith(value: string, prefix: string): boolean {
export const startsWith = (value: string, prefix: string): boolean => {
return value.lastIndexOf(prefix, 0) === 0;
}
};
export function endsWith(value: string, suffix: string): boolean {
export const endsWith = (value: string, suffix: string): boolean => {
return value.indexOf(suffix, value.length - suffix.length) !== -1;
}
};
export function errorExists(data: any): boolean {
export const errorExists = (data: any): boolean => {
return 'error' in data && data.error !== null && data.error !== '';
}
};
export function objectToQuery(object: any): string {
export const objectToQuery = (object: any): string => {
let p = [];
for (let i in object) {
for (const i in object) {
if (object.hasOwnProperty(i)) {

@@ -50,2 +46,2 @@ p.push(encodeURIComponent(i) + (object[i] ? '=' + encodeURIComponent(object[i]) : ''));

return p.join('&');
}
};

@@ -17,4 +17,3 @@ export * from './ISockJSOptions';

export * from './ICentrifugeLeaveResponse';
export * from './ISubscriptionError';
export * from './ISubscriptionSuccess';
export * from './ISubscriptionMessage';

@@ -0,0 +0,0 @@ export interface ISockJSOptions {

@@ -10,3 +10,2 @@ import {

ISubscriptionMessage,
ISubscriptionError,
ISubscriptionSuccess,

@@ -17,7 +16,7 @@ } from './interfaces';

static STATE_NEW: number = 0;
static STATE_SUBSCRIBING: number = 1;
static STATE_SUCCESS: number = 2;
static STATE_ERROR: number = 3;
static STATE_UNSUBSCRIBED: number = 4;
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;

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

private _status: number = Subscription.STATE_NEW;
private _error: ISubscriptionError = null;
private _error: ICentrifugeError = null;
private _centrifuge: Centrifuge = null;

@@ -98,3 +97,3 @@ private _isResubscribe: boolean = false;

public setSubscribeError(err: any): void {
public setSubscribeError(error: ICentrifugeError): void {
if (this._status === Subscription.STATE_ERROR) {

@@ -104,3 +103,3 @@ return;

this._status = Subscription.STATE_ERROR;
this._error = err;
this._error = error;
const errContext = this._getSubscribeError();

@@ -190,3 +189,3 @@ this.trigger('error', [errContext]);

private _getSubscribeError(): ISubscriptionError {
private _getSubscribeError(): ICentrifugeError {
const subscribeError = this._error;

@@ -193,0 +192,0 @@ subscribeError.channel = this.channel;

@@ -10,2 +10,5 @@ {

"removeComments": true,
"typeRoots": [
"node_modules/@types"
],
"lib": [

@@ -12,0 +15,0 @@ "es6",

@@ -0,0 +0,0 @@ const path = require('path');

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