mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 04:44:11 +02:00
implement subscribe/unsubscribe in MessagesClient
This commit is contained in:
parent
6b61ec569c
commit
f9a674bca5
2 changed files with 29 additions and 0 deletions
|
@ -106,6 +106,33 @@ void MessagesClient::sendMessage(const QString& channel, const QString& message)
|
|||
}
|
||||
}
|
||||
|
||||
// FIXME - we should keep track of the channels we are subscribed to locally, and
|
||||
// in the event that they mixer goes away and/or comes back we should automatically
|
||||
// resubscribe to those channels
|
||||
void MessagesClient::subscribe(const QString& channel) {
|
||||
qDebug() << "MessagesClient::subscribe() channel:" << channel;
|
||||
auto nodeList = DependencyManager::get<NodeList>();
|
||||
SharedNodePointer messagesMixer = nodeList->soloNodeOfType(NodeType::MessagesMixer);
|
||||
|
||||
if (messagesMixer) {
|
||||
auto packetList = NLPacketList::create(PacketType::MessagesSubscribe, QByteArray(), true, true);
|
||||
packetList->write(channel.toUtf8());
|
||||
nodeList->sendPacketList(std::move(packetList), *messagesMixer);
|
||||
}
|
||||
}
|
||||
|
||||
void MessagesClient::unsubscribe(const QString& channel) {
|
||||
qDebug() << "MessagesClient::unsubscribe() channel:" << channel;
|
||||
auto nodeList = DependencyManager::get<NodeList>();
|
||||
SharedNodePointer messagesMixer = nodeList->soloNodeOfType(NodeType::MessagesMixer);
|
||||
|
||||
if (messagesMixer) {
|
||||
auto packetList = NLPacketList::create(PacketType::MessagesUnsubscribe, QByteArray(), true, true);
|
||||
packetList->write(channel.toUtf8());
|
||||
nodeList->sendPacketList(std::move(packetList), *messagesMixer);
|
||||
}
|
||||
}
|
||||
|
||||
void MessagesClient::handleNodeKilled(SharedNodePointer node) {
|
||||
if (node->getType() != NodeType::MessagesMixer) {
|
||||
return;
|
||||
|
|
|
@ -29,6 +29,8 @@ public:
|
|||
Q_INVOKABLE void init();
|
||||
|
||||
Q_INVOKABLE void sendMessage(const QString& channel, const QString& message);
|
||||
Q_INVOKABLE void subscribe(const QString& channel);
|
||||
Q_INVOKABLE void unsubscribe(const QString& channel);
|
||||
|
||||
private slots:
|
||||
void handleMessagesPacket(QSharedPointer<NLPacketList> packetList, SharedNodePointer senderNode);
|
||||
|
|
Loading…
Reference in a new issue