An object compatible with the WebSocket interface.
The connection is closed or couldn't be opened.
The connection is in the process of closing.
The connection is not yet open.
The connection is open and ready to communicate.
A string indicating the type of binary data being transmitted by the connection. This should be either "blob" if DOM Blob objects are being used or "arraybuffer" if ArrayBuffer objects are being used.
Internal JSON-RPC error.
Invalid method parameter(s) on the client
Invalid method parameter(s).
The JSON sent is not a valid Request object.
The method does not exist / is not available.
Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.
Generic server-errors
Timeout server-errors
Response received for an unknown request server-errors
The number of bytes of data that have been queued using calls to send() but not yet transmitted to the network. This value resets to zero once all queued data has been sent. This value does not reset to zero when the connection is closed; if you keep calling send(), this will continue to climb. Read only
The extensions selected by the server. This is currently only the empty string or a list of extensions as negotiated by the connection.
An event listener to be called when the WebSocket connection's readyState changes to CLOSED. The listener receives a CloseEvent named "close".
An event listener to be called when the WebSocket connection's readyState changes to CLOSED. The listener receives a CloseEvent named "close".
An event listener to be called when an error occurs. This is a simple event named "error".
An event listener to be called when an error occurs. This is a simple event named "error".
An event listener to be called when a message is received from the server. The listener receives a MessageEvent named "message".
An event listener to be called when a message is received from the server. The listener receives a MessageEvent named "message".
An event listener to be called when the WebSocket connection's readyState changes to OPEN; this indicates that the connection is ready to send and receive data. The event is a simple one with the name "open".
An event listener to be called when the WebSocket connection's readyState changes to OPEN; this indicates that the connection is ready to send and receive data. The event is a simple one with the name "open".
The current state of the connection; this is one of the Ready state constants. Read only.
The URL as resolved by the constructor. This is always an absolute URL. Read only.
Register an event handler of a specific event type on the EventTarget.
Closes the WebSocket connection or connection attempt, if any. If the connection is already CLOSED, this method does nothing.
Destroy the Cable, send a timeout for all pending calls and clean the registered methods
Dispatch an event to this EventTarget.
The return value is false if event is cancelable and at least one of the event handlers which handled this event called Event.preventDefault(). Otherwise it returns true.
Unlike the request, notify will not wait for the server to reply
name
Register a new method on the websocket
name
handler
Removes an event listener from the EventTarget.
Make a Rpc call
name
Enqueues the specified data to be transmitted to the server over the WebSocket connection, increasing the value of bufferedAmount by the number of bytes needed to contain the data. If the data can't be sent (for example, because it needs to be buffered but the buffer is full), t he socket is closed automatically.
The data to send to the server. It may be one of the following types:
Generated using TypeDoc
RPC over websocket, using the JSON-RPC 2.0 Specification http://www.jsonrpc.org/specification
A
Cable
establish an RPC communication over a websocket, there is no server/client role, the same cable can you can define methods on both sides of the cable and call the remote methods// Client 1 const cable = new Cable(ws); cable.register("ping", async () => { return "pong"; }); cable.notify("hello", {name:"client 1"}); // Client 2 const cable = new Cable(ws); cable.register("hello", async ({name:string}) => { console.log(`${name} said hello`); }); try { const res = await cable.request("ping"); assert.equal(res,"pong"); } catch(e) { if(e.code === Cable.SERVER_ERROR) { console.log("Implementation error on the server"); } throw e; }