mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 14:08:51 +02:00
add a method to AddressManager to handle address maps from JS
This commit is contained in:
parent
cb7a6cb93c
commit
b90db2856b
2 changed files with 29 additions and 17 deletions
|
@ -139,14 +139,20 @@ void AddressManager::handleAPIResponse(QNetworkReply& requestReply) {
|
||||||
QJsonObject responseObject = QJsonDocument::fromJson(requestReply.readAll()).object();
|
QJsonObject responseObject = QJsonDocument::fromJson(requestReply.readAll()).object();
|
||||||
QJsonObject dataObject = responseObject["data"].toObject();
|
QJsonObject dataObject = responseObject["data"].toObject();
|
||||||
|
|
||||||
|
goToAddress(dataObject.toVariantMap());
|
||||||
|
|
||||||
|
emit lookupResultsFinished();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddressManager::goToAddress(const QVariantMap& addressMap) {
|
||||||
const QString ADDRESS_API_DOMAIN_KEY = "domain";
|
const QString ADDRESS_API_DOMAIN_KEY = "domain";
|
||||||
const QString ADDRESS_API_ONLINE_KEY = "online";
|
const QString ADDRESS_API_ONLINE_KEY = "online";
|
||||||
|
|
||||||
if (!dataObject.contains(ADDRESS_API_ONLINE_KEY)
|
if (!addressMap.contains(ADDRESS_API_ONLINE_KEY)
|
||||||
|| dataObject[ADDRESS_API_ONLINE_KEY].toBool()) {
|
|| addressMap[ADDRESS_API_ONLINE_KEY].toBool()) {
|
||||||
|
|
||||||
if (dataObject.contains(ADDRESS_API_DOMAIN_KEY)) {
|
if (addressMap.contains(ADDRESS_API_DOMAIN_KEY)) {
|
||||||
QJsonObject domainObject = dataObject[ADDRESS_API_DOMAIN_KEY].toObject();
|
QVariantMap domainObject = addressMap[ADDRESS_API_DOMAIN_KEY].toMap();
|
||||||
|
|
||||||
const QString DOMAIN_NETWORK_ADDRESS_KEY = "network_address";
|
const QString DOMAIN_NETWORK_ADDRESS_KEY = "network_address";
|
||||||
const QString DOMAIN_ICE_SERVER_ADDRESS_KEY = "ice_server_address";
|
const QString DOMAIN_ICE_SERVER_ADDRESS_KEY = "ice_server_address";
|
||||||
|
@ -178,10 +184,10 @@ void AddressManager::handleAPIResponse(QNetworkReply& requestReply) {
|
||||||
if (domainObject.contains(LOCATION_PATH_KEY)) {
|
if (domainObject.contains(LOCATION_PATH_KEY)) {
|
||||||
returnedPath = domainObject[LOCATION_PATH_KEY].toString();
|
returnedPath = domainObject[LOCATION_PATH_KEY].toString();
|
||||||
} else if (domainObject.contains(LOCATION_KEY)) {
|
} else if (domainObject.contains(LOCATION_KEY)) {
|
||||||
returnedPath = domainObject[LOCATION_KEY].toObject()[LOCATION_PATH_KEY].toString();
|
returnedPath = domainObject[LOCATION_KEY].toMap()[LOCATION_PATH_KEY].toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool shouldFaceViewpoint = dataObject.contains(ADDRESS_API_ONLINE_KEY);
|
bool shouldFaceViewpoint = addressMap.contains(ADDRESS_API_ONLINE_KEY);
|
||||||
|
|
||||||
if (!returnedPath.isEmpty()) {
|
if (!returnedPath.isEmpty()) {
|
||||||
// try to parse this returned path as a viewpoint, that's the only thing it could be for now
|
// try to parse this returned path as a viewpoint, that's the only thing it could be for now
|
||||||
|
@ -192,13 +198,12 @@ void AddressManager::handleAPIResponse(QNetworkReply& requestReply) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "Received an address manager API response with no domain key. Cannot parse.";
|
qDebug() << "Received an address manager API response with no domain key. Cannot parse.";
|
||||||
qDebug() << responseObject;
|
qDebug() << addressMap;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// we've been told that this result exists but is offline, emit our signal so the application can handle
|
// we've been told that this result exists but is offline, emit our signal so the application can handle
|
||||||
emit lookupResultIsOffline();
|
emit lookupResultIsOffline();
|
||||||
}
|
}
|
||||||
emit lookupResultsFinished();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddressManager::handleAPIError(QNetworkReply& errorReply) {
|
void AddressManager::handleAPIError(QNetworkReply& errorReply) {
|
||||||
|
@ -232,10 +237,8 @@ bool AddressManager::handleNetworkAddress(const QString& lookupString) {
|
||||||
if (hostnameRegex.indexIn(lookupString) != -1) {
|
if (hostnameRegex.indexIn(lookupString) != -1) {
|
||||||
QString domainHostname = hostnameRegex.cap(0);
|
QString domainHostname = hostnameRegex.cap(0);
|
||||||
|
|
||||||
emit possibleDomainChangeRequiredToHostname(domainHostname);
|
|
||||||
emit lookupResultsFinished();
|
emit lookupResultsFinished();
|
||||||
|
setDomainHostnameAndName(domainHostname);
|
||||||
_currentDomain = domainHostname;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -245,10 +248,9 @@ bool AddressManager::handleNetworkAddress(const QString& lookupString) {
|
||||||
if (ipAddressRegex.indexIn(lookupString) != -1) {
|
if (ipAddressRegex.indexIn(lookupString) != -1) {
|
||||||
QString domainIPString = ipAddressRegex.cap(0);
|
QString domainIPString = ipAddressRegex.cap(0);
|
||||||
|
|
||||||
emit possibleDomainChangeRequiredToHostname(domainIPString);
|
|
||||||
emit lookupResultsFinished();
|
emit lookupResultsFinished();
|
||||||
|
setDomainHostnameAndName(domainIPString);
|
||||||
|
|
||||||
_currentDomain = domainIPString;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,6 +324,12 @@ bool AddressManager::handleUsername(const QString& lookupString) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AddressManager::setDomainHostnameAndName(const QString& hostname, const QString& domainName) {
|
||||||
|
_currentDomain = domainName.isEmpty() ? hostname : domainName;
|
||||||
|
emit possibleDomainChangeRequiredToHostname(hostname);
|
||||||
|
}
|
||||||
|
|
||||||
void AddressManager::goToUser(const QString& username) {
|
void AddressManager::goToUser(const QString& username) {
|
||||||
QString formattedUsername = QUrl::toPercentEncoding(username);
|
QString formattedUsername = QUrl::toPercentEncoding(username);
|
||||||
// this is a username - pull the captured name and lookup that user's location
|
// this is a username - pull the captured name and lookup that user's location
|
||||||
|
|
|
@ -41,10 +41,9 @@ public:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void handleLookupString(const QString& lookupString);
|
void handleLookupString(const QString& lookupString);
|
||||||
|
|
||||||
void handleAPIResponse(QNetworkReply& requestReply);
|
|
||||||
void handleAPIError(QNetworkReply& errorReply);
|
|
||||||
void goToUser(const QString& username);
|
void goToUser(const QString& username);
|
||||||
|
void goToAddress(const QVariantMap& addressMap);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void lookupResultsFinished();
|
void lookupResultsFinished();
|
||||||
void lookupResultIsOffline();
|
void lookupResultIsOffline();
|
||||||
|
@ -54,9 +53,14 @@ signals:
|
||||||
void locationChangeRequired(const glm::vec3& newPosition,
|
void locationChangeRequired(const glm::vec3& newPosition,
|
||||||
bool hasOrientationChange, const glm::quat& newOrientation,
|
bool hasOrientationChange, const glm::quat& newOrientation,
|
||||||
bool shouldFaceLocation);
|
bool shouldFaceLocation);
|
||||||
|
private slots:
|
||||||
|
void handleAPIResponse(QNetworkReply& requestReply);
|
||||||
|
void handleAPIError(QNetworkReply& errorReply);
|
||||||
private:
|
private:
|
||||||
AddressManager();
|
AddressManager();
|
||||||
|
|
||||||
|
void setDomainHostnameAndName(const QString& hostname, const QString& domainName = QString());
|
||||||
|
|
||||||
const JSONCallbackParameters& apiCallbackParameters();
|
const JSONCallbackParameters& apiCallbackParameters();
|
||||||
|
|
||||||
bool handleUrl(const QUrl& lookupUrl);
|
bool handleUrl(const QUrl& lookupUrl);
|
||||||
|
|
Loading…
Reference in a new issue