Update index.md

This commit is contained in:
Björn Ritzl 2022-01-03 14:27:42 +01:00 committed by GitHub
parent 4cf11c3048
commit ace3242158
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,23 +14,23 @@ Here is how you connect to a websocket and listen to events:
```lua
local function websocket_callback(self, conn, data)
if data.event == websocket.EVENT_DISCONNECTED then
log("Disconnected: " .. tostring(conn))
print("Disconnected: " .. tostring(conn))
self.connection = nil
update_gui(self)
elseif data.event == websocket.EVENT_CONNECTED then
update_gui(self)
log("Connected: " .. tostring(conn))
print("Connected: " .. tostring(conn))
elseif data.event == websocket.EVENT_ERROR then
log("Error: '" .. tostring(data.message) .. "'")
print("Error: '" .. tostring(data.message) .. "'")
if data.handshake_response then
log("Handshake response status: '" .. tostring(data.handshake_response.status) .. "'")
print("Handshake response status: '" .. tostring(data.handshake_response.status) .. "'")
for key, value in pairs(data.handshake_response.headers) do
log("Handshake response header: '" .. key .. ": " .. value .. "'")
end
log("Handshake response body: '" .. tostring(data.handshake_response.response) .. "'")
print("Handshake response body: '" .. tostring(data.handshake_response.response) .. "'")
end
elseif data.event == websocket.EVENT_MESSAGE then
log("Receiving: '" .. tostring(data.message) .. "'")
print("Receiving: '" .. tostring(data.message) .. "'")
end
end