From 39ec26f5ff3d0d289540345622b7a053d8372617 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Fri, 17 Dec 2021 19:06:35 +0100 Subject: [PATCH] JSONRPC.Hello working now, hanging at first call after that --- .../connection/tunnelproxytransport.cpp | 31 ++++++++++++------- .../connection/tunnelproxytransport.h | 1 - libnymea-app/jsonrpc/jsonrpcclient.cpp | 8 ++--- nymea-remoteproxy | 2 +- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/libnymea-app/connection/tunnelproxytransport.cpp b/libnymea-app/connection/tunnelproxytransport.cpp index 783f8b6b..245b1f2e 100644 --- a/libnymea-app/connection/tunnelproxytransport.cpp +++ b/libnymea-app/connection/tunnelproxytransport.cpp @@ -34,12 +34,17 @@ using namespace remoteproxyclient; +#include "logging.h" + +// Note: Re-registering the same category as the proxy lib offers, so we can control it in the app +// However, as we can't link the same category twice, let's just create a dummy here with the category string matching the lib +NYMEA_LOGGING_CATEGORY(dcTunnelProxyRemoteConnectionDummy, "TunnelProxyRemoteConnection") + TunnelProxyTransport::TunnelProxyTransport(QObject *parent) : NymeaTransportInterface(parent) { m_remoteConnection = new TunnelProxyRemoteConnection(QUuid::createUuid(), qApp->applicationName(), this); QObject::connect(m_remoteConnection, &TunnelProxyRemoteConnection::stateChanged, this, &TunnelProxyTransport::onRemoteConnectionStateChanged); - QObject::connect(m_remoteConnection, &TunnelProxyRemoteConnection::remoteConnectedChanged, this, &TunnelProxyTransport::onRemoteConnectedChanged); QObject::connect(m_remoteConnection, &TunnelProxyRemoteConnection::dataReady, this, &TunnelProxyTransport::dataReady); QObject::connect(m_remoteConnection, &TunnelProxyRemoteConnection::errorOccurred, this, &TunnelProxyTransport::onRemoteConnectionErrorOccurred); QObject::connect(m_remoteConnection, &TunnelProxyRemoteConnection::sslErrors, this, [=](const QList &errors){ @@ -56,13 +61,13 @@ bool TunnelProxyTransport::connect(const QUrl &url) m_url = url; - // FIXME: get nymea uuid from URL somehow... - //QUrl("ssl://dev-remoteproxy.nymea.io:2213"); + QUrl serverUrl = QUrl("ssl://dev-remoteproxy.nymea.io:2213"); + QUuid serverUuid = url.host(); - //m_remoteConnection->connectServer() + qCritical() << "Calling connect"; - return false; + return m_remoteConnection->connectServer(serverUrl, serverUuid); } QUrl TunnelProxyTransport::url() const @@ -116,12 +121,16 @@ QSslCertificate TunnelProxyTransport::serverCertificate() const void TunnelProxyTransport::onRemoteConnectionStateChanged(remoteproxyclient::TunnelProxyRemoteConnection::State state) { - qCritical() << "FIXME TODO! remoteConnectionStateChanged"; -} - -void TunnelProxyTransport::onRemoteConnectedChanged(bool remoteConnected) -{ - qDebug() << "Tunnel proxy remote connection" << (remoteConnected ? "connected" : "disconnected"); + switch (state) { + case remoteproxyclient::TunnelProxyRemoteConnection::StateRemoteConnected: + emit connected(); + break; + case remoteproxyclient::TunnelProxyRemoteConnection::StateDisconnected: + emit disconnected(); + break; + default: + ; + } } void TunnelProxyTransport::onRemoteConnectionErrorOccurred(QAbstractSocket::SocketError error) diff --git a/libnymea-app/connection/tunnelproxytransport.h b/libnymea-app/connection/tunnelproxytransport.h index 6d619936..80129f04 100644 --- a/libnymea-app/connection/tunnelproxytransport.h +++ b/libnymea-app/connection/tunnelproxytransport.h @@ -63,7 +63,6 @@ public: private slots: void onRemoteConnectionStateChanged(remoteproxyclient::TunnelProxyRemoteConnection::State state); - void onRemoteConnectedChanged(bool remoteConnected); void onRemoteConnectionErrorOccurred(QAbstractSocket::SocketError error); private: diff --git a/libnymea-app/jsonrpc/jsonrpcclient.cpp b/libnymea-app/jsonrpc/jsonrpcclient.cpp index 497ebaa1..c7b69095 100644 --- a/libnymea-app/jsonrpc/jsonrpcclient.cpp +++ b/libnymea-app/jsonrpc/jsonrpcclient.cpp @@ -58,10 +58,10 @@ JsonRpcClient::JsonRpcClient(QObject *parent) : m_id(0) { m_connection = new NymeaConnection(this); -// m_connection->registerTransport(new TcpSocketTransportFactory()); -// m_connection->registerTransport(new WebsocketTransportFactory()); -// m_connection->registerTransport(new BluetoothTransportFactoy()); -// m_connection->registerTransport(new CloudTransportFactory()); + m_connection->registerTransport(new TcpSocketTransportFactory()); + m_connection->registerTransport(new WebsocketTransportFactory()); + m_connection->registerTransport(new BluetoothTransportFactoy()); + m_connection->registerTransport(new CloudTransportFactory()); m_connection->registerTransport(new TunnelProxyTransportFactory()); connect(m_connection, &NymeaConnection::availableBearerTypesChanged, this, &JsonRpcClient::availableBearerTypesChanged); diff --git a/nymea-remoteproxy b/nymea-remoteproxy index 99bf6349..7235a132 160000 --- a/nymea-remoteproxy +++ b/nymea-remoteproxy @@ -1 +1 @@ -Subproject commit 99bf634990dcd2231e6a265581a35aeffaf30037 +Subproject commit 7235a132b7fd77a9903d3b34b10dc4bf2a570085