Added support for SSL

This commit is contained in:
JCash
2020-08-28 12:43:50 +02:00
parent 0e589290ed
commit 1e6c534609
14 changed files with 124 additions and 4949 deletions

View File

@@ -707,6 +707,68 @@ nodes {
text_leading: 1.0
text_tracking: 0.0
}
nodes {
position {
x: 320.0
y: 568.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 200.0
y: 100.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_TEXT
blend_mode: BLEND_MODE_ALPHA
text: "<text>"
font: "example"
id: "connection_text"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
outline {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
shadow {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
adjust_mode: ADJUST_MODE_FIT
line_break: false
layer: ""
inherit_alpha: true
alpha: 1.0
outline_alpha: 1.0
shadow_alpha: 1.0
template_node_child: false
text_leading: 1.0
text_tracking: 0.0
}
layers {
name: "below"
}

View File

@@ -1,24 +1,29 @@
--local websocket_async = require "websocket.client_async"
local URL="://echo.websocket.org"
local function click_button(node, action)
--print("mouse", action.x, action.y)
return gui.is_enabled(node) and action.released and gui.pick_node(node, action.x, action.y)
return gui.is_enabled(node) and action.pressed and gui.pick_node(node, action.x, action.y)
end
local function update_buttons(self)
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)
gui.set_enabled(self.connect_wss_node, false)
gui.set_enabled(self.send_node, true)
gui.set_enabled(self.close_node, true)
gui.set_enabled(self.connection_text, true)
gui.set_text(self.connection_text, "Connected to " .. self.url)
else
gui.set_enabled(self.connect_ws_node, true)
gui.set_enabled(self.connect_wss_node, true)
gui.set_enabled(self.send_node, false)
gui.set_enabled(self.close_node, false)
gui.set_enabled(self.connection_text, false)
end
end
@@ -41,7 +46,10 @@ function init(self)
self.connect_wss_node = gui.get_node("connect_wss/button")
self.send_node = gui.get_node("send/button")
self.close_node = gui.get_node("close/button")
update_buttons(self)
self.connection_text = gui.get_node("connection_text")
update_gui(self)
--http.request("https://www.google.com", "GET", http_handle_response)
self.connection = nil
end
@@ -59,7 +67,7 @@ end
local function websocket_callback(self, conn, data)
if data.event == websocket.EVENT_DISCONNECTED then
self.connection = nil
update_buttons(self)
update_gui(self)
if data.error then
log("Diconnect error:", data.error)
self.connection = nil
@@ -69,7 +77,7 @@ local function websocket_callback(self, conn, data)
log("Connection error:", data.error)
self.connection = nil
end
update_buttons(self)
update_gui(self)
elseif data.event == websocket.EVENT_MESSAGE then
log("Receiving: '" .. tostring(data.message) .. "'")
end
@@ -84,12 +92,11 @@ local function connect(self, scheme)
--options = "all",
}
local url = scheme .. URL
log("Connecting to " .. url)
self.connection = websocket.connect(url, params, websocket_callback)
self.url = scheme .. URL
log("Connecting to " .. self.url)
self.connection = websocket.connect(self.url, params, websocket_callback)
if self.connection == nil then
print("Failed to connect to " .. url .. ": " .. err)
print("Failed to connect to " .. self.url .. ": " .. err)
end
end
@@ -104,10 +111,8 @@ end
function on_input(self, action_id, action)
--print("MAWE", action_id)
if click_button(self.connect_ws_node, action) then
print("MAWE click connect_ws_node")
connect(self, "ws")
elseif click_button(self.connect_wss_node, action) then
print("MAWE click connect_wss_node")
connect(self, "wss")
elseif click_button(self.close_node, action) then
disconnect(self)