From f14d141cb529c42a9e39f1966b7424c84f0cc92d Mon Sep 17 00:00:00 2001 From: trilene Date: Thu, 30 Jul 2020 19:59:54 -0400 Subject: Improve TURN server retrieval --- src/CallManager.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/CallManager.cpp') diff --git a/src/CallManager.cpp b/src/CallManager.cpp index 3ddcc227..cbfd5135 100644 --- a/src/CallManager.cpp +++ b/src/CallManager.cpp @@ -1,4 +1,6 @@ +#include #include +#include #include #include @@ -74,21 +76,23 @@ CallManager::CallManager(QSharedPointer userSettings) }); connect(&turnServerTimer_, &QTimer::timeout, this, &CallManager::retrieveTurnServer); - turnServerTimer_.start(2000); connect(this, &CallManager::turnServerRetrieved, this, [this](const mtx::responses::TurnServer &res) { nhlog::net()->info("TURN server(s) retrieved from homeserver:"); nhlog::net()->info("username: {}", res.username); - nhlog::net()->info("ttl: {}", res.ttl); + nhlog::net()->info("ttl: {} seconds", res.ttl); for (const auto &u : res.uris) nhlog::net()->info("uri: {}", u); // Request new credentials close to expiry // See https://tools.ietf.org/html/draft-uberti-behave-turn-rest-00 turnURIs_ = getTurnURIs(res); - turnServerTimer_.setInterval(res.ttl * 1000 * 0.9); + uint32_t ttl = std::max(res.ttl, UINT32_C(3600)); + if (res.ttl < 3600) + nhlog::net()->warn("Setting ttl to 1 hour"); + turnServerTimer_.setInterval(ttl * 1000 * 0.9); }); connect(&session_, &WebRTCSession::stateChanged, this, @@ -349,6 +353,13 @@ CallManager::endCall() remoteICECandidates_.clear(); } +void +CallManager::refreshTurnServer() +{ + turnURIs_.clear(); + turnServerTimer_.start(2000); +} + void CallManager::retrieveTurnServer() { -- cgit 1.4.1