示例#1
0
bool AddressManager::handleUrl(const QUrl& lookupUrl) {
    if (lookupUrl.scheme() == HIFI_URL_SCHEME) {
        
        qDebug() << "Trying to go to URL" << lookupUrl.toString();
        
        // there are 4 possible lookup strings
        
        // 1. global place name (name of domain or place) - example: sanfrancisco
        // 2. user name (prepended with @) - example: @philip
        // 3. location string (posX,posY,posZ/eulerX,eulerY,eulerZ)
        // 4. domain network address (IP or dns resolvable hostname)
        
        // use our regex'ed helpers to figure out what we're supposed to do with this
        if (!handleUsername(lookupUrl.authority())) {
            // we're assuming this is either a network address or global place name
            // check if it is a network address first
            if (handleNetworkAddress(lookupUrl.host()
                                      + (lookupUrl.port() == -1 ? "" : ":" + QString::number(lookupUrl.port())))) {
                // we may have a path that defines a relative viewpoint - if so we should jump to that now
                handleRelativeViewpoint(lookupUrl.path());
            } else {
                // wasn't an address - lookup the place name
                // we may have a path that defines a relative viewpoint - pass that through the lookup so we can go to it after
                attemptPlaceNameLookup(lookupUrl.host(), lookupUrl.path());
                
            }
        }
        
        return true;
    } else if (lookupUrl.toString().startsWith('/')) {
        qDebug() << "Going to relative path" << lookupUrl.path();
        
        // if this is a relative path then handle it as a relative viewpoint
        handleRelativeViewpoint(lookupUrl.path());
        emit lookupResultsFinished();
    }
    
    return false;
}
示例#2
0
void AddressManager::handleAPIResponse(const QJsonObject &jsonObject) {
    QJsonObject dataObject = jsonObject["data"].toObject();
    
    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 (dataObject.contains(ADDRESS_API_DOMAIN_KEY)) {
            QJsonObject domainObject = dataObject[ADDRESS_API_DOMAIN_KEY].toObject();
            
            const QString DOMAIN_NETWORK_ADDRESS_KEY = "network_address";
            QString domainHostname = domainObject[DOMAIN_NETWORK_ADDRESS_KEY].toString();
            
            emit possibleDomainChangeRequired(domainHostname);
            
            // take the path that came back
            const QString LOCATION_KEY = "location";
            const QString LOCATION_PATH_KEY = "path";
            QString returnedPath;
            
            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();
            }
            
            bool shouldFaceViewpoint = dataObject.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
                if (!handleRelativeViewpoint(returnedPath, shouldFaceViewpoint)) {
                    qDebug() << "Received a location path that was could not be handled as a viewpoint -" << returnedPath;
                }
            }
            
        } else {
            qDebug() << "Received an address manager API response with no domain key. Cannot parse.";
            qDebug() << jsonObject;
        }
    } else {
        // we've been told that this result exists but is offline, emit our signal so the application can handle
        emit lookupResultIsOffline();
    }
    emit lookupResultsFinished();
}
示例#3
0
void AddressManager::goToAddressFromObject(const QVariantMap& dataObject, const QNetworkReply& reply) {
    
    const QString DATA_OBJECT_PLACE_KEY = "place";
    const QString DATA_OBJECT_USER_LOCATION_KEY = "location";
    
    QVariantMap locationMap;
    if (dataObject.contains(DATA_OBJECT_PLACE_KEY)) {
        locationMap = dataObject[DATA_OBJECT_PLACE_KEY].toMap();
    } else {
        locationMap = dataObject[DATA_OBJECT_USER_LOCATION_KEY].toMap();
    }
    
    if (!locationMap.isEmpty()) {
        const QString LOCATION_API_ROOT_KEY = "root";
        const QString LOCATION_API_DOMAIN_KEY = "domain";
        const QString LOCATION_API_ONLINE_KEY = "online";
        
        if (!locationMap.contains(LOCATION_API_ONLINE_KEY)
            || locationMap[LOCATION_API_ONLINE_KEY].toBool()) {
            
            QVariantMap rootMap = locationMap[LOCATION_API_ROOT_KEY].toMap();
            if (rootMap.isEmpty()) {
                rootMap = locationMap;
            }
            
            QVariantMap domainObject = rootMap[LOCATION_API_DOMAIN_KEY].toMap();
            
            if (!domainObject.isEmpty()) {
                const QString DOMAIN_NETWORK_ADDRESS_KEY = "network_address";
                const QString DOMAIN_ICE_SERVER_ADDRESS_KEY = "ice_server_address";
                
                if (domainObject.contains(DOMAIN_NETWORK_ADDRESS_KEY)) {
                    QString domainHostname = domainObject[DOMAIN_NETWORK_ADDRESS_KEY].toString();
                    
                    qDebug() << "Possible domain change required to connect to" << domainHostname
                        << "on" << DEFAULT_DOMAIN_SERVER_PORT;
                    emit possibleDomainChangeRequired(domainHostname, DEFAULT_DOMAIN_SERVER_PORT);
                } else {
                    QString iceServerAddress = domainObject[DOMAIN_ICE_SERVER_ADDRESS_KEY].toString();
                    
                    const QString DOMAIN_ID_KEY = "id";
                    QString domainIDString = domainObject[DOMAIN_ID_KEY].toString();
                    QUuid domainID(domainIDString);
                    
                    qDebug() << "Possible domain change required to connect to domain with ID" << domainID
                        << "via ice-server at" << iceServerAddress;
                    
                    emit possibleDomainChangeRequiredViaICEForID(iceServerAddress, domainID);
                }
                
                // set our current root place id to the ID that came back
                const QString PLACE_ID_KEY = "id";
                _rootPlaceID = rootMap[PLACE_ID_KEY].toUuid();
                
                // set our current root place name to the name that came back
                const QString PLACE_NAME_KEY = "name";
                QString newRootPlaceName = rootMap[PLACE_NAME_KEY].toString();
                setRootPlaceName(newRootPlaceName);
                
                // check if we had a path to override the path returned
                QString overridePath = reply.property(OVERRIDE_PATH_KEY).toString();
                
                if (!overridePath.isEmpty()) {
                    if (!handleRelativeViewpoint(overridePath)){
                        qDebug() << "User entered path could not be handled as a viewpoint - " << overridePath;
                    }
                } else {
                    // take the path that came back
                    const QString PLACE_PATH_KEY = "path";
                    QString returnedPath = locationMap[PLACE_PATH_KEY].toString();
                    
                    bool shouldFaceViewpoint = locationMap.contains(LOCATION_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
                        if (!handleRelativeViewpoint(returnedPath, shouldFaceViewpoint)) {
                            qDebug() << "Received a location path that was could not be handled as a viewpoint -" << returnedPath;
                        }
                    }
                }
                
                
            } else {
                qDebug() << "Received an address manager API response with no domain key. Cannot parse.";
                qDebug() << locationMap;
            }
        } else {
            // we've been told that this result exists but is offline, emit our signal so the application can handle
            emit lookupResultIsOffline();
        }
    } else {
        qDebug() << "Received an address manager API response with no location key or place key. Cannot parse.";
        qDebug() << locationMap;
    }
}