The timeout in milliseconds used when connecting to the server. (default 10000
)
A password string to authenticate with, a buffer containing custom credentials in binary format, a typed array, or a regular array of octets.
The hostname to connect to (default 'localhost'
)
An optional HTTP/HTTPS proxy agent. (default undefined
)
If this is set, then the client will attempt to connect to the Diffusion server via a proxy server.
The proxy agent will be passed to the WebSocket constructor as the
agent
option. See https://www.npmjs.com/package/https-proxy-agent for
an example of a proxy agent.
This option is used for web socket connections and is intended for Node based clients only. Browser based clients will automatically use the browser's proxy settings.
Example:
const HttpsProxyAgent = require('https-proxy-agent');
const url = require('url');
const diffusion = require('diffusion');
const agent = new HttpsProxyAgent(url.parse('https://proxy.example.com:80'));
diffusion.connect({
host: 'https://diffusion.foo.com',
httpProxyAgent: agent
}).then((session) => {
// connected through proxy server
});
The maximum size of messages that may be received from the server. (default 2147483647
)
The request path used for connections (default /diffusion
)
The port to connect to (default 443
)
The principal name this session should connect with. Used for authentication.
An object of key-value pairs that define the user-defined session properties.
Property values will be sent as string
values. Non-string properties must
implement the toString()
method to allow conversion.
For details of how session properties are used see Session.
Reconnection options. (default true
)
A retry strategy that defines the behaviour for the initial connection attempt.
The default connection strategy will attempt each transport once before cascading to the next transport.
Whether to use secure connections.
An optional TLS options object. (default undefined
)
This option is used for secure web socket connections and is intended for
Node based clients only. Browser based clients will automatically use the
browser's TLS settings.
See https://nodejs.org/api/tls.html#tlscreatesecurecontextoptions for more information.
The transports to be used for connection establishment. (default "WEBSOCKET"
)
Provide Session configuration options.
Connection:
There are several option values that can be configured to change how Diffusion establishes a connection. These options are used to derive a connection URL in the format:{protocol}://{host}:{port}/{path}
. The protocol used is determined by the chosen transports and whether secure connections are enabled.localhost
80
or443
In case the client is being run in a page served via
https
(http
), the default secure (insecure) port is the port of the URI of the current page, otherwise the default secure (insecure) port is443
(80
)./diffusion
true
true
. If the port is explicitly specified the default value istrue
only if the port is equal to the default secure port, otherwisefalse
.In case the client is being run in a page served via
https
, the default secure port is the port of the URI of the current page, otherwise the default secure port is443
.Reconnection:
Reconnection is enabled by default. The
reconnect
key accepts several different option values.boolean
true
true
, reconnection will be enabled using the default timeout value and a periodic back-off strategy.number
60000
disconnected
state before the client is closed.function
disconnected
state, and subsequently if attempts to reconnect fail. Two arguments are provided,reconnect
andabort
- these are functions to be called within the strategy. Thereconnect
argument will initiate a reconnect attempt.abort
may be called to abort reconnection, in which case the client will be closed.Transports:
The
transports
property configures how the session should connect. It can be set to either astring
, or anarray
of strings to provide a transport cascading capability.ws
,WS
,WEBSOCKET
xhr
,XHR
,HTTP_POLLING
transports: ['WS', 'XHR']
indicates that the client will attempt to connect with the WebSocket transport, and if the connection fails, the client will attempt to connect with the HTTP Polling transport. When notransports
value is provided the client will default to using the WebSocket transport. Any string values that do not have an associated transport will be ignored.When the diffusion client is run in a browser environment,
transports
will default to['WEBSOCKET', 'XHR']
. When run in Node,transports
will default to['WEBSOCKET']
.Properties:
Supplied session properties will be provided to the server when a session is created using this session factory. The supplied properties will be validated during authentication and may be discarded or changed.
The specified properties will be added to any existing properties set for this session factory. If any of the keys have been previously declared then they will be overwritten with the new values.
For details of how session properties are used see Session.