Add a client web socket.
Client Molecule | |
Preference Dialog | |
Comments | Web socket requires a script molecule to receive socket events. |
Properties | |
type | string, ( r ) |
pref.name | string, ( r ) |
pref. | string, ( r, w ) |
bufferedAmount | int, ( r ) |
protocol | string, ( r ) |
readyState | int, ( r ) |
url | string, ( r ) |
binaryType | string, ( r ) |
Functions | |
attach | |
detach | |
delete | |
rename | |
clone | |
serialize | |
connect | |
send | |
read | |
close |
Web socket requires a script molecule to receive socket events. The events are passed to the script as input parameter params which has the following structure,
{ type: 'open' } { type: 'message' } { type: 'close', code: closeCode, reason: theReason, wasClean: true } { type: 'error'}
When an error occurs during connection, the script molecule first recieves an error event followed by a close event. The close event provides further details about the error. See this page for more information on close event’s attributes and a full listing of close codes.
On receiving message event, the implementer can use read function to read available data from receive buffer.
string, ( r )
The scriptable name for this molecule. This name can be set using rename function dynamically.
int, ( r )
The readyState attribute represents the state of the connection. It can have the following values,
CONNECTING(0) | he connection has not yet been established. |
OPEN(1) | The WebSocket connection is established and communication is possible. |
CLOSING(2) | The connection is going through the closing handshake, or the close() method has been invoked. |
CLOSED(3) | The connection has been closed or could not be opened. |
string, ( r )
Returns the result of resolving the URL that was passed to the web socket connect.
connect(ws_url, protocols);
Connect to server at ws_url and optionally request server to select a sub-protocols to communicate.
ws_url | (string) a valid web socket server address. (e.g. ws://game.example.com:12010/updates’.) |
protocols | (mixed) Optaional. Can be either a string or an array of strings. If it is a string, it is equivalent to an array consisting of just that string; if it is omitted, it is equivalent to the empty array. Each string in the array is a subprotocol name. The connection will only be established if the server reports that it has selected one of these subprotocols. |
(object) a web socket.