Drop logic to retrieve dynamic turn credentials
This commit is contained in:
parent
6c5f8c482a
commit
b1d1a89261
@ -171,7 +171,6 @@ void AWSConnector::setupSubscriptions()
|
|||||||
subscriptions.append(QString("%1/pair/response").arg(m_clientId));
|
subscriptions.append(QString("%1/pair/response").arg(m_clientId));
|
||||||
subscriptions.append(QString("%1/notify/response").arg(m_clientId));
|
subscriptions.append(QString("%1/notify/response").arg(m_clientId));
|
||||||
subscriptions.append(QString("%1/notify/info/endpoint").arg(m_clientId));
|
subscriptions.append(QString("%1/notify/info/endpoint").arg(m_clientId));
|
||||||
subscriptions.append(QString("%1/services/turn/response").arg(m_clientId));
|
|
||||||
subscribe(subscriptions);
|
subscribe(subscriptions);
|
||||||
|
|
||||||
// fetch previous pairings
|
// fetch previous pairings
|
||||||
@ -226,8 +225,6 @@ void AWSConnector::onPairingsRetrieved(const QVariantMap &pairings)
|
|||||||
}
|
}
|
||||||
|
|
||||||
emit pushNotificationEndpointsUpdated(pushNotificationEndpoints);
|
emit pushNotificationEndpointsUpdated(pushNotificationEndpoints);
|
||||||
|
|
||||||
requestTURNCredentials();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AWSConnector::disconnectAWS()
|
void AWSConnector::disconnectAWS()
|
||||||
@ -278,25 +275,6 @@ int AWSConnector::sendPushNotification(const QString &userId, const QString &end
|
|||||||
return m_transactionId;
|
return m_transactionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AWSConnector::requestTURNCredentials()
|
|
||||||
{
|
|
||||||
if (!isConnected()) {
|
|
||||||
qCWarning(dcAWS()) << "Not connected. Cannot request TURN credentials.";
|
|
||||||
emit turnCredentialsReceived(QVariantMap());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!m_cachedTURNCredentials.first.isEmpty() && QDateTime::currentDateTime().secsTo(m_cachedTURNCredentials.second) > 0) {
|
|
||||||
emit turnCredentialsReceived(m_cachedTURNCredentials.first);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
qCDebug(dcAWS()) << "Requesting TURN credentials";
|
|
||||||
QVariantMap params;
|
|
||||||
params.insert("id", QUuid::createUuid());
|
|
||||||
params.insert("command", "getTurnCredentials");
|
|
||||||
params.insert("timestamp", QDateTime::currentMSecsSinceEpoch());
|
|
||||||
publish(QString("%1/services/turn").arg(m_clientId), params);
|
|
||||||
}
|
|
||||||
|
|
||||||
quint16 AWSConnector::publish(const QString &topic, const QVariantMap &message)
|
quint16 AWSConnector::publish(const QString &topic, const QVariantMap &message)
|
||||||
{
|
{
|
||||||
if (!m_setupInProgress && !isConnected()) {
|
if (!m_setupInProgress && !isConnected()) {
|
||||||
@ -347,19 +325,6 @@ void AWSConnector::onDisconnected()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AWSConnector::onTurnCredentialsReceived(const QVariantMap &turnCredentials)
|
|
||||||
{
|
|
||||||
qCDebug(dcAWS()) << "Dynamic TURN credentials received";
|
|
||||||
|
|
||||||
m_cachedTURNCredentials.first = turnCredentials;
|
|
||||||
m_cachedTURNCredentials.second = QDateTime::currentDateTime().addSecs(turnCredentials.value("ttl").toInt());
|
|
||||||
emit turnCredentialsReceived(turnCredentials);
|
|
||||||
|
|
||||||
// refresh the cache
|
|
||||||
QTimer::singleShot((turnCredentials.value("ttl").toInt() - 10) * 1000, this, &AWSConnector::requestTURNCredentials);
|
|
||||||
qCDebug(dcAWS()) << "Refreshing TURN credentials in" << (turnCredentials.value("ttl").toInt() - 10) << "seconds.";
|
|
||||||
}
|
|
||||||
|
|
||||||
void AWSConnector::setName()
|
void AWSConnector::setName()
|
||||||
{
|
{
|
||||||
QVariantMap params;
|
QVariantMap params;
|
||||||
@ -423,7 +388,8 @@ void AWSConnector::onPublishReceived(const QString &topic, const QByteArray &pay
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
qCDebug(dcAWSTraffic()) << "Subscription received: Topic:" << topic << "payload:" << payload;
|
qCDebug(dcAWSTraffic()) << "Subscription received on topic" << topic;
|
||||||
|
qCDebug(dcAWSTraffic()) << qUtf8Printable(jsonDoc.toJson(QJsonDocument::Indented));
|
||||||
|
|
||||||
if (topic.startsWith("create/device/")) {
|
if (topic.startsWith("create/device/")) {
|
||||||
int statusCode = jsonDoc.toVariant().toMap().value("result").toMap().value("code").toInt();
|
int statusCode = jsonDoc.toVariant().toMap().value("result").toMap().value("code").toInt();
|
||||||
@ -495,13 +461,6 @@ void AWSConnector::onPublishReceived(const QString &topic, const QByteArray &pay
|
|||||||
ep.endpointId = endpoint.value(cognitoId).toMap().value("endpointId").toString();
|
ep.endpointId = endpoint.value(cognitoId).toMap().value("endpointId").toString();
|
||||||
ep.displayName = endpoint.value(cognitoId).toMap().value("displayName").toString();
|
ep.displayName = endpoint.value(cognitoId).toMap().value("displayName").toString();
|
||||||
emit pushNotificationEndpointAdded(ep);
|
emit pushNotificationEndpointAdded(ep);
|
||||||
} else if (topic == QString("%1/services/turn/response").arg(m_clientId)) {
|
|
||||||
QVariantMap turnCreds = jsonDoc.toVariant().toMap();
|
|
||||||
if (turnCreds.value("result").toMap().value("code").toInt() != 201) {
|
|
||||||
qCWarning(dcAWS()) << "Error retrieving TURN credentials:" << turnCreds.value("result").toMap().value("code").toInt() << turnCreds.value("result").toMap().value("message").toString();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
onTurnCredentialsReceived(turnCreds.value("turnCredentials").toMap());
|
|
||||||
} else {
|
} else {
|
||||||
qCWarning(dcAWS()) << "Unhandled subscription received!" << topic << payload;
|
qCWarning(dcAWS()) << "Unhandled subscription received!" << topic << payload;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,7 +51,6 @@ public:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
int sendPushNotification(const QString &userId, const QString &endpointId, const QString &title, const QString &text);
|
int sendPushNotification(const QString &userId, const QString &endpointId, const QString &title, const QString &text);
|
||||||
void requestTURNCredentials();
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void connected();
|
void connected();
|
||||||
@ -60,7 +59,6 @@ signals:
|
|||||||
void pushNotificationEndpointsUpdated(const QList<AWSConnector::PushNotificationsEndpoint> pushNotificationEndpoints);
|
void pushNotificationEndpointsUpdated(const QList<AWSConnector::PushNotificationsEndpoint> pushNotificationEndpoints);
|
||||||
void pushNotificationEndpointAdded(const AWSConnector::PushNotificationsEndpoint &pushNotificationEndpoint);
|
void pushNotificationEndpointAdded(const AWSConnector::PushNotificationsEndpoint &pushNotificationEndpoint);
|
||||||
void pushNotificationSent(int id, int status);
|
void pushNotificationSent(int id, int status);
|
||||||
void turnCredentialsReceived(const QVariantMap &turnCredentials);
|
|
||||||
|
|
||||||
void proxyConnectionRequestReceived(const QString &token, const QString &nonce, const QString &serverUrl);
|
void proxyConnectionRequestReceived(const QString &token, const QString &nonce, const QString &serverUrl);
|
||||||
|
|
||||||
@ -78,7 +76,6 @@ private slots:
|
|||||||
void fetchPairings();
|
void fetchPairings();
|
||||||
void onPairingsRetrieved(const QVariantMap &pairings);
|
void onPairingsRetrieved(const QVariantMap &pairings);
|
||||||
void setName();
|
void setName();
|
||||||
void onTurnCredentialsReceived(const QVariantMap &turnCredentials);
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user