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
optionalConfigparameter of this constructor - The
OraSocket.configurefunction
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
|
|
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:
-
- OraSocket for
OraSocket.configure
- OraSocket for
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 errorobject 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 messobject 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 messobject 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 atry/catchblock.
This status depends on the fallback requirements and options. It is returned as a JSON object.- Source:
- See:
-
- the WebSocket constructor.
Returns:
A JSON object in the following format:{ transport: "{transport}", timestamp: {timestamp}, nbshot: {nbshot}, actual: {actual} }- transport
- A
stringthat denotes the transport currently used. - timestamp
- A
longthat represents the time at which the information was obtained. - nbshot
- An
intthat represents the maximum number of consecutive retries to establish a connection on a given transport. - actual
-
An
intthat 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
optionalConfigparameter 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 atry/catchblock.- Source:
- See:
Returns:
- Type
- object
-
<inner> getServerURI() → {object}
-
Get the URI that was passed as the
serverURIparameter when thisWebSocketobject was created.This function takes no parameters.
Note: This function is not part of the WebSocket specification. It should be called within atry/catchblock.- Source:
- See:
-
- The WebSocket constructor.
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 atry/catchblock.- 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 atry/catchblock.Parameters:
Name Type Description dlint 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 atry/catchblock.Parameters:
Name Type Description transportstring The transport to use, which must be one of the following transports: WebSocketXMLHttpRequest
- Source:
Returns:
- Type
- void