QString GlobalServicesScriptingInterface::getFindableBy() const {
    auto discoverabilityManager = DependencyManager::get<DiscoverabilityManager>();
    return findableByString(discoverabilityManager->getDiscoverabilityMode());
}
void GlobalServicesScriptingInterface::discoverabilityModeChanged(Discoverability::Mode discoverabilityMode) {
    emit findableByChanged(findableByString(discoverabilityMode));
}
示例#3
0
void DiscoverabilityManager::updateLocation() {
    // since we store the last location and compare it to
    // the current one in this function, we need to do this in
    // the object's main thread (or use a mutex)
    if (QThread::currentThread() != thread()) {
        QMetaObject::invokeMethod(this, "updateLocation");
        return;
    }
    auto accountManager = DependencyManager::get<AccountManager>();
    auto addressManager = DependencyManager::get<AddressManager>();
    auto& domainHandler = DependencyManager::get<NodeList>()->getDomainHandler();
    bool discoverable = (_mode.get() != Discoverability::None) && !domainHandler.isServerless();


    if (accountManager->isLoggedIn()) {
        // construct a QJsonObject given the user's current address information
        QJsonObject rootObject;

        QJsonObject locationObject;

        QString pathString = addressManager->currentPath();

        const QString CONNECTED_KEY_IN_LOCATION = "connected";
        locationObject.insert(CONNECTED_KEY_IN_LOCATION, discoverable && domainHandler.isConnected());

        if (discoverable || _lastLocationObject.isEmpty()) { // Don't consider changes to these as update-worthy if we're not discoverable.
            const QString PATH_KEY_IN_LOCATION = "path";
            locationObject.insert(PATH_KEY_IN_LOCATION, pathString);

            if (!addressManager->getRootPlaceID().isNull()) {
                const QString PLACE_ID_KEY_IN_LOCATION = "place_id";
                locationObject.insert(PLACE_ID_KEY_IN_LOCATION,
                                      uuidStringWithoutCurlyBraces(addressManager->getRootPlaceID()));
            }

            if (!domainHandler.getUUID().isNull()) {
                const QString DOMAIN_ID_KEY_IN_LOCATION = "domain_id";
                locationObject.insert(DOMAIN_ID_KEY_IN_LOCATION,
                                      uuidStringWithoutCurlyBraces(domainHandler.getUUID()));
            }

            // in case the place/domain isn't in the database, we send the network address and port
            auto& domainSockAddr = domainHandler.getSockAddr();
            const QString NETWORK_ADDRESS_KEY_IN_LOCATION = "network_address";
            locationObject.insert(NETWORK_ADDRESS_KEY_IN_LOCATION, domainSockAddr.getAddress().toString());

            const QString NETWORK_ADDRESS_PORT_IN_LOCATION = "network_port";
            locationObject.insert(NETWORK_ADDRESS_PORT_IN_LOCATION, domainSockAddr.getPort());

            const QString NODE_ID_IN_LOCATION = "node_id";
            const int UUID_REAL_LENGTH = 36;
            locationObject.insert(NODE_ID_IN_LOCATION, DependencyManager::get<NodeList>()->getSessionUUID().toString().mid(1, UUID_REAL_LENGTH));
        }

        const QString AVAILABILITY_KEY_IN_LOCATION = "availability";
        locationObject.insert(AVAILABILITY_KEY_IN_LOCATION, findableByString(static_cast<Discoverability::Mode>(_mode.get())));

        JSONCallbackParameters callbackParameters;
        callbackParameters.jsonCallbackReceiver = this;
        callbackParameters.jsonCallbackMethod = "handleHeartbeatResponse";

        // figure out if we'll send a fresh location or just a simple heartbeat
        auto apiPath = API_USER_HEARTBEAT_PATH;

        if (locationObject != _lastLocationObject) {
            // we have a changed location, send it now
            _lastLocationObject = locationObject;

            const QString LOCATION_KEY_IN_ROOT = "location";
            rootObject.insert(LOCATION_KEY_IN_ROOT, locationObject);

            apiPath = API_USER_LOCATION_PATH;
        }

        accountManager->sendRequest(apiPath, AccountManagerAuth::Required,
                                   QNetworkAccessManager::PutOperation,
                                   callbackParameters, QJsonDocument(rootObject).toJson());

    } else if (UserActivityLogger::getInstance().isEnabled()) {
        // we still send a heartbeat to the metaverse server for stats collection

        JSONCallbackParameters callbackParameters;
        callbackParameters.jsonCallbackReceiver = this;
        callbackParameters.jsonCallbackMethod = "handleHeartbeatResponse";

        accountManager->sendRequest(API_USER_HEARTBEAT_PATH, AccountManagerAuth::Optional,
                                   QNetworkAccessManager::PutOperation, callbackParameters);
    }

    // Update Steam
    if (auto steamClient = PluginManager::getInstance()->getSteamClientPlugin()) {
        steamClient->updateLocation(domainHandler.getHostname(), addressManager->currentFacingPublicAddress());
    }
}