Closes the connection, sending a graceful teardown message to the other side.
Is there a message in the buffer already? If true, waitForNextMessage is guaranteed to return immediately. If false, check isDataPending as the next step.
Group: browser_api
Sends a ping message to the server. This is done automatically by the library if you set a non-zero Config.pingFrequency, but you can also send extra pings explicitly as well with this function.
Sends a pong message to the server. This is normally done automatically in response to pings.
Returns one of CONNECTING, OPEN, CLOSING, or CLOSED.
Sends a text message through the websocket.
Sends a binary message through the websocket.
Waits for and returns the next complete message on the socket.
Tells if waitForNextMessage would block.
The connection is closed or couldn't be opened.
The connection is in the process of closing.
Socket has been created. The connection is not yet open.
The connection is open and ready to communicate.
Arguments for the close event. The code and reason are provided from the close message on the websocket, if they are present. The spec says code 1000 indicates a normal, default reason close, but reserves the code range from 3000-5000 for future definition; the 3000s can be registered with IANA and the 4000's are application private use. The reason should be user readable, but not displayed to the end user. wasClean is true if the server actually sent a close event, false if it just disconnected.
Group: foundational
The CloseEvent you get references a temporary buffer that may be overwritten after your handler returns. If you want to keep it or the event.reason member, remember to .idup it.
WEBSOCKET SUPPORT:
Full example: