Skip to content

Commit

Permalink
work on readm
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Oberstein committed Mar 13, 2014
1 parent 1e92c30 commit 82e179e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
42 changes: 29 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ To **open a connection**:
```javascript
autobahn.Connection.open();
```
Starts the connection, which will establish a transport and create a new session running over the transport. If the transport is lost, automatic reconnection will be done. The latter can be configured using the `options` provided to the constructor of the `Connection` (see below).
This will establish an underlying transport (like WebSocket or long-poll) and create a new session running over the transport.

When the transport is lost, automatic reconnection will be done. The latter can be configured using the `options` provided to the constructor of the `Connection` (see below).

To **close a connection**:

Expand All @@ -266,7 +268,7 @@ autobahn.Connection.close(<reason|string>, <message|string>);

where

* `reason` is an optional WAMP URI providing a closing reason, e.g. `com.myapp.close.signout`.
* `reason` is an optional WAMP URI providing a closing reason, e.g. `com.myapp.close.signout` to the server-side.
* `message` is an optional (human readable) closing message.

When a connection was closed explicitly, no automatic reconnection will happen.
Expand All @@ -283,8 +285,7 @@ The **connection open callback**

```javascript
autobahn.Connection.onopen = function (session) {
// Underlying connection to WAMP router established
// and new WAMP session started.
// Underlying transport to WAMP router established and new WAMP session started.
// session is an instance of autobahn.Session
};
```
Expand All @@ -308,21 +309,36 @@ Here, the possible values for *reason* are:
* `"unreachable"`: The connection could not be established in the first place. No automatic reattempt will happen, since most often the cause is fatal (e.g. invalid server URL or server unreachable)



### Options

1. `url|string` (required): the WebSocket URL of the WAMP router to connect to
2. `realm|string` (required): the WAMP realm to join
3. `use_es6_promises|bool` (optional): use deferreds based on ES6 promises *
4. `use_deferred|callable` (optional): if provided, use this deferred constructor, e.g. `jQuery.Deferred` or `Q.defer`
5. `max_retries`: Not yet implemented.
6. `retry_delay`: Not yet implemented.
7. `skip_subprotocol_check`: Not yet implemented.
8. `skip_subprotocol_announce`: Not yet implemented.
The constructor of `autobahn.Connection` provides various options.

Required options:

* `url|string` (required): the WebSocket URL of the WAMP router to connect to
* `realm|string` (required): the WAMP realm to join

Options that control what kind of Deferreds to use:

* `use_es6_promises|bool` (optional): use deferreds based on ES6 promises *
* `use_deferred|callable` (optional): if provided, use this deferred constructor, e.g. `jQuery.Deferred` or `Q.defer`

> *: Using ES6-based promises has certain restrictions. E.g. no progressive call results are supported.
>
Options that control automatic reconnection:

* `max_retries|int`: Maximum number of reconnection attempts (default: **15**)
* `initial_retry_delay|float`: Initial delay for reconnection attempt in seconds (default: **1.5**).
* `max_retry_delay|float`: Maximum delay for reconnection attempts in seconds (default: **300**).
* `retry_delay_growth|float`: The growth factor applied to the retry delay between reconnection attempts (default: **1.5**).
* `retry_delay_jitter|float`: The standard deviation of a Gaussian to jitter the delay on each retry cycle as a fraction of the mean (default: **0.1**).

Options that control WebSocket subprotocol handling:

* `skip_subprotocol_check`: Not yet implemented.
* `skip_subprotocol_announce`: Not yet implemented.


### Properties

Expand Down
8 changes: 4 additions & 4 deletions package/lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ var Connection = function (options) {
self._max_retries = self._options.max_retries || 15;

// initial retry delay in seconds
self._initial_retry_delay = self._options.initial_retry_delay || (1.5 * 1000);
self._initial_retry_delay = self._options.initial_retry_delay || 1.5;

// maximum seconds between reconnection attempts
self._max_retry_delay = self._options.max_retry_delay || (5 * 60 * 1000);
self._max_retry_delay = self._options.max_retry_delay || 300;

// the growth factor applied to the retry delay on each retry cycle
self._retry_delay_growth = self._options.retry_delay_growth || 1.5;
Expand Down Expand Up @@ -225,8 +225,8 @@ Connection.prototype.open = function () {
self._retry_delay = self._max_retry_delay;
}

log.debug("retrying in " + self._retry_delay + " ms");
setTimeout(retry, self._retry_delay);
log.debug("retrying in " + self._retry_delay + " s");
setTimeout(retry, self._retry_delay * 1000);

// retry delay growth for next retry cycle
if (self._retry_delay_growth) {
Expand Down

0 comments on commit 82e179e

Please sign in to comment.