History

send a simple heartbeat if location has not changed

Stephen Birarda committed 10 years ago

Commit 7dd85151 parent a5d09e22 files · +25 −7Browse files

Showing the changes to interface/src/DiscoverabilityManager.cpp (1 of 2 files). Show all

Unified · Split

interface/src/DiscoverabilityManager.cpp+24−7
@@ -30,6 +30,7 @@ DiscoverabilityManager::DiscoverabilityManager() : · 29 unmodified lines
3030 }
3131
3232 const QString API_USER_LOCATION_PATH = "/api/v1/user/location";
33+const QString API_USER_HEARTBEAT_PATH = "/api/v1/user/heartbeat";
3334
3435 const QString SESSION_ID_KEY = "session_id";
3536
@@ -48,7 +49,6 @@ void DiscoverabilityManager::updateLocation() { · 12 unmodified lines
4849
4950 QJsonObject locationObject;
5051
51−
5252 QString pathString = addressManager->currentPath();
5353
5454 const QString LOCATION_KEY_IN_ROOT = "location";
@@ -78,16 +78,33 @@ void DiscoverabilityManager::updateLocation() { · 23 unmodified lines
7878
7979 const QString FRIENDS_ONLY_KEY_IN_LOCATION = "friends_only";
8080 locationObject.insert(FRIENDS_ONLY_KEY_IN_LOCATION, (_mode.get() == Discoverability::Friends));
81−
82− rootObject.insert(LOCATION_KEY_IN_ROOT, locationObject);
83−
84− accountManager.sendRequest(API_USER_LOCATION_PATH, AccountManagerAuth::Required,
81+
82+ // if we have a session ID add it now, otherwise add a null value
83+ rootObject[SESSION_ID_KEY] = _sessionID.isEmpty() ? QJsonValue() : _sessionID;
84+
85+ JSONCallbackParameters callbackParameters;
86+ callbackParameters.jsonCallbackReceiver = this;
87+ callbackParameters.jsonCallbackMethod = "handleHeartbeatResponse";
88+
89+ // figure out if we'll send a fresh location or just a simple heartbeat
90+ auto apiPath = API_USER_HEARTBEAT_PATH;
91+
92+ if (locationObject != _lastLocationObject) {
93+ // we have a changed location, send it now
94+ _lastLocationObject = locationObject;
95+
96+ rootObject.insert(LOCATION_KEY_IN_ROOT, locationObject);
97+
98+ apiPath = API_USER_LOCATION_PATH;
99+ }
100+
101+ accountManager.sendRequest(apiPath, AccountManagerAuth::Required,
85102 QNetworkAccessManager::PutOperation,
86− JSONCallbackParameters(), QJsonDocument(rootObject).toJson());
103+ callbackParameters, QJsonDocument(rootObject).toJson());
104+
87105 }
88106 } else if (UserActivityLogger::getInstance().isEnabled()) {
89107 // we still send a heartbeat to the metaverse server for stats collection
90− const QString API_USER_HEARTBEAT_PATH = "/api/v1/user/heartbeat";
91108
92109 JSONCallbackParameters callbackParameters;
93110 callbackParameters.jsonCallbackReceiver = this;