Class: WebSocket

WebSocket

new WebSocket(serverURI, subProtocol, optionalConfig) → {WebSocket}

WebSocket constructor.

This object is instantiated by the client. It has the same features as a native WebSocket object. Fallback to an alternative transport mechanism is invisible to users of the client.

Optionally, the behavior of the JavaScript client can be configured through either of the following items:

  • The optionalConfig parameter of this constructor
  • The OraSocket.configure function
For more information, see the description of the OraSocket configure function.

Parameters:
Name Type Argument Description
serverURI string Required. The URI of the server WebSocket endpoint to which the client should connect. The format of the URI is as follows:
scheme://host[:port]/ws-application/path
scheme
The URI scheme, which is either ws or wss.
  • The ws scheme represents an unencrypted WebSocket connection.
  • The wss scheme represents an encrypted WebSocket connection.
host
The host on which the server application is running.
port
Optional. The port on which the server listens for client requests.
The default port number is 80 for unencrypted connections and 443 for encrypted connections.
ws-application
The name with which the WebSocket server application is deployed.
path
The location of the server WebSocket endpoint within the server.
subProtocol string | Array.<string> <optional>
Optional. A string or an array of strings that contains one or more subprotocols to negotiate.
optionalConfig object <optional>
Optional. A JSON Object that contains properties for configuring WebSocket fallback.
Specify this parameter only if the fallback mechanism is guaranteed to be present. Otherwise, use the OraSocket.configure function to set properties for configuring WebSocket fallback.
The format of this parameter is identical to the format of the object to pass to the OraSocket.configure function.
Source:
See:
Returns:
Type
WebSocket

Methods

onclose() → {void}

Callback function that is called when a connection to the server is closed.

This function takes no parameters.

Source:
Returns:
Type
void

onerror(error) → {void}

Callback function that is called when a connection error occurs.
Parameters:
Name Type Description
error object The error that was raised.
Source:
Returns:
Type
void

onmessage(mess) → {void}

Callback function that is called when the client receives a message from the server.
Typically, the client-side logic of a WebSocket application is defined in this function.
Parameters:
Name Type Description
mess object The message received by the client.
Source:
Returns:
Type
void

onopen() → {void}

Callback function that is called when a connection to the server is established.

This function takes no parameters.

Source:
Returns:
Type
void

send(mess) → {void}

Send a message to the server within the context of the WebSocket application. This function is called from the client application.
Parameters:
Name Type Description
mess object The message to send to the server.
Source:
Returns:
Type
void

<inner> getConnectionTrialStatus() → {object}

Get a JSON object that contains information about the status of a connection attempt.

This function takes no parameters.

Note: This function is not part of the WebSocket specification. It should be called within a try/catch block.
This status depends on the fallback requirements and options. It is returned as a JSON object.
Source:
See:
Returns:
A JSON object in the following format:
  { 
    transport: "{transport}",
    timestamp: {timestamp},
    nbshot: {nbshot},
    actual: {actual}
  }
transport
A string that denotes the transport currently used.
timestamp
A long that represents the time at which the information was obtained.
nbshot
An int that represents the maximum number of consecutive retries to establish a connection on a given transport.
actual
An int that represents the number of times the connection has been actually reset.
Type
object

<inner> getConstructorOptions() → {object}

Get the configuration object, if any, that was passed as the optionalConfig parameter when this WebSocket object was created.

This function takes no parameters.

Note: This function is not part of the WebSocket specification. It should be called within a try/catch block.
Source:
See:
Returns:
Type
object

<inner> getServerURI() → {object}

Get the URI that was passed as the serverURI parameter when this WebSocket object was created.

This function takes no parameters.

Note: This function is not part of the WebSocket specification. It should be called within a try/catch block.
Source:
See:
Returns:
Type
object

<inner> getTransport() → {string}

Get the transport that is being used.
Note: This function is not part of the WebSocket specification. It should be called within a try/catch block.
Source:
Returns:
The transport that is being used.
Type
string

<inner> setDebugLevel(dl) → {void}

Set the debug level, which determines the amount of debugging information that is displayed on the console. A higher debug level specifies that more information is displayed.
Note: This function is not part of the WebSocket specification. It should be called within a try/catch block.
Parameters:
Name Type Description
dl int The debug level in the range 0-200. A value of 0 specifies that no debugging information is displayed.
Source:
Returns:
Type
void

<inner> setTransport(transport) → {void}

Enforce the specified transport.
Note: This function is not part of the WebSocket specification. It should be called within a try/catch block.
Parameters:
Name Type Description
transport string The transport to use, which must be one of the following transports:
  • WebSocket
  • XMLHttpRequest
Source:
Returns:
Type
void