centrifuge
Advanced tools
Comparing version 1.4.9 to 1.5.0
{ | ||
"name": "centrifuge", | ||
"version": "1.4.9", | ||
"version": "1.5.0", | ||
"ignore": [ | ||
@@ -5,0 +5,0 @@ "gulp", |
@@ -1,2 +0,2 @@ | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.Centrifuge=e()}}(function(){var e;return function t(e,n,i){function r(o,c){if(!n[o]){if(!e[o]){var a="function"==typeof require&&require;if(!c&&a)return a(o,!0);if(s)return s(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var h=n[o]={exports:{}};e[o][0].call(h.exports,function(t){var n=e[o][1][t];return r(n?n:t)},h,h.exports,t,e,n,i)}return n[o].exports}for(var s="function"==typeof require&&require,o=0;o<i.length;o++)r(i[o]);return r}({1:[function(t,n,i){(function(r,s){!function(t,r){"object"==typeof i&&"undefined"!=typeof n?n.exports=r():"function"==typeof e&&e.amd?e(r):t.ES6Promise=r()}(this,function(){"use strict";function e(e){var t=typeof e;return null!==e&&("object"===t||"function"===t)}function n(e){return"function"==typeof e}function i(e){z=e}function o(e){V=e}function c(){return function(){return r.nextTick(l)}}function a(){return"undefined"!=typeof X?function(){X(l)}:f()}function u(){var e=0,t=new $(l),n=document.createTextNode("");return t.observe(n,{characterData:!0}),function(){n.data=e=++e%2}}function h(){var e=new MessageChannel;return e.port1.onmessage=l,function(){return e.port2.postMessage(0)}}function f(){var e=setTimeout;return function(){return e(l,1)}}function l(){for(var e=0;W>e;e+=2){var t=Z[e],n=Z[e+1];t(n),Z[e]=void 0,Z[e+1]=void 0}W=0}function _(){try{var e=Function("return this")().require("vertx");return X=e.runOnLoop||e.runOnContext,a()}catch(t){return f()}}function d(e,t){var n=this,i=new this.constructor(p);void 0===i[te]&&I(i);var r=n._state;if(r){var s=arguments[r-1];V(function(){return A(r,i,s,n._result)})}else E(n,i,e,t);return i}function g(e){var t=this;if(e&&"object"==typeof e&&e.constructor===t)return e;var n=new t(p);return O(n,e),n}function p(){}function b(){return new TypeError("You cannot resolve a promise with itself")}function v(){return new TypeError("A promises callback cannot return that same promise.")}function m(e){try{return e.then}catch(t){return se.error=t,se}}function y(e,t,n,i){try{e.call(t,n,i)}catch(r){return r}}function w(e,t,n){V(function(e){var i=!1,r=y(n,t,function(n){i||(i=!0,t!==n?O(e,n):C(e,n))},function(t){i||(i=!0,R(e,t))},"Settle: "+(e._label||" unknown promise"));!i&&r&&(i=!0,R(e,r))},e)}function S(e,t){t._state===ie?C(e,t._result):t._state===re?R(e,t._result):E(t,void 0,function(t){return O(e,t)},function(t){return R(e,t)})}function k(e,t,i){t.constructor===e.constructor&&i===d&&t.constructor.resolve===g?S(e,t):i===se?(R(e,se.error),se.error=null):void 0===i?C(e,t):n(i)?w(e,t,i):C(e,t)}function O(t,n){t===n?R(t,b()):e(n)?k(t,n,m(n)):C(t,n)}function j(e){e._onerror&&e._onerror(e._result),x(e)}function C(e,t){e._state===ne&&(e._result=t,e._state=ie,0!==e._subscribers.length&&V(x,e))}function R(e,t){e._state===ne&&(e._state=re,e._result=t,V(j,e))}function E(e,t,n,i){var r=e._subscribers,s=r.length;e._onerror=null,r[s]=t,r[s+ie]=n,r[s+re]=i,0===s&&e._state&&V(x,e)}function x(e){var t=e._subscribers,n=e._state;if(0!==t.length){for(var i=void 0,r=void 0,s=e._result,o=0;o<t.length;o+=3)i=t[o],r=t[o+n],i?A(n,i,r,s):r(s);e._subscribers.length=0}}function T(e,t){try{return e(t)}catch(n){return se.error=n,se}}function A(e,t,i,r){var s=n(i),o=void 0,c=void 0,a=void 0,u=void 0;if(s){if(o=T(i,r),o===se?(u=!0,c=o.error,o.error=null):a=!0,t===o)return void R(t,v())}else o=r,a=!0;t._state!==ne||(s&&a?O(t,o):u?R(t,c):e===ie?C(t,o):e===re&&R(t,o))}function P(e,t){try{t(function(t){O(e,t)},function(t){R(e,t)})}catch(n){R(e,n)}}function M(){return oe++}function I(e){e[te]=oe++,e._state=void 0,e._result=void 0,e._subscribers=[]}function L(){return new Error("Array Methods must be provided an Array")}function J(e){return new ce(this,e).promise}function D(e){var t=this;return new t(H(e)?function(n,i){for(var r=e.length,s=0;r>s;s++)t.resolve(e[s]).then(n,i)}:function(e,t){return t(new TypeError("You must pass an array to race."))})}function q(e){var t=this,n=new t(p);return R(n,e),n}function N(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function U(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function B(){var e=void 0;if("undefined"!=typeof s)e=s;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;if(n){var i=null;try{i=Object.prototype.toString.call(n.resolve())}catch(t){}if("[object Promise]"===i&&!n.cast)return}e.Promise=ae}var F=void 0;F=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)};var H=F,W=0,X=void 0,z=void 0,V=function(e,t){Z[W]=e,Z[W+1]=t,W+=2,2===W&&(z?z(l):ee())},K="undefined"!=typeof window?window:void 0,Y=K||{},$=Y.MutationObserver||Y.WebKitMutationObserver,G="undefined"==typeof self&&"undefined"!=typeof r&&"[object process]"==={}.toString.call(r),Q="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,Z=new Array(1e3),ee=void 0;ee=G?c():$?u():Q?h():void 0===K&&"function"==typeof t?_():f();var te=Math.random().toString(36).substring(2),ne=void 0,ie=1,re=2,se={error:null},oe=0,ce=function(){function e(e,t){this._instanceConstructor=e,this.promise=new e(p),this.promise[te]||I(this.promise),H(t)?(this.length=t.length,this._remaining=t.length,this._result=new Array(this.length),0===this.length?C(this.promise,this._result):(this.length=this.length||0,this._enumerate(t),0===this._remaining&&C(this.promise,this._result))):R(this.promise,L())}return e.prototype._enumerate=function(e){for(var t=0;this._state===ne&&t<e.length;t++)this._eachEntry(e[t],t)},e.prototype._eachEntry=function(e,t){var n=this._instanceConstructor,i=n.resolve;if(i===g){var r=m(e);if(r===d&&e._state!==ne)this._settledAt(e._state,t,e._result);else if("function"!=typeof r)this._remaining--,this._result[t]=e;else if(n===ae){var s=new n(p);k(s,e,r),this._willSettleAt(s,t)}else this._willSettleAt(new n(function(t){return t(e)}),t)}else this._willSettleAt(i(e),t)},e.prototype._settledAt=function(e,t,n){var i=this.promise;i._state===ne&&(this._remaining--,e===re?R(i,n):this._result[t]=n),0===this._remaining&&C(i,this._result)},e.prototype._willSettleAt=function(e,t){var n=this;E(e,void 0,function(e){return n._settledAt(ie,t,e)},function(e){return n._settledAt(re,t,e)})},e}(),ae=function(){function e(t){this[te]=M(),this._result=this._state=void 0,this._subscribers=[],p!==t&&("function"!=typeof t&&N(),this instanceof e?P(this,t):U())}return e.prototype["catch"]=function(e){return this.then(null,e)},e.prototype["finally"]=function(e){var t=this,n=t.constructor;return t.then(function(t){return n.resolve(e()).then(function(){return t})},function(t){return n.resolve(e()).then(function(){throw t})})},e}();return ae.prototype.then=d,ae.all=J,ae.race=D,ae.resolve=g,ae.reject=q,ae._setScheduler=i,ae._setAsap=o,ae._asap=V,ae.polyfill=B,ae.Promise=ae,ae})}).call(this,t("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{_process:2}],2:[function(e,t,n){function i(){}var r=t.exports={};r.nextTick=function(){var e="undefined"!=typeof window&&window.setImmediate,t="undefined"!=typeof window&&window.MutationObserver,n="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(e)return function(e){return window.setImmediate(e)};var i=[];if(t){var r=document.createElement("div"),s=new MutationObserver(function(){var e=i.slice();i.length=0,e.forEach(function(e){e()})});return s.observe(r,{attributes:!0}),function(e){i.length||r.setAttribute("yes","no"),i.push(e)}}return n?(window.addEventListener("message",function(e){var t=e.source;if((t===window||null===t)&&"process-tick"===e.data&&(e.stopPropagation(),i.length>0)){var n=i.shift();n()}},!0),function(e){i.push(e),window.postMessage("process-tick","*")}):function(e){setTimeout(e,0)}}(),r.title="browser",r.browser=!0,r.env={},r.argv=[],r.on=i,r.addListener=i,r.once=i,r.off=i,r.removeListener=i,r.removeAllListeners=i,r.emit=i,r.binding=function(e){throw new Error("process.binding is not supported")},r.cwd=function(){return"/"},r.chdir=function(e){throw new Error("process.chdir is not supported")}},{}],3:[function(t,n,i){(function(){"use strict";function t(){}function i(e,t){for(var n=e.length;n--;)if(e[n].listener===t)return n;return-1}function r(e){return function(){return this[e].apply(this,arguments)}}var s=t.prototype,o=this,c=o.EventEmitter;s.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},s.flattenListeners=function(e){var t,n=[];for(t=0;t<e.length;t+=1)n.push(e[t].listener);return n},s.getListenersAsObject=function(e){var t,n=this.getListeners(e);return n instanceof Array&&(t={},t[e]=n),t||n},s.addListener=function(e,t){var n,r=this.getListenersAsObject(e),s="object"==typeof t;for(n in r)r.hasOwnProperty(n)&&-1===i(r[n],t)&&r[n].push(s?t:{listener:t,once:!1});return this},s.on=r("addListener"),s.addOnceListener=function(e,t){return this.addListener(e,{listener:t,once:!0})},s.once=r("addOnceListener"),s.defineEvent=function(e){return this.getListeners(e),this},s.defineEvents=function(e){for(var t=0;t<e.length;t+=1)this.defineEvent(e[t]);return this},s.removeListener=function(e,t){var n,r,s=this.getListenersAsObject(e);for(r in s)s.hasOwnProperty(r)&&(n=i(s[r],t),-1!==n&&s[r].splice(n,1));return this},s.off=r("removeListener"),s.addListeners=function(e,t){return this.manipulateListeners(!1,e,t)},s.removeListeners=function(e,t){return this.manipulateListeners(!0,e,t)},s.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},s.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},s.removeAllListeners=r("removeEvent"),s.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},s.trigger=r("emitEvent"),s.emit=function(e){var t=Array.prototype.slice.call(arguments,1);return this.emitEvent(e,t)},s.setOnceReturnValue=function(e){return this._onceReturnValue=e,this},s._getOnceReturnValue=function(){return this.hasOwnProperty("_onceReturnValue")?this._onceReturnValue:!0},s._getEvents=function(){return this._events||(this._events={})},t.noConflict=function(){return o.EventEmitter=c,t},"function"==typeof e&&e.amd?e(function(){return t}):"object"==typeof n&&n.exports?n.exports=t:o.EventEmitter=t}).call(this)},{}],4:[function(e,t,n){(function(n){function i(e,t){return e.prototype=Object.create(t.prototype),e.prototype.constructor=e,t.prototype}function r(e,t){try{return e[t]}catch(n){return void 0}}function s(e,t,n){for(var i=t||{},o=2,c=arguments.length;c>o;o++){var a=arguments[o];if(void 0!==a&&null!==a)for(var u in a){var h=r(a,u),f=r(i,u);if(h!==t&&void 0!==h)if(e&&"object"==typeof h&&null!==h)if(h instanceof Array)i[u]=s(e,f instanceof Array?f:[],h);else{var l="object"!=typeof f||f instanceof Array?{}:f;i[u]=s(e,l,h)}else i[u]=h}}return i}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 Object.prototype.toString.call(e)===Object.prototype.toString.call([])}function f(e){return void 0===e||null===e?!1:"function"==typeof e}function l(e,t){if(n.console){var i=n.console[e];f(i)&&i.apply(n.console,t)}}function _(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 d(e){return"error"in e&&null!==e.error&&""!==e.error}function g(e){this._sockJS=null,this._isSockJS=!1,this._status="disconnected",this._reconnect=!0,this._reconnecting=!1,this._transport=null,this._transportName=null,this._transportClosed=!0,this._messageId=0,this._clientID=null,this._subs={},this._lastMessageID={},this._messages=[],this._isBatching=!1,this._isAuthBatching=!1,this._authChannels={},this._numRefreshFailed=0,this._refreshTimeout=null,this._pingInterval=null,this._pongTimeout=null,this._retries=0,this._callbacks={},this._latency=null,this._latencyStart=null,this._config={sockJS:null,retry:1e3,maxRetry:2e4,timeout:5e3,info:"",resubscribe:!0,ping:!0,pingInterval:3e4,pongWaitTimeout:5e3,debug:!1,insecure:!1,server:null,privateChannelPrefix:"$",onTransportClose:null,transports:["websocket","xdr-streaming","xhr-streaming","eventsource","iframe-eventsource","iframe-htmlfile","xdr-polling","xhr-polling","iframe-xhr-polling","jsonp-polling"],onRefresh:null,refreshEndpoint:"/centrifuge/refresh/",refreshHeaders:{},refreshParams:{},refreshData:{},refreshTransport:"ajax",refreshAttempts:null,refreshInterval:3e3,refreshFailed:null,onPrivateChannelAuth:null,authEndpoint:"/centrifuge/auth/",authHeaders:{},authParams:{},authTransport:"ajax"},e&&this.configure(e)}function p(e,t,n){this._status=y,this._error=null,this._centrifuge=e,this.channel=t,this._setEvents(n),this._isResubscribe=!1,this._recovered=!1,this._ready=!1,this._promise=null,this._noResubscribe=!1,this._initializePromise()}var b=e("es6-promise").Promise,v=e("wolfy87-eventemitter");Object.create||(Object.create=function(){var e=function(){};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,t){if(!this)throw new TypeError('Array.prototype.indexOf() - can not convert "'+this+'" to object');var n=isFinite(t)?Math.floor(t):0,i=this instanceof Object?this:new Object(this),r=isFinite(i.length)?Math.floor(i.length):0;if(n>=r)return-1;if(0>n&&(n=Math.max(r+n,0)),void 0===e){do if(n in i&&void 0===i[n])return n;while(++n<r)}else do if(i[n]===e)return n;while(++n<r);return-1}),i(g,v),g._jsonpCallbacks={},g._jsonpTimeouts={},g._nextJSONPCallbackID=1;var m=g.prototype;m._jsonp=function(e,t,i,r,s){Object.keys(i).length>0&&this._log("Only AJAX request allows to send custom headers, it is not possible with JSONP."),this._debug("sending JSONP request to",e);var o="centrifuge_jsonp_"+g._nextJSONPCallbackID.toString();g._nextJSONPCallbackID++;var c=n.document,a=c.createElement("script"),u=setTimeout(function(){g._jsonpCallbacks[o]=function(){},s(!0,"timeout")},3e3);g._jsonpCallbacks[o]=function(e){clearTimeout(u),s(!1,e),delete g._jsonpCallbacks[o]};var h="";for(var f in t)t.hasOwnProperty(f)&&(h.length>0&&(h+="&"),h+=encodeURIComponent(f)+"="+encodeURIComponent(t[f]));var l="Centrifuge._jsonpCallbacks['"+o+"']";a.src=this._config.authEndpoint+"?callback="+encodeURIComponent(l)+"&data="+encodeURIComponent(JSON.stringify(r))+"&"+h;var _=c.getElementsByTagName("head")[0]||c.documentElement;_.insertBefore(a,_.firstChild)},m._ajax=function(e,t,i,r,s){var o=this;o._debug("sending AJAX request to",e);var c=n.XMLHttpRequest?new n.XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),a="";for(var u in t)t.hasOwnProperty(u)&&(a.length>0&&(a+="&"),a+=encodeURIComponent(u)+"="+encodeURIComponent(t[u]));a.length>0&&(a="?"+a),c.open("POST",e+a,!0),"withCredentials"in c&&(c.withCredentials=!0),c.setRequestHeader("X-Requested-With","XMLHttpRequest"),c.setRequestHeader("Content-Type","application/json");for(var h in i)i.hasOwnProperty(h)&&c.setRequestHeader(h,i[h]);return c.onreadystatechange=function(){if(4===c.readyState)if(200===c.status){var e,t=!1;try{e=JSON.parse(c.responseText),t=!0}catch(n){s(!0,"JSON returned was invalid, yet status code was 200. Data was: "+c.responseText)}t&&s(!1,e)}else o._log("Couldn't get auth info from application",c.status),s(!0,c.status)},setTimeout(function(){c.send(JSON.stringify(r))},20),c},m._log=function(){l("info",arguments)},m._debug=function(){this._config.debug===!0&&l("debug",arguments)},m._websocketSupported=function(){return!("function"!=typeof WebSocket&&"object"!=typeof WebSocket)},m._sockjsEndpoint=function(){var e=this._config.url;return e=e.replace("ws://","http://").replace("wss://","https://"),e=a(e),o(this._config.url,"connection")||(e+="/connection"),e},m._rawWebsocketEndpoint=function(){var e=this._config.url;return e=e.replace("http://","ws://").replace("https://","wss://"),e=a(e),o(this._config.url,"connection/websocket")||(e+="/connection/websocket"),e},m._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"),null!==this._config.sockJS)this._debug("SockJS explicitly provided in options"),this._sockJS=this._config.sockJS;else{if("undefined"==typeof 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"),this._sockJS=SockJS}else o(this._config.url,"connection/websocket")?this._debug("client will connect to raw Websocket endpoint"):(this._debug("client will detect connection endpoint itself"),null!==this._config.sockJS?(this._debug("SockJS explicitly provided in options"),this._sockJS=this._config.sockJS):"undefined"==typeof SockJS?this._debug("SockJS not found"):(this._debug("use globally defined SockJS"),this._sockJS=SockJS))},m._setStatus=function(e){this._status!==e&&(this._debug("Status",this._status,"->",e),this._status=e)},m._isDisconnected=function(){return"disconnected"===this._status},m._isConnecting=function(){return"connecting"===this._status},m._isConnected=function(){return"connected"===this._status},m._nextMessageId=function(){return++this._messageId},m._resetRetry=function(){this._debug("reset retries count to 0"),this._retries=0},m._getRetryInterval=function(){var e=_(this._retries,this._config.retry,this._config.maxRetry);return this._retries+=1,e},m._clearConnectedState=function(e){this._clientID=null;for(var t in this._callbacks)if(this._callbacks.hasOwnProperty(t)){var n=this._callbacks[t],i=n.errback;if(!i)continue;i(this._createErrorObject("disconnected","retry"))}this._callbacks={};for(var r in this._subs)if(this._subs.hasOwnProperty(r)){var s=this._subs[r];e?(s._isSuccess()&&s._triggerUnsubscribe(),s._setSubscribing()):s._setUnsubscribed()}this._config.resubscribe&&this._reconnect||(this._subs={})},m._send=function(e){0!==e.length&&(1===e.length&&(e=e[0]),this._debug("Send",e),this._transport.send(JSON.stringify(e)))},m._setupTransport=function(){var e=this;if(this._isSockJS=!1,null!==this._sockJS){var t={transports:this._config.transports};null!==this._config.server&&(t.server=this._config.server),this._isSockJS=!0,this._transport=new this._sockJS(this._sockjsEndpoint(),null,t)}else{if(!this._websocketSupported())return void this._debug("No Websocket support and no SockJS configured, can not connect");this._transport=new WebSocket(this._rawWebsocketEndpoint())}this._transport.onopen=function(){e._transportClosed=!1,e._reconnecting=!1,e._isSockJS?(e._transportName=e._transport.transport,e._transport.onheartbeat=function(){e._restartPing()}):e._transportName="raw-websocket",e._resetRetry(),u(e._config.user)||e._log("user expected to be string"),u(e._config.info)||e._log("info expected to be string");var t={method:"connect",params:{user:e._config.user,info:e._config.info}};e._config.insecure||(t.params.timestamp=e._config.timestamp,t.params.token=e._config.token,u(e._config.timestamp)||e._log("timestamp expected to be string"),u(e._config.token)||e._log("token expected to be string")),e._addMessage(t),e._latencyStart=new Date},this._transport.onerror=function(t){e._debug("transport level error",t)},this._transport.onclose=function(t){e._transportClosed=!0;var n="connection closed",i=!0;if(t&&"reason"in t&&t.reason)try{var r=JSON.parse(t.reason);e._debug("reason is an advice object",r),n=r.reason,i=r.reconnect}catch(s){n=t.reason,e._debug("reason is a plain string",n),i="disconnect"!==n}if(null!==e._config.onTransportClose&&e._config.onTransportClose({event:t,reason:n,reconnect:i}),e._disconnect(n,i),e._reconnect===!0){e._reconnecting=!0;var o=e._getRetryInterval();e._debug("reconnect after "+o+" milliseconds"),setTimeout(function(){e._reconnect===!0&&e._connect.call(e)},o)}},this._transport.onmessage=function(t){var n;n=JSON.parse(t.data),e._debug("Received",n),e._receive(n),e._restartPing()}},m._connect=function(e){return this.isConnected()?void this._debug("connect called when already connected"):void("connecting"!==this._status&&(this._debug("start connecting"),this._setStatus("connecting"),this._clientID=null,this._reconnect=!0,e&&this.on("connect",e),this._setupTransport()))},m._disconnect=function(e,t){if(!this.isDisconnected()){this._debug("disconnected:",e,t);var n=t||!1;n===!1&&(this._reconnect=!1),this._clearConnectedState(n),this.isDisconnected()||(this._setStatus("disconnected"),this._refreshTimeout&&clearTimeout(this._refreshTimeout),this._reconnecting===!1&&this.trigger("disconnect",[{reason:e,reconnect:n}])),this._transportClosed||this._transport.close()}},m._refreshFailed=function(){this._numRefreshFailed=0,this.isDisconnected()||this._disconnect("refresh failed",!1),null!==this._config.refreshFailed&&this._config.refreshFailed()},m._refresh=function(){var e=this;if(this._debug("refresh credentials"),0===e._config.refreshAttempts)return this._debug("refresh attempts set to 0, do not send refresh request at all"),void e._refreshFailed();null!==e._refreshTimeout&&clearTimeout(e._refreshTimeout);var t=function(t,n){return t===!0?(e._debug("error getting connection credentials from refresh endpoint",n),e._numRefreshFailed++,e._refreshTimeout&&clearTimeout(e._refreshTimeout),null!==e._config.refreshAttempts&&e._numRefreshFailed>=e._config.refreshAttempts?void e._refreshFailed():void(e._refreshTimeout=setTimeout(function(){e._refresh.call(e)},e._config.refreshInterval+Math.round(1e3*Math.random())))):(e._numRefreshFailed=0,e._config.user=n.user,e._config.timestamp=n.timestamp,"info"in n&&(e._config.info=n.info),e._config.token=n.token,void(e.isDisconnected()?(e._debug("credentials refreshed, connect from scratch"),e._connect()):(e._debug("send refreshed credentials"),e._addMessage({method:"refresh",params:{user:e._config.user,timestamp:e._config.timestamp,info:e._config.info,token:e._config.token}}))))};if(null!==this._config.onRefresh){var n={};this._config.onRefresh(n,t)}else{var i=this._config.refreshTransport.toLowerCase();if("ajax"===i)this._ajax(this._config.refreshEndpoint,this._config.refreshParams,this._config.refreshHeaders,this._config.refreshData,t);else{if("jsonp"!==i)throw"Unknown refresh transport "+i;this._jsonp(this._config.refreshEndpoint,this._config.refreshParams,this._config.refreshHeaders,this._config.refreshData,t)}}},m._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(c(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)}},m._unsubscribe=function(e){this.isConnected()&&this._addMessage({method:"unsubscribe",params:{channel:e.channel}})},m._getSub=function(e){var t=this._subs[e];return t?t:null},m._connectResponse=function(e){if(!this.isConnected())if(d(e))this.trigger("error",[{message:e}]);else{if(null!==this._latencyStart&&(this._latency=(new Date).getTime()-this._latencyStart.getTime(),this._latencyStart=null),!e.body)return;if(e.body.expires){var t=e.body.expired;if(t)return this._reconnecting=!0,this._disconnect("expired",!0),void this._refresh()}this._clientID=e.body.client,this._setStatus("connected"),this._refreshTimeout&&clearTimeout(this._refreshTimeout);var n=this;if(e.body.expires&&(this._refreshTimeout=setTimeout(function(){n._refresh.call(n)},1e3*e.body.ttl)),this._config.resubscribe){this.startBatching(),this.startAuthBatching();for(var i in this._subs)if(this._subs.hasOwnProperty(i)){var r=this._subs[i];r._shouldResubscribe()&&this._subscribe(r)}this.stopAuthBatching(),this.stopBatching(!0)}this._restartPing(),this.trigger("connect",[{client:e.body.client,transport:this._transportName,latency:this._latency}])}},m._stopPing=function(){null!==this._pongTimeout&&clearTimeout(this._pongTimeout),null!==this._pingInterval&&clearInterval(this._pingInterval)},m._startPing=function(){if(!(this._config.ping!==!0||this._config.pingInterval<=0)&&this.isConnected()){var e=this;this._pingInterval=setInterval(function(){return e.isConnected()?(e.ping(),void(e._pongTimeout=setTimeout(function(){e._disconnect("no ping",!0)},e._config.pongWaitTimeout))):void e._stopPing()},this._config.pingInterval)}},m._restartPing=function(){this._stopPing(),this._startPing()},m._disconnectResponse=function(e){if(d(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)}},m._subscribeResponse=function(e){var t=e.body;if(null!==t){var n=t.channel,i=this._getSub(n);if(i&&i._isSubscribing())if(d(e))this.trigger("error",[{message:e}]),i._setSubscribeError(this._errorObjectFromMessage(e));else{var r=t.messages;if(r&&r.length>0){r=r.reverse();for(var s in r)r.hasOwnProperty(s)&&this._messageResponse({body:r[s]})}else"last"in t&&(this._lastMessageID[n]=t.last);var o=!1;"recovered"in t&&(o=t.recovered),i._setSubscribeSuccess(o)}}},m._unsubscribeResponse=function(e){var t=e.uid,n=e.body,i=n.channel,r=this._getSub(i);r&&(d(e)?this.trigger("error",[{message:e}]):t||r._setUnsubscribed())},m._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],d(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)}}},m._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],d(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)}}},m._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],d(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)}}},m._joinResponse=function(e){var t=e.body,n=t.channel,i=this._getSub(n);i&&i.trigger("join",[t])},m._leaveResponse=function(e){var t=e.body,n=t.channel,i=this._getSub(n);i&&i.trigger("leave",[t])},m._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])},m._refreshResponse=function(e){if(this._refreshTimeout&&clearTimeout(this._refreshTimeout),d(e))this.trigger("error",[{message:e}]);else if(e.body.expires){var t=this,n=e.body.expired;if(n)return void(t._refreshTimeout=setTimeout(function(){t._refresh.call(t)},t._config.refreshInterval+Math.round(1e3*Math.random())));this._clientID=e.body.client,t._refreshTimeout=setTimeout(function(){t._refresh.call(t)},1e3*e.body.ttl)}},m._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)}},m._receive=function(e){if(h(e))for(var t in e)e.hasOwnProperty(t)&&this._dispatchMessage(e[t]);else Object.prototype.toString.call(e)===Object.prototype.toString.call({})&&this._dispatchMessage(e)},m._flush=function(){var e=this._messages.slice(0);this._messages=[],this._send(e)},m._ping=function(){this._addMessage({method:"ping"})},m._recover=function(e){return e in this._lastMessageID},m._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),"")},m._createErrorObject=function(e,t){var n={error:e};return t&&(n.advice=t),n},m._errorObjectFromMessage=function(e){return this._createErrorObject(e.error,e.advice)},m._registerCall=function(e,t,n){var i=this;this._callbacks[e]={callback:t,errback:n},setTimeout(function(){delete i._callbacks[e],f(n)&&n(i._createErrorObject("timeout","retry"))},this._config.timeout)},m._addMessage=function(e){var t=""+this._nextMessageId();return e.uid=t,this._isBatching===!0?this._messages.push(e):this._send([e]),t},m.getClientId=function(){return this._clientID},m.isConnected=m._isConnected,m.isDisconnected=m._isDisconnected,m.configure=function(e){this._configure.call(this,e)},m.connect=m._connect,m.disconnect=function(){this._disconnect("client",!1)},m.ping=m._ping,m.startBatching=function(){this._isBatching=!0},m.stopBatching=function(e){e=e||!1,this._isBatching=!1,e===!0&&this.flush()},m.flush=function(){this._flush()},m.startAuthBatching=function(){this._isAuthBatching=!0},m.stopAuthBatching=function(){var e,t;this._isAuthBatching=!1;var n=this._authChannels;this._authChannels={};var i=[];for(t in n)if(n.hasOwnProperty(t)){var r=this._getSub(t);if(!r)continue;i.push(t)}if(0!==i.length){var s={client:this.getClientId(),channels:i},o=this,c=function(n,r){if(n!==!0){var s;if(r.channels&&h(r.channels)){s={};for(e in r.channels){var c=r.channels[e];c.channel&&(s[c.channel]=c)}}else s=r;var a=!1;o._isBatching||(o.startBatching(),a=!0);for(e in i)if(i.hasOwnProperty(e)){t=i[e];var u=s[t];if(!u){o._subscribeResponse({error:"channel not found in authorization response", | ||
advice:"fix",body:{channel:t}});continue}if(u.status&&200!==u.status)o._subscribeResponse({error:u.status,body:{channel:t}});else{var f={method:"subscribe",params:{channel:t,client:o.getClientId(),info:u.info,sign:u.sign}},l=o._recover(t);l===!0&&(f.params.recover=!0,f.params.last=o._getLastID(t)),o._addMessage(f)}}a&&o.stopBatching(!0)}else{o._debug("authorization request failed");for(e in i)i.hasOwnProperty(e)&&(t=i[e],o._subscribeResponse({error:"authorization request failed",advice:"fix",body:{channel:t}}))}};if(null!==this._config.onPrivateChannelAuth)this._config.onPrivateChannelAuth({data:s},c);else{var a=this._config.authTransport.toLowerCase();if("ajax"===a)this._ajax(this._config.authEndpoint,this._config.authParams,this._config.authHeaders,s,c);else{if("jsonp"!==a)throw"Unknown private channel auth transport "+a;this._jsonp(this._config.authEndpoint,this._config.authParams,this._config.authHeaders,s,c)}}}},m.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._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._isUnsubscribed()&&n.subscribe(),n;var i=new p(this,e,t);return this._subs[e]=i,i.subscribe(),i};var y=0,w=1,S=2,k=3,O=4;i(p,v);var j=p.prototype;j._initializePromise=function(){this._ready=!1;var e=this;this._promise=new b(function(t,n){e._resolve=function(n){e._ready=!0,t(n)},e._reject=function(t){e._ready=!0,n(t)}})},j._setEvents=function(e){if(e)if(f(e))this.on("message",e);else if(Object.prototype.toString.call(e)===Object.prototype.toString.call({}))for(var t=["message","join","leave","unsubscribe","subscribe","error"],n=0,i=t.length;i>n;n++){var r=t[n];r in e&&this.on(r,e[r])}},j._isNew=function(){return this._status===y},j._isUnsubscribed=function(){return this._status===O},j._isSubscribing=function(){return this._status===w},j._isReady=function(){return this._status===S||this._status===k},j._isSuccess=function(){return this._status===S},j._isError=function(){return this._status===k},j._setNew=function(){this._status=y},j._setSubscribing=function(){this._ready===!0&&(this._initializePromise(),this._isResubscribe=!0),this._status=w},j._setSubscribeSuccess=function(e){if(this._status!==S){this._recovered=e,this._status=S;var t=this._getSubscribeSuccessContext(e);this.trigger("subscribe",[t]),this._resolve(t)}},j._setSubscribeError=function(e){if(this._status!==k){this._status=k,this._error=e;var t=this._getSubscribeErrorContext();this.trigger("error",[t]),this._reject(t)}},j._triggerUnsubscribe=function(){this.trigger("unsubscribe",[{channel:this.channel}])},j._setUnsubscribed=function(e){this._status!==O&&(this._status=O,e===!0&&(this._noResubscribe=!0),this._triggerUnsubscribe())},j._shouldResubscribe=function(){return!this._noResubscribe},j._getSubscribeSuccessContext=function(){return{channel:this.channel,isResubscribe:this._isResubscribe,recovered:this._recovered}},j._getSubscribeErrorContext=function(){var e=this._error;return e.channel=this.channel,e.isResubscribe=this._isResubscribe,e},j.ready=function(e,t){this._ready&&(this._isSuccess()?e(this._getSubscribeSuccessContext()):t(this._getSubscribeErrorContext()))},j.subscribe=function(){return this._status!==S?(this._centrifuge._subscribe(this),this):void 0},j.unsubscribe=function(){this._setUnsubscribed(!0),this._centrifuge._unsubscribe(this)},j.publish=function(e){var t=this;return new b(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=t._centrifuge._addMessage({method:"publish",params:{channel:t.channel,data:e}});t._centrifuge._registerCall(r,n,i)},function(e){i(e)})})},j.presence=function(){var e=this;return new b(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=e._centrifuge._addMessage({method:"presence",params:{channel:e.channel}});e._centrifuge._registerCall(i,t,n)},function(e){n(e)})})},j.history=function(){var e=this;return new b(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=e._centrifuge._addMessage({method:"history",params:{channel:e.channel}});e._centrifuge._registerCall(i,t,n)},function(e){n(e)})})},t.exports=g}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"es6-promise":1,"wolfy87-eventemitter":3}]},{},[4])(4)}); | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.Centrifuge=e()}}(function(){var e;return function t(e,n,i){function s(o,c){if(!n[o]){if(!e[o]){var a="function"==typeof require&&require;if(!c&&a)return a(o,!0);if(r)return r(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var h=n[o]={exports:{}};e[o][0].call(h.exports,function(t){var n=e[o][1][t];return s(n?n:t)},h,h.exports,t,e,n,i)}return n[o].exports}for(var r="function"==typeof require&&require,o=0;o<i.length;o++)s(i[o]);return s}({1:[function(t,n,i){(function(s,r){!function(t,s){"object"==typeof i&&"undefined"!=typeof n?n.exports=s():"function"==typeof e&&e.amd?e(s):t.ES6Promise=s()}(this,function(){"use strict";function e(e){var t=typeof e;return null!==e&&("object"===t||"function"===t)}function n(e){return"function"==typeof e}function i(e){z=e}function o(e){V=e}function c(){return function(){return s.nextTick(l)}}function a(){return"undefined"!=typeof X?function(){X(l)}:f()}function u(){var e=0,t=new $(l),n=document.createTextNode("");return t.observe(n,{characterData:!0}),function(){n.data=e=++e%2}}function h(){var e=new MessageChannel;return e.port1.onmessage=l,function(){return e.port2.postMessage(0)}}function f(){var e=setTimeout;return function(){return e(l,1)}}function l(){for(var e=0;W>e;e+=2){var t=Z[e],n=Z[e+1];t(n),Z[e]=void 0,Z[e+1]=void 0}W=0}function _(){try{var e=Function("return this")().require("vertx");return X=e.runOnLoop||e.runOnContext,a()}catch(t){return f()}}function d(e,t){var n=this,i=new this.constructor(p);void 0===i[te]&&I(i);var s=n._state;if(s){var r=arguments[s-1];V(function(){return A(s,i,r,n._result)})}else E(n,i,e,t);return i}function g(e){var t=this;if(e&&"object"==typeof e&&e.constructor===t)return e;var n=new t(p);return O(n,e),n}function p(){}function b(){return new TypeError("You cannot resolve a promise with itself")}function v(){return new TypeError("A promises callback cannot return that same promise.")}function m(e){try{return e.then}catch(t){return re.error=t,re}}function y(e,t,n,i){try{e.call(t,n,i)}catch(s){return s}}function w(e,t,n){V(function(e){var i=!1,s=y(n,t,function(n){i||(i=!0,t!==n?O(e,n):C(e,n))},function(t){i||(i=!0,R(e,t))},"Settle: "+(e._label||" unknown promise"));!i&&s&&(i=!0,R(e,s))},e)}function S(e,t){t._state===ie?C(e,t._result):t._state===se?R(e,t._result):E(t,void 0,function(t){return O(e,t)},function(t){return R(e,t)})}function k(e,t,i){t.constructor===e.constructor&&i===d&&t.constructor.resolve===g?S(e,t):i===re?(R(e,re.error),re.error=null):void 0===i?C(e,t):n(i)?w(e,t,i):C(e,t)}function O(t,n){t===n?R(t,b()):e(n)?k(t,n,m(n)):C(t,n)}function j(e){e._onerror&&e._onerror(e._result),x(e)}function C(e,t){e._state===ne&&(e._result=t,e._state=ie,0!==e._subscribers.length&&V(x,e))}function R(e,t){e._state===ne&&(e._state=se,e._result=t,V(j,e))}function E(e,t,n,i){var s=e._subscribers,r=s.length;e._onerror=null,s[r]=t,s[r+ie]=n,s[r+se]=i,0===r&&e._state&&V(x,e)}function x(e){var t=e._subscribers,n=e._state;if(0!==t.length){for(var i=void 0,s=void 0,r=e._result,o=0;o<t.length;o+=3)i=t[o],s=t[o+n],i?A(n,i,s,r):s(r);e._subscribers.length=0}}function T(e,t){try{return e(t)}catch(n){return re.error=n,re}}function A(e,t,i,s){var r=n(i),o=void 0,c=void 0,a=void 0,u=void 0;if(r){if(o=T(i,s),o===re?(u=!0,c=o.error,o.error=null):a=!0,t===o)return void R(t,v())}else o=s,a=!0;t._state!==ne||(r&&a?O(t,o):u?R(t,c):e===ie?C(t,o):e===se&&R(t,o))}function M(e,t){try{t(function(t){O(e,t)},function(t){R(e,t)})}catch(n){R(e,n)}}function P(){return oe++}function I(e){e[te]=oe++,e._state=void 0,e._result=void 0,e._subscribers=[]}function L(){return new Error("Array Methods must be provided an Array")}function J(e){return new ce(this,e).promise}function D(e){var t=this;return new t(H(e)?function(n,i){for(var s=e.length,r=0;s>r;r++)t.resolve(e[r]).then(n,i)}:function(e,t){return t(new TypeError("You must pass an array to race."))})}function q(e){var t=this,n=new t(p);return R(n,e),n}function N(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function U(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function B(){var e=void 0;if("undefined"!=typeof r)e=r;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;if(n){var i=null;try{i=Object.prototype.toString.call(n.resolve())}catch(t){}if("[object Promise]"===i&&!n.cast)return}e.Promise=ae}var F=void 0;F=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)};var H=F,W=0,X=void 0,z=void 0,V=function(e,t){Z[W]=e,Z[W+1]=t,W+=2,2===W&&(z?z(l):ee())},K="undefined"!=typeof window?window:void 0,Y=K||{},$=Y.MutationObserver||Y.WebKitMutationObserver,G="undefined"==typeof self&&"undefined"!=typeof s&&"[object process]"==={}.toString.call(s),Q="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,Z=new Array(1e3),ee=void 0;ee=G?c():$?u():Q?h():void 0===K&&"function"==typeof t?_():f();var te=Math.random().toString(36).substring(2),ne=void 0,ie=1,se=2,re={error:null},oe=0,ce=function(){function e(e,t){this._instanceConstructor=e,this.promise=new e(p),this.promise[te]||I(this.promise),H(t)?(this.length=t.length,this._remaining=t.length,this._result=new Array(this.length),0===this.length?C(this.promise,this._result):(this.length=this.length||0,this._enumerate(t),0===this._remaining&&C(this.promise,this._result))):R(this.promise,L())}return e.prototype._enumerate=function(e){for(var t=0;this._state===ne&&t<e.length;t++)this._eachEntry(e[t],t)},e.prototype._eachEntry=function(e,t){var n=this._instanceConstructor,i=n.resolve;if(i===g){var s=m(e);if(s===d&&e._state!==ne)this._settledAt(e._state,t,e._result);else if("function"!=typeof s)this._remaining--,this._result[t]=e;else if(n===ae){var r=new n(p);k(r,e,s),this._willSettleAt(r,t)}else this._willSettleAt(new n(function(t){return t(e)}),t)}else this._willSettleAt(i(e),t)},e.prototype._settledAt=function(e,t,n){var i=this.promise;i._state===ne&&(this._remaining--,e===se?R(i,n):this._result[t]=n),0===this._remaining&&C(i,this._result)},e.prototype._willSettleAt=function(e,t){var n=this;E(e,void 0,function(e){return n._settledAt(ie,t,e)},function(e){return n._settledAt(se,t,e)})},e}(),ae=function(){function e(t){this[te]=P(),this._result=this._state=void 0,this._subscribers=[],p!==t&&("function"!=typeof t&&N(),this instanceof e?M(this,t):U())}return e.prototype["catch"]=function(e){return this.then(null,e)},e.prototype["finally"]=function(e){var t=this,n=t.constructor;return t.then(function(t){return n.resolve(e()).then(function(){return t})},function(t){return n.resolve(e()).then(function(){throw t})})},e}();return ae.prototype.then=d,ae.all=J,ae.race=D,ae.resolve=g,ae.reject=q,ae._setScheduler=i,ae._setAsap=o,ae._asap=V,ae.polyfill=B,ae.Promise=ae,ae})}).call(this,t("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{_process:2}],2:[function(e,t,n){function i(){}var s=t.exports={};s.nextTick=function(){var e="undefined"!=typeof window&&window.setImmediate,t="undefined"!=typeof window&&window.MutationObserver,n="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(e)return function(e){return window.setImmediate(e)};var i=[];if(t){var s=document.createElement("div"),r=new MutationObserver(function(){var e=i.slice();i.length=0,e.forEach(function(e){e()})});return r.observe(s,{attributes:!0}),function(e){i.length||s.setAttribute("yes","no"),i.push(e)}}return n?(window.addEventListener("message",function(e){var t=e.source;if((t===window||null===t)&&"process-tick"===e.data&&(e.stopPropagation(),i.length>0)){var n=i.shift();n()}},!0),function(e){i.push(e),window.postMessage("process-tick","*")}):function(e){setTimeout(e,0)}}(),s.title="browser",s.browser=!0,s.env={},s.argv=[],s.on=i,s.addListener=i,s.once=i,s.off=i,s.removeListener=i,s.removeAllListeners=i,s.emit=i,s.binding=function(e){throw new Error("process.binding is not supported")},s.cwd=function(){return"/"},s.chdir=function(e){throw new Error("process.chdir is not supported")}},{}],3:[function(t,n,i){(function(){"use strict";function t(){}function i(e,t){for(var n=e.length;n--;)if(e[n].listener===t)return n;return-1}function s(e){return function(){return this[e].apply(this,arguments)}}var r=t.prototype,o=this,c=o.EventEmitter;r.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},r.flattenListeners=function(e){var t,n=[];for(t=0;t<e.length;t+=1)n.push(e[t].listener);return n},r.getListenersAsObject=function(e){var t,n=this.getListeners(e);return n instanceof Array&&(t={},t[e]=n),t||n},r.addListener=function(e,t){var n,s=this.getListenersAsObject(e),r="object"==typeof t;for(n in s)s.hasOwnProperty(n)&&-1===i(s[n],t)&&s[n].push(r?t:{listener:t,once:!1});return this},r.on=s("addListener"),r.addOnceListener=function(e,t){return this.addListener(e,{listener:t,once:!0})},r.once=s("addOnceListener"),r.defineEvent=function(e){return this.getListeners(e),this},r.defineEvents=function(e){for(var t=0;t<e.length;t+=1)this.defineEvent(e[t]);return this},r.removeListener=function(e,t){var n,s,r=this.getListenersAsObject(e);for(s in r)r.hasOwnProperty(s)&&(n=i(r[s],t),-1!==n&&r[s].splice(n,1));return this},r.off=s("removeListener"),r.addListeners=function(e,t){return this.manipulateListeners(!1,e,t)},r.removeListeners=function(e,t){return this.manipulateListeners(!0,e,t)},r.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},r.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},r.removeAllListeners=s("removeEvent"),r.emitEvent=function(e,t){var n,i,s,r,o,c=this.getListenersAsObject(e);for(r in c)if(c.hasOwnProperty(r))for(n=c[r].slice(0),s=n.length;s--;)i=n[s],i.once===!0&&this.removeListener(e,i.listener),o=i.listener.apply(this,t||[]),o===this._getOnceReturnValue()&&this.removeListener(e,i.listener);return this},r.trigger=s("emitEvent"),r.emit=function(e){var t=Array.prototype.slice.call(arguments,1);return this.emitEvent(e,t)},r.setOnceReturnValue=function(e){return this._onceReturnValue=e,this},r._getOnceReturnValue=function(){return this.hasOwnProperty("_onceReturnValue")?this._onceReturnValue:!0},r._getEvents=function(){return this._events||(this._events={})},t.noConflict=function(){return o.EventEmitter=c,t},"function"==typeof e&&e.amd?e(function(){return t}):"object"==typeof n&&n.exports?n.exports=t:o.EventEmitter=t}).call(this)},{}],4:[function(e,t,n){(function(n){function i(e,t){return e.prototype=Object.create(t.prototype),e.prototype.constructor=e,t.prototype}function s(e,t){try{return e[t]}catch(n){return void 0}}function r(e,t,n){for(var i=t||{},o=2,c=arguments.length;c>o;o++){var a=arguments[o];if(void 0!==a&&null!==a)for(var u in a){var h=s(a,u),f=s(i,u);if(h!==t&&void 0!==h)if(e&&"object"==typeof h&&null!==h)if(h instanceof Array)i[u]=r(e,f instanceof Array?f:[],h);else{var l="object"!=typeof f||f instanceof Array?{}:f;i[u]=r(e,l,h)}else i[u]=h}}return i}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 Object.prototype.toString.call(e)===Object.prototype.toString.call([])}function f(e){return void 0===e||null===e?!1:"function"==typeof e}function l(e,t){if(n.console){var i=n.console[e];f(i)&&i.apply(n.console,t)}}function _(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 d(e){return"error"in e&&null!==e.error&&""!==e.error}function g(e){this._sockJS=null,this._isSockJS=!1,this._status="disconnected",this._reconnect=!0,this._reconnecting=!1,this._transport=null,this._transportName=null,this._transportClosed=!0,this._messageId=0,this._clientID=null,this._subs={},this._lastMessageID={},this._messages=[],this._isBatching=!1,this._isAuthBatching=!1,this._authChannels={},this._numRefreshFailed=0,this._refreshTimeout=null,this._pingInterval=null,this._pongTimeout=null,this._retries=0,this._callbacks={},this._latency=null,this._latencyStart=null,this._config={sockJS:null,retry:1e3,maxRetry:2e4,timeout:5e3,info:"",resubscribe:!0,ping:!0,pingInterval:3e4,pongWaitTimeout:5e3,debug:!1,insecure:!1,server:null,privateChannelPrefix:"$",onTransportClose:null,transports:["websocket","xdr-streaming","xhr-streaming","eventsource","iframe-eventsource","iframe-htmlfile","xdr-polling","xhr-polling","iframe-xhr-polling","jsonp-polling"],onRefresh:null,refreshEndpoint:"/centrifuge/refresh/",refreshHeaders:{},refreshParams:{},refreshData:{},refreshTransport:"ajax",refreshAttempts:null,refreshInterval:3e3,refreshFailed:null,onPrivateChannelAuth:null,authEndpoint:"/centrifuge/auth/",authHeaders:{},authParams:{},authTransport:"ajax"},e&&this.configure(e)}function p(e,t,n){this.channel=t,this._centrifuge=e,this._setEvents(n),this._status=y,this._error=null,this._isResubscribe=!1,this._ready=!1,this._promise=null,this._noResubscribe=!1,this._initializePromise()}var b=e("es6-promise").Promise,v=e("wolfy87-eventemitter");Object.create||(Object.create=function(){var e=function(){};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,t){if(!this)throw new TypeError('Array.prototype.indexOf() - can not convert "'+this+'" to object');var n=isFinite(t)?Math.floor(t):0,i=this instanceof Object?this:new Object(this),s=isFinite(i.length)?Math.floor(i.length):0;if(n>=s)return-1;if(0>n&&(n=Math.max(s+n,0)),void 0===e){do if(n in i&&void 0===i[n])return n;while(++n<s)}else do if(i[n]===e)return n;while(++n<s);return-1}),i(g,v),g._jsonpCallbacks={},g._jsonpTimeouts={},g._nextJSONPCallbackID=1;var m=g.prototype;m._jsonp=function(e,t,i,s,r){Object.keys(i).length>0&&this._log("Only AJAX request allows to send custom headers, it is not possible with JSONP."),this._debug("sending JSONP request to",e);var o="centrifuge_jsonp_"+g._nextJSONPCallbackID.toString();g._nextJSONPCallbackID++;var c=n.document,a=c.createElement("script"),u=setTimeout(function(){g._jsonpCallbacks[o]=function(){},r(!0,"timeout")},3e3);g._jsonpCallbacks[o]=function(e){clearTimeout(u),r(!1,e),delete g._jsonpCallbacks[o]};var h="";for(var f in t)t.hasOwnProperty(f)&&(h.length>0&&(h+="&"),h+=encodeURIComponent(f)+"="+encodeURIComponent(t[f]));var l="Centrifuge._jsonpCallbacks['"+o+"']";a.src=this._config.authEndpoint+"?callback="+encodeURIComponent(l)+"&data="+encodeURIComponent(JSON.stringify(s))+"&"+h;var _=c.getElementsByTagName("head")[0]||c.documentElement;_.insertBefore(a,_.firstChild)},m._ajax=function(e,t,i,s,r){var o=this;o._debug("sending AJAX request to",e);var c=n.XMLHttpRequest?new n.XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),a="";for(var u in t)t.hasOwnProperty(u)&&(a.length>0&&(a+="&"),a+=encodeURIComponent(u)+"="+encodeURIComponent(t[u]));a.length>0&&(a="?"+a),c.open("POST",e+a,!0),"withCredentials"in c&&(c.withCredentials=!0),c.setRequestHeader("X-Requested-With","XMLHttpRequest"),c.setRequestHeader("Content-Type","application/json");for(var h in i)i.hasOwnProperty(h)&&c.setRequestHeader(h,i[h]);return c.onreadystatechange=function(){if(4===c.readyState)if(200===c.status){var e,t=!1;try{e=JSON.parse(c.responseText),t=!0}catch(n){r(!0,"JSON returned was invalid, yet status code was 200. Data was: "+c.responseText)}t&&r(!1,e)}else o._log("Couldn't get auth info from application",c.status),r(!0,c.status)},setTimeout(function(){c.send(JSON.stringify(s))},20),c},m._log=function(){l("info",arguments)},m._debug=function(){this._config.debug===!0&&l("debug",arguments)},m._websocketSupported=function(){return!("function"!=typeof WebSocket&&"object"!=typeof WebSocket)},m._sockjsEndpoint=function(){var e=this._config.url;return e=e.replace("ws://","http://").replace("wss://","https://"),e=a(e),o(this._config.url,"connection")||(e+="/connection"),e},m._rawWebsocketEndpoint=function(){var e=this._config.url;return e=e.replace("http://","ws://").replace("https://","wss://"),e=a(e),o(this._config.url,"connection/websocket")||(e+="/connection/websocket"),e},m._configure=function(e){if(this._debug("Configuring centrifuge object with",e),e||(e={}),this._config=r(!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"),null!==this._config.sockJS)this._debug("SockJS explicitly provided in options"),this._sockJS=this._config.sockJS;else{if("undefined"==typeof 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"),this._sockJS=SockJS}else o(this._config.url,"connection/websocket")?this._debug("client will connect to raw Websocket endpoint"):(this._debug("client will detect connection endpoint itself"),null!==this._config.sockJS?(this._debug("SockJS explicitly provided in options"),this._sockJS=this._config.sockJS):"undefined"==typeof SockJS?this._debug("SockJS not found"):(this._debug("use globally defined SockJS"),this._sockJS=SockJS))},m._setStatus=function(e){this._status!==e&&(this._debug("Status",this._status,"->",e),this._status=e)},m._isDisconnected=function(){return"disconnected"===this._status},m._isConnecting=function(){return"connecting"===this._status},m._isConnected=function(){return"connected"===this._status},m._nextMessageId=function(){return++this._messageId},m._resetRetry=function(){this._debug("reset retries count to 0"),this._retries=0},m._getRetryInterval=function(){var e=_(this._retries,this._config.retry,this._config.maxRetry);return this._retries+=1,e},m._clearConnectedState=function(e){this._clientID=null;for(var t in this._callbacks)if(this._callbacks.hasOwnProperty(t)){var n=this._callbacks[t],i=n.errback;if(!i)continue;i(this._createErrorObject("disconnected","retry"))}this._callbacks={};for(var s in this._subs)if(this._subs.hasOwnProperty(s)){var r=this._subs[s];e?(r._isSuccess()&&r._triggerUnsubscribe(),r._setSubscribing()):r._setUnsubscribed()}this._config.resubscribe&&this._reconnect||(this._subs={})},m._send=function(e){0!==e.length&&(1===e.length&&(e=e[0]),this._debug("Send",e),this._transport.send(JSON.stringify(e)))},m._setupTransport=function(){var e=this;if(this._isSockJS=!1,null!==this._sockJS){var t={transports:this._config.transports};null!==this._config.server&&(t.server=this._config.server),this._isSockJS=!0,this._transport=new this._sockJS(this._sockjsEndpoint(),null,t)}else{if(!this._websocketSupported())return void this._debug("No Websocket support and no SockJS configured, can not connect");this._transport=new WebSocket(this._rawWebsocketEndpoint())}this._transport.onopen=function(){e._transportClosed=!1,e._isSockJS?(e._transportName=e._transport.transport,e._transport.onheartbeat=function(){e._restartPing()}):e._transportName="raw-websocket",e._resetRetry(),u(e._config.user)||e._log("user expected to be string"),u(e._config.info)||e._log("info expected to be string");var t={method:"connect",params:{user:e._config.user,info:e._config.info}};e._config.insecure||(t.params.timestamp=e._config.timestamp,t.params.token=e._config.token,u(e._config.timestamp)||e._log("timestamp expected to be string"),u(e._config.token)||e._log("token expected to be string")),e._addMessage(t),e._latencyStart=new Date},this._transport.onerror=function(t){e._debug("transport level error",t)},this._transport.onclose=function(t){e._transportClosed=!0;var n="connection closed",i=!0;if(t&&"reason"in t&&t.reason)try{var s=JSON.parse(t.reason);e._debug("reason is an advice object",s),n=s.reason,i=s.reconnect}catch(r){n=t.reason,e._debug("reason is a plain string",n),i="disconnect"!==n}if(null!==e._config.onTransportClose&&e._config.onTransportClose({event:t,reason:n,reconnect:i}),e._disconnect(n,i),e._reconnect===!0){e._reconnecting=!0;var o=e._getRetryInterval();e._debug("reconnect after "+o+" milliseconds"),setTimeout(function(){e._reconnect===!0&&e._connect.call(e)},o)}},this._transport.onmessage=function(t){var n;n=JSON.parse(t.data),e._debug("Received",n),e._receive(n),e._restartPing()}},m._connect=function(e){return this.isConnected()?void this._debug("connect called when already connected"):void("connecting"!==this._status&&(this._debug("start connecting"),this._setStatus("connecting"),this._clientID=null,this._reconnect=!0,e&&this.on("connect",e),this._setupTransport()))},m._disconnect=function(e,t){if(!this.isDisconnected()){this._debug("disconnected:",e,t);var n=t||!1;n===!1&&(this._reconnect=!1),this._clearConnectedState(n),this.isDisconnected()||(this._setStatus("disconnected"),this._refreshTimeout&&clearTimeout(this._refreshTimeout),this._reconnecting===!1&&this.trigger("disconnect",[{reason:e,reconnect:n}])),this._transportClosed||this._transport.close()}},m._refreshFailed=function(){this._numRefreshFailed=0,this.isDisconnected()||this._disconnect("refresh failed",!1),null!==this._config.refreshFailed&&this._config.refreshFailed()},m._refresh=function(){var e=this;if(this._debug("refresh credentials"),0===e._config.refreshAttempts)return this._debug("refresh attempts set to 0, do not send refresh request at all"),void e._refreshFailed();null!==e._refreshTimeout&&clearTimeout(e._refreshTimeout);var t=function(t,n){return t===!0?(e._debug("error getting connection credentials from refresh endpoint",n),e._numRefreshFailed++,e._refreshTimeout&&clearTimeout(e._refreshTimeout),null!==e._config.refreshAttempts&&e._numRefreshFailed>=e._config.refreshAttempts?void e._refreshFailed():void(e._refreshTimeout=setTimeout(function(){e._refresh.call(e)},e._config.refreshInterval+Math.round(1e3*Math.random())))):(e._numRefreshFailed=0,e._config.user=n.user,e._config.timestamp=n.timestamp,"info"in n&&(e._config.info=n.info),e._config.token=n.token,void(e.isDisconnected()?(e._debug("credentials refreshed, connect from scratch"),e._connect()):(e._debug("send refreshed credentials"),e._addMessage({method:"refresh",params:{user:e._config.user,timestamp:e._config.timestamp,info:e._config.info,token:e._config.token}}))))};if(null!==this._config.onRefresh){var n={};this._config.onRefresh(n,t)}else{var i=this._config.refreshTransport.toLowerCase();if("ajax"===i)this._ajax(this._config.refreshEndpoint,this._config.refreshParams,this._config.refreshHeaders,this._config.refreshData,t);else{if("jsonp"!==i)throw"Unknown refresh transport "+i;this._jsonp(this._config.refreshEndpoint,this._config.refreshParams,this._config.refreshHeaders,this._config.refreshData,t)}}},m._subscribe=function(e,t){var n=e.channel;if(n in this._subs||(this._subs[n]=e),!this.isConnected())return void e._setNew();e._setSubscribing(t);var i={method:"subscribe",params:{channel:n}};if(c(n,this._config.privateChannelPrefix))this._isAuthBatching?this._authChannels[n]=!0:(this.startAuthBatching(),this._subscribe(e),this.stopAuthBatching());else{var s=this._recover(n);s===!0&&(i.params.recover=!0,i.params.last=this._getLastID(n)),this._addMessage(i)}},m._unsubscribe=function(e){this.isConnected()&&this._addMessage({method:"unsubscribe",params:{channel:e.channel}})},m._getSub=function(e){var t=this._subs[e];return t?t:null},m._connectResponse=function(e){if(!this.isConnected())if(d(e))this.trigger("error",[{message:e}]);else{if(null!==this._latencyStart&&(this._latency=(new Date).getTime()-this._latencyStart.getTime(),this._latencyStart=null),!e.body)return;if(e.body.expires){var t=e.body.expired;if(t)return this._reconnecting=!0,this._disconnect("expired",!0),void this._refresh()}this._clientID=e.body.client,this._setStatus("connected");var n=this._reconnecting;this._reconnecting=!1,this._refreshTimeout&&clearTimeout(this._refreshTimeout);var i=this;if(e.body.expires&&(this._refreshTimeout=setTimeout(function(){i._refresh.call(i)},1e3*e.body.ttl)),this._config.resubscribe){this.startBatching(),this.startAuthBatching();for(var s in this._subs)if(this._subs.hasOwnProperty(s)){var r=this._subs[s];r._shouldResubscribe()&&this._subscribe(r,n)}this.stopAuthBatching(),this.stopBatching(!0)}this._restartPing(),this.trigger("connect",[{client:e.body.client,transport:this._transportName,latency:this._latency}])}},m._stopPing=function(){null!==this._pongTimeout&&(clearTimeout(this._pongTimeout),this._pongTimeout=null),null!==this._pingInterval&&(clearInterval(this._pingInterval),this._pingInterval=null)},m._startPing=function(){if(!(this._config.ping!==!0||this._config.pingInterval<=0)&&this.isConnected()){var e=this;this._pingInterval=setInterval(function(){return e.isConnected()?(e.ping(),void(e._pongTimeout=setTimeout(function(){e._disconnect("no ping",!0)},e._config.pongWaitTimeout))):void e._stopPing()},this._config.pingInterval)}},m._restartPing=function(){this._stopPing(),this._startPing()},m._disconnectResponse=function(e){if(d(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)}},m._subscribeResponse=function(e){var t=e.body;if(null!==t){var n=t.channel,i=this._getSub(n);if(i&&i._isSubscribing())if(d(e))this.trigger("error",[{message:e}]),i._setSubscribeError(this._errorObjectFromMessage(e));else{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[n]=t.last);var o=!1;"recovered"in t&&(o=t.recovered),i._setSubscribeSuccess(o)}}},m._unsubscribeResponse=function(e){var t=e.uid,n=e.body,i=n.channel,s=this._getSub(i);s&&(d(e)?this.trigger("error",[{message:e}]):t||s._setUnsubscribed(!0))},m._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],d(e)){var s=i.errback;if(!s)return;s(this._errorObjectFromMessage(e)),this.trigger("error",[{message:e}])}else{var r=i.callback;if(!r)return;r(n)}}},m._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],d(e)){var s=i.errback;if(!s)return;s(this._errorObjectFromMessage(e)),this.trigger("error",[{message:e}])}else{var r=i.callback;if(!r)return;r(n)}}},m._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],d(e)){var s=i.errback;if(!s)return;s(this._errorObjectFromMessage(e)),this.trigger("error",[{message:e}])}else{var r=i.callback;if(!r)return;r(n)}}},m._joinResponse=function(e){var t=e.body,n=t.channel,i=this._getSub(n);i&&i.trigger("join",[t])},m._leaveResponse=function(e){var t=e.body,n=t.channel,i=this._getSub(n);i&&i.trigger("leave",[t])},m._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])},m._refreshResponse=function(e){if(this._refreshTimeout&&clearTimeout(this._refreshTimeout),d(e))this.trigger("error",[{message:e}]);else if(e.body.expires){var t=this,n=e.body.expired;if(n)return void(t._refreshTimeout=setTimeout(function(){t._refresh.call(t)},t._config.refreshInterval+Math.round(1e3*Math.random())));this._clientID=e.body.client,t._refreshTimeout=setTimeout(function(){t._refresh.call(t)},1e3*e.body.ttl)}},m._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)}},m._receive=function(e){if(h(e))for(var t in e)e.hasOwnProperty(t)&&this._dispatchMessage(e[t]);else Object.prototype.toString.call(e)===Object.prototype.toString.call({})&&this._dispatchMessage(e)},m._flush=function(){var e=this._messages.slice(0);this._messages=[],this._send(e)},m._ping=function(){this._addMessage({method:"ping"})},m._recover=function(e){return e in this._lastMessageID},m._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),"")},m._createErrorObject=function(e,t){var n={error:e};return t&&(n.advice=t),n},m._errorObjectFromMessage=function(e){return this._createErrorObject(e.error,e.advice)},m._registerCall=function(e,t,n){var i=this;this._callbacks[e]={callback:t,errback:n},setTimeout(function(){delete i._callbacks[e],f(n)&&n(i._createErrorObject("timeout","retry"))},this._config.timeout)},m._addMessage=function(e){var t=""+this._nextMessageId();return e.uid=t,this._isBatching===!0?this._messages.push(e):this._send([e]),t},m.getClientId=function(){return this._clientID},m.isConnected=m._isConnected,m.isDisconnected=m._isDisconnected,m.configure=function(e){this._configure.call(this,e)},m.connect=m._connect,m.disconnect=function(){this._disconnect("client",!1)},m.ping=m._ping,m.startBatching=function(){this._isBatching=!0},m.stopBatching=function(e){e=e||!1,this._isBatching=!1,e===!0&&this.flush()},m.flush=function(){this._flush()},m.startAuthBatching=function(){this._isAuthBatching=!0},m.stopAuthBatching=function(){var e,t;this._isAuthBatching=!1;var n=this._authChannels;this._authChannels={};var i=[];for(t in n)if(n.hasOwnProperty(t)){var s=this._getSub(t);if(!s)continue;i.push(t)}if(0!==i.length){var r={client:this.getClientId(),channels:i},o=this,c=function(n,s){if(n!==!0){var r;if(s.channels&&h(s.channels)){r={};for(e in s.channels){var c=s.channels[e];c.channel&&(r[c.channel]=c)}}else r=s;var a=!1;o._isBatching||(o.startBatching(),a=!0);for(e in i)if(i.hasOwnProperty(e)){ | ||
t=i[e];var u=r[t];if(!u){o._subscribeResponse({error:"channel not found in authorization response",advice:"fix",body:{channel:t}});continue}if(u.status&&200!==u.status)o._subscribeResponse({error:u.status,body:{channel:t}});else{var f={method:"subscribe",params:{channel:t,client:o.getClientId(),info:u.info,sign:u.sign}},l=o._recover(t);l===!0&&(f.params.recover=!0,f.params.last=o._getLastID(t)),o._addMessage(f)}}a&&o.stopBatching(!0)}else{o._debug("authorization request failed");for(e in i)i.hasOwnProperty(e)&&(t=i[e],o._subscribeResponse({error:"authorization request failed",advice:"fix",body:{channel:t}}))}};if(null!==this._config.onPrivateChannelAuth)this._config.onPrivateChannelAuth({data:r},c);else{var 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 private channel auth transport "+a;this._jsonp(this._config.authEndpoint,this._config.authParams,this._config.authHeaders,r,c)}}}},m.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._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._isUnsubscribed()&&n.subscribe(),n;var i=new p(this,e,t);return this._subs[e]=i,i.subscribe(),i};var y=0,w=1,S=2,k=3,O=4;i(p,v);var j=p.prototype;j._initializePromise=function(){this._ready=!1;var e=this;this._promise=new b(function(t,n){e._resolve=function(n){e._ready=!0,t(n)},e._reject=function(t){e._ready=!0,n(t)}})},j._setEvents=function(e){if(e)if(f(e))this.on("message",e);else if(Object.prototype.toString.call(e)===Object.prototype.toString.call({}))for(var t=["message","join","leave","unsubscribe","subscribe","error"],n=0,i=t.length;i>n;n++){var s=t[n];s in e&&this.on(s,e[s])}},j._isNew=function(){return this._status===y},j._isUnsubscribed=function(){return this._status===O},j._isSubscribing=function(){return this._status===w},j._isReady=function(){return this._status===S||this._status===k},j._isSuccess=function(){return this._status===S},j._isError=function(){return this._status===k},j._setNew=function(){this._status=y},j._setSubscribing=function(e){this._isResubscribe=e||!1,this._ready===!0&&this._initializePromise(),this._status=w},j._setSubscribeSuccess=function(e){if(this._status!==S){this._status=S;var t=this._getSubscribeSuccessContext(e);this.trigger("subscribe",[t]),this._resolve(t)}},j._setSubscribeError=function(e){if(this._status!==k){this._status=k,this._error=e;var t=this._getSubscribeErrorContext();this.trigger("error",[t]),this._reject(t)}},j._triggerUnsubscribe=function(){this.trigger("unsubscribe",[{channel:this.channel}])},j._setUnsubscribed=function(e){this._status!==O&&(this._status=O,e===!0&&(this._noResubscribe=!0,delete this._centrifuge._lastMessageID[this.channel]),this._triggerUnsubscribe())},j._shouldResubscribe=function(){return!this._noResubscribe},j._getSubscribeSuccessContext=function(e){return{channel:this.channel,isResubscribe:this._isResubscribe,recovered:e}},j._getSubscribeErrorContext=function(){var e=this._error;return e.channel=this.channel,e.isResubscribe=this._isResubscribe,e},j.ready=function(e,t){this._ready&&(this._isSuccess()?e(this._getSubscribeSuccessContext()):t(this._getSubscribeErrorContext()))},j.subscribe=function(){return this._status!==S?(this._noResubscribe=!1,this._centrifuge._subscribe(this),this):void 0},j.unsubscribe=function(){this._setUnsubscribed(!0),this._centrifuge._unsubscribe(this)},j.publish=function(e){var t=this;return new b(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 s=t._centrifuge._addMessage({method:"publish",params:{channel:t.channel,data:e}});t._centrifuge._registerCall(s,n,i)},function(e){i(e)})})},j.presence=function(){var e=this;return new b(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=e._centrifuge._addMessage({method:"presence",params:{channel:e.channel}});e._centrifuge._registerCall(i,t,n)},function(e){n(e)})})},j.history=function(){var e=this;return new b(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=e._centrifuge._addMessage({method:"history",params:{channel:e.channel}});e._centrifuge._registerCall(i,t,n)},function(e){n(e)})})},t.exports=g}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"es6-promise":1,"wolfy87-eventemitter":3}]},{},[4])(4)}); |
@@ -0,1 +1,8 @@ | ||
1.5.0 | ||
===== | ||
* fix isResubscribe flag behaviour to only be `true` after resubscribe on reconnect. See more details in [#62](https://github.com/centrifugal/centrifuge-js/issues/62) | ||
* fix resubscribe behaviour after `unsubscribe` sent from server - this is th remaining part of [#46](https://github.com/centrifugal/centrifuge-js/issues/46) | ||
1.4.9 | ||
@@ -2,0 +9,0 @@ ===== |
{ | ||
"name": "centrifuge", | ||
"version": "1.4.9", | ||
"version": "1.5.0", | ||
"description": "Centrifuge javascript client", | ||
@@ -5,0 +5,0 @@ "main": "src/centrifuge.js", |
@@ -573,3 +573,2 @@ var Promise = require('es6-promise').Promise; | ||
self._transportClosed = false; | ||
self._reconnecting = false; | ||
@@ -815,3 +814,3 @@ if (self._isSockJS) { | ||
centrifugeProto._subscribe = function (sub) { | ||
centrifugeProto._subscribe = function (sub, isResubscribe) { | ||
@@ -830,3 +829,3 @@ var channel = sub.channel; | ||
sub._setSubscribing(); | ||
sub._setSubscribing(isResubscribe); | ||
@@ -909,2 +908,4 @@ var msg = { | ||
this._setStatus('connected'); | ||
var wasReconnecting = this._reconnecting; | ||
this._reconnecting = false; | ||
@@ -930,3 +931,3 @@ if (this._refreshTimeout) { | ||
if (sub._shouldResubscribe()) { | ||
this._subscribe(sub); | ||
this._subscribe(sub, wasReconnecting); | ||
} | ||
@@ -955,5 +956,7 @@ } | ||
clearTimeout(this._pongTimeout); | ||
this._pongTimeout = null; | ||
} | ||
if (this._pingInterval !== null) { | ||
clearInterval(this._pingInterval); | ||
this._pingInterval = null; | ||
} | ||
@@ -1066,4 +1069,4 @@ }; | ||
if (!uid) { | ||
// unsubscribe command from server – unsubscribe all current subs | ||
sub._setUnsubscribed(); | ||
// unsubscribe command from server | ||
sub._setUnsubscribed(true); | ||
} | ||
@@ -1571,9 +1574,8 @@ // ignore client initiated successful unsubscribe responses as we | ||
function Sub(centrifuge, channel, events) { | ||
this.channel = channel; | ||
this._centrifuge = centrifuge; | ||
this._setEvents(events); | ||
this._status = _STATE_NEW; | ||
this._error = null; | ||
this._centrifuge = centrifuge; | ||
this.channel = channel; | ||
this._setEvents(events); | ||
this._isResubscribe = false; | ||
this._recovered = false; | ||
this._ready = false; | ||
@@ -1649,7 +1651,7 @@ this._promise = null; | ||
subProto._setSubscribing = function () { | ||
subProto._setSubscribing = function (isResubscribe) { | ||
this._isResubscribe = isResubscribe || false; | ||
if (this._ready === true) { | ||
// new promise for this subscription | ||
this._initializePromise(); | ||
this._isResubscribe = true; | ||
} | ||
@@ -1663,3 +1665,2 @@ this._status = _STATE_SUBSCRIBING; | ||
} | ||
this._recovered = recovered; | ||
this._status = _STATE_SUCCESS; | ||
@@ -1695,2 +1696,3 @@ var successContext = this._getSubscribeSuccessContext(recovered); | ||
this._noResubscribe = true; | ||
delete this._centrifuge._lastMessageID[this.channel]; | ||
} | ||
@@ -1704,7 +1706,7 @@ this._triggerUnsubscribe(); | ||
subProto._getSubscribeSuccessContext = function () { | ||
subProto._getSubscribeSuccessContext = function (recovered) { | ||
return { | ||
channel: this.channel, | ||
isResubscribe: this._isResubscribe, | ||
recovered: this._recovered | ||
recovered: recovered | ||
}; | ||
@@ -1734,2 +1736,3 @@ }; | ||
} | ||
this._noResubscribe = false; | ||
this._centrifuge._subscribe(this); | ||
@@ -1736,0 +1739,0 @@ return this; |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
206054
4921