Ref T730, allow to update voice server URL

This commit is contained in:
Klaus Basan
2019-10-08 03:00:02 +02:00
committed by Mat Sutcliffe
parent c842820267
commit e485824bfc
6 changed files with 38 additions and 8 deletions

View File

@@ -650,6 +650,12 @@ namespace BlackCore
return {}; return {};
} }
bool CAfvClient::updateVoiceServerUrl(const QString &url)
{
if (m_connection) { return false; }
return m_connection->updateVoiceServerUrl(url);
}
void CAfvClient::initialize() void CAfvClient::initialize()
{ {
CLogMessage(this).info(u"Initialize AFV client in thread: %1") << CThreadUtils::threadInfo(this->thread()); CLogMessage(this).info(u"Initialize AFV client in thread: %1") << CThreadUtils::threadInfo(this->thread());

View File

@@ -199,6 +199,9 @@ namespace BlackCore
QString getReceivingCallsignsCom2(); QString getReceivingCallsignsCom2();
//! @} //! @}
//! Update the voice server URL
bool updateVoiceServerUrl(const QString &url);
signals: signals:
//! Receiving callsigns have been changed //! Receiving callsigns have been changed
//! \remark callsigns I do receive //! \remark callsigns I do receive

View File

@@ -11,6 +11,7 @@
#include "blackmisc/network/networkutils.h" #include "blackmisc/network/networkutils.h"
#include "blackmisc/network/external/qjsonwebtoken.h" #include "blackmisc/network/external/qjsonwebtoken.h"
#include "blackmisc/logmessage.h" #include "blackmisc/logmessage.h"
#include "blackmisc/stringutils.h"
#include <QJsonObject> #include <QJsonObject>
#include <QJsonArray> #include <QJsonArray>
@@ -37,7 +38,7 @@ namespace BlackCore
CApiServerConnection::CApiServerConnection(const QString &address, QObject *parent) : CApiServerConnection::CApiServerConnection(const QString &address, QObject *parent) :
QObject(parent), QObject(parent),
m_address(address) m_addressUrl(address)
{ {
CLogMessage(this).debug(u"ApiServerConnection instantiated"); CLogMessage(this).debug(u"ApiServerConnection instantiated");
} }
@@ -51,7 +52,7 @@ namespace BlackCore
m_networkVersion = networkVersion; m_networkVersion = networkVersion;
m_isAuthenticated = false; m_isAuthenticated = false;
QUrl url(m_address); QUrl url(m_addressUrl);
url.setPath("/api/v1/auth"); url.setPath("/api/v1/auth");
QJsonObject obj QJsonObject obj
@@ -157,6 +158,13 @@ namespace BlackCore
return {}; return {};
} }
bool CApiServerConnection::setUrl(const QString &url)
{
if (stringCompare(m_addressUrl, url, Qt::CaseInsensitive)) { return false; }
m_addressUrl = url;
return true;
}
QByteArray CApiServerConnection::getWithResponse(const QNetworkRequest &request) QByteArray CApiServerConnection::getWithResponse(const QNetworkRequest &request)
{ {
if (isShuttingDown()) { return {}; } if (isShuttingDown()) { return {}; }
@@ -240,7 +248,7 @@ namespace BlackCore
this->checkExpiry(); this->checkExpiry();
QUrl url(m_address); QUrl url(m_addressUrl);
url.setPath(resource); url.setPath(resource);
QNetworkRequest request(url); QNetworkRequest request(url);
request.setRawHeader("Authorization", "Bearer " + m_jwt); request.setRawHeader("Authorization", "Bearer " + m_jwt);
@@ -268,7 +276,7 @@ namespace BlackCore
if (isShuttingDown()) { return; } if (isShuttingDown()) { return; }
if (!m_isAuthenticated) { return; } if (!m_isAuthenticated) { return; }
QUrl url(m_address); QUrl url(m_addressUrl);
url.setPath(resource); url.setPath(resource);
QNetworkRequest request(url); QNetworkRequest request(url);

View File

@@ -13,6 +13,7 @@
#include "blackcore/afv/dto.h" #include "blackcore/afv/dto.h"
#include "blackcore/application.h" #include "blackcore/application.h"
#include "blackmisc/logmessage.h"
#include "blackmisc/logcategorylist.h" #include "blackmisc/logcategorylist.h"
#include <QString> #include <QString>
@@ -71,6 +72,9 @@ namespace BlackCore
//! All aliased stations //! All aliased stations
QVector<StationDto> getAllAliasedStations(); QVector<StationDto> getAllAliasedStations();
//! Set the URL
bool setUrl(const QString &url);
private: private:
//! Post to resource //! Post to resource
template<typename TResponse> template<typename TResponse>
@@ -84,7 +88,7 @@ namespace BlackCore
this->checkExpiry(); this->checkExpiry();
QUrl url(m_address); QUrl url(m_addressUrl);
url.setPath(resource); url.setPath(resource);
QNetworkRequest request(url); QNetworkRequest request(url);
request.setRawHeader("Authorization", "Bearer " + m_jwt); request.setRawHeader("Authorization", "Bearer " + m_jwt);
@@ -107,7 +111,7 @@ namespace BlackCore
this->checkExpiry(); this->checkExpiry();
QUrl url(m_address); QUrl url(m_addressUrl);
url.setPath(resource); url.setPath(resource);
QNetworkRequest request(url); QNetworkRequest request(url);
request.setRawHeader("Authorization", "Bearer " + m_jwt); request.setRawHeader("Authorization", "Bearer " + m_jwt);
@@ -155,7 +159,7 @@ namespace BlackCore
//! Application shutting down //! Application shutting down
static bool isShuttingDown(); static bool isShuttingDown();
const QString m_address; QString m_addressUrl;
QByteArray m_jwt; QByteArray m_jwt;
QString m_username; QString m_username;
QString m_password; QString m_password;

View File

@@ -96,6 +96,12 @@ namespace BlackCore
return m_apiServerConnection->getAllAliasedStations(); return m_apiServerConnection->getAllAliasedStations();
} }
bool CClientConnection::updateVoiceServerUrl(const QString &url)
{
if (!m_apiServerConnection) { return false; }
return m_apiServerConnection->setUrl(url);
}
void CClientConnection::connectToVoiceServer() void CClientConnection::connectToVoiceServer()
{ {
QHostAddress localAddress(QHostAddress::AnyIPv4); QHostAddress localAddress(QHostAddress::AnyIPv4);

View File

@@ -60,7 +60,7 @@ namespace BlackCore
} }
//! @} //! @}
//! Send voiceDTO to server //! Send voice DTO to server
template<typename T> template<typename T>
void sendToVoiceServer(const T &dto) void sendToVoiceServer(const T &dto)
{ {
@@ -75,6 +75,9 @@ namespace BlackCore
//! All aliased stations //! All aliased stations
QVector<StationDto> getAllAliasedStations(); QVector<StationDto> getAllAliasedStations();
//! Update the voice server URL
bool updateVoiceServerUrl(const QString &url);
signals: signals:
//! Audio has been received //! Audio has been received
void audioReceived(const AudioRxOnTransceiversDto &dto); void audioReceived(const AudioRxOnTransceiversDto &dto);