Ahh...It's beautiful and simple now.

This commit is contained in:
Zach Fox 2016-12-29 13:09:40 -08:00
parent 24eac77115
commit 10b5b957f2
9 changed files with 88 additions and 154 deletions

View file

@ -65,8 +65,6 @@ AudioMixer::AudioMixer(ReceivedMessage& message) :
packetReceiver.registerListener(PacketType::NegotiateAudioFormat, this, "handleNegotiateAudioFormat");
packetReceiver.registerListener(PacketType::MuteEnvironment, this, "handleMuteEnvironmentPacket");
packetReceiver.registerListener(PacketType::NodeIgnoreRequest, this, "handleNodeIgnoreRequestPacket");
packetReceiver.registerListener(PacketType::NodePersonalMuteRequest, this, "handleNodePersonalMuteRequestPacket");
packetReceiver.registerListener(PacketType::NodePersonalMuteStatusRequest, this, "handleNodePersonalMuteStatusRequestPacket");
packetReceiver.registerListener(PacketType::KillAvatar, this, "handleKillAvatarPacket");
packetReceiver.registerListener(PacketType::NodeMuteRequest, this, "handleNodeMuteRequestPacket");
packetReceiver.registerListener(PacketType::RadiusIgnoreRequest, this, "handleRadiusIgnoreRequestPacket");
@ -227,55 +225,6 @@ void AudioMixer::handleNodeIgnoreRequestPacket(QSharedPointer<ReceivedMessage> p
sendingNode->parseIgnoreRequestMessage(packet);
}
void AudioMixer::handleNodePersonalMuteRequestPacket(QSharedPointer<ReceivedMessage> packet, SharedNodePointer sendingNode) {
// parse out the UUID being muted from the packet
QUuid ignoredUUID = QUuid::fromRfc4122(packet->readWithoutCopy(NUM_BYTES_RFC4122_UUID));
bool enabled;
packet->readPrimitive(&enabled);
if (!ignoredUUID.isNull() && ignoredUUID != _uuid) {
if (enabled) {
qDebug() << "Adding" << uuidStringWithoutCurlyBraces(ignoredUUID) << "to personally muted set for"
<< uuidStringWithoutCurlyBraces(_uuid);
// Add the session UUID to the set of personally muted ones for this listening node
sendingNode->addIgnoredNode(ignoredUUID);
} else {
qDebug() << "Removing" << uuidStringWithoutCurlyBraces(ignoredUUID) << "from personally muted set for"
<< uuidStringWithoutCurlyBraces(_uuid);
// Remove the session UUID to the set of personally muted ones for this listening node
sendingNode->removeIgnoredNode(ignoredUUID);
}
} else {
qWarning() << "Node::handlePersonalMutedNode called with null ID or ID of personal muting node.";
}
}
void AudioMixer::handleNodePersonalMuteStatusRequestPacket(QSharedPointer<ReceivedMessage> packet, SharedNodePointer sendingNode) {
// parse out the UUID whose personal mute status is being requested from the packet
QUuid UUIDToCheck = QUuid::fromRfc4122(packet->readWithoutCopy(NUM_BYTES_RFC4122_UUID));
if (!UUIDToCheck.isNull()) {
// First, make sure we actually have a node with this UUID
auto limitedNodeList = DependencyManager::get<LimitedNodeList>();
auto matchingNode = limitedNodeList->nodeWithUUID(UUIDToCheck);
// If we do have a matching node...
if (matchingNode) {
auto personalMuteStatusPacket = NLPacket::create(PacketType::NodePersonalMuteStatusReply, NUM_BYTES_RFC4122_UUID + sizeof(bool), true);
bool isMuted = sendingNode->isIgnoringNodeWithID(UUIDToCheck);
// write the node ID to the packet
personalMuteStatusPacket->write(UUIDToCheck.toRfc4122());
personalMuteStatusPacket->writePrimitive(isMuted);
qDebug() << "Personal Mute Status: node" << uuidStringWithoutCurlyBraces(UUIDToCheck) << "mute status:" << isMuted;
limitedNodeList->sendPacket(std::move(personalMuteStatusPacket), *sendingNode);
}
}
}
void AudioMixer::handleRadiusIgnoreRequestPacket(QSharedPointer<ReceivedMessage> packet, SharedNodePointer sendingNode) {
sendingNode->parseIgnoreRadiusRequestMessage(packet);
}

View file

@ -62,8 +62,6 @@ private slots:
void handleNegotiateAudioFormat(QSharedPointer<ReceivedMessage> message, SharedNodePointer sendingNode);
void handleNodeKilled(SharedNodePointer killedNode);
void handleNodeIgnoreRequestPacket(QSharedPointer<ReceivedMessage> packet, SharedNodePointer sendingNode);
void handleNodePersonalMuteRequestPacket(QSharedPointer<ReceivedMessage> packet, SharedNodePointer sendingNode);
void handleNodePersonalMuteStatusRequestPacket(QSharedPointer<ReceivedMessage> packet, SharedNodePointer sendingNode);
void handleRadiusIgnoreRequestPacket(QSharedPointer<ReceivedMessage> packet, SharedNodePointer sendingNode);
void handleKillAvatarPacket(QSharedPointer<ReceivedMessage> packet, SharedNodePointer sendingNode);
void handleNodeMuteRequestPacket(QSharedPointer<ReceivedMessage> packet, SharedNodePointer sendingNode);

View file

@ -202,7 +202,7 @@ Item {
// This CheckBox belongs in the columns that contain the action buttons ("Mute", "Ban", etc)
HifiControls.CheckBox {
visible: isCheckBox
visible: styleData.role === "personalMute" ? (model["ignore"] === true ? false : true) : isCheckBox
anchors.centerIn: parent
checked: model[styleData.role]
boxSize: 24
@ -211,7 +211,10 @@ Item {
var datum = userData[model.userIndex]
datum[styleData.role] = model[styleData.role] = newValue
if (styleData.role === "personalMute" || styleData.role === "ignore") {
Users[styleData.role](model.sessionId, newValue)
Users[styleData.role](model.sessionId, newValue)
if (styleData.role === "ignore") {
datum["personalMute"] = model["personalMute"] = newValue
}
} else {
Users[styleData.role](model.sessionId)
// Just for now, while we cannot undo things:
@ -404,13 +407,6 @@ Item {
}
}
break;
case 'updatePersonalMutedStatus':
var userId = message.params[0];
var enabled = message.params[1];
var userIndex = findSessionIndex(userId);
userModel.setProperty(userIndex, "personalMute", enabled);
userData[userIndex].personalMute.property = enabled; // Defensive programming
break;
default:
console.log('Unrecognized message:', JSON.stringify(message));
}

View file

@ -129,7 +129,6 @@ NodeList::NodeList(char newOwnerType, int socketListenPort, int dtlsListenPort)
packetReceiver.registerListener(PacketType::DomainServerPathResponse, this, "processDomainServerPathResponse");
packetReceiver.registerListener(PacketType::DomainServerRemovedNode, this, "processDomainServerRemovedNode");
packetReceiver.registerListener(PacketType::UsernameFromIDReply, this, "processUsernameFromIDReply");
packetReceiver.registerListener(PacketType::NodePersonalMuteStatusReply, this, "processPersonalMuteStatusReply");
}
qint64 NodeList::sendStats(QJsonObject statsObject, HifiSockAddr destination) {
@ -802,14 +801,18 @@ void NodeList::ignoreNodeBySessionID(const QUuid& nodeID, bool ignoreEnabled) {
sendPacket(std::move(ignorePacket), *destinationNode);
});
QReadLocker setLocker { &_ignoredSetLock }; // write lock for insert and unsafe_erase
QReadLocker ignoredSetLocker { &_ignoredSetLock }; // write lock for insert and unsafe_erase
QReadLocker personalMutedSetLocker{ &_personalMutedSetLock }; // write lock for insert and unsafe_erase
if (ignoreEnabled) {
// add this nodeID to our set of ignored IDs
_ignoredNodeIDs.insert(nodeID);
// add this nodeID to our set of personal muted IDs
_personalMutedNodeIDs.insert(nodeID);
emit ignoredNode(nodeID);
} else {
_ignoredNodeIDs.unsafe_erase(nodeID);
_personalMutedNodeIDs.unsafe_erase(nodeID);
emit unignoredNode(nodeID);
}
@ -819,16 +822,82 @@ void NodeList::ignoreNodeBySessionID(const QUuid& nodeID, bool ignoreEnabled) {
}
bool NodeList::isIgnoringNode(const QUuid& nodeID) const {
QReadLocker setLocker { &_ignoredSetLock };
QReadLocker ignoredSetLocker{ &_ignoredSetLock };
return _ignoredNodeIDs.find(nodeID) != _ignoredNodeIDs.cend();
}
void NodeList::personalMuteNodeBySessionID(const QUuid& nodeID, bool muteEnabled) {
// cannot personal mute yourself, or nobody
if (!nodeID.isNull() && _sessionUUID != nodeID) {
auto audioMixer = soloNodeOfType(NodeType::AudioMixer);
if (audioMixer) {
if (isIgnoringNode(nodeID)) {
qCDebug(networking) << "You can't personally mute or unmute a node you're already ignoring.";
}
else {
// setup the packet
auto personalMutePacket = NLPacket::create(PacketType::NodeIgnoreRequest, NUM_BYTES_RFC4122_UUID + sizeof(bool), true);
// write the node ID to the packet
personalMutePacket->write(nodeID.toRfc4122());
personalMutePacket->writePrimitive(muteEnabled);
qCDebug(networking) << "Sending Personal Mute Packet to" << (muteEnabled ? "mute" : "unmute") << "node" << uuidStringWithoutCurlyBraces(nodeID);
sendPacket(std::move(personalMutePacket), *audioMixer);
QReadLocker personalMutedSetLocker{ &_personalMutedSetLock }; // write lock for insert and unsafe_erase
if (muteEnabled) {
// add this nodeID to our set of personal muted IDs
_personalMutedNodeIDs.insert(nodeID);
} else {
_personalMutedNodeIDs.unsafe_erase(nodeID);
}
}
} else {
qWarning() << "Couldn't find audio mixer to send node personal mute request";
}
} else {
qWarning() << "NodeList::personalMuteNodeBySessionID called with an invalid ID or an ID which matches the current session ID.";
}
}
bool NodeList::isPersonalMutingNode(const QUuid& nodeID) const {
QReadLocker personalMutedSetLocker{ &_personalMutedSetLock };
return _personalMutedNodeIDs.find(nodeID) != _personalMutedNodeIDs.cend();
}
void NodeList::maybeSendIgnoreSetToNode(SharedNodePointer newNode) {
if (newNode->getType() == NodeType::AudioMixer || newNode->getType() == NodeType::AvatarMixer) {
if (newNode->getType() == NodeType::AudioMixer) {
// this is a mixer that we just added - it's unlikely it knows who we were previously ignoring in this session,
// so send that list along now (assuming it isn't empty)
QReadLocker setLocker { &_ignoredSetLock };
QReadLocker personalMutedSetLocker{ &_personalMutedSetLock };
if (_personalMutedNodeIDs.size() > 0) {
// setup a packet list so we can send the stream of ignore IDs
auto personalMutePacketList = NLPacketList::create(PacketType::NodeIgnoreRequest, QByteArray(), true);
// enumerate the ignored IDs and write them to the packet list
auto it = _personalMutedNodeIDs.cbegin();
while (it != _personalMutedNodeIDs.end()) {
personalMutePacketList->write(it->toRfc4122());
++it;
}
// send this NLPacketList to the new node
sendPacketList(std::move(personalMutePacketList), *newNode);
}
// also send them the current ignore radius state.
sendIgnoreRadiusStateToNode(newNode);
}
if (newNode->getType() == NodeType::AvatarMixer) {
// this is a mixer that we just added - it's unlikely it knows who we were previously ignoring in this session,
// so send that list along now (assuming it isn't empty)
QReadLocker ignoredSetLocker{ &_ignoredSetLock };
if (_ignoredNodeIDs.size() > 0) {
// setup a packet list so we can send the stream of ignore IDs
@ -850,64 +919,6 @@ void NodeList::maybeSendIgnoreSetToNode(SharedNodePointer newNode) {
}
}
void NodeList::personalMuteNodeBySessionID(const QUuid& nodeID, bool muteEnabled) {
// cannot personal mute yourself, or nobody
if (!nodeID.isNull() && _sessionUUID != nodeID) {
auto audioMixer = soloNodeOfType(NodeType::AudioMixer);
if (audioMixer) {
// setup the packet
auto personalMutePacket = NLPacket::create(PacketType::NodePersonalMuteRequest, NUM_BYTES_RFC4122_UUID + sizeof(bool), true);
// write the node ID to the packet
personalMutePacket->write(nodeID.toRfc4122());
personalMutePacket->writePrimitive(muteEnabled);
qCDebug(networking) << "Sending Personal Mute Packet to" << (muteEnabled ? "mute" : "unmute") << "node" << uuidStringWithoutCurlyBraces(nodeID);
sendPacket(std::move(personalMutePacket), *audioMixer);
} else {
qWarning() << "Couldn't find audio mixer to send node personal mute request";
}
} else {
qWarning() << "NodeList::personalMuteNodeBySessionID called with an invalid ID or an ID which matches the current session ID.";
}
}
void NodeList::requestPersonalMuteStatus(const QUuid& nodeID) {
// cannot personal mute yourself, or nobody; don't bother checking the status
if (!nodeID.isNull() && _sessionUUID != nodeID) {
auto audioMixer = soloNodeOfType(NodeType::AudioMixer);
if (audioMixer) {
// send a request to the audio mixer to get the personal mute status associated with the given session ID
// setup the packet
auto personalMuteStatusPacket = NLPacket::create(PacketType::NodePersonalMuteStatusRequest, NUM_BYTES_RFC4122_UUID, true);
// write the node ID to the packet
personalMuteStatusPacket->write(nodeID.toRfc4122());
qCDebug(networking) << "Sending Personal Mute Status Request Packet for node" << uuidStringWithoutCurlyBraces(nodeID);
sendPacket(std::move(personalMuteStatusPacket), *audioMixer);
} else {
qWarning() << "Couldn't find audio mixer to send node personal mute status request";
}
} else {
qWarning() << "NodeList::requestPersonalMuteStatus called with an invalid ID or an ID which matches the current session ID.";
}
}
void NodeList::processPersonalMuteStatusReply(QSharedPointer<ReceivedMessage> message) {
// read the UUID from the packet
QString nodeUUIDString = (QUuid::fromRfc4122(message->readWithoutCopy(NUM_BYTES_RFC4122_UUID))).toString();
// read the personal mute status
bool isPersonalMuted;
message->readPrimitive(&isPersonalMuted);
qCDebug(networking) << "Got personal muted status" << isPersonalMuted << "for node" << nodeUUIDString;
emit personalMuteStatusReply(nodeUUIDString, isPersonalMuted);
}
void NodeList::kickNodeBySessionID(const QUuid& nodeID) {
// send a request to domain-server to kick the node with the given session ID
// the domain-server will handle the persistence of the kick (via username or IP)

View file

@ -79,7 +79,7 @@ public:
void ignoreNodeBySessionID(const QUuid& nodeID, bool ignoreEnabled);
bool isIgnoringNode(const QUuid& nodeID) const;
void personalMuteNodeBySessionID(const QUuid& nodeID, bool muteEnabled);
void requestPersonalMuteStatus(const QUuid& nodeID);
bool isPersonalMutingNode(const QUuid& nodeID) const;
void kickNodeBySessionID(const QUuid& nodeID);
void muteNodeBySessionID(const QUuid& nodeID);
@ -105,7 +105,6 @@ public slots:
void processICEPingPacket(QSharedPointer<ReceivedMessage> message);
void processUsernameFromIDReply(QSharedPointer<ReceivedMessage> message);
void processPersonalMuteStatusReply(QSharedPointer<ReceivedMessage> message);
#if (PR_BUILD || DEV_BUILD)
void toggleSendNewerDSConnectVersion(bool shouldSendNewerVersion) { _shouldSendNewerVersion = shouldSendNewerVersion; }
@ -118,7 +117,6 @@ signals:
void unignoredNode(const QUuid& nodeID);
void ignoreRadiusEnabledChanged(bool isIgnored);
void usernameFromIDReply(const QString& nodeID, const QString& username, const QString& machineFingerprint);
void personalMuteStatusReply(const QString& nodeID, bool isPersonalMuted);
private slots:
void stopKeepalivePingTimer();
@ -164,6 +162,8 @@ private:
mutable QReadWriteLock _ignoredSetLock;
tbb::concurrent_unordered_set<QUuid, UUIDHasher> _ignoredNodeIDs;
mutable QReadWriteLock _personalMutedSetLock;
tbb::concurrent_unordered_set<QUuid, UUIDHasher> _personalMutedNodeIDs;
void sendIgnoreRadiusStateToNode(const SharedNodePointer& destinationNode);
Setting::Handle<bool> _ignoreRadiusEnabled { "IgnoreRadiusEnabled", true };

View file

@ -105,10 +105,7 @@ public:
UsernameFromIDReply,
ViewFrustum,
RequestsDomainListData,
NodePersonalMuteRequest,
NodePersonalMuteStatusRequest,
NodePersonalMuteStatusReply,
LAST_PACKET_TYPE = NodePersonalMuteStatusReply
LAST_PACKET_TYPE = RequestsDomainListData
};
};

View file

@ -21,7 +21,6 @@ UsersScriptingInterface::UsersScriptingInterface() {
connect(nodeList.data(), &NodeList::usernameFromIDReply, this, &UsersScriptingInterface::usernameFromIDReply);
connect(nodeList.data(), &NodeList::ignoredNode, this, &UsersScriptingInterface::ignoredNode);
connect(nodeList.data(), &NodeList::unignoredNode, this, &UsersScriptingInterface::unignoredNode);
connect(nodeList.data(), &NodeList::personalMuteStatusReply, this, &UsersScriptingInterface::personalMuteStatusReply);
}
void UsersScriptingInterface::ignore(const QUuid& nodeID, bool ignoreEnabled) {
@ -40,9 +39,9 @@ void UsersScriptingInterface::personalMute(const QUuid& nodeID, bool muteEnabled
DependencyManager::get<NodeList>()->personalMuteNodeBySessionID(nodeID, muteEnabled);
}
void UsersScriptingInterface::requestPersonalMuteStatus(const QUuid& nodeID) {
// ask the Audio Mixer via the NodeList for the Personal Mute status associated with the given session ID
DependencyManager::get<NodeList>()->requestPersonalMuteStatus(nodeID);
bool UsersScriptingInterface::getPersonalMuteStatus(const QUuid& nodeID) {
// ask the NodeList for the Personal Mute status associated with the given session ID
return DependencyManager::get<NodeList>()->isPersonalMutingNode(nodeID);
}
void UsersScriptingInterface::kick(const QUuid& nodeID) {

View file

@ -59,7 +59,7 @@ public slots:
* @function Users.requestPersonalMuteStatus
* @param {nodeID} nodeID The node or session ID of the user whose personal mute status you want.
*/
void requestPersonalMuteStatus(const QUuid& nodeID);
bool getPersonalMuteStatus(const QUuid& nodeID);
/**jsdoc
* Kick another user.
@ -132,12 +132,6 @@ signals:
*/
void usernameFromIDReply(const QString& nodeID, const QString& username, const QString& machineFingerprint);
/**jsdoc
* Notifies scripts of the Personal Mute status associated with a UUID.
* @function Users.usernameFromIDReply
*/
void personalMuteStatusReply(const QString& nodeID, bool isPersonalMuted);
private:
bool getRequestsDomainListData();
void setRequestsDomainListData(bool requests);

View file

@ -136,7 +136,7 @@ function populateUserList() {
// and ignore status from AudioMixer/AvatarMixer
// (as long as we're not requesting it for our own ID)
if (id) {
Users.requestPersonalMuteStatus(id);
avatarPalDatum['personalMute'] = Users.getPersonalMuteStatus(id);
avatarPalDatum['ignore'] = Users.getIgnoreStatus(id);
}
data.push(avatarPalDatum);
@ -165,14 +165,6 @@ function usernameFromIDReply(id, username, machineFingerprint) {
pal.sendToQml({ method: 'updateUsername', params: data });
}
// The function that handles the personal muted status from the AudioMixer
function personalMuteStatusReply(id, isPersonalMuted) {
var data = [id, isPersonalMuted];
print('Personal Muted Status Data:', JSON.stringify(data));
// Ship the data off to QML
pal.sendToQml({ method: 'updatePersonalMutedStatus', params: data });
}
var pingPong = true;
function updateOverlays() {
var eye = Camera.position;
@ -343,7 +335,6 @@ button.clicked.connect(onClicked);
pal.visibleChanged.connect(onVisibleChanged);
pal.closed.connect(off);
Users.usernameFromIDReply.connect(usernameFromIDReply);
Users.personalMuteStatusReply.connect(personalMuteStatusReply);
function onIgnore(sessionId) { // make it go away in the usual way, since we'll still get data keeping it live
// Why doesn't this work from .qml? (crashes)
@ -361,7 +352,6 @@ Script.scriptEnding.connect(function () {
pal.closed.disconnect(off);
Users.usernameFromIDReply.disconnect(usernameFromIDReply);
Users.ignoredNode.disconnect(onIgnore);
Users.personalMuteStatusReply.disconnect(personalMuteStatusReply);
off();
});