mirror of
https://github.com/defold/extension-websocket.git
synced 2025-06-27 09:47:44 +02:00
Update index.md
This commit is contained in:
parent
4cf11c3048
commit
ace3242158
@ -14,23 +14,23 @@ Here is how you connect to a websocket and listen to events:
|
|||||||
```lua
|
```lua
|
||||||
local function websocket_callback(self, conn, data)
|
local function websocket_callback(self, conn, data)
|
||||||
if data.event == websocket.EVENT_DISCONNECTED then
|
if data.event == websocket.EVENT_DISCONNECTED then
|
||||||
log("Disconnected: " .. tostring(conn))
|
print("Disconnected: " .. tostring(conn))
|
||||||
self.connection = nil
|
self.connection = nil
|
||||||
update_gui(self)
|
update_gui(self)
|
||||||
elseif data.event == websocket.EVENT_CONNECTED then
|
elseif data.event == websocket.EVENT_CONNECTED then
|
||||||
update_gui(self)
|
update_gui(self)
|
||||||
log("Connected: " .. tostring(conn))
|
print("Connected: " .. tostring(conn))
|
||||||
elseif data.event == websocket.EVENT_ERROR then
|
elseif data.event == websocket.EVENT_ERROR then
|
||||||
log("Error: '" .. tostring(data.message) .. "'")
|
print("Error: '" .. tostring(data.message) .. "'")
|
||||||
if data.handshake_response then
|
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
|
for key, value in pairs(data.handshake_response.headers) do
|
||||||
log("Handshake response header: '" .. key .. ": " .. value .. "'")
|
log("Handshake response header: '" .. key .. ": " .. value .. "'")
|
||||||
end
|
end
|
||||||
log("Handshake response body: '" .. tostring(data.handshake_response.response) .. "'")
|
print("Handshake response body: '" .. tostring(data.handshake_response.response) .. "'")
|
||||||
end
|
end
|
||||||
elseif data.event == websocket.EVENT_MESSAGE then
|
elseif data.event == websocket.EVENT_MESSAGE then
|
||||||
log("Receiving: '" .. tostring(data.message) .. "'")
|
print("Receiving: '" .. tostring(data.message) .. "'")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user