mirror of https://github.com/nymea/nymea.git
it's somewhat working
parent
c5f4c9dc51
commit
4e3ab48e58
|
|
@ -514,7 +514,8 @@ ResponseCode AWSConnector::onSubscriptionReceivedCallback(util::String topic_nam
|
|||
// silently drop our own things (should not be subscribed to that in the first place)
|
||||
} else if (topic.startsWith(QString("%1/eu-west-1:").arg(connector->m_clientId)) && topic.contains("proxy")) {
|
||||
qCDebug(dcAWS) << "Proxy remote connection request received";
|
||||
connector->staticMetaObject.invokeMethod(connector, "proxyConnectionRequestReceived", Qt::QueuedConnection);
|
||||
QString token = jsonDoc.toVariant().toMap().value("token").toString();
|
||||
connector->staticMetaObject.invokeMethod(connector, "proxyConnectionRequestReceived", Qt::QueuedConnection, Q_ARG(QString, token));
|
||||
} else if (topic == QString("%1/notify/response").arg(connector->m_clientId)) {
|
||||
int transactionId = jsonDoc.toVariant().toMap().value("id").toInt();
|
||||
int status = jsonDoc.toVariant().toMap().value("status").toInt();
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ signals:
|
|||
void pushNotificationSent(int id, int status);
|
||||
void turnCredentialsReceived(const QVariantMap &turnCredentials);
|
||||
|
||||
void proxyConnectionRequestReceived();
|
||||
void proxyConnectionRequestReceived(const QString &token);
|
||||
|
||||
private slots:
|
||||
void doConnect();
|
||||
|
|
|
|||
|
|
@ -1,22 +1,25 @@
|
|||
#include "cloudtransport.h"
|
||||
#include "loggingcategories.h"
|
||||
|
||||
#include "libnymea-remoteproxyclient/remoteproxyconnection.h"
|
||||
|
||||
using namespace remoteproxyclient;
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
CloudTransport::CloudTransport(const ServerConfiguration &config, QObject *parent):
|
||||
TransportInterface(config, parent),
|
||||
m_remoteProxy(new RemoteProxyConnection(QUuid::createUuid(), "nymea:core", RemoteProxyConnection::ConnectionTypeWebSocket, this))
|
||||
TransportInterface(config, parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CloudTransport::sendData(const QUuid &clientId, const QByteArray &data)
|
||||
{
|
||||
qCDebug(dcCloud) << "Should send data" << clientId << data;
|
||||
foreach (const ConnectionContext &ctx, m_connections) {
|
||||
if (ctx.clientId == clientId) {
|
||||
ctx.proxyConnection->sendData(data);
|
||||
return;
|
||||
}
|
||||
}
|
||||
qCWarning(dcCloud()) << "Error sending data. No such clientId";
|
||||
}
|
||||
|
||||
void CloudTransport::sendData(const QList<QUuid> &clientIds, const QByteArray &data)
|
||||
|
|
@ -38,10 +41,51 @@ bool CloudTransport::stopServer()
|
|||
return true;
|
||||
}
|
||||
|
||||
void CloudTransport::connectToCloud()
|
||||
void CloudTransport::connectToCloud(const QString &token)
|
||||
{
|
||||
qCDebug(dcCloud) << "Should connect to cloud";
|
||||
m_remoteProxy->connectServer(QHostAddress("127.0.0.1"), 1212);
|
||||
ConnectionContext context;
|
||||
context.clientId = QUuid::createUuid();
|
||||
context.token = token;
|
||||
context.proxyConnection = new RemoteProxyConnection(QUuid::createUuid(), "nymea:core", RemoteProxyConnection::ConnectionTypeWebSocket, this);
|
||||
m_connections.insert(context.proxyConnection, context);
|
||||
|
||||
context.proxyConnection->setInsecureConnection(true);
|
||||
connect(context.proxyConnection, &RemoteProxyConnection::ready, this, &CloudTransport::transportReady);
|
||||
connect(context.proxyConnection, &RemoteProxyConnection::stateChanged, this, &CloudTransport::remoteConnectionStateChanged);
|
||||
connect(context.proxyConnection, &RemoteProxyConnection::dataReady, this, &CloudTransport::transportDataReady);
|
||||
|
||||
context.proxyConnection->connectServer(QHostAddress("127.0.0.1"), 1212);
|
||||
}
|
||||
|
||||
void CloudTransport::remoteConnectionStateChanged(RemoteProxyConnection::State state)
|
||||
{
|
||||
qCDebug(dcCloud) << "Remote connection state changed" << state;
|
||||
RemoteProxyConnection *proxyConnection = qobject_cast<RemoteProxyConnection*>(sender());
|
||||
ConnectionContext context = m_connections.value(proxyConnection);
|
||||
|
||||
if (state == RemoteProxyConnection::StateRemoteConnected) {
|
||||
emit clientConnected(context.clientId);
|
||||
} else if (state ==RemoteProxyConnection::StateDisconnected) {
|
||||
emit clientDisconnected(context.clientId);
|
||||
}
|
||||
}
|
||||
|
||||
void CloudTransport::transportReady()
|
||||
{
|
||||
qCDebug(dcCloud) << "Transport ready";
|
||||
RemoteProxyConnection *proxyConnection = qobject_cast<RemoteProxyConnection*>(sender());
|
||||
ConnectionContext context = m_connections.value(proxyConnection);
|
||||
|
||||
context.proxyConnection->authenticate(context.token);
|
||||
}
|
||||
|
||||
void CloudTransport::transportDataReady(const QByteArray &data)
|
||||
{
|
||||
RemoteProxyConnection *proxyConnection = qobject_cast<RemoteProxyConnection*>(sender());
|
||||
ConnectionContext context = m_connections.value(proxyConnection);
|
||||
|
||||
emit dataAvailable(context.clientId, data);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,10 +3,8 @@
|
|||
|
||||
#include <QObject>
|
||||
#include "../transportinterface.h"
|
||||
#include "libnymea-remoteproxyclient/remoteproxyconnection.h"
|
||||
|
||||
namespace remoteproxyclient {
|
||||
class RemoteProxyConnection;
|
||||
}
|
||||
namespace nymeaserver {
|
||||
|
||||
class CloudTransport : public TransportInterface
|
||||
|
|
@ -23,10 +21,22 @@ public:
|
|||
signals:
|
||||
|
||||
public slots:
|
||||
void connectToCloud();
|
||||
void connectToCloud(const QString &token);
|
||||
void remoteConnectionStateChanged(remoteproxyclient::RemoteProxyConnection::State state);
|
||||
|
||||
private slots:
|
||||
void transportReady();
|
||||
void transportDataReady(const QByteArray &data);
|
||||
|
||||
private:
|
||||
remoteproxyclient::RemoteProxyConnection *m_remoteProxy = nullptr;
|
||||
class ConnectionContext {
|
||||
public:
|
||||
QUuid clientId;
|
||||
QString token;
|
||||
remoteproxyclient::RemoteProxyConnection* proxyConnection;
|
||||
};
|
||||
QHash<remoteproxyclient::RemoteProxyConnection*, ConnectionContext> m_connections;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue