websocket
A long-lived socket for text or binary frames. Events reach the node's on_websocket_event (or on_event) as a map with socket and kind: open, message…
A long-lived socket for text or binary frames. Events reach the node's on_websocket_event (or on_event) as a map with socket and kind: open, message, binary, closed or error, each an EVENT_* constant. An error carries its reason, and the HTTP status when a server refused the upgrade.
5 functions, 9 constants. Scripts reach it as websocket::.
Functions
Argument kinds are the script values a call passes: node is a node handle, any a table or value of any kind, fn a callback.
| function | acts on | what it does |
|---|---|---|
close(int) -> bool |
— | Ask the connection to close, which still delivers a closed event with its code; false when it was already gone. |
connect(Node?, string, websocket::ConnectOptions?) -> int |
— | Open a connection and return the id send_text, send_bytes and close take, which task.wait resumes on with the open or error event; options are on_event, compression and headers. With no node, only a task.wait hears it. |
send_bytes(int, [int]) -> bool |
— | Queue a binary frame on the connection; false when it is already gone. |
send_text(int, string) -> bool |
— | Queue a text frame on the connection; false when it is already gone. |
state(int) -> string |
— | Where the connection is: connecting, open, closing or closed, each a STATE_* constant. |
Constants
| name | value |
|---|---|
EVENT_BINARY |
"binary" |
EVENT_CLOSED |
"closed" |
EVENT_ERROR |
"error" |
EVENT_MESSAGE |
"message" |
EVENT_OPEN |
"open" |
STATE_CLOSED |
"closed" |
STATE_CLOSING |
"closing" |
STATE_CONNECTING |
"connecting" |
STATE_OPEN |
"open" |