Start the WebSocket server. Must be called after createServer()
.
You should setup state update handlers before calling this method,
since some errors (e.g. port already in use) may occur after starting the server
and will be reported through a state update.
If the server is not in the correct state, an error will be thrown.
Handle the server's state update.
You should respond properly to the "failed" or "cancelled" state.
The server will be removed if the state is "failed" or "cancelled",
and you must call createServer()
and startServer()
again to create a new one.
It is possible that you receive a "failed" state immediately after calling startServer()
,
which indicates that an error occurred when starting the server.
The callback function.
The server's new state.
Optional
error: { The error if the state is failed
or waiting
.
Handle a new connection to the server.
The callback function.
An unique ID for this connection.
The information of the client.
Handle a connection's state change. You should respond properly to the "failed" or "cancelled" state, e.g. remove the connection ID from your cached list.
The callback function.
The connection ID.
The connection's new state.
Optional
error: { The error if the state is failed
or waiting
.
Handle a message from a connection.
The connection ID.
The message content.
Send a message to a connection. The message will be encoded as UTF-8 and sent as binary data.
"no_connection" if the connection does not exist, "success" if the message is sent successfully.
Any error occurred when sending the message.
The connection ID.
The text to send.
Generated using TypeDoc
The
WebSocket
module provides a simple interface to create local WebSocket servers, therefore enabling the plugin to communicate with other applications. It is only available on macOS 10.15 or later.Currently, TLS (thus the
wss://
protocol) is not supported. When connecting to the server, a client should use thews://
protocol.Example
Available In Entry
Main and Global