Skip to content

Commit

Permalink
Support getting topic names and message types (#102)
Browse files Browse the repository at this point in the history
Signed-off-by: Nate Koenig <[email protected]>

Co-authored-by: Nate Koenig <[email protected]>
  • Loading branch information
nkoenig and Nate Koenig authored Apr 9, 2021
1 parent 3296a3e commit 88c2355
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
31 changes: 31 additions & 0 deletions plugins/websocket_server/WebsocketServer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <ignition/common/Image.hh>
#include <ignition/common/Util.hh>
#include <ignition/msgs.hh>
#include <ignition/transport/Publisher.hh>

#include "MessageDefinitions.hh"
#include "WebsocketServer.hh"
Expand Down Expand Up @@ -700,6 +701,36 @@ void WebsocketServer::OnMessage(int _socketId, const std::string &_msg)
this->QueueMessage(this->connections[_socketId].get(),
data.c_str(), data.length());
}
else if (frameParts[0] == "topics-types")
{
igndbg << "Topic and message type list request recieved\n";
ignition::msgs::Publishers msg;

std::vector<std::string> topics;

// Get the list of topics
this->node.TopicList(topics);

// Store the topics in a message and serialize the message.
for (const std::string &topic : topics)
{
std::vector<transport::MessagePublisher> publishers;
this->node.TopicInfo(topic, publishers);
for (const transport::MessagePublisher &publisher : publishers)
{
msgs::Publish *pubMsg = msg.add_publisher();
pubMsg->set_topic(topic);
pubMsg->set_msg_type(publisher.MsgTypeName());
}
}

std::string data = BUILD_MSG(this->operations[PUBLISH], frameParts[0],
std::string("ignition.msgs.Publishers"), msg.SerializeAsString());

// Queue the message for delivery.
this->QueueMessage(this->connections[_socketId].get(),
data.c_str(), data.length());
}
else if (frameParts[0] == "worlds")
{
igndbg << "World info request recieved\n";
Expand Down
4 changes: 3 additions & 1 deletion plugins/websocket_server/WebsocketServer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ namespace ignition
/// 1. "sub": Subscribe to the topic in the `topic_name` component,
/// 2. "pub": Publish a message from the Ignition Transport topic in
/// the `topic_name` component,
/// 3. "topics": Get the list of available topics, and
/// 3. "topics": Get the list of available topics,
/// 3. "topics-types": Get the list of available topics and their
/// message types, and
/// 4. "protos": Get a string containing all the protobuf
/// definitions.
///
Expand Down

0 comments on commit 88c2355

Please sign in to comment.