Compare commits

..

No commits in common. "4f949a723931a256fd42e0af176eb58159ec6a77" and "25296ae38d67817029b2cf1f394e83fac5a63db4" have entirely different histories.

2 changed files with 10 additions and 13 deletions

View file

@ -74,16 +74,13 @@ func set_variable(name: String, value: Variant, button_id: String = "") -> bool:
last_error_description = response.error_message last_error_description = response.error_message
return false return false
func delete_variable(name: String, button_id: String = "") -> bool: func delete_variable(name: String, button_id) -> bool:
var api_path: String = "/api" var api_path: String = "/api" % name
var req: Dictionary = { var req: Dictionary = {
"request": "deleteVariable", "request": "deleteVariable",
"name": name "name": name,
"buttonID": button_id
} }
if button_id != "":
req["buttonID"] = button_id
client.request(SammiClient.Method.POST, api_path, JSON.stringify(req)) client.request(SammiClient.Method.POST, api_path, JSON.stringify(req))
var response: SammiClient.SammiResponse = await client.request_completed var response: SammiClient.SammiResponse = await client.request_completed
if response.code == 200: if response.code == 200:

View file

@ -43,7 +43,6 @@ func request(method: Method, api_path: String, body: String) -> void:
self.query = api_path self.query = api_path
self.body = body self.body = body
self.method = method
self.client = StreamPeerTCP.new() self.client = StreamPeerTCP.new()
self.client.connect_to_host(host, port) self.client.connect_to_host(host, port)
self.state = State.CONNECTING self.state = State.CONNECTING
@ -52,6 +51,11 @@ func _process(_delta: float) -> void:
if not client: if not client:
return return
if state == State.CLOSED:
client.disconnect_from_host()
client = null
return
client.poll() client.poll()
if client.get_status() == StreamPeerTCP.Status.STATUS_CONNECTED and state == State.CONNECTING: if client.get_status() == StreamPeerTCP.Status.STATUS_CONNECTED and state == State.CONNECTING:
state = State.REQUESTING state = State.REQUESTING
@ -126,12 +130,8 @@ func _read_response() -> void:
buffer.append_array(chunk[1]) buffer.append_array(chunk[1])
else: else:
response = SammiResponse.new(headers, buffer, query) response = SammiResponse.new(headers, buffer, query)
state = State.CLOSED
headers = []
buffer = []
client.disconnect_from_host()
client = null
request_completed.emit(response) request_completed.emit(response)
state = State.CLOSED
class SammiResponse: class SammiResponse: