Namespace: OraSocket

OraSocket

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 the orasocket.js library is unavailable , this function should be called in a try/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\xE2\x80?.

The following example shows how to pass the JSON object customConfig from the previous example to the configure 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 JavaScript WebSocket client. The function call to create the WebSocket object conforms to the syntax in the W3C WebSocket specification. Calling the configure function in a try/catch block ensures that the application continues to run even if the orasocket.js library is unavailable.

The following example shows how pass the JSON object customConfig as a parameter to the constructor of the WebSocket object:

var ws = new WebSocket("ws://machine:8080/websocket/the-coolest-wsapp", customConfig);
The code in this example can be used only in JavaScript WebSocket clients to which the orasocket.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
NameTypeDefaultDescription
baseUrlstring"."The location of the scripts directory, relative to the HTML context of the page.
PING_INTERVALinteger25000Interval in milliseconds between consecutive pings to the server.
ENCODE_FOR_IE_BELOWinteger10The version of the Internet Explorer browser below which Base16 encoding is to be used for framed data.
NB_TRY_FOR_EACH_TRANSPORTinteger2The maximum number of consecutive retries to establish a connection on a given transport.
TRY_AGAIN_INTERVALinteger10000The 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_ENCODINGBooleanfalseWhether Base16 encoding should be used.
SERVER_PING_ENABLEDBooleantrueWhether pings from the client to the server are enabled.
WEBSOCKET_CREATION_TIMEOUTinteger1000The number of milliseconds after which creation of a WebSocket connection is considered to have failed.
debuginteger0The debug level.
transportstringnoneThe enforced transport, which can be one of the following transports:
  • WebSocket
  • XMLHttpRequest
Every member has a default value. No member is required.
Source:
Returns:
Type
void

<inner> displayConfig() → {void}

Display the configuration of a WebSocket object's fallback behavior. This function uses the console.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