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:
+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);
|
||||
|
||||
Reference in New Issue
Block a user