fix string JSON unmarshal, add basic avatar values

This commit is contained in:
Stephen Birarda 2015-04-30 08:55:08 -07:00
parent 73da4828b1
commit 2c0604afd1
5 changed files with 30 additions and 6 deletions

View file

@ -338,6 +338,22 @@ void AvatarMixer::sendStatsPacket() {
statsObject["trailing_sleep_percentage"] = _trailingSleepRatio * 100; statsObject["trailing_sleep_percentage"] = _trailingSleepRatio * 100;
statsObject["performance_throttling_ratio"] = _performanceThrottlingRatio; statsObject["performance_throttling_ratio"] = _performanceThrottlingRatio;
QJsonObject avatarsObject;
auto nodeList = DependencyManager::get<NodeList>();
// add stats for each listerner
nodeList->eachNode([&](const SharedNodePointer& node) {
QJsonObject avatarStats;
avatarStats["bytes_per_second"] = node->getOutboundBandwidth();
AvatarMixerClientData* clientData = static_cast<AvatarMixerClientData*>(node->getLinkedData());
if (clientData) {
clientData->loadJSONStats(avatarStats);
}
avatarsObject[uuidStringWithoutCurlyBraces(node->getUUID())] = avatarStats;
});
statsObject["avatars"] = avatarsObject;
ThreadedAssignment::addPacketStatsAndSendStatsPacket(statsObject); ThreadedAssignment::addPacketStatsAndSendStatsPacket(statsObject);
_sumListeners = 0; _sumListeners = 0;

View file

@ -33,3 +33,8 @@ bool AvatarMixerClientData::checkAndSetHasReceivedFirstPackets() {
_hasReceivedFirstPackets = true; _hasReceivedFirstPackets = true;
return oldValue; return oldValue;
} }
void AvatarMixerClientData::loadJSONStats(QJsonObject& jsonObject) const {
jsonObject["display_name"] = _avatar.getDisplayName();
jsonObject["full_rate_distance"] = _fullRateDistance;
}

View file

@ -14,6 +14,7 @@
#include <cfloat> #include <cfloat>
#include <QtCore/QJsonObject>
#include <QtCore/QUrl> #include <QtCore/QUrl>
#include <AvatarData.h> #include <AvatarData.h>
@ -36,6 +37,8 @@ public:
void setIdentityChangeTimestamp(quint64 identityChangeTimestamp) { _identityChangeTimestamp = identityChangeTimestamp; } void setIdentityChangeTimestamp(quint64 identityChangeTimestamp) { _identityChangeTimestamp = identityChangeTimestamp; }
float getFullRateDistance() const { return _fullRateDistance; } float getFullRateDistance() const { return _fullRateDistance; }
void loadJSONStats(QJsonObject& jsonObject) const;
private: private:
AvatarData _avatar; AvatarData _avatar;
bool _hasReceivedFirstPackets; bool _hasReceivedFirstPackets;

View file

@ -121,10 +121,10 @@ QVariant JSONBreakableMarshal::fromString(const QString& marshalValue) {
} else { } else {
// we need to figure out if this is a string // we need to figure out if this is a string
// use a regex to look for surrounding quotes first // use a regex to look for surrounding quotes first
const QString JSON_STRING_REGEX = "\\A\"([\\w\\W]*)\"\\z"; const QString JSON_STRING_REGEX = "^\"([\\s\\S]*)\"$";
QRegExp stringRegex(JSON_STRING_REGEX); QRegExp stringRegex(JSON_STRING_REGEX);
if (stringRegex.indexIn(marshalValue)) { if (stringRegex.indexIn(marshalValue) != -1) {
// set the result to the string value // set the result to the string value
result = stringRegex.cap(1); result = stringRegex.cap(1);
} else { } else {