mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 08:04:01 +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 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_ONLINE_KEY = "online";
|
||||
|
||||
if (!dataObject.contains(ADDRESS_API_ONLINE_KEY)
|
||||
|| dataObject[ADDRESS_API_ONLINE_KEY].toBool()) {
|
||||
if (!addressMap.contains(ADDRESS_API_ONLINE_KEY)
|
||||
|| addressMap[ADDRESS_API_ONLINE_KEY].toBool()) {
|
||||
|
||||
if (dataObject.contains(ADDRESS_API_DOMAIN_KEY)) {
|
||||
QJsonObject domainObject = dataObject[ADDRESS_API_DOMAIN_KEY].toObject();
|
||||
if (addressMap.contains(ADDRESS_API_DOMAIN_KEY)) {
|
||||
QVariantMap domainObject = addressMap[ADDRESS_API_DOMAIN_KEY].toMap();
|
||||
|
||||
const QString DOMAIN_NETWORK_ADDRESS_KEY = "network_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)) {
|
||||
returnedPath = domainObject[LOCATION_PATH_KEY].toString();
|
||||
} 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()) {
|
||||
// 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 {
|
||||
qDebug() << "Received an address manager API response with no domain key. Cannot parse.";
|
||||
qDebug() << responseObject;
|
||||
qDebug() << addressMap;
|
||||
}
|
||||
} else {
|
||||
// we've been told that this result exists but is offline, emit our signal so the application can handle
|
||||
emit lookupResultIsOffline();
|
||||
}
|
||||
emit lookupResultsFinished();
|
||||
}
|
||||
|
||||
void AddressManager::handleAPIError(QNetworkReply& errorReply) {
|
||||
|
@ -232,10 +237,8 @@ bool AddressManager::handleNetworkAddress(const QString& lookupString) {
|
|||
if (hostnameRegex.indexIn(lookupString) != -1) {
|
||||
QString domainHostname = hostnameRegex.cap(0);
|
||||
|
||||
emit possibleDomainChangeRequiredToHostname(domainHostname);
|
||||
emit lookupResultsFinished();
|
||||
|
||||
_currentDomain = domainHostname;
|
||||
setDomainHostnameAndName(domainHostname);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -245,10 +248,9 @@ bool AddressManager::handleNetworkAddress(const QString& lookupString) {
|
|||
if (ipAddressRegex.indexIn(lookupString) != -1) {
|
||||
QString domainIPString = ipAddressRegex.cap(0);
|
||||
|
||||
emit possibleDomainChangeRequiredToHostname(domainIPString);
|
||||
emit lookupResultsFinished();
|
||||
setDomainHostnameAndName(domainIPString);
|
||||
|
||||
_currentDomain = domainIPString;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -322,6 +324,12 @@ bool AddressManager::handleUsername(const QString& lookupString) {
|
|||
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) {
|
||||
QString formattedUsername = QUrl::toPercentEncoding(username);
|
||||
// this is a username - pull the captured name and lookup that user's location
|
||||
|
|
|
@ -41,10 +41,9 @@ public:
|
|||
|
||||
public slots:
|
||||
void handleLookupString(const QString& lookupString);
|
||||
|
||||
void handleAPIResponse(QNetworkReply& requestReply);
|
||||
void handleAPIError(QNetworkReply& errorReply);
|
||||
void goToUser(const QString& username);
|
||||
void goToAddress(const QVariantMap& addressMap);
|
||||
|
||||
signals:
|
||||
void lookupResultsFinished();
|
||||
void lookupResultIsOffline();
|
||||
|
@ -54,9 +53,14 @@ signals:
|
|||
void locationChangeRequired(const glm::vec3& newPosition,
|
||||
bool hasOrientationChange, const glm::quat& newOrientation,
|
||||
bool shouldFaceLocation);
|
||||
private slots:
|
||||
void handleAPIResponse(QNetworkReply& requestReply);
|
||||
void handleAPIError(QNetworkReply& errorReply);
|
||||
private:
|
||||
AddressManager();
|
||||
|
||||
void setDomainHostnameAndName(const QString& hostname, const QString& domainName = QString());
|
||||
|
||||
const JSONCallbackParameters& apiCallbackParameters();
|
||||
|
||||
bool handleUrl(const QUrl& lookupUrl);
|
||||
|
|
Loading…
Reference in a new issue