WebSocket
Represents a WebSocket connection.Constructor
The URL to connect to. Must use
ws: or wss: protocol.Optional subprotocol(s) to negotiate.
Constants
Connection is being established.
Connection is established and ready to communicate.
Connection is closing.
Connection is closed.
Properties
The URL of the WebSocket connection.
Current state of the connection (0-3, see constants above).
Negotiated subprotocol.
Negotiated extensions.
Number of bytes queued for transmission.
Type for binary data. Default is
'arraybuffer'.Event handlers
Called when the connection is established.
Called when a message is received.
Called when an error occurs.
Called when the connection is closed.
Methods
Send data through the WebSocket.
Close the WebSocket connection.
code: Optional close code (default: 1000)reason: Optional close reason (max 123 bytes UTF-8)
Add an event listener.
Remove an event listener.
WebSocketPair
Create a pair of WebSocket objects that are connected to each other.Constructor
Properties
First WebSocket of the pair.
Second WebSocket of the pair.
MessageEvent
Event object for WebSocket messages.The message data.
Event type.
CloseEvent
Event object for WebSocket close events.Close status code.
Close reason.
True if the connection closed cleanly.
Close codes
Normal closure; the connection successfully completed.
Endpoint is going away (e.g., server shutdown).
Endpoint terminating due to protocol error.
Endpoint terminating due to unsupported data type.
Reserved; indicates no status code was provided.
Reserved; indicates connection closed abnormally.
Endpoint terminating due to inconsistent message data.
Endpoint terminating due to policy violation.
Endpoint terminating due to message too large.
Client terminating due to missing expected extension.
Server terminating due to unexpected condition.
Reserved; indicates TLS handshake failure.