From e25db0b419c1b74dbd5bb0d4c6884d05db66fdf8 Mon Sep 17 00:00:00 2001 From: prplV Date: Wed, 23 Oct 2024 15:27:32 +0300 Subject: [PATCH] bugfix + output fix --- thirdparty/index.css | 1 + thirdparty/index.js | 29 ++++++++++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/thirdparty/index.css b/thirdparty/index.css index cf6f129..5b4ce33 100644 --- a/thirdparty/index.css +++ b/thirdparty/index.css @@ -86,6 +86,7 @@ button:hover { height: 90vh; max-height: 90vh; width: 30%; + max-width: 30%; border-radius: 4px; padding: 10px; overflow-y: scroll; diff --git a/thirdparty/index.js b/thirdparty/index.js index e18965e..1c1ab14 100644 --- a/thirdparty/index.js +++ b/thirdparty/index.js @@ -1,6 +1,6 @@ $(window).ready(function () { var isConnected = false; - var apiIsAlive = true; + var apiIsAlive = false; // TODO: change to valid url var apiServer = "http://localhost:8080"; @@ -53,6 +53,8 @@ $(window).ready(function () { } const fabric = new PacketFabric(); + let hello_check = fabric.new_hello(); + queryConstructor(hello_check); function dataConstructor(packet){ switch (packet.type) { @@ -86,7 +88,7 @@ $(window).ready(function () { apiIsAlive = status; return status ? ok_msg_conn(`API-Server is running. Connection established`) - : err_msg_conn(`API-Server unreachable. Error: ${JSON.stringify(er)}`); + : err_msg_conn(`API-Server unreachable. Error: ${er.statusText}. Status : ${er.status}`); case 'close': isConnected = status ? false : isConnected; if (status) { @@ -98,7 +100,7 @@ $(window).ready(function () { } return status ? ok_msg_conn(`Connection closed`) - : err_msg_conn(`Cannot close connection. Error: ${JSON.stringify(er)}`); + : err_msg_conn(`Cannot close connection. Error: ${er.statusText}. Status : ${er.status}`); case 'connect': isConnected = status ? true : isConnected; if (status) { @@ -113,7 +115,7 @@ $(window).ready(function () { } return status ? ok_msg_conn(`Successfully connected to PLD ${packet.ip}:${packet.port}`) - : err_msg_conn(`Cannot open web-socket with ${packet.ip}:${packet.port}. Error: ${JSON.stringify(er)}`); + : err_msg_conn(`Cannot open web-socket with ${packet.ip}:${packet.port}. Error: ${er.statusText}. Status : ${er.status}`); case 'send': if (status) { valid('address'); @@ -126,7 +128,7 @@ $(window).ready(function () { } return status ? ok_msg_conn(`Successfully sent data to ${packet.register_address}`) - : err_msg_conn(`Cannot send data to ${packet.register_address}. Error: ${JSON.stringify(er)}`); + : err_msg_conn(`Cannot send data to ${packet.register_address}. Error: ${er.statusText}. Status : ${er.status}`); default: return packet } @@ -150,8 +152,10 @@ $(window).ready(function () { $('#connect-btn').click(function() { if (!apiIsAlive) { - err_msg_conn("Cannot work without API-Server. Check its health..."); - return; + if (!hello_api()) { + err_msg_conn("Cannot work without API-Server. Check it health..."); + return; + } } if (isConnected) { @@ -174,8 +178,10 @@ $(window).ready(function () { $('#send-btn').click(() => { if (!apiIsAlive) { - err_msg_conn("Cannot work without API-Server. Check it health..."); - return; + if (!hello_api()) { + err_msg_conn("Cannot work without API-Server. Check it health..."); + return; + } } const address = document.getElementById('address').value; const data = document.getElementById('data').value; @@ -203,6 +209,11 @@ $(window).ready(function () { } }); + function hello_api() { + let packet = fabric.new_hello; + return queryConstructor(packet); + } + function valid(id) { var obj = document.getElementById(id).classList; if (obj.contains('invalid-args')) {