import { type WS } from "https://deno.land/x/cav@0.2.0-alpha.7/examples/chat/deps_dom.ts";
Isomorphic WebSocket interface with JSON serialization and typed messages.
Properties
Send data to the connected party. The data provided is serialized to JSON before being sent.
Closes the web socket connection. An optional code and reason may be provided, and will be available to all "close" event listeners.
Listener for the "open" event, triggered when the web socket connection is established. The socket can't send data until the open event occurs.
Listener for the "close" event, triggered when the web socket connection is ended.
Listener for the "message" event, triggered whenever a message is received from the connected party. The message received is deserialized to the event's "message" property.
Listener for the "error" event, triggered when the connection has been closed due to an error or when received/sent data couldn't be deserialized/parsed.
Methods
Register an event listener for the "open" event, triggered when the web socket connection is established. The socket can't send data until the open event occurs.
Register an event listener for the "close" event, triggered when the web socket connection is ended.
Register an event listener for the "message" event, triggered whenever a message is received from the connected party. The message received is deserialized before the listener is called.
Register an event listener for the "error" event, triggered when the connection has been closed due to an error or when an error is thrown inside one of the event listeners. This is also the event triggered when the server sends back an HttpError due to invalid input.