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

centrifuge

Package Overview
Dependencies
Maintainers
1
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

centrifuge - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

2

bower.json
{
"name": "centrifuge",
"version": "1.2.0",
"version": "1.3.0",
"ignore": [

@@ -5,0 +5,0 @@ "node_modules",

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

(function(){"use strict";function e(e,t){return e.prototype=Object.create(t.prototype),e.prototype.constructor=e,t.prototype}function t(){}function n(e,t){for(var n=e.length;n--;)if(e[n].listener===t)return n;return-1}function i(e){return function(){return this[e].apply(this,arguments)}}function s(e,t){for(var n=t||{},i=2;i<arguments.length;++i){var o=arguments[i];if(void 0!==o&&null!==o)for(var c in o){var a=r(o,c),u=r(n,c);if(a!==t&&void 0!==a)if(e&&"object"==typeof a&&null!==a)if(a instanceof Array)n[c]=s(e,u instanceof Array?u:[],a);else{var h="object"!=typeof u||u instanceof Array?{}:u;n[c]=s(e,h,a)}else n[c]=a}}return n}function r(e,t){try{return e[t]}catch(n){return void 0}}function o(e,t){return-1!==e.indexOf(t,e.length-t.length)}function c(e,t){return 0===e.lastIndexOf(t,0)}function a(e){return"/"==e.substring(e.length-1)&&(e=e.substring(0,e.length-1)),e}function u(e){return void 0===e||null===e?!1:"string"==typeof e||e instanceof String}function h(e){return void 0===e||null===e?!1:"function"==typeof e}function f(e,t){if(window.console){var n=window.console[e];h(n)&&n.apply(window.console,t)}}function l(e,t,n){var i=.5*Math.random(),s=t*Math.pow(2,e+1);return s>n&&(s=n),Math.floor((1-i)*s)}function g(e){return"error"in e&&null!==e.error&&""!==e.error}function _(e){this._sockjs=!1,this._sockjsVersion=null,this._status="disconnected",this._reconnect=!0,this._transport=null,this._latency=null,this._latencyStart=null,this._messageId=0,this._clientId=null,this._subscriptions={},this._lastMessageID={},this._messages=[],this._isBatching=!1,this._isAuthBatching=!1,this._authChannels={},this._refreshTimeout=null,this._retries=0,this._config={retry:1e3,maxRetry:2e4,info:"",debug:!1,insecure:!1,server:null,privateChannelPrefix:"$",protocols_whitelist:["websocket","xdr-streaming","xhr-streaming","iframe-eventsource","iframe-htmlfile","xdr-polling","xhr-polling","iframe-xhr-polling","jsonp-polling"],transports:["websocket","xdr-streaming","xhr-streaming","eventsource","iframe-eventsource","iframe-htmlfile","xdr-polling","xhr-polling","iframe-xhr-polling","jsonp-polling"],refreshEndpoint:"/centrifuge/refresh",refreshHeaders:{},refreshParams:{},refreshTransport:"ajax",authEndpoint:"/centrifuge/auth",authHeaders:{},authParams:{},authTransport:"ajax"},e&&this.configure(e)}function d(e,t){this._centrifuge=e,this.channel=t}Object.create||(Object.create=function(){function e(){}return function(t){if(1!=arguments.length)throw new Error("Object.create implementation only accepts one parameter.");return e.prototype=t,new e}}()),Array.prototype.indexOf||(Array.prototype.indexOf=function(e){if(null==this)throw new TypeError;var t,n,i=Object(this),s=i.length>>>0;if(0===s)return-1;if(t=0,arguments.length>1&&(t=Number(arguments[1]),t!=t?t=0:0!=t&&1/0!=t&&t!=-1/0&&(t=(t>0||-1)*Math.floor(Math.abs(t)))),t>=s)return-1;for(n=t>=0?t:Math.max(s-Math.abs(t),0);s>n;n++)if(n in i&&i[n]===e)return n;return-1});var p=t.prototype;p.getListeners=function(e){var t,n,i=this._getEvents();if("object"==typeof e){t={};for(n in i)i.hasOwnProperty(n)&&e.test(n)&&(t[n]=i[n])}else t=i[e]||(i[e]=[]);return t},p.flattenListeners=function(e){var t,n=[];for(t=0;t<e.length;t+=1)n.push(e[t].listener);return n},p.getListenersAsObject=function(e){var t,n=this.getListeners(e);return n instanceof Array&&(t={},t[e]=n),t||n},p.addListener=function(e,t){var i,s=this.getListenersAsObject(e),r="object"==typeof t;for(i in s)s.hasOwnProperty(i)&&-1===n(s[i],t)&&s[i].push(r?t:{listener:t,once:!1});return this},p.on=i("addListener"),p.addOnceListener=function(e,t){return this.addListener(e,{listener:t,once:!0})},p.once=i("addOnceListener"),p.defineEvent=function(e){return this.getListeners(e),this},p.defineEvents=function(e){for(var t=0;t<e.length;t+=1)this.defineEvent(e[t]);return this},p.removeListener=function(e,t){var i,s,r=this.getListenersAsObject(e);for(s in r)r.hasOwnProperty(s)&&(i=n(r[s],t),-1!==i&&r[s].splice(i,1));return this},p.off=i("removeListener"),p.addListeners=function(e,t){return this.manipulateListeners(!1,e,t)},p.removeListeners=function(e,t){return this.manipulateListeners(!0,e,t)},p.manipulateListeners=function(e,t,n){var i,s,r=e?this.removeListener:this.addListener,o=e?this.removeListeners:this.addListeners;if("object"!=typeof t||t instanceof RegExp)for(i=n.length;i--;)r.call(this,t,n[i]);else for(i in t)t.hasOwnProperty(i)&&(s=t[i])&&("function"==typeof s?r.call(this,i,s):o.call(this,i,s));return this},p.removeEvent=function(e){var t,n=typeof e,i=this._getEvents();if("string"===n)delete i[e];else if("object"===n)for(t in i)i.hasOwnProperty(t)&&e.test(t)&&delete i[t];else delete this._events;return this},p.emitEvent=function(e,t){var n,i,s,r,o=this.getListenersAsObject(e);for(s in o)if(o.hasOwnProperty(s))for(i=o[s].length;i--;)n=o[s][i],n.once===!0&&this.removeListener(e,n.listener),r=n.listener.apply(this,t||[]),r===this._getOnceReturnValue()&&this.removeListener(e,n.listener);return this},p.trigger=i("emitEvent"),p.emit=function(e){var t=Array.prototype.slice.call(arguments,1);return this.emitEvent(e,t)},p.setOnceReturnValue=function(e){return this._onceReturnValue=e,this},p._getOnceReturnValue=function(){return this.hasOwnProperty("_onceReturnValue")?this._onceReturnValue:!0},p._getEvents=function(){return this._events||(this._events={})},e(_,t),_._authCallbacks={},_._nextAuthCallbackID=1;var b=_.prototype;b._jsonp=function(e,t,n,i,s){n.length>0&&this._log("Only AJAX request allows to send custom headers, it's not possible with JSONP."),self._debug("sending JSONP request to",e);var r=_._nextAuthCallbackID.toString();_._nextAuthCallbackID++;var o=window.document,c=o.createElement("script");_._authCallbacks[r]=function(e){s(!1,e),delete _[r]};var a="";for(var u in t)a.length>0&&(a+="&"),a+=encodeURIComponent(u)+"="+encodeURIComponent(t[u]);var h="Centrifuge._authCallbacks['"+r+"']";c.src=this._config.authEndpoint+"?callback="+encodeURIComponent(h)+"&data="+encodeURIComponent(JSON.stringify(i))+"&"+a;var f=o.getElementsByTagName("head")[0]||o.documentElement;f.insertBefore(c,f.firstChild)},b._ajax=function(e,t,n,i,s){var r=this;r._debug("sending AJAX request to",e);var o=window.XMLHttpRequest?new window.XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),c="";for(var a in t)c.length>0&&(c+="&"),c+=encodeURIComponent(a)+"="+encodeURIComponent(t[a]);c.length>0&&(c="?"+c),o.open("POST",e+c,!0),o.setRequestHeader("X-Requested-With","XMLHttpRequest"),o.setRequestHeader("Content-Type","application/json");for(var u in n)o.setRequestHeader(u,n[u]);return o.onreadystatechange=function(){if(4===o.readyState)if(200===o.status){var e,t=!1;try{e=JSON.parse(o.responseText),t=!0}catch(n){s(!0,"JSON returned from webapp was invalid, yet status code was 200. Data was: "+o.responseText)}t&&s(!1,e)}else r._log("Couldn't get auth info from your webapp",o.status),s(!0,o.status)},setTimeout(function(){o.send(JSON.stringify(i))},20),o},b._log=function(){f("info",arguments)},b._debug=function(){this._config.debug===!0&&f("debug",arguments)},b._configure=function(e){if(this._debug("Configuring centrifuge object with",e),e||(e={}),this._config=s(!1,this._config,e),!this._config.url)throw"Missing required configuration parameter 'url' specifying server URL";if(!this._config.user&&""!==this._config.user){if(!this._config.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"),this._config.user=""}if(!this._config.timestamp){if(!this._config.insecure)throw"Missing required configuration parameter 'timestamp'";this._debug("token not found but this is OK for insecure mode")}if(!this._config.token){if(!this._config.insecure)throw"Missing required configuration parameter 'token' specifying the sign of authorization request";this._debug("timestamp not found but this is OK for insecure mode")}if(this._config.url=a(this._config.url),o(this._config.url,"connection")){if(this._debug("client will connect to SockJS endpoint"),"undefined"==typeof SockJS)throw"include SockJS client library before Centrifuge javascript client library or use raw Websocket connection endpoint";this._sockjs=!0,this._sockjsVersion=SockJS.version}else o(this._config.url,"connection/websocket")?(this._debug("client will connect to raw Websocket endpoint"),this._config.url=this._config.url.replace("http://","ws://"),this._config.url=this._config.url.replace("https://","wss://")):(this._debug("client will detect connection endpoint itself"),"undefined"==typeof SockJS?(this._debug("no SockJS found, client will connect to raw Websocket endpoint"),this._config.url+="/connection/websocket",this._config.url=this._config.url.replace("http://","ws://"),this._config.url=this._config.url.replace("https://","wss://")):(this._debug("SockJS found, client will connect to SockJS endpoint"),this._config.url+="/connection",this._sockjs=!0,this._sockjsVersion=SockJS.version))},b._setStatus=function(e){this._status!==e&&(this._debug("Status",this._status,"->",e),this._status=e)},b._isDisconnected=function(){return this._isConnected()===!1},b._isConnected=function(){return"connected"===this._status},b._isConnecting=function(){return"connecting"===this._status},b._nextMessageId=function(){return++this._messageId},b._clearSubscriptions=function(){this._subscriptions={}},b._resetRetry=function(){this._debug("reset retries count to 0"),this._retries=0},b._getRetryInterval=function(){var e=l(this._retries,this._config.retry,this._config.maxRetry);return this._retries+=1,e},b._send=function(e){for(var t=0;t<e.length;++t){var n=e[t];n.uid=""+this._nextMessageId(),this._clientId&&(n.clientId=this._clientId),this._debug("Send",n),this._transport.send(JSON.stringify(n))}},b._connect=function(e){if(!this.isConnected()){this._clientId=null,this._reconnect=!0,this._clearSubscriptions(),this._setStatus("connecting");var t=this;if(e&&this.on("connect",e),this._sockjs===!0){var n={};c(this._sockjsVersion,"1.")?n.transports=this._config.transports:(this._log("SockJS <= 0.3.4 is deprecated, use SockJS >= 1.0.0 instead"),n.protocols_whitelist=this._config.protocols_whitelist),null!==this._config.server&&(n.server=this._config.server),this._transport=new SockJS(this._config.url,null,n)}else this._transport=new WebSocket(this._config.url);this._setStatus("connecting"),this._transport.onopen=function(){t._resetRetry(),u(t._config.user)||t._debug("user expected to be string"),u(t._config.info)||t._debug("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,u(t._config.timestamp)||t._debug("timestamp expected to be string"),u(t._config.token)||t._debug("token expected to be string")),t.send(e),t._latencyStart=new Date},this._transport.onerror=function(e){t._debug(e)},this._transport.onclose=function(){if(t._setStatus("disconnected"),t.trigger("disconnect"),t._reconnect===!0){var e=t._getRetryInterval();t._debug("reconnect after "+e+" milliseconds"),window.setTimeout(function(){t._reconnect===!0&&t._connect.call(t)},e)}},this._transport.onmessage=function(e){var n;n=JSON.parse(e.data),t._debug("Received",n),t._receive(n)}}},b._disconnect=function(e){var t=e||!1;this._clientId=null,this._setStatus("disconnected"),t===!1&&(this._subscriptions={},this._reconnect=!1),this._transport.close()},b._getSubscription=function(e){var t;return t=this._subscriptions[e],t?t:null},b._removeSubscription=function(e){try{delete this._subscriptions[e]}catch(t){this._debug("nothing to delete for channel ",e)}try{delete this._authChannels[e]}catch(t){this._debug("nothing to delete from authChannels for channel ",e)}},b._connectResponse=function(e){if(null!==this._latencyStart){var t=new Date;this._latency=t.getTime()-this._latencyStart.getTime(),this._latencyStart=null}if(!this.isConnected())if(g(e))this.trigger("error",[e]),this.trigger("connect:error",[e]);else{if(!e.body)return;if(e.body.expires){var n=e.body.expired;if(n)return void this.refresh()}if(this._clientId=e.body.client,this._setStatus("connected"),this.trigger("connect",[e]),this._refreshTimeout&&window.clearTimeout(this._refreshTimeout),e.body.expires){var i=this;this._refreshTimeout=window.setTimeout(function(){i.refresh.call(i)},1e3*e.body.ttl)}}},b._disconnectResponse=function(e){if(g(e))this.trigger("error",[e]),this.trigger("disconnect:error",[e.error]);else{var t=!1;"reconnect"in e.body&&(t=e.body.reconnect),this.disconnect(t),"reason"in e.body&&this._debug("disconnected:",e.body.reason)}},b._subscribeResponse=function(e){g(e)&&this.trigger("error",[e]);var t=e.body;if(null!==t){var n=t.channel,i=this.getSubscription(n);if(i)if(g(e))i.trigger("subscribe:error",[e.error]),i.trigger("error",[e]);else{i.trigger("subscribe:success",[t]),i.trigger("ready",[t]);var s=t.messages;if(s&&s.length>0)for(var r in s.reverse())this._messageResponse({body:s[r]});else"last"in t&&(this._lastMessageID[n]=t.last)}}},b._unsubscribeResponse=function(e){var t=e.body,n=t.channel,i=this.getSubscription(n);i&&(g(e)||(i.trigger("unsubscribe",[t]),this._removeSubscription(n)))},b._publishResponse=function(e){var t=e.body,n=t.channel,i=this.getSubscription(n);i&&(g(e)?(i.trigger("publish:error",[e.error]),this.trigger("error",[e])):i.trigger("publish:success",[t]))},b._presenceResponse=function(e){var t=e.body,n=t.channel,i=this.getSubscription(n);i&&(g(e)?(i.trigger("presence:error",[e.error]),this.trigger("error",[e])):(i.trigger("presence",[t]),i.trigger("presence:success",[t])))},b._historyResponse=function(e){var t=e.body,n=t.channel,i=this.getSubscription(n);i&&(g(e)?(i.trigger("history:error",[e.error]),this.trigger("error",[e])):(i.trigger("history",[t]),i.trigger("history:success",[t])))},b._joinResponse=function(e){var t=e.body,n=t.channel,i=this.getSubscription(n);i&&i.trigger("join",[t])},b._leaveResponse=function(e){var t=e.body,n=t.channel,i=this.getSubscription(n);i&&i.trigger("leave",[t])},b._messageResponse=function(e){var t=e.body,n=t.channel,i=this.getSubscription(n);null!==i&&(this._lastMessageID[n]=t.uid,i.trigger("message",[t]))},b._refreshResponse=function(e){if(this._refreshTimeout&&window.clearTimeout(this._refreshTimeout),e.body.expires){var t=this,n=e.body.expired;if(n)return void(t._refreshTimeout=window.setTimeout(function(){t.refresh.call(t)},3e3+Math.round(1e3*Math.random())));this._clientId=e.body.client,t._refreshTimeout=window.setTimeout(function(){t.refresh.call(t)},1e3*e.body.ttl)}},b._dispatchMessage=function(e){if(void 0!==e&&null!==e){var t=e.method;if(t)switch(t){case"connect":this._connectResponse(e);break;case"disconnect":this._disconnectResponse(e);break;case"subscribe":this._subscribeResponse(e);break;case"unsubscribe":this._unsubscribeResponse(e);break;case"publish":this._publishResponse(e);break;case"presence":this._presenceResponse(e);break;case"history":this._historyResponse(e);break;case"join":this._joinResponse(e);break;case"leave":this._leaveResponse(e);break;case"ping":break;case"refresh":this._refreshResponse(e);break;case"message":this._messageResponse(e)}}},b._receive=function(e){if(Object.prototype.toString.call(e)===Object.prototype.toString.call([])){for(var t in e)if(e.hasOwnProperty(t)){var n=e[t];this._dispatchMessage(n)}}else Object.prototype.toString.call(e)===Object.prototype.toString.call({})&&this._dispatchMessage(e)},b._flush=function(){var e=this._messages.slice(0);this._messages=[],this._send(e)},b._ping=function(){var e={method:"ping",params:{}};this.send(e)},b._recover=function(e){return e in this._lastMessageID},b._getLastID=function(e){var t=this._lastMessageID[e];return t?(this._debug("last uid found and sent for channel",e),t):(this._debug("no last uid found for channel",e),"")},b.getClientId=function(){return this._clientId},b.isConnected=b._isConnected,b.isConnecting=b._isConnecting,b.isDisconnected=b._isDisconnected,b.configure=function(e){this._configure.call(this,e)},b.connect=b._connect,b.disconnect=b._disconnect,b.getSubscription=b._getSubscription,b.ping=b._ping,b.send=function(e){this._isBatching===!0?this._messages.push(e):this._send([e])},b.startBatching=function(){this._isBatching=!0},b.stopBatching=function(e){e=e||!1,this._isBatching=!1,e===!0&&this.flush()},b.flush=function(){this._flush()},b.startAuthBatching=function(){this._isAuthBatching=!0},b.stopAuthBatching=function(e){this._isAuthBatching=!1;var t=this._authChannels;this._authChannels={};var n=[];for(var i in t){var s=this.getSubscription(i);s&&n.push(i)}if(0==n.length)return void(e&&e());var r={client:this.getClientId(),channels:n},o=this,c=function(t,i){if(t===!0){o._debug("authorization request failed");for(var s in n){var r=n[s];o._subscribeResponse({error:"authorization request failed",body:{channel:r}})}return void(e&&e())}for(var s in n){var r=n[s],c=i[r];if(c)if(c.status&&200!==c.status)o._subscribeResponse({error:c.status,body:{channel:r}});else{var a={method:"subscribe",params:{channel:r,client:o.getClientId(),info:c.info,sign:c.sign}},u=o._recover(r);u===!0&&(a.params.recover=!0,a.params.last=o._getLastID(r)),o.send(a)}else o._subscribeResponse({error:404,body:{channel:r}})}e&&e()},a=this._config.authTransport.toLowerCase();if("ajax"===a)this._ajax(this._config.authEndpoint,this._config.authParams,this._config.authHeaders,r,c);else{if("jsonp"!==a)throw"Unknown auth transport "+a;this._jsonp(this._config.authEndpoint,this._config.authParams,this._config.authHeaders,r,c)}},b.subscribe=function(e,t){if(arguments.length<1)throw"Illegal arguments number: required 1, got "+arguments.length;if(!u(e))throw"Illegal argument type: channel must be a string";if(this.isDisconnected())throw"Can not subscribe in disconnected state";var n=this.getSubscription(e);if(null!==n)return n;var i=new d(this,e);return this._subscriptions[e]=i,i.subscribe(t),i},b.unsubscribe=function(e){if(arguments.length<1)throw"Illegal arguments number: required 1, got "+arguments.length;if(!u(e))throw"Illegal argument type: channel must be a string";if(!this.isDisconnected()){var t=this.getSubscription(e);null!==t&&t.unsubscribe()}},b.publish=function(e,t,n){var i=this.getSubscription(e);return null===i?(this._debug("subscription not found for channel "+e),null):(i.publish(t,n),i)},b.presence=function(e,t){var n=this.getSubscription(e);return null===n?(this._debug("subscription not found for channel "+e),null):(n.presence(t),n)},b.history=function(e,t){var n=this.getSubscription(e);return null===n?(this._debug("subscription not found for channel "+e),null):(n.history(t),n)},b.refresh=function(){var e=this;this._debug("refresh credentials");var t=function(t,n){if(t===!0)return e._debug("error getting connect parameters",n),e._refreshTimeout&&window.clearTimeout(e._refreshTimeout),void(e._refreshTimeout=window.setTimeout(function(){e.refresh.call(e)},3e3));if(e._config.user=n.user,e._config.timestamp=n.timestamp,e._config.info=n.info,e._config.token=n.token,e.isDisconnected())e._debug("credentials refreshed, connect from scratch"),e._connect();else{e._debug("send refreshed credentials");var i={method:"refresh",params:{user:e._config.user,timestamp:e._config.timestamp,info:e._config.info,token:e._config.token}};e.send(i)}},n=this._config.refreshTransport.toLowerCase();if("ajax"===n)this._ajax(this._config.refreshEndpoint,this._config.refreshParams,this._config.refreshHeaders,{},t);else{if("jsonp"!==n)throw"Unknown refresh transport "+n;this._jsonp(this._config.refreshEndpoint,this._config.refreshParams,this._config.refreshHeaders,{},t)}},e(d,t);var m=d.prototype;m.getChannel=function(){return this.channel},m.getCentrifuge=function(){return this._centrifuge},m.subscribe=function(e){var t={method:"subscribe",params:{channel:this.channel}};if(c(this.channel,this._centrifuge._config.privateChannelPrefix))this._centrifuge._isAuthBatching?this._centrifuge._authChannels[this.channel]=!0:(this._centrifuge.startAuthBatching(),this.subscribe(e),this._centrifuge.stopAuthBatching());else{var n=this._centrifuge._recover(this.channel);n===!0&&(t.params.recover=!0,t.params.last=this._centrifuge._getLastID(this.channel)),this._centrifuge.send(t)}e&&this.on("message",e)},m.unsubscribe=function(){this._centrifuge._removeSubscription(this.channel);var e={method:"unsubscribe",params:{channel:this.channel}};this._centrifuge.send(e)},m.publish=function(e,t){var n={method:"publish",params:{channel:this.channel,data:e}};t&&this.on("publish:success",t),this._centrifuge.send(n)},m.presence=function(e){var t={method:"presence",params:{channel:this.channel}};e&&this.on("presence",e),this._centrifuge.send(t)},m.history=function(e){var t={method:"history",params:{channel:this.channel}};e&&this.on("history",e),this._centrifuge.send(t)},"function"==typeof define&&define.amd?define(function(){return _}):"object"==typeof module&&module.exports?module.exports=_:this.Centrifuge=_}).call(this);
(function(){"use strict";function e(e,t){return e.prototype=Object.create(t.prototype),e.prototype.constructor=e,t.prototype}function t(e,t){try{return e[t]}catch(n){return void 0}}function n(e,i){for(var r=i||{},s=2;s<arguments.length;++s){var o=arguments[s];if(void 0!==o&&null!==o)for(var c in o){var a=t(o,c),u=t(r,c);if(a!==i&&void 0!==a)if(e&&"object"==typeof a&&null!==a)if(a instanceof Array)r[c]=n(e,u instanceof Array?u:[],a);else{var h="object"!=typeof u||u instanceof Array?{}:u;r[c]=n(e,h,a)}else r[c]=a}}return r}function i(e,t){return-1!==e.indexOf(t,e.length-t.length)}function r(e,t){return 0===e.lastIndexOf(t,0)}function s(e){return"/"==e.substring(e.length-1)&&(e=e.substring(0,e.length-1)),e}function o(e){return void 0===e||null===e?!1:"string"==typeof e||e instanceof String}function c(e){return void 0===e||null===e?!1:"function"==typeof e}function a(e,t){if(window.console){var n=window.console[e];c(n)&&n.apply(window.console,t)}}function u(e,t,n){var i=.5*Math.random(),r=t*Math.pow(2,e+1);return r>n&&(r=n),Math.floor((1-i)*r)}function h(e){return"error"in e&&null!==e.error&&""!==e.error}function f(e){this._sockjs=!1,this._status="disconnected",this._reconnect=!0,this._reconnecting=!1,this._transport=null,this._transportName=null,this._messageId=0,this._clientID=null,this._subs={},this._lastMessageID={},this._messages=[],this._isBatching=!1,this._isAuthBatching=!1,this._authChannels={},this._refreshTimeout=null,this._retries=0,this._callbacks={},this._config={retry:1e3,maxRetry:2e4,timeout:5e3,info:"",resubscribe:!0,debug:!1,insecure:!1,server:null,privateChannelPrefix:"$",transports:["websocket","xdr-streaming","xhr-streaming","eventsource","iframe-eventsource","iframe-htmlfile","xdr-polling","xhr-polling","iframe-xhr-polling","jsonp-polling"],refreshEndpoint:"/centrifuge/refresh/",refreshHeaders:{},refreshParams:{},refreshTransport:"ajax",authEndpoint:"/centrifuge/auth/",authHeaders:{},authParams:{},authTransport:"ajax"},e&&this.configure(e)}function l(e,t,n){this._status=g,this._error=null,this._centrifuge=e,this.channel=t,this._setEvents(n),this._isResubscribe=!1,this._ready=!1,this._promise=null,this._initializePromise()}(function(){function e(e){return"function"==typeof e||"object"==typeof e&&null!==e}function t(e){return"function"==typeof e}function n(e){return"object"==typeof e&&null!==e}function i(e){N=e}function r(e){F=e}function s(){return function(){process.nextTick(h)}}function o(){return function(){J(h)}}function c(){var e=0,t=new K(h),n=document.createTextNode("");return t.observe(n,{characterData:!0}),function(){n.data=e=++e%2}}function a(){var e=new MessageChannel;return e.port1.onmessage=h,function(){e.port2.postMessage(0)}}function u(){return function(){setTimeout(h,1)}}function h(){for(var e=0;z>e;e+=2){var t=G[e],n=G[e+1];t(n),G[e]=void 0,G[e+1]=void 0}z=0}function f(){try{var e=require,t=e("vertx");return J=t.runOnLoop||t.runOnContext,o()}catch(n){return u()}}function l(){}function _(){return new TypeError("You cannot resolve a promise with itself")}function g(){return new TypeError("A promises callback cannot return that same promise.")}function d(e){try{return e.then}catch(t){return tt.error=t,tt}}function b(e,t,n,i){try{e.call(t,n,i)}catch(r){return r}}function p(e,t,n){F(function(e){var i=!1,r=b(n,t,function(n){i||(i=!0,t!==n?y(e,n):S(e,n))},function(t){i||(i=!0,k(e,t))},"Settle: "+(e._label||" unknown promise"));!i&&r&&(i=!0,k(e,r))},e)}function v(e,t){t._state===Z?S(e,t._result):t._state===et?k(e,t._result):j(t,void 0,function(t){y(e,t)},function(t){k(e,t)})}function m(e,n){if(n.constructor===e.constructor)v(e,n);else{var i=d(n);i===tt?k(e,tt.error):void 0===i?S(e,n):t(i)?p(e,n,i):S(e,n)}}function y(t,n){t===n?k(t,_()):e(n)?m(t,n):S(t,n)}function w(e){e._onerror&&e._onerror(e._result),E(e)}function S(e,t){e._state===Q&&(e._result=t,e._state=Z,0!==e._subscribers.length&&F(E,e))}function k(e,t){e._state===Q&&(e._state=et,e._result=t,F(w,e))}function j(e,t,n,i){var r=e._subscribers,s=r.length;e._onerror=null,r[s]=t,r[s+Z]=n,r[s+et]=i,0===s&&e._state&&F(E,e)}function E(e){var t=e._subscribers,n=e._state;if(0!==t.length){for(var i,r,s=e._result,o=0;o<t.length;o+=3)i=t[o],r=t[o+n],i?C(n,i,r,s):r(s);e._subscribers.length=0}}function O(){this.error=null}function R(e,t){try{return e(t)}catch(n){return nt.error=n,nt}}function C(e,n,i,r){var s,o,c,a,u=t(i);if(u){if(s=R(i,r),s===nt?(a=!0,o=s.error,s=null):c=!0,n===s)return void k(n,g())}else s=r,c=!0;n._state!==Q||(u&&c?y(n,s):a?k(n,o):e===Z?S(n,s):e===et&&k(n,s))}function x(e,t){try{t(function(t){y(e,t)},function(t){k(e,t)})}catch(n){k(e,n)}}function M(e,t){var n=this;n._instanceConstructor=e,n.promise=new e(l),n._validateInput(t)?(n._input=t,n.length=t.length,n._remaining=t.length,n._init(),0===n.length?S(n.promise,n._result):(n.length=n.length||0,n._enumerate(),0===n._remaining&&S(n.promise,n._result))):k(n.promise,n._validationError())}function A(e){return new it(this,e).promise}function T(e){function t(e){y(r,e)}function n(e){k(r,e)}var i=this,r=new i(l);if(!X(e))return k(r,new TypeError("You must pass an array to race.")),r;for(var s=e.length,o=0;r._state===Q&&s>o;o++)j(i.resolve(e[o]),void 0,t,n);return r}function I(e){var t=this;if(e&&"object"==typeof e&&e.constructor===t)return e;var n=new t(l);return y(n,e),n}function L(e){var t=this,n=new t(l);return k(n,e),n}function P(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function D(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function B(e){this._id=at++,this._state=void 0,this._result=void 0,this._subscribers=[],l!==e&&(t(e)||P(),this instanceof B||D(),x(this,e))}function q(){var e;if("undefined"!=typeof global)e=global;else if("undefined"!=typeof self)e=self;else try{e=Function("return this")()}catch(t){throw new Error("polyfill failed because global object is unavailable in this environment")}var n=e.Promise;(!n||"[object Promise]"!==Object.prototype.toString.call(n.resolve())||n.cast)&&(e.Promise=ut)}var U;U=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)};var J,N,H,X=U,z=0,F=({}.toString,function(e,t){G[z]=e,G[z+1]=t,z+=2,2===z&&(N?N(h):H())}),V="undefined"!=typeof window?window:void 0,W=V||{},K=W.MutationObserver||W.WebKitMutationObserver,Y="undefined"!=typeof process&&"[object process]"==={}.toString.call(process),$="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,G=new Array(1e3);H=Y?s():K?c():$?a():void 0===V&&"function"==typeof require?f():u();var Q=void 0,Z=1,et=2,tt=new O,nt=new O;M.prototype._validateInput=function(e){return X(e)},M.prototype._validationError=function(){return new Error("Array Methods must be provided an Array")},M.prototype._init=function(){this._result=new Array(this.length)};var it=M;M.prototype._enumerate=function(){for(var e=this,t=e.length,n=e.promise,i=e._input,r=0;n._state===Q&&t>r;r++)e._eachEntry(i[r],r)},M.prototype._eachEntry=function(e,t){var i=this,r=i._instanceConstructor;n(e)?e.constructor===r&&e._state!==Q?(e._onerror=null,i._settledAt(e._state,t,e._result)):i._willSettleAt(r.resolve(e),t):(i._remaining--,i._result[t]=e)},M.prototype._settledAt=function(e,t,n){var i=this,r=i.promise;r._state===Q&&(i._remaining--,e===et?k(r,n):i._result[t]=n),0===i._remaining&&S(r,i._result)},M.prototype._willSettleAt=function(e,t){var n=this;j(e,void 0,function(e){n._settledAt(Z,t,e)},function(e){n._settledAt(et,t,e)})};var rt=A,st=T,ot=I,ct=L,at=0,ut=B;B.all=rt,B.race=st,B.resolve=ot,B.reject=ct,B._setScheduler=i,B._setAsap=r,B._asap=F,B.prototype={constructor:B,then:function(e,t){var n=this,i=n._state;if(i===Z&&!e||i===et&&!t)return this;var r=new this.constructor(l),s=n._result;if(i){var o=arguments[i-1];F(function(){C(i,r,o,s)})}else j(n,r,e,t);return r},"catch":function(e){return this.then(null,e)}};var ht=q,ft={Promise:ut,polyfill:ht};"function"==typeof define&&define.amd?define(function(){return ft}):"undefined"!=typeof module&&module.exports?module.exports=ft:"undefined"!=typeof this&&(this.ES6Promise=ft),ht()}).call(this),function(){function e(){}function t(e,t){for(var n=e.length;n--;)if(e[n].listener===t)return n;return-1}function n(e){return function(){return this[e].apply(this,arguments)}}var i=e.prototype,r=this,s=r.EventEmitter;i.getListeners=function(e){var t,n,i=this._getEvents();if(e instanceof RegExp){t={};for(n in i)i.hasOwnProperty(n)&&e.test(n)&&(t[n]=i[n])}else t=i[e]||(i[e]=[]);return t},i.flattenListeners=function(e){var t,n=[];for(t=0;t<e.length;t+=1)n.push(e[t].listener);return n},i.getListenersAsObject=function(e){var t,n=this.getListeners(e);return n instanceof Array&&(t={},t[e]=n),t||n},i.addListener=function(e,n){var i,r=this.getListenersAsObject(e),s="object"==typeof n;for(i in r)r.hasOwnProperty(i)&&-1===t(r[i],n)&&r[i].push(s?n:{listener:n,once:!1});return this},i.on=n("addListener"),i.addOnceListener=function(e,t){return this.addListener(e,{listener:t,once:!0})},i.once=n("addOnceListener"),i.defineEvent=function(e){return this.getListeners(e),this},i.defineEvents=function(e){for(var t=0;t<e.length;t+=1)this.defineEvent(e[t]);return this},i.removeListener=function(e,n){var i,r,s=this.getListenersAsObject(e);for(r in s)s.hasOwnProperty(r)&&(i=t(s[r],n),-1!==i&&s[r].splice(i,1));return this},i.off=n("removeListener"),i.addListeners=function(e,t){return this.manipulateListeners(!1,e,t)},i.removeListeners=function(e,t){return this.manipulateListeners(!0,e,t)},i.manipulateListeners=function(e,t,n){var i,r,s=e?this.removeListener:this.addListener,o=e?this.removeListeners:this.addListeners;if("object"!=typeof t||t instanceof RegExp)for(i=n.length;i--;)s.call(this,t,n[i]);else for(i in t)t.hasOwnProperty(i)&&(r=t[i])&&("function"==typeof r?s.call(this,i,r):o.call(this,i,r));return this},i.removeEvent=function(e){var t,n=typeof e,i=this._getEvents();if("string"===n)delete i[e];else if(e instanceof RegExp)for(t in i)i.hasOwnProperty(t)&&e.test(t)&&delete i[t];else delete this._events;return this},i.removeAllListeners=n("removeEvent"),i.emitEvent=function(e,t){var n,i,r,s,o,c=this.getListenersAsObject(e);for(s in c)if(c.hasOwnProperty(s))for(n=c[s].slice(0),r=n.length;r--;)i=n[r],i.once===!0&&this.removeListener(e,i.listener),o=i.listener.apply(this,t||[]),o===this._getOnceReturnValue()&&this.removeListener(e,i.listener);return this},i.trigger=n("emitEvent"),i.emit=function(e){var t=Array.prototype.slice.call(arguments,1);return this.emitEvent(e,t)},i.setOnceReturnValue=function(e){return this._onceReturnValue=e,this},i._getOnceReturnValue=function(){return this.hasOwnProperty("_onceReturnValue")?this._onceReturnValue:!0},i._getEvents=function(){return this._events||(this._events={})},e.noConflict=function(){return r.EventEmitter=s,e},"function"==typeof define&&define.amd?define(function(){return e}):"object"==typeof module&&module.exports?module.exports=e:r.EventEmitter=e}.call(this),Object.create||(Object.create=function(){function e(){}return function(t){if(1!=arguments.length)throw new Error("Object.create implementation only accepts one parameter.");return e.prototype=t,new e}}()),Array.prototype.indexOf||(Array.prototype.indexOf=function(e){if(null==this)throw new TypeError;var t,n,i=Object(this),r=i.length>>>0;if(0===r)return-1;if(t=0,arguments.length>1&&(t=Number(arguments[1]),t!=t?t=0:0!=t&&1/0!=t&&t!=-1/0&&(t=(t>0||-1)*Math.floor(Math.abs(t)))),t>=r)return-1;for(n=t>=0?t:Math.max(r-Math.abs(t),0);r>n;n++)if(n in i&&i[n]===e)return n;return-1}),e(f,EventEmitter),f._authCallbacks={},f._nextAuthCallbackID=1;var _=f.prototype;_._jsonp=function(e,t,n,i,r){n.length>0&&this._log("Only AJAX request allows to send custom headers, it's not possible with JSONP."),self._debug("sending JSONP request to",e);var s=f._nextAuthCallbackID.toString();f._nextAuthCallbackID++;var o=window.document,c=o.createElement("script");f._authCallbacks[s]=function(e){r(!1,e),delete f[s]};var a="";for(var u in t)a.length>0&&(a+="&"),a+=encodeURIComponent(u)+"="+encodeURIComponent(t[u]);var h="Centrifuge._authCallbacks['"+s+"']";c.src=this._config.authEndpoint+"?callback="+encodeURIComponent(h)+"&data="+encodeURIComponent(JSON.stringify(i))+"&"+a;var l=o.getElementsByTagName("head")[0]||o.documentElement;l.insertBefore(c,l.firstChild)},_._ajax=function(e,t,n,i,r){var s=this;s._debug("sending AJAX request to",e);var o=window.XMLHttpRequest?new window.XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),c="";for(var a in t)c.length>0&&(c+="&"),c+=encodeURIComponent(a)+"="+encodeURIComponent(t[a]);c.length>0&&(c="?"+c),o.open("POST",e+c,!0),o.setRequestHeader("X-Requested-With","XMLHttpRequest"),o.setRequestHeader("Content-Type","application/json");for(var u in n)o.setRequestHeader(u,n[u]);return o.onreadystatechange=function(){if(4===o.readyState)if(200===o.status){var e,t=!1;try{e=JSON.parse(o.responseText),t=!0}catch(n){r(!0,"JSON returned was invalid, yet status code was 200. Data was: "+o.responseText)}t&&r(!1,e)}else s._log("Couldn't get auth info from application",o.status),r(!0,o.status)},setTimeout(function(){o.send(JSON.stringify(i))},20),o},_._log=function(){a("info",arguments)},_._debug=function(){this._config.debug===!0&&a("debug",arguments)},_._configure=function(e){if(this._debug("Configuring centrifuge object with",e),e||(e={}),this._config=n(!1,this._config,e),!this._config.url)throw"Missing required configuration parameter 'url' specifying server URL";if(!this._config.user&&""!==this._config.user){if(!this._config.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"),this._config.user=""}if(!this._config.timestamp){if(!this._config.insecure)throw"Missing required configuration parameter 'timestamp'";this._debug("token not found but this is OK for insecure mode")}if(!this._config.token){if(!this._config.insecure)throw"Missing required configuration parameter 'token' specifying the sign of authorization request";this._debug("timestamp not found but this is OK for insecure mode")}if(this._config.url=s(this._config.url),i(this._config.url,"connection")){if(this._debug("client will connect to SockJS endpoint"),"undefined"==typeof SockJS)throw"include SockJS client library before Centrifuge javascript client library or use raw Websocket connection endpoint";this._sockjs=!0}else i(this._config.url,"connection/websocket")?(this._debug("client will connect to raw Websocket endpoint"),this._config.url=this._config.url.replace("http://","ws://"),this._config.url=this._config.url.replace("https://","wss://")):(this._debug("client will detect connection endpoint itself"),"undefined"==typeof SockJS?(this._debug("no SockJS found, client will connect to raw Websocket endpoint"),this._config.url+="/connection/websocket",this._config.url=this._config.url.replace("http://","ws://"),this._config.url=this._config.url.replace("https://","wss://")):(this._debug("SockJS found, client will connect to SockJS endpoint"),this._config.url+="/connection",this._sockjs=!0))},_._setStatus=function(e){this._status!==e&&(this._debug("Status",this._status,"->",e),this._status=e)},_._isDisconnected=function(){return"disconnected"===this._status},_._isConnecting=function(){return"connecting"===this._status},_._isConnected=function(){return"connected"===this._status},_._nextMessageId=function(){return++this._messageId},_._resetRetry=function(){this._debug("reset retries count to 0"),this._retries=0},_._getRetryInterval=function(){var e=u(this._retries,this._config.retry,this._config.maxRetry);return this._retries+=1,e},_._clearConnectedState=function(e){self._clientID=null;for(var t in this._callbacks){var n=this._callbacks[t],i=n.errback;i&&i(this._createErrorObject("disconnected","retry"))}this._callbacks={};for(var r in this._subs){var s=this._subs[r];e?(s._isSuccess()&&s._triggerUnsubscribe(),s._setSubscribing()):s._setUnsubscribed()}this._config.resubscribe&&this._reconnect||(this._subs={})},_._send=function(e){0!==e.length&&(this._debug("Send",e),this._transport.send(JSON.stringify(e)))},_._connect=function(e){if(this.isConnected())return void this._debug("connect called when already connected");this._setStatus("connecting"),this._clientID=null,this._reconnect=!0;var t=this;if(e&&this.on("connect",e),this._sockjs===!0){var n={transports:this._config.transports};null!==this._config.server&&(n.server=this._config.server),this._transport=new SockJS(this._config.url,null,n)}else this._transport=new WebSocket(this._config.url);this._transport.onopen=function(){t._reconnecting=!1,t._transportName=t._sockjs?t._transport._transport.transportName:"raw-websocket",t._resetRetry(),o(t._config.user)||t._log("user expected to be string"),o(t._config.info)||t._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,o(t._config.timestamp)||t._log("timestamp expected to be string"),o(t._config.token)||t._log("token expected to be string")),t._addMessage(e)},this._transport.onerror=function(e){t._debug("transport level error",e)},this._transport.onclose=function(){t._disconnect("connection closed",!0,!1)},this._transport.onmessage=function(e){var n;n=JSON.parse(e.data),t._debug("Received",n),t._receive(n)}},_._disconnect=function(e,t,n){this._debug("disconnected:",e,t);var i=t||!1;if(i===!1&&(this._reconnect=!1),this._clearConnectedState(t),!this.isDisconnected()){this._setStatus("disconnected");var r={reason:e,reconnect:i};this._reconnecting===!1&&this.trigger("disconnect",[r])}n&&this._transport.close();var s=this;if(t===!0&&s._reconnect===!0){s._reconnecting=!0;var o=s._getRetryInterval();s._debug("reconnect after "+o+" milliseconds"),window.setTimeout(function(){s._reconnect===!0&&s._connect.call(s)},o)}},_._refresh=function(){var e=this;this._debug("refresh credentials");var t=function(t,n){if(t===!0)return e._debug("error getting connect parameters",n),e._refreshTimeout&&window.clearTimeout(e._refreshTimeout),void(e._refreshTimeout=window.setTimeout(function(){e._refresh.call(e)},3e3));if(e._config.user=n.user,e._config.timestamp=n.timestamp,e._config.info=n.info,e._config.token=n.token,e.isDisconnected())e._debug("credentials refreshed, connect from scratch"),e._connect();else{e._debug("send refreshed credentials");var i={method:"refresh",params:{user:e._config.user,timestamp:e._config.timestamp,info:e._config.info,token:e._config.token}};e._addMessage(i)}},n=this._config.refreshTransport.toLowerCase();if("ajax"===n)this._ajax(this._config.refreshEndpoint,this._config.refreshParams,this._config.refreshHeaders,{},t);else{if("jsonp"!==n)throw"Unknown refresh transport "+n;this._jsonp(this._config.refreshEndpoint,this._config.refreshParams,this._config.refreshHeaders,{},t)}},_._subscribe=function(e){var t=e.channel;if(t in this._subs||(this._subs[t]=e),!this.isConnected())return void e._setNew();e._setSubscribing();var n={method:"subscribe",params:{channel:t}};if(r(t,this._config.privateChannelPrefix))this._isAuthBatching?this._authChannels[t]=!0:(this.startAuthBatching(),this._subscribe(e),this.stopAuthBatching());else{var i=this._recover(t);i===!0&&(n.params.recover=!0,n.params.last=this._getLastID(t)),this._addMessage(n)}},_._unsubscribe=function(e){if(this.isConnected()){var t={method:"unsubscribe",params:{channel:e.channel}};this._addMessage(t)}},_._getSub=function(e){var t=this._subs[e];return t?t:null},_._connectResponse=function(e){if(!this.isConnected())if(h(e))this.trigger("error",[{message:e}]);else{if(!e.body)return;if(e.body.expires){var t=e.body.expired;if(t)return void this._refresh()}if(this._clientID=e.body.client,this._setStatus("connected"),this._refreshTimeout&&window.clearTimeout(this._refreshTimeout),e.body.expires){var n=this;this._refreshTimeout=window.setTimeout(function(){n._refresh.call(n)},1e3*e.body.ttl)}if(this._config.resubscribe){this.startBatching(),this.startAuthBatching();for(var i in this._subs){var r=this._subs[i];this._subscribe(r)}this.stopAuthBatching(),this.stopBatching(!0)}var s={client:e.body.client,transport:this._transportName};this.trigger("connect",[s])}},_._disconnectResponse=function(e){if(h(e))this.trigger("error",[{message:e}]);else{var t=!1;"reconnect"in e.body&&(t=e.body.reconnect);var n="";"reason"in e.body&&(n=e.body.reason),this._disconnect(n,t,!0)}},_._subscribeResponse=function(e){var t=e.body;if(null!==t){var n=t.channel,i=this._getSub(n);if(i&&i._isSubscribing())if(h(e))this.trigger("error",[{message:e}]),i._setSubscribeError(this._errorObjectFromMessage(e));else{i._setSubscribeSuccess();var r=t.messages;if(r&&r.length>0)for(var s in r.reverse())this._messageResponse({body:r[s]});else"last"in t&&(this._lastMessageID[n]=t.last)}}},_._unsubscribeResponse=function(e){var t=e.uid,n=e.body,i=n.channel,r=this._getSub(i);r&&(h(e)?this.trigger("error",[{message:e}]):t||r._setUnsubscribed())},_._publishResponse=function(e){var t=e.uid,n=e.body;if(t in this._callbacks){var i=this._callbacks[t];if(delete this._callbacks[t],h(e)){var r=i.errback;if(!r)return;r(this._errorObjectFromMessage(e)),this.trigger("error",[{message:e}])}else{var s=i.callback;if(!s)return;s(n)}}},_._presenceResponse=function(e){var t=e.uid,n=e.body;if(t in this._callbacks){var i=this._callbacks[t];if(delete this._callbacks[t],h(e)){var r=i.errback;if(!r)return;r(this._errorObjectFromMessage(e)),this.trigger("error",[{message:e}])}else{var s=i.callback;if(!s)return;s(n)}}},_._historyResponse=function(e){var t=e.uid,n=e.body;if(t in this._callbacks){var i=this._callbacks[t];if(delete this._callbacks[t],h(e)){var r=i.errback;if(!r)return;r(this._errorObjectFromMessage(e)),this.trigger("error",[{message:e}])}else{var s=i.callback;if(!s)return;s(n)}}},_._joinResponse=function(e){var t=e.body,n=t.channel,i=this._getSub(n);i&&i.trigger("join",[t])},_._leaveResponse=function(e){var t=e.body,n=t.channel,i=this._getSub(n);i&&i.trigger("leave",[t])},_._messageResponse=function(e){var t=e.body,n=t.channel;this._lastMessageID[n]=t.uid;var i=this._getSub(n);i&&i.trigger("message",[t])},_._refreshResponse=function(e){if(this._refreshTimeout&&window.clearTimeout(this._refreshTimeout),h(e))this.trigger("error",[{message:e}]);else if(e.body.expires){var t=this,n=e.body.expired;if(n)return void(t._refreshTimeout=window.setTimeout(function(){t._refresh.call(t)},3e3+Math.round(1e3*Math.random())));this._clientID=e.body.client,t._refreshTimeout=window.setTimeout(function(){t._refresh.call(t)},1e3*e.body.ttl)}},_._dispatchMessage=function(e){if(void 0===e||null===e)return void this._debug("dispatch: got undefined or null message");var t=e.method;if(!t)return void this._debug("dispatch: got message with empty method");switch(t){case"connect":this._connectResponse(e);break;case"disconnect":this._disconnectResponse(e);break;case"subscribe":this._subscribeResponse(e);break;case"unsubscribe":this._unsubscribeResponse(e);break;case"publish":this._publishResponse(e);break;case"presence":this._presenceResponse(e);break;case"history":this._historyResponse(e);break;case"join":this._joinResponse(e);break;case"leave":this._leaveResponse(e);break;case"ping":break;case"refresh":this._refreshResponse(e);break;case"message":this._messageResponse(e);break;default:this._debug("dispatch: got message with unknown method"+t)}},_._receive=function(e){if(Object.prototype.toString.call(e)===Object.prototype.toString.call([])){for(var t in e)if(e.hasOwnProperty(t)){var n=e[t];this._dispatchMessage(n)}}else Object.prototype.toString.call(e)===Object.prototype.toString.call({})&&this._dispatchMessage(e)},_._flush=function(){var e=this._messages.slice(0);this._messages=[],this._send(e)},_._ping=function(){var e={method:"ping",params:{}};this._addMessage(e)},_._recover=function(e){return e in this._lastMessageID},_._getLastID=function(e){var t=this._lastMessageID[e];return t?(this._debug("last uid found and sent for channel",e),t):(this._debug("no last uid found for channel",e),"")},_._createErrorObject=function(e,t){var n={error:e};return t&&(n.advice=t),n},_._errorObjectFromMessage=function(e){var t=e.error,n=e.advice;return this._createErrorObject(t,n)},_._registerCall=function(e,t,n){var i=this;this._callbacks[e]={callback:t,errback:n},setTimeout(function(){delete i._callbacks[e],c(n)&&n(i._createErrorObject("timeout","retry"))},this._config.timeout)},_._addMessage=function(e){var t=""+this._nextMessageId();return e.uid=t,this._isBatching===!0?this._messages.push(e):this._send([e]),t},_.getClientId=function(){return this._clientID},_.isConnected=_._isConnected,_.isDisconnected=_._isDisconnected,_.configure=function(e){this._configure.call(this,e)},_.connect=_._connect,_.disconnect=function(){this._disconnect("client",!1,!0)},_.ping=_._ping,_.startBatching=function(){this._isBatching=!0},_.stopBatching=function(e){e=e||!1,this._isBatching=!1,e===!0&&this.flush()},_.flush=function(){this._flush()},_.startAuthBatching=function(){this._isAuthBatching=!0},_.stopAuthBatching=function(){this._isAuthBatching=!1;var e=this._authChannels;this._authChannels={};var t=[];for(var n in e){var i=this._getSub(n);i&&t.push(n)}if(0!=t.length){var r={client:this.getClientId(),channels:t},s=this,o=function(e,n){if(e!==!0){var i=!1;s._isBatching||(s.startBatching(),i=!0);for(var r in t){var o=t[r],c=n[o];if(c)if(c.status&&200!==c.status)s._subscribeResponse({error:c.status,body:{channel:o}});else{var a={method:"subscribe",params:{channel:o,client:s.getClientId(),info:c.info,sign:c.sign}},u=s._recover(o);u===!0&&(a.params.recover=!0,a.params.last=s._getLastID(o)),s._addMessage(a)}else s._subscribeResponse({error:"channel not found in authorization response",advice:"fix",body:{channel:o}})}i&&s.stopBatching(!0)}else{s._debug("authorization request failed");for(var r in t){var o=t[r];s._subscribeResponse({error:"authorization request failed",advice:"fix",body:{channel:o}})}}},c=this._config.authTransport.toLowerCase();if("ajax"===c)this._ajax(this._config.authEndpoint,this._config.authParams,this._config.authHeaders,r,o);else{if("jsonp"!==c)throw"Unknown auth transport "+c;this._jsonp(this._config.authEndpoint,this._config.authParams,this._config.authHeaders,r,o)}}},_.subscribe=function(e,t){if(arguments.length<1)throw"Illegal arguments number: required 1, got "+arguments.length;if(!o(e))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(e);if(null!==n)return n._setEvents(t),n;var i=new l(this,e,t);return this._subs[e]=i,i.subscribe(),i};var g=0,d=1,b=2,p=3,v=4;e(l,EventEmitter);var m=l.prototype;m._initializePromise=function(){this._ready=!1;var e=this;this._promise=new Promise(function(t,n){e._resolve=function(n){e._ready=!0,t(n)},e._reject=function(t){e._ready=!0,n(t)}})},m._setEvents=function(e){if(e)if(c(e))this.on("message",e);else if(Object.prototype.toString.call(e)===Object.prototype.toString.call({})){var t=["message","join","leave","unsubscribe","subscribe","error"];for(var n in t){var i=t[n];i in e&&this.on(i,e[i])}}},m._isNew=function(){return this._status===g},m._isUnsubscribed=function(){return this._status===v},m._isSubscribing=function(){return this._status===d},m._isReady=function(){return this._status===b||this._status===p},m._isSuccess=function(){return this._status===b},m._isError=function(){return this._status===p},m._setNew=function(){this._status=g},m._setSubscribing=function(){this._ready===!0&&(this._initializePromise(),this._isResubscribe=!0),this._status=d},m._setSubscribeSuccess=function(){if(this._status!=b){this._status=b;var e=this._getSubscribeSuccessContext();this.trigger("subscribe",[e]),this._resolve(e)}},m._setSubscribeError=function(e){if(this._status!=p){this._status=p,this._error=e;var t=this._getSubscribeErrorContext();this.trigger("error",[t]),this._reject(t)}},m._triggerUnsubscribe=function(){var e={channel:this.channel};this.trigger("unsubscribe",[e])},m._setUnsubscribed=function(){this._status!=v&&(this._status=v,this._triggerUnsubscribe())},m._getSubscribeSuccessContext=function(){return{channel:this.channel,isResubscribe:this._isResubscribe}},m._getSubscribeErrorContext=function(){var e=this._error;return e.channel=this.channel,e.isResubscribe=this._isResubscribe,e},m.ready=function(e,t){this._ready&&(this._isSuccess()?e(this._getSubscribeSuccessContext()):t(this._getSubscribeErrorContext()))},m.subscribe=function(){return this._status!=b?(this._centrifuge._subscribe(this),this):void 0},m.unsubscribe=function(){this._setUnsubscribed(),this._centrifuge._unsubscribe(this)},m.publish=function(e){var t=this;return new Promise(function(n,i){return t._isUnsubscribed()?void i(t._centrifuge._createErrorObject("subscription unsubscribed","fix")):void t._promise.then(function(){if(!t._centrifuge.isConnected())return void i(t._centrifuge._createErrorObject("disconnected","retry"));var r={method:"publish",params:{channel:t.channel,data:e}},s=t._centrifuge._addMessage(r);t._centrifuge._registerCall(s,n,i)},function(e){i(e)})})},m.presence=function(){var e=this;return new Promise(function(t,n){return e._isUnsubscribed()?void n(e._centrifuge._createErrorObject("subscription unsubscribed","fix")):void e._promise.then(function(){if(!e._centrifuge.isConnected())return void n(e._centrifuge._createErrorObject("disconnected","retry"));var i={method:"presence",params:{channel:e.channel}},r=e._centrifuge._addMessage(i);e._centrifuge._registerCall(r,t,n)},function(e){n(e)})})},m.history=function(){var e=this;return new Promise(function(t,n){return e._isUnsubscribed()?void n(e._centrifuge._createErrorObject("subscription unsubscribed","fix")):void e._promise.then(function(){if(!e._centrifuge.isConnected())return void n(e._centrifuge._createErrorObject("disconnected","retry"));var i={method:"history",params:{channel:e.channel}},r=e._centrifuge._addMessage(i);e._centrifuge._registerCall(r,t,n)},function(e){n(e)})})},"function"==typeof define&&define.amd?define(function(){return f}):"object"==typeof module&&module.exports?module.exports=f:this.Centrifuge=f}).call(this);

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

1.3.0
=====
**Client API completely refactored in this release**. You can still use previous versions
to communicate with Centrifugo server from browser environment but new implementation much
more comfortable to use in our opinion and will be supported in future releases so consider
upgrading!
Highlights of this release:
* automatic resubscribe, no need to subscribe manually in `connect` event handler
* more opaque error handling
* drop support for SockJS < 1.0.0 (but if you still use SockJS 0.3.4 then feel free to open
issue and we will return its support to client)
Please, read [new documentation](https://fzambia.gitbooks.io/centrifugal/content/clients/javascript.html)
for Javascript browser client.
Also, DOM plugin was removed from repository as new client API design solves most of problems
that DOM plugin existed for - i.e. abstracting subscribe on many channels and automatically
resubscribe on them. With new client you can have one global connection to Centrifugo and
subscribe on channels at any moment from any part of your javascript code.
Also we updated [examples](https://github.com/centrifugal/examples) to fit new changes.
If you are searching for old API docs (`centrifuge-js` <= 1.2.0) - [you can find it here](https://github.com/centrifugal/documentation/tree/c69ca51f21c028a6b9bd582afdbf0a5c13331957/client)
1.2.0

@@ -2,0 +29,0 @@ =====

{
"name": "centrifuge",
"version": "1.2.0",
"version": "1.3.0",
"description": "Centrifuge javascript client",

@@ -11,5 +11,3 @@ "main": "centrifuge.js",

"build-minified-js": "cat src/centrifuge.js | uglifyjs -cm > centrifuge.min.js",
"build-dom-plugin": "cat plugins/centrifuge-dom/centrifuge.dom.js | uglifyjs -cm > plugins/centrifuge-dom/centrifuge.dom.min.js",
"build": "npm run build-js && npm run build-minified-js",
"build-plugins": "npm run build-dom-plugin"
"build": "npm run build-js && npm run build-minified-js"
},

@@ -16,0 +14,0 @@ "author": "Alexandr Emelin",

@@ -1,20 +0,6 @@

centrifuge-js
=============
Browser Javascript client for Centrifugo
========================================
[Documentation](http://fzambia.gitbooks.io/centrifugal/content/client/index.html)
Please note, that with version 1.3.0 client API was completely refactored ((changelog)[https://github.com/centrifugal/centrifuge-js/blob/master/CHANGELOG.md#130]).
```
npm install centrifuge
```
or
```
bower install centrifuge
```
or just download `centrifuge.min.js` and include `script` tag into your HTML page.
```
<script type="text/javascript" src="https://rawgit.com/centrifugal/centrifuge-js/master/centrifuge.min.js"></script>
```
See client [documentation](http://fzambia.gitbooks.io/centrifugal/content/client/index.html)

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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