update to latest remoteproxy lib
This commit is contained in:
parent
234aaec54c
commit
1b2b7cf42f
@ -690,7 +690,7 @@ void AWSClient::getCredentialsForIdentity(const QString &identityId)
|
|||||||
if (qc.method == "fetchDevices") {
|
if (qc.method == "fetchDevices") {
|
||||||
fetchDevices();
|
fetchDevices();
|
||||||
} else if (qc.method == "postToMQTT") {
|
} 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());
|
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 ×tamp, std::function<void(bool)> callback)
|
||||||
{
|
{
|
||||||
if (!isLoggedIn()) {
|
if (!isLoggedIn()) {
|
||||||
qWarning() << "Cannot post to MQTT. Not logged in to AWS";
|
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()) {
|
if (tokensExpired()) {
|
||||||
qDebug() << "Cannot post to MQTT. Need to refresh the tokens first";
|
qDebug() << "Cannot post to MQTT. Need to refresh the tokens first";
|
||||||
refreshAccessToken();
|
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
|
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));
|
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;
|
QVariantMap params;
|
||||||
params.insert("token", m_idToken);
|
params.insert("token", m_idToken);
|
||||||
params.insert("timestamp", QDateTime::currentDateTime().toSecsSinceEpoch());
|
params.insert("timestamp", timestamp);
|
||||||
QByteArray payload = QJsonDocument::fromVariant(params).toJson(QJsonDocument::Compact);
|
QByteArray payload = QJsonDocument::fromVariant(params).toJson(QJsonDocument::Compact);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -109,7 +109,7 @@ public:
|
|||||||
|
|
||||||
Q_INVOKABLE void fetchDevices();
|
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 ×tamp, std::function<void(bool)> callback);
|
||||||
Q_INVOKABLE void getId();
|
Q_INVOKABLE void getId();
|
||||||
|
|
||||||
bool tokensExpired() const;
|
bool tokensExpired() const;
|
||||||
@ -165,9 +165,10 @@ private:
|
|||||||
public:
|
public:
|
||||||
QueuedCall(const QString &method): method(method) { }
|
QueuedCall(const QString &method): method(method) { }
|
||||||
QueuedCall(const QString &method, const QString &boxId): method(method), boxId(boxId) { }
|
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 ×tamp, std::function<void(bool)> callback): method(method), boxId(boxId), timestamp(timestamp), callback(callback) {}
|
||||||
QString method;
|
QString method;
|
||||||
QString boxId;
|
QString boxId;
|
||||||
|
QString timestamp;
|
||||||
std::function<void(bool)> callback;
|
std::function<void(bool)> callback;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -29,7 +29,7 @@ CloudTransport::CloudTransport(AWSClient *awsClient, QObject *parent):
|
|||||||
|
|
||||||
QObject::connect(m_remoteproxyConnection, &RemoteProxyConnection::ready, this,[this]() {
|
QObject::connect(m_remoteproxyConnection, &RemoteProxyConnection::ready, this,[this]() {
|
||||||
qDebug() << "Proxy ready. Authenticating channel.";
|
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) {
|
QObject::connect(m_remoteproxyConnection, &RemoteProxyConnection::dataReady, this, [this](const QByteArray &data) {
|
||||||
emit dataReady(data);
|
emit dataReady(data);
|
||||||
@ -55,7 +55,8 @@ bool CloudTransport::connect(const QUrl &url)
|
|||||||
|
|
||||||
qDebug() << "Connecting to" << 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) {
|
if (success) {
|
||||||
|
|
||||||
m_remoteproxyConnection->connectServer(QUrl("wss://remoteproxy.nymea.io"));
|
m_remoteproxyConnection->connectServer(QUrl("wss://remoteproxy.nymea.io"));
|
||||||
|
|||||||
@ -27,6 +27,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
AWSClient *m_awsClient = nullptr;
|
AWSClient *m_awsClient = nullptr;
|
||||||
remoteproxyclient::RemoteProxyConnection *m_remoteproxyConnection = nullptr;
|
remoteproxyclient::RemoteProxyConnection *m_remoteproxyConnection = nullptr;
|
||||||
|
QDateTime m_timestamp;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CLOUDTRANSPORT_H
|
#endif // CLOUDTRANSPORT_H
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
Subproject commit 3b97bc60bbaf1ae5d4ced7eb1586d2d20fe5b0ab
|
Subproject commit eacffb695f8870c75b027a701277f6ec4455d327
|
||||||
Reference in New Issue
Block a user