diff --git a/docs/index.md b/docs/index.md index c26656e..57f5517 100644 --- a/docs/index.md +++ b/docs/index.md @@ -14,18 +14,16 @@ 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 - print("disconnected " .. conn) + log("Disconnected: " .. tostring(conn)) self.connection = nil + update_gui(self) elseif data.event == websocket.EVENT_CONNECTED then - print("Connected " .. conn) - -- self.connection = conn + update_gui(self) + log("Connected: " .. tostring(conn)) elseif data.event == websocket.EVENT_ERROR then - print("Error:", data.message) + log("Error: '" .. data.error .. "'") elseif data.event == websocket.EVENT_MESSAGE then - print("Receiving: '" .. tostring(data.message) .. "'") - end - elseif data.event == websocket.EVENT_DISCONNECTED then - print("Disconnected: '" .. tostring(data.message) .. "'") + log("Receiving: '" .. tostring(data.message) .. "'") end end diff --git a/websocket/api/api.script_api b/websocket/api/api.script_api index 855e072..39f2f3a 100644 --- a/websocket/api/api.script_api +++ b/websocket/api/api.script_api @@ -65,15 +65,16 @@ ```lua local function websocket_callback(self, conn, data) if data.event == websocket.EVENT_DISCONNECTED then - print("disconnected " .. conn) + log("Disconnected: " .. tostring(conn)) self.connection = nil + update_gui(self) elseif data.event == websocket.EVENT_CONNECTED then - print("Connected " .. conn) - -- self.connection = conn + update_gui(self) + log("Connected: " .. tostring(conn)) elseif data.event == websocket.EVENT_ERROR then - print("Error:", data.error) + log("Error: '" .. data.error .. "'") elseif data.event == websocket.EVENT_MESSAGE then - print("Receiving: '" .. tostring(data.message) .. "'") + log("Receiving: '" .. tostring(data.message) .. "'") end end