mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-26 21:51:13 +01:00
fixes for wasm client
- ui_enum - spdlog pthread - url hostname from emscripten - websocket ping pong not exposed on js - version string in client - cleanup the generation of the version string - set fixed path for wasm ws
This commit is contained in:
@@ -21,9 +21,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
|
||||
set(PROJECT_DIR ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
# defines targets and sources
|
||||
if(NOT EMSCRIPTEN)
|
||||
add_subdirectory(UI)
|
||||
endif()
|
||||
|
||||
add_subdirectory(client)
|
||||
|
||||
|
||||
+2
-1
@@ -1,5 +1,5 @@
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
if(NOT EMSCRIPTEN)
|
||||
add_library(UI STATIC)
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core SerialBus)
|
||||
@@ -39,6 +39,7 @@ target_link_libraries(UI
|
||||
Qt::SerialBus
|
||||
UI_enum
|
||||
)
|
||||
endif()
|
||||
|
||||
add_library(UI_enum INTERFACE)
|
||||
|
||||
|
||||
+10
-6
@@ -33,9 +33,10 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription("unisim_cpp client\n\tversion: " + QString::fromStdString(Git_version::branch) +
|
||||
"-" + QString::fromStdString(Git_version::shortSha1) +
|
||||
QString::fromStdString(Git_version::dirty ? "-dirty" : ""));
|
||||
parser.setApplicationDescription(QString("unisim_cpp client\n\tVersion: %1-%2%3")
|
||||
.arg(Git_version::branch)
|
||||
.arg(Git_version::shortSha1)
|
||||
.arg(Git_version::dirty ? "-dirty" : ""));
|
||||
parser.addHelpOption();
|
||||
|
||||
QCommandLineOption host_option(QStringList() << "s"
|
||||
@@ -70,11 +71,15 @@ int main(int argc, char *argv[])
|
||||
.value_or(spdlog::level::off));
|
||||
|
||||
QUrl url;
|
||||
url.setScheme("ws");
|
||||
#ifdef EMSCRIPTEN
|
||||
emscripten::val location = emscripten::val::global("location");
|
||||
url.setHost(QString::fromStdString(location["href"].as<std::string>()));
|
||||
url.setHost(QString::fromStdString(location["hostname"].as<std::string>()));
|
||||
url.setPath("/ws");
|
||||
url.setPort(443);
|
||||
url.setScheme("wss");
|
||||
#else
|
||||
url.setScheme("ws");
|
||||
url.setPort(parser.value(port_option).toInt());
|
||||
url.setHost(parser.value(host_option));
|
||||
#if defined(__linux__)
|
||||
if (parser.value(host_option).endsWith(".local"))
|
||||
@@ -101,7 +106,6 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
url.setPort(parser.value(port_option).toInt());
|
||||
QString default_sim = parser.value(default_sim_option);
|
||||
SPDLOG_INFO("Connecting client on {}", url.toString().toStdString());
|
||||
MainWindow w(url, default_sim);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "mainwindow.hpp"
|
||||
#include "factory.hpp"
|
||||
#include "git_version.h"
|
||||
#include "ui_base.hpp"
|
||||
#include "ui_mainwindow.h"
|
||||
#include "web_socket_wrapper.hpp"
|
||||
@@ -15,6 +16,10 @@ MainWindow::MainWindow(QUrl ws_url, QString sim, QWidget *parent)
|
||||
m_web_socket(new Web_socket_wrapper(ws_url))
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->statusbar->showMessage(QString("Version: %1-%2%3")
|
||||
.arg(Git_version::branch)
|
||||
.arg(Git_version::shortSha1)
|
||||
.arg(Git_version::dirty ? "-dirty" : ""));
|
||||
connect(m_web_socket.get(), &Web_socket_wrapper::log_signal, this,
|
||||
[](const char *filename_in, int line_in, const char *funcname_in, int level, QString msg) {
|
||||
if (spdlog::default_logger_raw()->should_log((spdlog::level::level_enum)level))
|
||||
|
||||
@@ -22,6 +22,22 @@ Web_socket_wrapper::Web_socket_wrapper(const QUrl &url, QObject *parent)
|
||||
emit on_connected();
|
||||
});
|
||||
connect(m_web_socket, &QWebSocket::disconnected, this, [=, this] { emit on_closed(); });
|
||||
connect(m_web_socket, &QWebSocket::errorOccurred, this, [this](QAbstractSocket::SocketError error) {
|
||||
LOG_ERROR(QString::fromStdString(std::string(magic_enum::enum_name(error))));
|
||||
});
|
||||
connect(m_ping_timer, &QTimer::timeout, this, [=, this] {
|
||||
#ifdef EMSCRIPTEN
|
||||
if (m_web_socket->state() != QAbstractSocket::ConnectedState)
|
||||
{
|
||||
m_web_socket->close();
|
||||
emit on_closed();
|
||||
}
|
||||
m_ping_timer->start(1000);
|
||||
});
|
||||
#else
|
||||
m_web_socket->ping();
|
||||
m_pong_timer->start(1000);
|
||||
});
|
||||
connect(m_web_socket, &QWebSocket::pong, this, [=, this](quint64 elapsedTime) {
|
||||
if (elapsedTime > 1000)
|
||||
{
|
||||
@@ -32,18 +48,12 @@ Web_socket_wrapper::Web_socket_wrapper(const QUrl &url, QObject *parent)
|
||||
m_pong_timer->stop();
|
||||
m_ping_timer->start(1000);
|
||||
});
|
||||
connect(m_web_socket, &QWebSocket::errorOccurred, this, [this](QAbstractSocket::SocketError error) {
|
||||
LOG_ERROR(QString::fromStdString(std::string(magic_enum::enum_name(error))));
|
||||
});
|
||||
connect(m_ping_timer, &QTimer::timeout, this, [=, this] {
|
||||
m_web_socket->ping();
|
||||
m_pong_timer->start(1000);
|
||||
});
|
||||
connect(m_pong_timer, &QTimer::timeout, this, [=, this] {
|
||||
LOG_CRITICAL("Pong timeout");
|
||||
m_web_socket->close();
|
||||
emit on_closed();
|
||||
});
|
||||
#endif
|
||||
m_ping_timer->setSingleShot(true);
|
||||
m_pong_timer->setSingleShot(true);
|
||||
m_web_socket->setProxy(QNetworkProxy::NoProxy);
|
||||
|
||||
Vendored
+12
@@ -7,3 +7,15 @@ add_subdirectory(json)
|
||||
add_subdirectory(magic_enum)
|
||||
add_subdirectory(spdlog)
|
||||
add_subdirectory(qwt)
|
||||
|
||||
if (EMSCRIPTEN)
|
||||
target_compile_options(spdlog
|
||||
PRIVATE
|
||||
-pthread
|
||||
)
|
||||
|
||||
target_link_options(spdlog
|
||||
PRIVATE
|
||||
-pthread
|
||||
)
|
||||
endif()
|
||||
+4
-3
@@ -29,9 +29,10 @@ int main(int argc, char *argv[])
|
||||
QCoreApplication a(argc, argv);
|
||||
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription("unisim_cpp server\n\tversion: " + QString::fromStdString(Git_version::branch) +
|
||||
"-" + QString::fromStdString(Git_version::shortSha1) +
|
||||
QString::fromStdString(Git_version::dirty ? "-dirty" : ""));
|
||||
parser.setApplicationDescription(QString("unisim_cpp server\n\tVersion: %1-%2%3")
|
||||
.arg(Git_version::branch)
|
||||
.arg(Git_version::shortSha1)
|
||||
.arg(Git_version::dirty ? "-dirty" : ""));
|
||||
parser.addHelpOption();
|
||||
|
||||
QCommandLineOption port_option(QStringList() << "p"
|
||||
|
||||
@@ -215,8 +215,8 @@ json Simulators::changed_UI_items()
|
||||
json changed;
|
||||
changed["event"]["type"] = "ui_changed";
|
||||
|
||||
const auto& ui_items = after["UI_items"];
|
||||
const auto& prev_ui_items = m_before["UI_items"]; // may be null on first call
|
||||
const auto &ui_items = after["UI_items"];
|
||||
const auto &prev_ui_items = m_before["UI_items"]; // may be null on first call
|
||||
|
||||
const size_t count = ui_items.size();
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
|
||||
Reference in New Issue
Block a user