mirror of
https://github.com/overte-org/overte.git
synced 2025-04-19 15:43:50 +02:00
don't require an active domain connection for location update
This commit is contained in:
parent
ed1ddc2a8b
commit
258c5308db
1 changed files with 55 additions and 56 deletions
|
@ -37,72 +37,71 @@ const QString SESSION_ID_KEY = "session_id";
|
|||
void DiscoverabilityManager::updateLocation() {
|
||||
AccountManager& accountManager = AccountManager::getInstance();
|
||||
|
||||
if (_mode.get() != Discoverability::None) {
|
||||
if (_mode.get() != Discoverability::None && accountManager.isLoggedIn()) {
|
||||
auto addressManager = DependencyManager::get<AddressManager>();
|
||||
DomainHandler& domainHandler = DependencyManager::get<NodeList>()->getDomainHandler();
|
||||
|
||||
if (accountManager.isLoggedIn() && domainHandler.isConnected()
|
||||
&& (!addressManager->getRootPlaceID().isNull() || !domainHandler.getUUID().isNull())) {
|
||||
|
||||
// construct a QJsonObject given the user's current address information
|
||||
QJsonObject rootObject;
|
||||
|
||||
QJsonObject locationObject;
|
||||
|
||||
QString pathString = addressManager->currentPath();
|
||||
|
||||
const QString LOCATION_KEY_IN_ROOT = "location";
|
||||
|
||||
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()));
|
||||
}
|
||||
// construct a QJsonObject given the user's current address information
|
||||
QJsonObject rootObject;
|
||||
|
||||
if (!domainHandler.getUUID().isNull()) {
|
||||
const QString DOMAIN_ID_KEY_IN_LOCATION = "domain_id";
|
||||
locationObject.insert(DOMAIN_ID_KEY_IN_LOCATION,
|
||||
uuidStringWithoutCurlyBraces(domainHandler.getUUID()));
|
||||
}
|
||||
QJsonObject locationObject;
|
||||
|
||||
// in case the place/domain isn't in the database, we send the network address and port
|
||||
auto& domainSockAddr = domainHandler.getSockAddr();
|
||||
const QString NETWORK_ADRESS_KEY_IN_LOCATION = "network_address";
|
||||
locationObject.insert(NETWORK_ADRESS_KEY_IN_LOCATION, domainSockAddr.getAddress().toString());
|
||||
QString pathString = addressManager->currentPath();
|
||||
|
||||
const QString NETWORK_ADDRESS_PORT_IN_LOCATION = "network_port";
|
||||
locationObject.insert(NETWORK_ADDRESS_PORT_IN_LOCATION, domainSockAddr.getPort());
|
||||
const QString LOCATION_KEY_IN_ROOT = "location";
|
||||
|
||||
const QString FRIENDS_ONLY_KEY_IN_LOCATION = "friends_only";
|
||||
locationObject.insert(FRIENDS_ONLY_KEY_IN_LOCATION, (_mode.get() == Discoverability::Friends));
|
||||
const QString PATH_KEY_IN_LOCATION = "path";
|
||||
locationObject.insert(PATH_KEY_IN_LOCATION, pathString);
|
||||
|
||||
// if we have a session ID add it now, otherwise add a null value
|
||||
rootObject[SESSION_ID_KEY] = _sessionID.isEmpty() ? QJsonValue() : _sessionID;
|
||||
|
||||
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;
|
||||
|
||||
rootObject.insert(LOCATION_KEY_IN_ROOT, locationObject);
|
||||
|
||||
apiPath = API_USER_LOCATION_PATH;
|
||||
}
|
||||
|
||||
accountManager.sendRequest(apiPath, AccountManagerAuth::Required,
|
||||
QNetworkAccessManager::PutOperation,
|
||||
callbackParameters, QJsonDocument(rootObject).toJson());
|
||||
const QString CONNECTED_KEY_IN_LOCATION = "connected";
|
||||
locationObject.insert(CONNECTED_KEY_IN_LOCATION, domainHandler.isConnected());
|
||||
|
||||
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_ADRESS_KEY_IN_LOCATION = "network_address";
|
||||
locationObject.insert(NETWORK_ADRESS_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 FRIENDS_ONLY_KEY_IN_LOCATION = "friends_only";
|
||||
locationObject.insert(FRIENDS_ONLY_KEY_IN_LOCATION, (_mode.get() == Discoverability::Friends));
|
||||
|
||||
// if we have a session ID add it now, otherwise add a null value
|
||||
rootObject[SESSION_ID_KEY] = _sessionID.isEmpty() ? QJsonValue() : _sessionID;
|
||||
|
||||
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;
|
||||
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in a new issue