websocket module
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.
4 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) -> any |
— | Ask the connection to close, which still delivers a closed event with its code; false when it was already gone. |
connect(any, string, any?) -> any |
— | Open a connection and return the id send and close take, which task.wait resumes on with the open or error event; options are on_event, compression and headers. |
send(int, any) -> any |
— | Queue a frame on the connection, text for a string and binary for bytes; false when it is already gone. |
state(int) -> any |
— | 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 |