diffusion
Advanced tools
Comparing version 5.5.0 to 5.5.1
{ | ||
"name": "diffusion", | ||
"version": "5.5.0", | ||
"version": "5.5.1", | ||
"description": "Diffusion Javascript UCI client", | ||
@@ -5,0 +5,0 @@ "keywords" : ["diffusion", "reappt", "websockets", "data"], |
@@ -1,2 +0,2 @@ | ||
##Diffusion JS API | ||
##Diffusion JavaScript API | ||
@@ -31,3 +31,3 @@ The Diffusion JavaScript API allows interaction with a Diffusion server from both | ||
```javascript | ||
diffuion.connect('diffusion.example.com').then(function(session) { | ||
diffusion.connect('diffusion.example.com').then(function(session) { | ||
// Connected! | ||
@@ -77,5 +77,5 @@ }, function(error) { | ||
It is possible to register any number of listeners to a subscriptions update events. They will each be called when a | ||
new value is received. By default, received values will be provided as buffers. For browsers, a shim is used to provide | ||
an equivalent API. | ||
It is possible to register any number of listeners to a subscriptions update events. They will each be called when a new | ||
value is received. By default, received values will be provided as Buffer objects which provide a clean interface for | ||
accessing binary data. | ||
@@ -82,0 +82,0 @@ Because clients will most likely wish to consume data in a more specific type, subscriptions can be transformed. |
@@ -24,5 +24,5 @@ var SessionImpl = require('session/session-impl'); | ||
*/ | ||
version : '5.5.0', | ||
version : '5.5.1', | ||
build : '0_01#30948', | ||
build : '1_01#31128', | ||
@@ -29,0 +29,0 @@ /** |
var Emitter = require('events/emitter'); | ||
var reconnectStrategy = require('client/reconnect-strategy'); | ||
var ServiceAdapter = require('client/service-adapter'); | ||
@@ -100,3 +99,3 @@ var ServiceLocator = require('client/service-locator'); | ||
var request = ConnectionRequest.reconnect(token); | ||
connection.connect(request, opts); | ||
connection.connect(request, opts, opts.reconnect.timeout); | ||
} else { | ||
@@ -122,5 +121,2 @@ log.debug('Unable to attempt reconnect, session state: ', fsm.state); | ||
// Create the reconnection strategy from provided options | ||
var strategy = reconnectStrategy(opts, reconnect, abort); | ||
// Handle messages from connection | ||
@@ -138,3 +134,5 @@ connection.on('data', routing.route); | ||
// Call reconnect if applicable | ||
if (opts.reconnect && reason.canReconnect) { | ||
if (opts.reconnect.timeout > 0 && reason.canReconnect) { | ||
opts.token = token; | ||
// Only emit the disconnect state once | ||
@@ -145,3 +143,3 @@ if (fsm.state === 'disconnected') { | ||
strategy(reason); | ||
opts.reconnect.strategy(curry(reconnect, opts), abort, reason); | ||
} else { | ||
@@ -148,0 +146,0 @@ abort(reason); |
@@ -118,3 +118,3 @@ var connectionResponseDeserialiser = require('protocol/connection-response-deserialiser'); | ||
*/ | ||
this.connect = function connect(request, opts) { | ||
this.connect = function connect(request, opts, timeout) { | ||
if (fsm.state !== 'disconnected') { | ||
@@ -126,2 +126,4 @@ logger.warn('Cannot connect, current state: ', fsm.state); | ||
if (fsm.change('connecting')) { | ||
timeout = timeout === undefined ? CONNECT_TIMEOUT : timeout; | ||
closeReason = CloseReason.CONNECTION_ERROR; | ||
@@ -137,7 +139,7 @@ transport = transports.get(opts); | ||
scheduledClose = setTimeout(function() { | ||
logger.debug('Timed out connection attempt after ' + CONNECT_TIMEOUT); | ||
logger.debug('Timed out connection attempt after ' + timeout); | ||
closeReason = CloseReason.CONNECTION_TIMEOUT; | ||
transport.close(); | ||
}, CONNECT_TIMEOUT); | ||
}, timeout); | ||
} | ||
@@ -144,0 +146,0 @@ }; |
@@ -6,4 +6,12 @@ var DEFAULT_HOST = 'localhost'; | ||
var DEFAULT_SECURE = true; | ||
var DEFAULT_RECONNECT = true; | ||
var DEFAULT_RECONNECT_TIMEOUT = 60000; | ||
var DEFAULT_RECONNECT_STRATEGY = function(start, abort) { | ||
setTimeout(start, 5000); | ||
}; | ||
var DEFAULT_ABORT_STRATEGY = function(start, abort) { | ||
abort(); | ||
}; | ||
var DEFAULT_PRINCIPAL = ""; | ||
@@ -14,2 +22,11 @@ var DEFAULT_PASSWORD = ""; | ||
* Provide Session configuration options. | ||
* <P> | ||
* Reconnection will be automatically enabled, and accepts several option values. A boolean will set whether it is | ||
* enabled or disabled, using default settings. Passing a <code>number</code> will specify the timeout value, or a | ||
* <code>function</code> will specify the reconnection strategy. An object containing both <code>timeout</code> and | ||
* <code>strategy</code> keys can be used to specify both values. | ||
* <P> | ||
* The reconnection strategy should be a function that accepts two arguments; the first will be a function that can | ||
* be called to attempt to reconnect, the second a function that can be called to abort. If reconnection is aborted, | ||
* or times out, the session will close. | ||
* | ||
@@ -20,5 +37,5 @@ * @typedef Session.Options | ||
* @property {Boolean} [secure=true] - Whether to use secure connections | ||
* @property {Boolean} [reconnect=true] - Whether to enable automatic reconnect | ||
* @property {String} [principal] - The principal name this session should connect with. Used for authentication. | ||
* @property {String} [credentials] - A password string to authenticate with. | ||
* @property {Boolean|Number|Function|Object} [reconnect=true] - Reconnection options. | ||
*/ | ||
@@ -56,9 +73,35 @@ function Options(options) { | ||
this.secure = (options.secure !== undefined) ? options.secure : DEFAULT_SECURE; | ||
this.reconnect = (options.reconnect !== undefined) ? options.reconnect : DEFAULT_RECONNECT; | ||
if (options.principal !== undefined) { | ||
this.principal = options.principal || DEFAULT_PRINCIPAL; | ||
this.credentials = options.credentials || DEFAULT_PASSWORD; | ||
if (options.reconnect === undefined || (typeof options.reconnect === 'boolean') && options.reconnect) { | ||
this.reconnect = { | ||
timeout : DEFAULT_RECONNECT_TIMEOUT, | ||
strategy : DEFAULT_RECONNECT_STRATEGY | ||
}; | ||
} else if (typeof options.reconnect === 'number') { | ||
this.reconnect = { | ||
timeout : options.reconnect, | ||
strategy : DEFAULT_RECONNECT_STRATEGY | ||
}; | ||
} else if (typeof options.reconnect === 'function') { | ||
this.reconnect = { | ||
timeout : DEFAULT_RECONNECT_TIMEOUT, | ||
strategy : options.reconnect | ||
}; | ||
} else if (typeof options.reconnect === 'object') { | ||
this.reconnect = { | ||
timeout : options.reconnect.timeout || DEFAULT_RECONNECT_TIMEOUT, | ||
strategy : options.reconnect.strategy || DEFAULT_RECONNECT_STRATEGY | ||
}; | ||
} else { | ||
this.reconnect = { | ||
timeout : 0, | ||
strategy : DEFAULT_ABORT_STRATEGY | ||
}; | ||
} | ||
if (options.principal !== undefined) { | ||
this.principal = options.principal || DEFAULT_PRINCIPAL; | ||
this.credentials = options.credentials || DEFAULT_PASSWORD; | ||
} | ||
} | ||
@@ -65,0 +108,0 @@ /** |
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
313050
8789
176