ws
The ws namespace — the engine's Luau API reference for ws.
The ws namespace — 5 functions.
ws/close
ws.close(handle)
Close the connection. Pending ws.recv promises resolve with {kind='closed'}.
ws/connect
ws.connect(url, headers?) -> string
Open a WebSocket. Returns a promise id — use task.await + ws.poll. Headers is an optional table of {name=value} string pairs.
ws/poll
ws.poll(promise_id) -> table | nil
Poll one ws.connect / ws.recv promise. Returns nil while pending. On resolution returns one of {kind='connected', handle}, {kind='connect_failed', error}, {kind='frame', text|bytes}, {kind='closed', reason}, {kind='recv_failed', error}.
ws/recv
ws.recv(handle) -> string
Async-wait for one frame on an open connection. Returns a promise id — ws.poll resolves with {kind='frame', text|bytes} or {kind='closed', reason} or {kind='recv_failed', error}.
ws/send
ws.send(handle, text)
Send a text frame on an open connection. Silent no-op if the handle is unknown / closed. Binary frames not yet supported by this surface.