mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-26 13:08:48 +03:00
Improve TURN server retrieval
This commit is contained in:
parent
c0743f9688
commit
f14d141cb5
3 changed files with 17 additions and 3 deletions
|
@ -1,4 +1,6 @@
|
||||||
|
#include <algorithm>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
#include <cstdint>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
#include <QMediaPlaylist>
|
#include <QMediaPlaylist>
|
||||||
|
@ -74,21 +76,23 @@ CallManager::CallManager(QSharedPointer<UserSettings> userSettings)
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(&turnServerTimer_, &QTimer::timeout, this, &CallManager::retrieveTurnServer);
|
connect(&turnServerTimer_, &QTimer::timeout, this, &CallManager::retrieveTurnServer);
|
||||||
turnServerTimer_.start(2000);
|
|
||||||
|
|
||||||
connect(this, &CallManager::turnServerRetrieved, this,
|
connect(this, &CallManager::turnServerRetrieved, this,
|
||||||
[this](const mtx::responses::TurnServer &res)
|
[this](const mtx::responses::TurnServer &res)
|
||||||
{
|
{
|
||||||
nhlog::net()->info("TURN server(s) retrieved from homeserver:");
|
nhlog::net()->info("TURN server(s) retrieved from homeserver:");
|
||||||
nhlog::net()->info("username: {}", res.username);
|
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)
|
for (const auto &u : res.uris)
|
||||||
nhlog::net()->info("uri: {}", u);
|
nhlog::net()->info("uri: {}", u);
|
||||||
|
|
||||||
// Request new credentials close to expiry
|
// Request new credentials close to expiry
|
||||||
// See https://tools.ietf.org/html/draft-uberti-behave-turn-rest-00
|
// See https://tools.ietf.org/html/draft-uberti-behave-turn-rest-00
|
||||||
turnURIs_ = getTurnURIs(res);
|
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,
|
connect(&session_, &WebRTCSession::stateChanged, this,
|
||||||
|
@ -349,6 +353,13 @@ CallManager::endCall()
|
||||||
remoteICECandidates_.clear();
|
remoteICECandidates_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CallManager::refreshTurnServer()
|
||||||
|
{
|
||||||
|
turnURIs_.clear();
|
||||||
|
turnServerTimer_.start(2000);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
CallManager::retrieveTurnServer()
|
CallManager::retrieveTurnServer()
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,6 +29,7 @@ public:
|
||||||
void sendInvite(const QString &roomid);
|
void sendInvite(const QString &roomid);
|
||||||
void hangUp(mtx::events::msg::CallHangUp::Reason = mtx::events::msg::CallHangUp::Reason::User);
|
void hangUp(mtx::events::msg::CallHangUp::Reason = mtx::events::msg::CallHangUp::Reason::User);
|
||||||
bool onActiveCall();
|
bool onActiveCall();
|
||||||
|
void refreshTurnServer();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void syncEvent(const mtx::events::collections::TimelineEvents &event);
|
void syncEvent(const mtx::events::collections::TimelineEvents &event);
|
||||||
|
|
|
@ -723,6 +723,8 @@ ChatPage::bootstrap(QString userid, QString homeserver, QString token)
|
||||||
const bool isInitialized = cache::isInitialized();
|
const bool isInitialized = cache::isInitialized();
|
||||||
const auto cacheVersion = cache::formatVersion();
|
const auto cacheVersion = cache::formatVersion();
|
||||||
|
|
||||||
|
callManager_.refreshTurnServer();
|
||||||
|
|
||||||
if (!isInitialized) {
|
if (!isInitialized) {
|
||||||
cache::setCurrentFormat();
|
cache::setCurrentFormat();
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue