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
WebSocketobject.This function must be called before the
WebSocketobject is created. To ensure that the application does not fail if theorasocket.jslibrary is unavailable , this function should be called in atry/catchblock.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\xE2\x80?.
The following example shows how to pass the JSON object
customConfigfrom the previous example to theconfigurefunction: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 JavaScriptWebSocketclient. The function call to create theWebSocketobject conforms to the syntax in the W3C WebSocket specification. Calling theconfigurefunction in atry/catchblock ensures that the application continues to run even if theorasocket.jslibrary is unavailable.The following example shows how pass the JSON object
customConfigas a parameter to the constructor of theWebSocketobject:var ws = new WebSocket("ws://machine:8080/websocket/the-coolest-wsapp", customConfig);The code in this example can be used only in JavaScriptWebSocketclients to which theorasocket.jslibrary is available. Otherwise, any application that contains this code fails.Parameters:
Name Type Description configObjectobject A JSON structure that contains the members in the following table
Every member has a default value. No member is required.Name Type Default Description baseUrlstring "." The location of the scriptsdirectory, relative to the HTML context of the page.PING_INTERVALinteger 25000 Interval in milliseconds between consecutive pings to the server. ENCODE_FOR_IE_BELOWinteger 10 The version of the Internet Explorer browser below which Base16 encoding is to be used for framed data. NB_TRY_FOR_EACH_TRANSPORTinteger 2 The maximum number of consecutive retries to establish a connection on a given transport. TRY_AGAIN_INTERVALinteger 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_ENCODINGBoolean false Whether Base16 encoding should be used. SERVER_PING_ENABLEDBoolean true Whether pings from the client to the server are enabled. WEBSOCKET_CREATION_TIMEOUTinteger 1000 The number of milliseconds after which creation of a WebSocket connection is considered to have failed. debuginteger 0 The debug level. transportstring none The enforced transport, which can be one of the following transports: WebSocketXMLHttpRequest
- Source:
Returns:
- Type
- void
-
<inner> displayConfig() → {void}
-
Display the configuration of a
WebSocketobject's fallback behavior. This function uses theconsole.logfunction.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