How To Call It
This is an object method: call it with a colon on a connection object opened with WebSocket.connect(url) (socket:<method>(...)). The global WebSocket table does not have this method.
Waits for the next event and returns an event table with a type field ("message", "close" or "error"); nil on timeout.
Documented for app version 1.0.51Updated:
This is an object method: call it with a colon on a connection object opened with WebSocket.connect(url) (socket:<method>(...)). The global WebSocket table does not have this method.
For network integration, use HTTPS only, keep the response size bounded, and validate the response code before moving into JSON or File steps.
Optional: timeoutMs (omit to pass nil and use the runtime default). Returns a Lua table, or nil.
The most common pattern is to check a Request response with getResponseCode(), read its body with getData() and parse it with JSON.parse().
The snippet below is a starter pattern that can be applied directly in runtime flow.
local socket = WebSocket.connect("wss://example.com/socket")
socket:send("ping")
local result = socket:receive()From foundation to combined usage, each level is provided as a separate code block so you can copy the level you need and adapt it directly.
local socket = WebSocket.connect("wss://example.com/socket")
socket:send("ping")
local result = socket:receive()local stepOk = true
local socket = WebSocket.connect("wss://example.com/socket")
socket:send("ping")
local result = socket:receive()
if stepOk then
wait(200)
endlocal ok, err = pcall(function()
local socket = WebSocket.connect("wss://example.com/socket")
socket:send("ping")
local result = socket:receive()
end)
if not ok then
print("API step failed: WebSocket:receive: " .. tostring(err))
requestStop()
end-- For network integration, use HTTPS only, keep the response size bounded, and validate the response code before moving into JSON or File steps.
local function run_receive_step()
local socket = WebSocket.connect("wss://example.com/socket")
socket:send("ping")
local result = socket:receive()
end
local ok, err = pcall(run_receive_step)
if not ok then
toast("Step failed")
print(err)
endlocal socket = WebSocket.connect("wss://example.com/socket")
socket:send("ping")
local result = socket:receive()
KV.set("last_network_step", DateTime.now():format("yyyy-MM-dd HH:mm:ss"))
print("Network step finished")