From b558ac3d4ea8fd1756eaf75d756de7dee668041d Mon Sep 17 00:00:00 2001 From: 30hours Date: Tue, 27 Feb 2024 01:49:10 +0000 Subject: [PATCH] Fixed weird timeout issue --- api/main.py | 7 ++++--- api/map/event/radar.js | 15 +++++++++++---- api/map/main.js | 2 +- api/public/js/index.js | 2 +- common/Message.py | 4 ++-- event/event.py | 5 ++++- 6 files changed, 23 insertions(+), 12 deletions(-) diff --git a/api/main.py b/api/main.py index 0aee2d4..6b29118 100644 --- a/api/main.py +++ b/api/main.py @@ -60,10 +60,11 @@ def serve_static(file): @app.route("/api") def api(): api = request.query_string.decode('utf-8') - reply = message_api_request.send_message(api) + try: + reply = message_api_request.send_message(api) + except Exception as e: + reply = "Exception: " + str(e) print(reply, flush=True) - urls = request.args.getlist("url") - data = [{"url": 'http://' + url} for url in urls] return reply @app.route("/map/") diff --git a/api/map/event/radar.js b/api/map/event/radar.js index 453f95c..d6576bc 100644 --- a/api/map/event/radar.js +++ b/api/map/event/radar.js @@ -1,7 +1,7 @@ function event_radar() { - radar_url = window.location.origin + '/api' + window.location.search; - console.log(radar_url); + var radar_url = window.location.origin + + '/api' + window.location.search; fetch(radar_url) .then(response => { @@ -11,8 +11,15 @@ function event_radar() { return response.json(); }) .then(data => { - // Update aircraft points based on new data - console.log("test"); + for (const key in data["detections_localised"]) { + if (data["detections_localised"].hasOwnProperty(key)) { + const target = data["detections_localised"][key]; + const points = target["points"]; + + console.log(points); + + } + } }) .catch(error => { // Handle errors during fetch diff --git a/api/map/main.js b/api/map/main.js index 981a54a..2055ac7 100644 --- a/api/map/main.js +++ b/api/map/main.js @@ -184,7 +184,7 @@ window.addEventListener('load', function () { // add radar points const radar_names = new URLSearchParams( - window.location.search).getAll('url'); + window.location.search).getAll('server'); console.log(radar_names); var radar_config_url = radar_names.map( url => `http://${url}/api/config`); diff --git a/api/public/js/index.js b/api/public/js/index.js index 87005f6..de61c3e 100644 --- a/api/public/js/index.js +++ b/api/public/js/index.js @@ -45,7 +45,7 @@ document.getElementById('buttonMap').addEventListener('click', function() { var adsb = document.querySelector('[name="adsb"]').value; // Construct the URL with the form values - var apiUrl = '?url=' + Array.from(servers).map(server => server.value).join('&url='); + var apiUrl = '?server=' + Array.from(servers).map(server => server.value).join('&server='); var mapUrl = '/map/index.html' + apiUrl + '&associator=' + associator + '&coordreg=' + coordreg + '&adsb=' + adsb; // Redirect to the constructed URL diff --git a/common/Message.py b/common/Message.py index 5e9f748..3f9c2c4 100644 --- a/common/Message.py +++ b/common/Message.py @@ -58,7 +58,7 @@ class Message: with conn: while True: - data = conn.recv(65000) + data = conn.recv(8096) if not data: break decoded_data = data.decode() @@ -82,7 +82,7 @@ class Message: try: client_socket.connect((self.host, self.port)) client_socket.sendall(message.encode()) - reply = client_socket.recv(65000).decode() + reply = client_socket.recv(8096).decode() return reply except ConnectionRefusedError: print(f"Connection to {self.host}:{self.port} refused.") diff --git a/event/event.py b/event/event.py index a72fa63..93f758f 100644 --- a/event/event.py +++ b/event/event.py @@ -181,7 +181,10 @@ async def callback_message_received(msg): api[-1]["server"] = [api[-1]["server"]] # json dump - output = json.dumps(api) + for item in api: + if item["hash"] == short_hash(msg): + output = json.dumps(item) + break return output