mirror of
https://github.com/defold/extension-websocket.git
synced 2025-09-27 07:52:18 +02:00
Websocket now supports html5 as well
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user