This namespace contains utilities for configuring the fallback behavior of a
WebSocket
object
and displaying the resulting configuration.- Source:
Methods
-
<inner> configure(configObject) → {void}
-
Configure the fallback behavior of a
WebSocket
object.This function must be called before the
WebSocket
object is created. To ensure that the application does not fail if theorasocket.js
library is unavailable , this function should be called in atry/catch
block.This function takes a JSON object as a parameter, as shown in the following example:
var customConfig = { baseUrl: "ws-dir", PING_INTERVAL: 1000, ENCODE_FOR_IE_BELOW: 10, WEBSOCKET_CREATION_TIMEOUT:1000, NB_TRY_FOR_EACH_TRANSPORT: 2, TRY_AGAIN_INTERVAL: 10000, SERVER_PING_ENABLED: true, ENFORCE_ENCODING: false };
For more information about this object, see “Parameters�?.
The following example shows how to pass the JSON object
customConfig
from the previous example to theconfigure
function:try { OraSocket.configure(customConfig); } catch (err) {} var ws = new WebSocket("ws://machine:8080/websocket/the-coolest-wsapp");
The code in this example can be used in any JavaScriptWebSocket
client. The function call to create theWebSocket
object conforms to the syntax in the W3C WebSocket specification. Calling theconfigure
function in atry/catch
block ensures that the application continues to run even if theorasocket.js
library is unavailable.The following example shows how pass the JSON object
customConfig
as a parameter to the constructor of theWebSocket
object:var ws = new WebSocket("ws://machine:8080/websocket/the-coolest-wsapp", customConfig);
The code in this example can be used only in JavaScriptWebSocket
clients to which theorasocket.js
library is available. Otherwise, any application that contains this code fails.Parameters:
Name Type Description configObject
object A JSON structure that contains the members in the following table Name Type Default Description baseUrl
string "." The location of the scripts
directory, relative to the HTML context of the page.PING_INTERVAL
integer 25000 Interval in milliseconds between consecutive pings to the server. ENCODE_FOR_IE_BELOW
integer 10 The version of the Internet Explorer browser below which Base16 encoding is to be used for framed data. NB_TRY_FOR_EACH_TRANSPORT
integer 2 The maximum number of consecutive retries to establish a connection on a given transport. TRY_AGAIN_INTERVAL
integer 10000 The number of milliseconds after which an unsuccessful connection attempt is repeated with the same transport. The retry count for the transport is not incremented.
If the attempt fails within this number of milliseconds, the retry count is incremented by 1.ENFORCE_ENCODING
Boolean false Whether Base16 encoding should be used. SERVER_PING_ENABLED
Boolean true Whether pings from the client to the server are enabled. WEBSOCKET_CREATION_TIMEOUT
integer 1000 The number of milliseconds after which creation of a WebSocket connection is considered to have failed. debug
integer 0 The debug level. transport
string none The enforced transport, which can be one of the following transports: WebSocket
XMLHttpRequest
- Source:
Returns:
- Type
- void
-
<inner> displayConfig() → {void}
-
Display the configuration of a
WebSocket
object's fallback behavior. This function uses theconsole.log
function.This function can be called from debugging tools such as WebKit and similar tools.
The following example shows the output from this function:Base URL :. Ping interval :1000 ms Encoding required for IE below version:10 WebSocket creation timeout :1000 ms Nb try for each transport :2 time(s) Try-again interval :10000 ms Ping enabled :true Enforce encoding :false Debug level :0 Enforced transport :none
- Source:
- See:
Returns:
- Type
- void