Configuration
JavaScript Cometd API: Configuration and Initialization
After you have setup your skeleton project following the Primer, you may want to fully understand how to customize and configure the parameters that govern the behavior of the Cometd implementation.
The whole API is available through a single object prototype named org.cometd.Cometd.
The Dojo toolkit has one instance of this object available under the name dojox.cometd, while for jQuery it is available under the name $.cometd.
This default cometd object has been instantiated and configured with the default values and it has not started any Bayeux communication yet.
Before it can start any Bayeux communication it needs a mandatory parameter: the URL of the Bayeux server.
There are 2 ways of passing this parameter:
// First style: URL string
cometd.configure('http://localhost:8080/cometd');
// Second style: configuration object
cometd.configure({
url: 'http://localhost:8080/cometd'
});
The first way is a shorthand for the second way.
However, the second way allows to pass other configuration parameters, currently:
| Parameter Name | Required | Default Value | Parameter Description |
|---|---|---|---|
| url | yes | The URL of the Bayeux server this client will connect to | |
| logLevel | no | info | The log level. Possible values are: "warn", "info", "debug". Output to window.console if available |
| maxConnection | no | 2 | The max number of connections used to connect to the Bayeux server. Only change this value if you know exactly what is the client's connection limit and what "request queued behind long poll" means |
| backoffIncrement | no | 1000 | The number of milliseconds of which the backoff time is incremented every time a connection with the Bayeux server fails. A reconnection will be attempted after the backoff time elapses |
| maxBackoff | no | 60000 | The max number of milliseconds of the backoff time after which the backoff time is not incremented anymore |
| reverseIncomingExtensions | no | true | Controls whether the incoming extensions will be called in reverse order with respect to the registration order |
| maxNetworkDelay | no | 10000 | The max number of milliseconds to wait before considering a request to the Bayeux server failed. |
| requestHeaders | no | {} | An object containing the request headers to be sent for every bayeux request (for example: {"My-Custom-Header":"MyValue"}) |
After you have configured the cometd object, it has not started the Bayeux communication yet. To start the Bayeux communication, you need to call handshake(), see the next section.
Previous users of the JavaScript Cometd implementation were used to call a method called init(). This method still exists, and it is a shorthand for calling configure() followed by handshake().
Follow the advices in the next section as they apply as well to init().
- Printer-friendly version
- Login to post comments