update to latest remoteproxy lib

This commit is contained in:
Michael Zanetti 2018-09-01 01:21:56 +02:00
parent 234aaec54c
commit 1b2b7cf42f
5 changed files with 12 additions and 9 deletions

View File

@ -690,7 +690,7 @@ void AWSClient::getCredentialsForIdentity(const QString &identityId)
if (qc.method == "fetchDevices") {
fetchDevices();
} else if (qc.method == "postToMQTT") {
postToMQTT(qc.boxId, qc.callback);
postToMQTT(qc.boxId, qc.timestamp, qc.callback);
}
}
});
@ -701,7 +701,7 @@ bool AWSClient::tokensExpired() const
return (m_accessTokenExpiry.addSecs(-10) < QDateTime::currentDateTime()) || (m_sessionTokenExpiry.addSecs(-10) < QDateTime::currentDateTime());
}
bool AWSClient::postToMQTT(const QString &boxId, std::function<void(bool)> callback)
bool AWSClient::postToMQTT(const QString &boxId, const QString &timestamp, std::function<void(bool)> callback)
{
if (!isLoggedIn()) {
qWarning() << "Cannot post to MQTT. Not logged in to AWS";
@ -710,7 +710,7 @@ bool AWSClient::postToMQTT(const QString &boxId, std::function<void(bool)> callb
if (tokensExpired()) {
qDebug() << "Cannot post to MQTT. Need to refresh the tokens first";
refreshAccessToken();
m_callQueue.append(QueuedCall("postToMQTT", boxId, callback));
m_callQueue.append(QueuedCall("postToMQTT", boxId, timestamp, callback));
return true; // So far it looks we're doing ok... let's return true
}
QString topic = QString("%1/%2/proxy").arg(boxId).arg(QString(m_identityId));
@ -726,7 +726,7 @@ bool AWSClient::postToMQTT(const QString &boxId, std::function<void(bool)> callb
QVariantMap params;
params.insert("token", m_idToken);
params.insert("timestamp", QDateTime::currentDateTime().toSecsSinceEpoch());
params.insert("timestamp", timestamp);
QByteArray payload = QJsonDocument::fromVariant(params).toJson(QJsonDocument::Compact);

View File

@ -109,7 +109,7 @@ public:
Q_INVOKABLE void fetchDevices();
Q_INVOKABLE bool postToMQTT(const QString &boxId, std::function<void(bool)> callback);
Q_INVOKABLE bool postToMQTT(const QString &boxId, const QString &timestamp, std::function<void(bool)> callback);
Q_INVOKABLE void getId();
bool tokensExpired() const;
@ -165,9 +165,10 @@ private:
public:
QueuedCall(const QString &method): method(method) { }
QueuedCall(const QString &method, const QString &boxId): method(method), boxId(boxId) { }
QueuedCall(const QString &method, const QString &boxId, std::function<void(bool)> callback): method(method), boxId(boxId), callback(callback) {}
QueuedCall(const QString &method, const QString &boxId, const QString &timestamp, std::function<void(bool)> callback): method(method), boxId(boxId), timestamp(timestamp), callback(callback) {}
QString method;
QString boxId;
QString timestamp;
std::function<void(bool)> callback;
};

View File

@ -29,7 +29,7 @@ CloudTransport::CloudTransport(AWSClient *awsClient, QObject *parent):
QObject::connect(m_remoteproxyConnection, &RemoteProxyConnection::ready, this,[this]() {
qDebug() << "Proxy ready. Authenticating channel.";
m_remoteproxyConnection->authenticate(m_awsClient->idToken());
m_remoteproxyConnection->authenticate(m_awsClient->idToken(), QString::number(m_timestamp.toMSecsSinceEpoch()));
});
QObject::connect(m_remoteproxyConnection, &RemoteProxyConnection::dataReady, this, [this](const QByteArray &data) {
emit dataReady(data);
@ -55,7 +55,8 @@ bool CloudTransport::connect(const QUrl &url)
qDebug() << "Connecting to" << url;
bool postResult = m_awsClient->postToMQTT(url.host(), [this](bool success) {
m_timestamp = QDateTime::currentDateTime();
bool postResult = m_awsClient->postToMQTT(url.host(), QString::number(m_timestamp.toMSecsSinceEpoch()), [this](bool success) {
if (success) {
m_remoteproxyConnection->connectServer(QUrl("wss://remoteproxy.nymea.io"));

View File

@ -27,6 +27,7 @@ public:
private:
AWSClient *m_awsClient = nullptr;
remoteproxyclient::RemoteProxyConnection *m_remoteproxyConnection = nullptr;
QDateTime m_timestamp;
};
#endif // CLOUDTRANSPORT_H

@ -1 +1 @@
Subproject commit 3b97bc60bbaf1ae5d4ced7eb1586d2d20fe5b0ab
Subproject commit eacffb695f8870c75b027a701277f6ec4455d327