diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ce97f717..5406def01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## [Unreleased] +## [1.0.2] - 2016-07-28 ### Bug Fixes diff --git a/dist/deepstream.js b/dist/deepstream.js index 16053c06f..526b8ccb1 100644 --- a/dist/deepstream.js +++ b/dist/deepstream.js @@ -4654,6 +4654,8 @@ exports.TOPIC.PRIVATE = 'PRIVATE/'; exports.EVENT = {}; exports.EVENT.CONNECTION_ERROR = 'connectionError'; exports.EVENT.CONNECTION_STATE_CHANGED = 'connectionStateChanged'; +exports.EVENT.MAX_RECONNECTION_ATTEMPTS_REACHED = 'MAX_RECONNECTION_ATTEMPTS_REACHED'; +exports.EVENT.CONNECTION_AUTHENTICATION_TIMEOUT = 'CONNECTION_AUTHENTICATION_TIMEOUT'; exports.EVENT.ACK_TIMEOUT = 'ACK_TIMEOUT'; exports.EVENT.NO_RPC_PROVIDER = 'NO_RPC_PROVIDER'; exports.EVENT.RESPONSE_TIMEOUT = 'RESPONSE_TIMEOUT'; @@ -4763,6 +4765,13 @@ module.exports = { */ reconnectIntervalIncrement: 4000, + /** + * @param {Number} maxReconnectInterval Specifies the maximum number of milliseconds for the reconnectIntervalIncrement + * The amount of reconnections will reach this value + * then reconnectIntervalIncrement will be ignored. + */ + maxReconnectInterval: 180000, + /** * @param {Number} maxReconnectAttempts The number of reconnection attempts until the client gives * up and declares the connection closed @@ -5133,6 +5142,7 @@ var Connection = function( client, url, options ) { this._deliberateClose = false; this._redirecting = false; this._tooManyAuthAttempts = false; + this._connectionAuthenticationTimeout = false; this._challengeDenied = false; this._queuedMessages = []; this._reconnectTimeout = null; @@ -5148,7 +5158,7 @@ var Connection = function( client, url, options ) { /** * Returns the current connection state. - * (One of constants.CONNECTION_STATE) + * (One of constants.CONNECTION_STATE) * * @public * @returns {String} connectionState @@ -5172,7 +5182,7 @@ Connection.prototype.authenticate = function( authParams, callback ) { this._authParams = authParams; this._authCallback = callback; - if( this._tooManyAuthAttempts || this._challengeDenied ) { + if( this._tooManyAuthAttempts || this._challengeDenied || this._connectionAuthenticationTimeout ) { this._client._$onError( C.TOPIC.ERROR, C.EVENT.IS_CLOSED, 'this client\'s connection was closed' ); return; } @@ -5181,7 +5191,7 @@ Connection.prototype.authenticate = function( authParams, callback ) { this._deliberateClose = false; return; } - + if( this._state === C.CONNECTION_STATE.AWAITING_AUTHENTICATION ) { this._sendAuthParams(); } @@ -5221,7 +5231,7 @@ Connection.prototype.send = function( message ) { this._currentMessageResetTimeout = utils.nextTick( this._resetCurrentMessageCount.bind( this ) ); } - if( this._state === C.CONNECTION_STATE.OPEN && + if( this._state === C.CONNECTION_STATE.OPEN && this._queuedMessages.length < this._options.maxMessagesPerPacket && this._currentPacketMessageCount < this._options.maxMessagesPerPacket ) { this._sendQueuedMessages(); @@ -5341,7 +5351,7 @@ Connection.prototype._sendAuthParams = function() { /** * Will be invoked once the connection is established. The client - * can't send messages yet, and needs to get a connection ACK or REDIRECT + * can't send messages yet, and needs to get a connection ACK or REDIRECT * from the server before authenticating * * @private @@ -5394,7 +5404,7 @@ Connection.prototype._onClose = function() { } else if( this._deliberateClose === true ) { this._setState( C.CONNECTION_STATE.CLOSED ); - } + } else { if( this._originalUrl !== this._url ) { this._url = this._originalUrl; @@ -5442,7 +5452,7 @@ Connection.prototype._onMessage = function( message ) { * by the client until the authentication is successful. * * If a challenge is recieved, the user will send the url to the server - * in response to get the appropriate redirect. If the URL is invalid the + * in response to get the appropriate redirect. If the URL is invalid the * server will respond with a REJECTION resulting in the client connection * being permanently closed. * @@ -5457,15 +5467,15 @@ Connection.prototype._onMessage = function( message ) { Connection.prototype._handleConnectionResponse = function( message ) { var data; - if( message.action === C.ACTIONS.ACK ) { + if( message.action === C.ACTIONS.ACK ) { this._setState( C.CONNECTION_STATE.AWAITING_AUTHENTICATION ); if( this._authParams ) { this._sendAuthParams(); } - } + } else if( message.action === C.ACTIONS.CHALLENGE ) { this._setState( C.CONNECTION_STATE.CHALLENGING ); - this._endpoint.send( messageBuilder.getMsg( C.TOPIC.CONNECTION, C.ACTIONS.CHALLENGE_RESPONSE, [ this._originalUrl ] ) ); + this._endpoint.send( messageBuilder.getMsg( C.TOPIC.CONNECTION, C.ACTIONS.CHALLENGE_RESPONSE, [ this._originalUrl ] ) ); } else if( message.action === C.ACTIONS.REJECTION ) { this._challengeDenied = true; @@ -5476,6 +5486,13 @@ Connection.prototype._handleConnectionResponse = function( message ) { this._redirecting = true; this._endpoint.close(); } + else if( message.action === C.ACTIONS.ERROR ) { + if( message.data[ 0 ] === C.EVENT.CONNECTION_AUTHENTICATION_TIMEOUT ) { + this._deliberateClose = true; + this._connectionAuthenticationTimeout = true; + this._client._$onError( C.TOPIC.CONNECTION, message.data[ 0 ], message.data[ 1 ] ); + } + } }; /** @@ -5493,21 +5510,21 @@ Connection.prototype._handleAuthResponse = function( message ) { var data; if( message.action === C.ACTIONS.ERROR ) { - + if( message.data[ 0 ] === C.EVENT.TOO_MANY_AUTH_ATTEMPTS ) { this._deliberateClose = true; this._tooManyAuthAttempts = true; } else { this._setState( C.CONNECTION_STATE.AWAITING_AUTHENTICATION ); } - + if( this._authCallback ) { this._authCallback( false, this._getAuthData( message.data[ 1 ] ) ); } - + } else if( message.action === C.ACTIONS.ACK ) { this._setState( C.CONNECTION_STATE.OPEN ); - + if( this._authCallback ) { this._authCallback( true, this._getAuthData( message.data[ 0 ] ) ); } @@ -5534,7 +5551,7 @@ Connection.prototype._getAuthData = function( data ) { }; /** - * Updates the connection state and emits the + * Updates the connection state and emits the * connectionStateChanged event on the client * * @private @@ -5551,7 +5568,7 @@ Connection.prototype._setState = function( state ) { * * If the number of failed reconnection attempts exceeds * options.maxReconnectAttempts the connection is closed - * + * * @private * @returns {void} */ @@ -5564,18 +5581,22 @@ Connection.prototype._tryReconnect = function() { this._setState( C.CONNECTION_STATE.RECONNECTING ); this._reconnectTimeout = setTimeout( this._tryOpen.bind( this ), - this._options.reconnectIntervalIncrement * this._reconnectionAttempt + Math.min( + this._options.maxReconnectInterval, + this._options.reconnectIntervalIncrement * this._reconnectionAttempt + ) ); this._reconnectionAttempt++; } else { this._clearReconnect(); this.close(); + this._client.emit( C.MAX_RECONNECTION_ATTEMPTS_REACHED, this._reconnectionAttempt ); } }; /** * Attempts to open a errourosly closed connection - * + * * @private * @returns {void} */ @@ -5600,6 +5621,7 @@ Connection.prototype._clearReconnect = function() { }; module.exports = Connection; + },{"../constants/constants":35,"../tcp/tcp-connection":31,"../utils/utils":54,"./message-builder":40,"./message-parser":41,"engine.io-client":2}],40:[function(_dereq_,module,exports){ var C = _dereq_( '../constants/constants' ), SEP = C.MESSAGE_PART_SEPERATOR; @@ -6287,10 +6309,22 @@ List.prototype.subscribe = function() { } //Make sure the callback is invoked with an empty array for new records - parameters.callback = function( callback ) { + var listCallback = function( callback ) { callback( this.getEntries() ); }.bind( this, parameters.callback ); + /** + * Adding a property onto a function directly is terrible practice, + * and we will change this as soon as we have a more seperate approach + * of creating lists that doesn't have records default state. + * + * The reason we are holding a referencing to wrapped array is so that + * on unsubscribe it can provide a reference to the actual method the + * record is subscribed too. + **/ + parameters.callback.wrappedCallback = listCallback; + parameters.callback = listCallback; + this._record.subscribe( parameters ); }; @@ -6308,6 +6342,7 @@ List.prototype.unsubscribe = function() { throw new Error( 'path is not supported for List.unsubscribe' ); } + parameters.callback = parameters.callback.wrappedCallback; this._record.unsubscribe( parameters ); }; @@ -6389,7 +6424,7 @@ List.prototype._hasIndex = function( index ) { /** * Establishes the current structure of the list, provided the client has attached any - * add / move / remove listener + * add / move / remove listener * * This will be called before any change to the list, regardsless if the change was triggered * by an incoming message from the server or by the client @@ -6434,7 +6469,7 @@ List.prototype._afterChange = function() { } } } - + if( this._hasAddListener || this._hasMoveListener ) { for( entry in after ) { if( before[ entry ] === undefined ) { @@ -6463,7 +6498,7 @@ List.prototype._afterChange = function() { * { * 'recordA': [ 0, 3 ], * 'recordB': [ 1 ], - * 'recordC': [ 2 ] + * 'recordC': [ 2 ] * } * * @private @@ -6626,7 +6661,7 @@ RecordHandler.prototype.unlisten = function( pattern ) { * @public */ RecordHandler.prototype.snapshot = function( name, callback ) { - if( this._records[ name ] ) { + if( this._records[ name ] && this._records[ name ].isReady ) { callback( null, this._records[ name ].get() ); } else { this._snapshotRegistry.request( name, callback ); @@ -6962,20 +6997,23 @@ Record.prototype.set = function( pathOrData, data ) { * @returns {void} */ Record.prototype.subscribe = function( path, callback, triggerNow ) { - var i, args = this._normalizeArguments( arguments ); + var args = this._normalizeArguments( arguments ); if( this._checkDestroyed( 'subscribe' ) ) { return; } - this._eventEmitter.on( args.path || ALL_EVENT, args.callback ); - - if( args.triggerNow && this.isReady ) { - if( args.path ) { - args.callback( this._getPath( args.path ).getValue() ); - } else { - args.callback( this._$data ); - } + if( args.triggerNow ) { + this.whenReady(function () { + this._eventEmitter.on( args.path || ALL_EVENT, args.callback ); + if( args.path ) { + args.callback( this._getPath( args.path ).getValue() ); + } else { + args.callback( this._$data ); + } + }.bind(this)); + } else { + this._eventEmitter.on( args.path || ALL_EVENT, args.callback ); } }; @@ -6997,11 +7035,16 @@ Record.prototype.subscribe = function( path, callback, triggerNow ) { * @returns {void} */ Record.prototype.unsubscribe = function( pathOrCallback, callback ) { + var args = this._normalizeArguments( arguments ); + if( this._checkDestroyed( 'unsubscribe' ) ) { return; } - var event = arguments.length === 2 ? pathOrCallback : ALL_EVENT; - this._eventEmitter.off( event, callback ); + if ( args.path ) { + this._eventEmitter.off( args.path, args.callback ); + } else { + this._eventEmitter.off( ALL_EVENT, args.callback ); + } }; /** @@ -7012,15 +7055,14 @@ Record.prototype.unsubscribe = function( pathOrCallback, callback ) { * @returns {void} */ Record.prototype.discard = function() { - this.usages--; - - if( this.usages <= 0 ) { - this.whenReady( function() { - this.emit( 'destroyPending' ); - this._discardTimeout = setTimeout( this._onTimeout.bind( this, C.EVENT.ACK_TIMEOUT ), this._options.subscriptionTimeout ); - this._connection.sendMsg( C.TOPIC.RECORD, C.ACTIONS.UNSUBSCRIBE, [ this.name ] ); - }.bind( this ) ); - } + this.whenReady( function() { + this.usages--; + if( this.usages <= 0 ) { + this.emit( 'destroyPending' ); + this._discardTimeout = setTimeout( this._onTimeout.bind( this, C.EVENT.ACK_TIMEOUT ), this._options.subscriptionTimeout ); + this._connection.sendMsg( C.TOPIC.RECORD, C.ACTIONS.UNSUBSCRIBE, [ this.name ] ); + } + }.bind( this ) ); }; /** diff --git a/dist/deepstream.min.js b/dist/deepstream.min.js index b0eb7e6e7..1d04c8a45 100644 --- a/dist/deepstream.min.js +++ b/dist/deepstream.min.js @@ -1,5 +1,5 @@ -/*! deepstream.io-client-js 1.0.1 (c)2016 deepstreamHub GmbH, with parts (c)2016 Joyent and contributers @licence Apache-2.0*/ +/*! deepstream.io-client-js 1.0.2 (c)2016 deepstreamHub GmbH, with parts (c)2016 Joyent and contributers @licence Apache-2.0*/ !function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.deepstream=a()}}(function(){var a;return function b(a,c,d){function e(g,h){if(!c[g]){if(!a[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};a[g][0].call(k.exports,function(b){var c=a[g][1][b];return e(c?c:b)},k,k.exports,b,a,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g0&&(this.extraHeaders=b.extraHeaders),this.open()}function e(a){var b={};for(var c in a)a.hasOwnProperty(c)&&(b[c]=a[c]);return b}var f=a("./transports"),g=a("component-emitter"),h=a("debug")("engine.io-client:socket"),i=a("indexof"),j=a("engine.io-parser"),k=a("parseuri"),l=a("parsejson"),m=a("parseqs");b.exports=d,d.priorWebsocketSuccess=!1,g(d.prototype),d.protocol=j.protocol,d.Socket=d,d.Transport=a("./transport"),d.transports=a("./transports"),d.parser=a("engine.io-parser"),d.prototype.createTransport=function(a){h('creating transport "%s"',a);var b=e(this.query);b.EIO=j.protocol,b.transport=a,this.id&&(b.sid=this.id);var c=new f[a]({agent:this.agent,hostname:this.hostname,port:this.port,secure:this.secure,path:this.path,query:b,forceJSONP:this.forceJSONP,jsonp:this.jsonp,forceBase64:this.forceBase64,enablesXDR:this.enablesXDR,timestampRequests:this.timestampRequests,timestampParam:this.timestampParam,policyPort:this.policyPort,socket:this,pfx:this.pfx,key:this.key,passphrase:this.passphrase,cert:this.cert,ca:this.ca,ciphers:this.ciphers,rejectUnauthorized:this.rejectUnauthorized,perMessageDeflate:this.perMessageDeflate,extraHeaders:this.extraHeaders});return c},d.prototype.open=function(){var a;if(this.rememberUpgrade&&d.priorWebsocketSuccess&&this.transports.indexOf("websocket")!=-1)a="websocket";else{if(0===this.transports.length){var b=this;return void setTimeout(function(){b.emit("error","No transports available")},0)}a=this.transports[0]}this.readyState="opening";try{a=this.createTransport(a)}catch(c){return this.transports.shift(),void this.open()}a.open(),this.setTransport(a)},d.prototype.setTransport=function(a){h("setting transport %s",a.name);var b=this;this.transport&&(h("clearing existing transport %s",this.transport.name),this.transport.removeAllListeners()),this.transport=a,a.on("drain",function(){b.onDrain()}).on("packet",function(a){b.onPacket(a)}).on("error",function(a){b.onError(a)}).on("close",function(){b.onClose("transport close")})},d.prototype.probe=function(a){function b(){if(m.onlyBinaryUpgrades){var b=!this.supportsBinary&&m.transport.supportsBinary;l=l||b}l||(h('probe transport "%s" opened',a),k.send([{type:"ping",data:"probe"}]),k.once("packet",function(b){if(!l)if("pong"==b.type&&"probe"==b.data){if(h('probe transport "%s" pong',a),m.upgrading=!0,m.emit("upgrading",k),!k)return;d.priorWebsocketSuccess="websocket"==k.name,h('pausing current transport "%s"',m.transport.name),m.transport.pause(function(){l||"closed"!=m.readyState&&(h("changing transport and sending upgrade packet"),j(),m.setTransport(k),k.send([{type:"upgrade"}]),m.emit("upgrade",k),k=null,m.upgrading=!1,m.flush())})}else{h('probe transport "%s" failed',a);var c=new Error("probe error");c.transport=k.name,m.emit("upgradeError",c)}}))}function c(){l||(l=!0,j(),k.close(),k=null)}function e(b){var d=new Error("probe error: "+b);d.transport=k.name,c(),h('probe transport "%s" failed because of error: %s',a,b),m.emit("upgradeError",d)}function f(){e("transport closed")}function g(){e("socket closed")}function i(a){k&&a.name!=k.name&&(h('"%s" works - aborting "%s"',a.name,k.name),c())}function j(){k.removeListener("open",b),k.removeListener("error",e),k.removeListener("close",f),m.removeListener("close",g),m.removeListener("upgrading",i)}h('probing transport "%s"',a);var k=this.createTransport(a,{probe:1}),l=!1,m=this;d.priorWebsocketSuccess=!1,k.once("open",b),k.once("error",e),k.once("close",f),this.once("close",g),this.once("upgrading",i),k.open()},d.prototype.onOpen=function(){if(h("socket open"),this.readyState="open",d.priorWebsocketSuccess="websocket"==this.transport.name,this.emit("open"),this.flush(),"open"==this.readyState&&this.upgrade&&this.transport.pause){h("starting upgrade probes");for(var a=0,b=this.upgrades.length;a';f=document.createElement(b)}catch(a){f=document.createElement("iframe"),f.name=e.iframeId,f.src="javascript:0"}f.id=e.iframeId,e.form.appendChild(f),e.iframe=f}var e=this;if(!this.form){var f,g=document.createElement("form"),h=document.createElement("textarea"),k=this.iframeId="eio_iframe_"+this.index;g.className="socketio",g.style.position="absolute",g.style.top="-1000px",g.style.left="-1000px",g.target=k,g.method="POST",g.setAttribute("accept-charset","utf-8"),h.name="d",g.appendChild(h),document.body.appendChild(g),this.form=g,this.area=h}this.form.action=this.uri(),d(),a=a.replace(j,"\\\n"),this.area.value=a.replace(i,"\\n");try{this.form.submit()}catch(l){}this.iframe.attachEvent?this.iframe.onreadystatechange=function(){"complete"==e.iframe.readyState&&c()}:this.iframe.onload=c}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./polling":9,"component-inherit":12}],8:[function(a,b,c){(function(c){function d(){}function e(a){if(i.call(this,a),c.location){var b="https:"==location.protocol,d=location.port;d||(d=b?443:80),this.xd=a.hostname!=c.location.hostname||d!=a.port,this.xs=a.secure!=b}else this.extraHeaders=a.extraHeaders}function f(a){this.method=a.method||"GET",this.uri=a.uri,this.xd=!!a.xd,this.xs=!!a.xs,this.async=!1!==a.async,this.data=void 0!=a.data?a.data:null,this.agent=a.agent,this.isBinary=a.isBinary,this.supportsBinary=a.supportsBinary,this.enablesXDR=a.enablesXDR,this.pfx=a.pfx,this.key=a.key,this.passphrase=a.passphrase,this.cert=a.cert,this.ca=a.ca,this.ciphers=a.ciphers,this.rejectUnauthorized=a.rejectUnauthorized,this.extraHeaders=a.extraHeaders,this.create()}function g(){for(var a in f.requests)f.requests.hasOwnProperty(a)&&f.requests[a].abort()}var h=a("xmlhttprequest-ssl"),i=a("./polling"),j=a("component-emitter"),k=a("component-inherit"),l=a("debug")("engine.io-client:polling-xhr");b.exports=e,b.exports.Request=f,k(e,i),e.prototype.supportsBinary=!0,e.prototype.request=function(a){return a=a||{},a.uri=this.uri(),a.xd=this.xd,a.xs=this.xs,a.agent=this.agent||!1,a.supportsBinary=this.supportsBinary,a.enablesXDR=this.enablesXDR,a.pfx=this.pfx,a.key=this.key,a.passphrase=this.passphrase,a.cert=this.cert,a.ca=this.ca,a.ciphers=this.ciphers,a.rejectUnauthorized=this.rejectUnauthorized,a.extraHeaders=this.extraHeaders,new f(a)},e.prototype.doWrite=function(a,b){var c="string"!=typeof a&&void 0!==a,d=this.request({method:"POST",data:a,isBinary:c}),e=this;d.on("success",b),d.on("error",function(a){e.onError("xhr post error",a)}),this.sendXhr=d},e.prototype.doPoll=function(){l("xhr poll");var a=this.request(),b=this;a.on("data",function(a){b.onData(a)}),a.on("error",function(a){b.onError("xhr poll error",a)}),this.pollXhr=a},j(f.prototype),f.prototype.create=function(){var a={agent:this.agent,xdomain:this.xd,xscheme:this.xs,enablesXDR:this.enablesXDR};a.pfx=this.pfx,a.key=this.key,a.passphrase=this.passphrase,a.cert=this.cert,a.ca=this.ca,a.ciphers=this.ciphers,a.rejectUnauthorized=this.rejectUnauthorized;var b=this.xhr=new h(a),d=this;try{l("xhr open %s: %s",this.method,this.uri),b.open(this.method,this.uri,this.async);try{if(this.extraHeaders){b.setDisableHeaderCheck(!0);for(var e in this.extraHeaders)this.extraHeaders.hasOwnProperty(e)&&b.setRequestHeader(e,this.extraHeaders[e])}}catch(g){}if(this.supportsBinary&&(b.responseType="arraybuffer"),"POST"==this.method)try{this.isBinary?b.setRequestHeader("Content-type","application/octet-stream"):b.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch(g){}"withCredentials"in b&&(b.withCredentials=!0),this.hasXDR()?(b.onload=function(){d.onLoad()},b.onerror=function(){d.onError(b.responseText)}):b.onreadystatechange=function(){4==b.readyState&&(200==b.status||1223==b.status?d.onLoad():setTimeout(function(){d.onError(b.status)},0))},l("xhr data %s",this.data),b.send(this.data)}catch(g){return void setTimeout(function(){d.onError(g)},0)}c.document&&(this.index=f.requestsCount++,f.requests[this.index]=this)},f.prototype.onSuccess=function(){this.emit("success"),this.cleanup()},f.prototype.onData=function(a){this.emit("data",a),this.onSuccess()},f.prototype.onError=function(a){this.emit("error",a),this.cleanup(!0)},f.prototype.cleanup=function(a){if("undefined"!=typeof this.xhr&&null!==this.xhr){if(this.hasXDR()?this.xhr.onload=this.xhr.onerror=d:this.xhr.onreadystatechange=d,a)try{this.xhr.abort()}catch(b){}c.document&&delete f.requests[this.index],this.xhr=null}},f.prototype.onLoad=function(){var a;try{var b;try{b=this.xhr.getResponseHeader("Content-Type").split(";")[0]}catch(c){}if("application/octet-stream"===b)a=this.xhr.response;else if(this.supportsBinary)try{a=String.fromCharCode.apply(null,new Uint8Array(this.xhr.response))}catch(c){for(var d=new Uint8Array(this.xhr.response),e=[],f=0,g=d.length;f=31}function e(){var a=arguments,b=this.useColors;if(a[0]=(b?"%c":"")+this.namespace+(b?" %c":" ")+a[0]+(b?"%c ":" ")+"+"+c.humanize(this.diff),!b)return a;var d="color: "+this.color;a=[a[0],d,"color: inherit"].concat(Array.prototype.slice.call(a,1));var e=0,f=0;return a[0].replace(/%[a-z%]/g,function(a){"%%"!==a&&(e++,"%c"===a&&(f=e))}),a.splice(f,0,d),a}function f(){return"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}function g(a){try{null==a?c.storage.removeItem("debug"):c.storage.debug=a}catch(b){}}function h(){var a;try{a=c.storage.debug}catch(b){}return a}function i(){try{return window.localStorage}catch(a){}}c=b.exports=a("./debug"),c.log=f,c.formatArgs=e,c.save=g,c.load=h,c.useColors=d,c.storage="undefined"!=typeof chrome&&"undefined"!=typeof chrome.storage?chrome.storage.local:i(),c.colors=["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"],c.formatters.j=function(a){return JSON.stringify(a)},c.enable(h())},{"./debug":14}],14:[function(a,b,c){function d(){return c.colors[k++%c.colors.length]}function e(a){function b(){}function e(){var a=e,b=+new Date,f=b-(j||b);a.diff=f,a.prev=j,a.curr=b,j=b,null==a.useColors&&(a.useColors=c.useColors()),null==a.color&&a.useColors&&(a.color=d());var g=Array.prototype.slice.call(arguments);g[0]=c.coerce(g[0]),"string"!=typeof g[0]&&(g=["%o"].concat(g));var h=0;g[0]=g[0].replace(/%([a-z%])/g,function(b,d){if("%%"===b)return b;h++;var e=c.formatters[d];if("function"==typeof e){var f=g[h];b=e.call(a,f),g.splice(h,1),h--}return b}),"function"==typeof c.formatArgs&&(g=c.formatArgs.apply(a,g));var i=e.log||c.log||console.log.bind(console);i.apply(a,g)}b.enabled=!1,e.enabled=!0;var f=c.enabled(a)?e:b;return f.namespace=a,f}function f(a){c.save(a);for(var b=(a||"").split(/[\s,]+/),d=b.length,e=0;e1e4)){var b=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(a);if(b){var c=parseFloat(b[1]),d=(b[2]||"ms").toLowerCase();switch(d){case"years":case"year":case"yrs":case"yr":case"y":return c*l;case"days":case"day":case"d":return c*k;case"hours":case"hour":case"hrs":case"hr":case"h":return c*j;case"minutes":case"minute":case"mins":case"min":case"m":return c*i;case"seconds":case"second":case"secs":case"sec":case"s":return c*h;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return c}}}}function e(a){return a>=k?Math.round(a/k)+"d":a>=j?Math.round(a/j)+"h":a>=i?Math.round(a/i)+"m":a>=h?Math.round(a/h)+"s":a+"ms"}function f(a){return g(a,k,"day")||g(a,j,"hour")||g(a,i,"minute")||g(a,h,"second")||a+" ms"}function g(a,b,c){if(!(a1?{ -type:s[f],data:a.substring(1)}:{type:s[f]}:t}var g=new Uint8Array(a),f=g[0],h=k(a,1);return u&&"blob"===b&&(h=new u([h])),{type:s[f],data:h}},c.decodeBase64Packet=function(a,c){var d=s[a.charAt(0)];if(!b.ArrayBuffer)return{type:d,data:{base64:!0,data:a.substr(1)}};var e=l.decode(a.substr(1));return"blob"===c&&u&&(e=new u([e])),{type:d,data:e}},c.encodePayload=function(a,b,d){function e(a){return a.length+":"+a}function f(a,d){c.encodePacket(a,!!g&&b,!0,function(a){d(null,e(a))})}"function"==typeof b&&(d=b,b=null);var g=j(a);return b&&g?u&&!q?c.encodePayloadAsBlob(a,d):c.encodePayloadAsArrayBuffer(a,d):a.length?void h(a,f,function(a,b){return d(b.join(""))}):d("0:")},c.decodePayload=function(a,b,d){if("string"!=typeof a)return c.decodePayloadAsBinary(a,b,d);"function"==typeof b&&(d=b,b=null);var e;if(""==a)return d(t,0,1);for(var f,g,h="",i=0,j=a.length;i0;){for(var h=new Uint8Array(e),i=0===h[0],j="",l=1;255!=h[l];l++){if(j.length>310){g=!0;break}j+=h[l]}if(g)return d(t,0,1);e=k(e,2+j.length),j=parseInt(j);var m=k(e,0,j);if(i)try{m=String.fromCharCode.apply(null,new Uint8Array(m))}catch(n){var o=new Uint8Array(m);m="";for(var l=0;ld&&(c=d),b>=d||b>=c||0===d)return new ArrayBuffer(0);for(var e=new Uint8Array(a),f=new Uint8Array(c-b),g=b,h=0;g>2],f+=a[(3&d[c])<<4|d[c+1]>>4],f+=a[(15&d[c+1])<<2|d[c+2]>>6],f+=a[63&d[c+2]];return e%3===2?f=f.substring(0,f.length-1)+"=":e%3===1&&(f=f.substring(0,f.length-2)+"=="),f},c.decode=function(b){var c,d,e,f,g,h=.75*b.length,i=b.length,j=0;"="===b[b.length-1]&&(h--,"="===b[b.length-2]&&h--);var k=new ArrayBuffer(h),l=new Uint8Array(k);for(c=0;c>4,l[j++]=(15&e)<<4|f>>2,l[j++]=(3&f)<<6|63&g;return k}}("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")},{}],21:[function(a,b,c){(function(a){function c(a){for(var b=0;b=55296&&b<=56319&&e65535&&(b-=65536,e+=u(b>>>10&1023|55296),b=56320|1023&b),e+=u(b);return e}function h(a){if(a>=55296&&a<=57343)throw Error("Lone surrogate U+"+a.toString(16).toUpperCase()+" is not a scalar value")}function i(a,b){return u(a>>b&63|128)}function j(a){if(0==(4294967168&a))return u(a);var b="";return 0==(4294965248&a)?b=u(a>>6&31|192):0==(4294901760&a)?(h(a),b=u(a>>12&15|224),b+=i(a,6)):0==(4292870144&a)&&(b=u(a>>18&7|240),b+=i(a,12),b+=i(a,6)),b+=u(63&a|128)}function k(a){for(var b,c=f(a),d=c.length,e=-1,g="";++e=s)throw Error("Invalid byte index");var a=255&r[t];if(t++,128==(192&a))return 63&a;throw Error("Invalid continuation byte")}function m(){var a,b,c,d,e;if(t>s)throw Error("Invalid byte index");if(t==s)return!1;if(a=255&r[t],t++,0==(128&a))return a;if(192==(224&a)){var b=l();if(e=(31&a)<<6|b,e>=128)return e;throw Error("Invalid continuation byte")}if(224==(240&a)){if(b=l(),c=l(),e=(15&a)<<12|b<<6|c,e>=2048)return h(e),e;throw Error("Invalid continuation byte")}if(240==(248&a)&&(b=l(),c=l(),d=l(),e=(15&a)<<18|b<<12|c<<6|d,e>=65536&&e<=1114111))return e;throw Error("Invalid UTF-8 detected")}function n(a){r=f(a),s=r.length,t=0;for(var b,c=[];(b=m())!==!1;)c.push(b);return g(c)}var o="object"==typeof d&&d,p="object"==typeof c&&c&&c.exports==o&&c,q="object"==typeof b&&b;q.global!==q&&q.window!==q||(e=q);var r,s,t,u=String.fromCharCode,v={version:"2.0.0",encode:k,decode:n};if("function"==typeof a&&"object"==typeof a.amd&&a.amd)a(function(){return v});else if(o&&!o.nodeType)if(p)p.exports=v;else{var w={},x=w.hasOwnProperty;for(var y in v)x.call(v,y)&&(o[y]=v[y])}else e.utf8=v}(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],25:[function(a,b,c){try{b.exports="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(d){b.exports=!1}},{}],26:[function(a,b,c){var d=[].indexOf;b.exports=function(a,b){if(d)return a.indexOf(b);for(var c=0;c0);return b}function e(a){var b=0;for(l=0;l1)for(var c=1;c2&&e.push(this._parseMessage(f[c],b));return e},e.prototype.convertTyped=function(a,b){var c=a.charAt(0);if(c===d.TYPES.STRING)return a.substr(1);if(c===d.TYPES.OBJECT)try{return JSON.parse(a.substr(1))}catch(e){return void b._$onError(d.TOPIC.ERROR,d.EVENT.MESSAGE_PARSE_ERROR,e.toString()+"("+a+")")}return c===d.TYPES.NUMBER?parseFloat(a.substr(1)):c===d.TYPES.NULL?null:c===d.TYPES.TRUE||c!==d.TYPES.FALSE&&void(c!==d.TYPES.UNDEFINED&&b._$onError(d.TOPIC.ERROR,d.EVENT.MESSAGE_PARSE_ERROR,"UNKNOWN_TYPE ("+a+")"))},e.prototype._getActions=function(){var a,b={};for(a in d.ACTIONS)b[d.ACTIONS[a]]=a;return b},e.prototype._parseMessage=function(a,b){var c=a.split(d.MESSAGE_PART_SEPERATOR),e={};return c.length<2?(a.processedError=!0,b._$onError(d.TOPIC.ERROR,d.EVENT.MESSAGE_PARSE_ERROR,"Insufficiant message parts"),null):void 0===this._actions[c[1]]?(a.processedError=!0,b._$onError(d.TOPIC.ERROR,d.EVENT.MESSAGE_PARSE_ERROR,"Unknown action "+c[1]),null):(e.raw=a,e.topic=c[0],e.action=c[1],e.data=c.splice(2),e)},b.exports=new e},{"../constants/constants":35}],42:[function(a,b,c){var d=a("./record"),e=a("component-emitter"),f=function(a){this.name=null,this._recordHandler=a,this._record=null,this._subscriptions=[],this._proxyMethod("delete"),this._proxyMethod("set"),this._proxyMethod("unsubscribe"),this._proxyMethod("discard")};e(f.prototype),f.prototype.get=function(a){if(null!==this._record)return this._record.get(a)},f.prototype.subscribe=function(){var a=d.prototype._normalizeArguments(arguments);a.triggerNow=!0,this._subscriptions.push(a),null!==this._record&&this._record.subscribe(a)},f.prototype.unsubscribe=function(){var a,b=d.prototype._normalizeArguments(arguments),c=[];for(a=0;a=c.length||a<0))throw new Error("Index must be within current entries");b=!0}return b},j.prototype._beforeChange=function(){this._hasAddListener=this.listeners(g).length>0,this._hasRemoveListener=this.listeners(h).length>0,this._hasMoveListener=this.listeners(i).length>0,this._hasAddListener||this._hasRemoveListener||this._hasMoveListener?this._beforeStructure=this._getStructure():this._beforeStructure=null},j.prototype._afterChange=function(){if(null!==this._beforeStructure){var a,b,c=this._getStructure(),d=this._beforeStructure;if(this._hasRemoveListener)for(a in d)for(b=0;b0;){for(var h=new Uint8Array(e),i=0===h[0],j="",l=1;255!=h[l];l++){if(j.length>310){g=!0;break}j+=h[l]}if(g)return d(t,0,1);e=k(e,2+j.length),j=parseInt(j);var m=k(e,0,j);if(i)try{m=String.fromCharCode.apply(null,new Uint8Array(m))}catch(n){var o=new Uint8Array(m);m="";for(var l=0;ld&&(c=d),b>=d||b>=c||0===d)return new ArrayBuffer(0);for(var e=new Uint8Array(a),f=new Uint8Array(c-b),g=b,h=0;g>2],f+=a[(3&d[c])<<4|d[c+1]>>4],f+=a[(15&d[c+1])<<2|d[c+2]>>6],f+=a[63&d[c+2]];return e%3===2?f=f.substring(0,f.length-1)+"=":e%3===1&&(f=f.substring(0,f.length-2)+"=="),f},c.decode=function(b){var c,d,e,f,g,h=.75*b.length,i=b.length,j=0;"="===b[b.length-1]&&(h--,"="===b[b.length-2]&&h--);var k=new ArrayBuffer(h),l=new Uint8Array(k);for(c=0;c>4,l[j++]=(15&e)<<4|f>>2,l[j++]=(3&f)<<6|63&g;return k}}("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")},{}],21:[function(a,b,c){(function(a){function c(a){for(var b=0;b=55296&&b<=56319&&e65535&&(b-=65536,e+=u(b>>>10&1023|55296),b=56320|1023&b),e+=u(b);return e}function h(a){if(a>=55296&&a<=57343)throw Error("Lone surrogate U+"+a.toString(16).toUpperCase()+" is not a scalar value")}function i(a,b){return u(a>>b&63|128)}function j(a){if(0==(4294967168&a))return u(a);var b="";return 0==(4294965248&a)?b=u(a>>6&31|192):0==(4294901760&a)?(h(a),b=u(a>>12&15|224),b+=i(a,6)):0==(4292870144&a)&&(b=u(a>>18&7|240),b+=i(a,12),b+=i(a,6)),b+=u(63&a|128)}function k(a){for(var b,c=f(a),d=c.length,e=-1,g="";++e=s)throw Error("Invalid byte index");var a=255&r[t];if(t++,128==(192&a))return 63&a;throw Error("Invalid continuation byte")}function m(){var a,b,c,d,e;if(t>s)throw Error("Invalid byte index");if(t==s)return!1;if(a=255&r[t],t++,0==(128&a))return a;if(192==(224&a)){var b=l();if(e=(31&a)<<6|b,e>=128)return e;throw Error("Invalid continuation byte")}if(224==(240&a)){if(b=l(),c=l(),e=(15&a)<<12|b<<6|c,e>=2048)return h(e),e;throw Error("Invalid continuation byte")}if(240==(248&a)&&(b=l(),c=l(),d=l(),e=(15&a)<<18|b<<12|c<<6|d,e>=65536&&e<=1114111))return e;throw Error("Invalid UTF-8 detected")}function n(a){r=f(a),s=r.length,t=0;for(var b,c=[];(b=m())!==!1;)c.push(b);return g(c)}var o="object"==typeof d&&d,p="object"==typeof c&&c&&c.exports==o&&c,q="object"==typeof b&&b;q.global!==q&&q.window!==q||(e=q);var r,s,t,u=String.fromCharCode,v={version:"2.0.0",encode:k,decode:n};if("function"==typeof a&&"object"==typeof a.amd&&a.amd)a(function(){return v});else if(o&&!o.nodeType)if(p)p.exports=v;else{var w={},x=w.hasOwnProperty;for(var y in v)x.call(v,y)&&(o[y]=v[y])}else e.utf8=v}(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],25:[function(a,b,c){try{b.exports="undefined"!=typeof XMLHttpRequest&&"withCredentials"in new XMLHttpRequest}catch(d){b.exports=!1}},{}],26:[function(a,b,c){var d=[].indexOf;b.exports=function(a,b){if(d)return a.indexOf(b);for(var c=0;c0);return b}function e(a){var b=0;for(l=0;l1)for(var c=1;c2&&e.push(this._parseMessage(f[c],b));return e},e.prototype.convertTyped=function(a,b){var c=a.charAt(0);if(c===d.TYPES.STRING)return a.substr(1);if(c===d.TYPES.OBJECT)try{return JSON.parse(a.substr(1))}catch(e){return void b._$onError(d.TOPIC.ERROR,d.EVENT.MESSAGE_PARSE_ERROR,e.toString()+"("+a+")")}return c===d.TYPES.NUMBER?parseFloat(a.substr(1)):c===d.TYPES.NULL?null:c===d.TYPES.TRUE||c!==d.TYPES.FALSE&&void(c!==d.TYPES.UNDEFINED&&b._$onError(d.TOPIC.ERROR,d.EVENT.MESSAGE_PARSE_ERROR,"UNKNOWN_TYPE ("+a+")"))},e.prototype._getActions=function(){var a,b={};for(a in d.ACTIONS)b[d.ACTIONS[a]]=a;return b},e.prototype._parseMessage=function(a,b){var c=a.split(d.MESSAGE_PART_SEPERATOR),e={};return c.length<2?(a.processedError=!0,b._$onError(d.TOPIC.ERROR,d.EVENT.MESSAGE_PARSE_ERROR,"Insufficiant message parts"),null):void 0===this._actions[c[1]]?(a.processedError=!0,b._$onError(d.TOPIC.ERROR,d.EVENT.MESSAGE_PARSE_ERROR,"Unknown action "+c[1]),null):(e.raw=a,e.topic=c[0],e.action=c[1],e.data=c.splice(2),e)},b.exports=new e},{"../constants/constants":35}],42:[function(a,b,c){var d=a("./record"),e=a("component-emitter"),f=function(a){this.name=null,this._recordHandler=a,this._record=null,this._subscriptions=[],this._proxyMethod("delete"),this._proxyMethod("set"),this._proxyMethod("unsubscribe"),this._proxyMethod("discard")};e(f.prototype),f.prototype.get=function(a){if(null!==this._record)return this._record.get(a)},f.prototype.subscribe=function(){var a=d.prototype._normalizeArguments(arguments);a.triggerNow=!0,this._subscriptions.push(a),null!==this._record&&this._record.subscribe(a)},f.prototype.unsubscribe=function(){var a,b=d.prototype._normalizeArguments(arguments),c=[];for(a=0;a=c.length||a<0))throw new Error("Index must be within current entries");b=!0}return b},j.prototype._beforeChange=function(){this._hasAddListener=this.listeners(g).length>0,this._hasRemoveListener=this.listeners(h).length>0,this._hasMoveListener=this.listeners(i).length>0,this._hasAddListener||this._hasRemoveListener||this._hasMoveListener?this._beforeStructure=this._getStructure():this._beforeStructure=null},j.prototype._afterChange=function(){if(null!==this._beforeStructure){var a,b,c=this._getStructure(),d=this._beforeStructure;if(this._hasRemoveListener)for(a in d)for(b=0;b