Websocket now supports html5 as well

This commit is contained in:
JCash
2020-09-02 10:44:02 +02:00
parent 1e6c534609
commit 5de32250c3
7 changed files with 371 additions and 147 deletions

View File

@@ -1,15 +1,9 @@
local URL="://echo.websocket.org"
local function click_button(node, action)
--print("mouse", action.x, action.y)
return gui.is_enabled(node) and action.pressed and gui.pick_node(node, action.x, action.y)
end
local function http_handle_response(self, id, response)
print(response.status, response.response)
end
local function update_gui(self)
if self.connection then
gui.set_enabled(self.connect_ws_node, false)
@@ -47,11 +41,8 @@ function init(self)
self.send_node = gui.get_node("send/button")
self.close_node = gui.get_node("close/button")
self.connection_text = gui.get_node("connection_text")
update_gui(self)
--http.request("https://www.google.com", "GET", http_handle_response)
self.connection = nil
update_gui(self)
end
function final(self)
@@ -78,19 +69,17 @@ local function websocket_callback(self, conn, data)
self.connection = nil
end
update_gui(self)
elseif data.event == websocket.EVENT_ERROR then
if data.error then
log("Error:", data.error)
end
elseif data.event == websocket.EVENT_MESSAGE then
log("Receiving: '" .. tostring(data.message) .. "'")
end
end
local function connect(self, scheme)
local params = {
mode = "client" --only supported mode currently
--mode = "client",
--protocol = "tlsv1_2",
--verify = "none",
--options = "all",
}
local params = {}
self.url = scheme .. URL
log("Connecting to " .. self.url)
@@ -109,7 +98,6 @@ end
function on_input(self, action_id, action)
--print("MAWE", action_id)
if click_button(self.connect_ws_node, action) then
connect(self, "ws")
elseif click_button(self.connect_wss_node, action) then