handle socketActivated

This commit is contained in:
Brad Hefta-Gaub 2015-11-17 15:55:41 -08:00
parent 9c4286b6ca
commit 073215d067
2 changed files with 16 additions and 5 deletions

View file

@ -84,7 +84,6 @@ void MessagesClient::subscribe(const QString& channel) {
auto packetList = NLPacketList::create(PacketType::MessagesSubscribe, QByteArray(), true, true);
packetList->write(channel.toUtf8());
nodeList->sendPacketList(std::move(packetList), *messagesMixer);
qDebug() << "sending MessagesSubscribe for channel:" << channel;
}
}
@ -102,10 +101,20 @@ void MessagesClient::unsubscribe(const QString& channel) {
void MessagesClient::handleNodeAdded(SharedNodePointer node) {
if (node->getType() == NodeType::MessagesMixer) {
qDebug() << "messages-mixer node type added...";
for (const auto& channel : _subscribedChannels) {
qDebug() << "subscribing to channel:" << channel;
subscribe(channel);
if (!node->getActiveSocket()) {
connect(node.data(), &NetworkPeer::socketActivated, this, &MessagesClient::socketActivated);
} else {
resubscribeToAll();
}
}
}
void MessagesClient::socketActivated(const HifiSockAddr& sockAddr) {
resubscribeToAll();
}
void MessagesClient::resubscribeToAll() {
for (const auto& channel : _subscribedChannels) {
subscribe(channel);
}
}

View file

@ -38,8 +38,10 @@ signals:
private slots:
void handleMessagesPacket(QSharedPointer<NLPacketList> packetList, SharedNodePointer senderNode);
void handleNodeAdded(SharedNodePointer node);
void socketActivated(const HifiSockAddr& sockAddr);
protected:
void resubscribeToAll();
QSet<QString> _subscribedChannels;
};