diff --git a/plugins/websocket_server/WebsocketServer.cc b/plugins/websocket_server/WebsocketServer.cc index 6b535543..bd20d93b 100644 --- a/plugins/websocket_server/WebsocketServer.cc +++ b/plugins/websocket_server/WebsocketServer.cc @@ -19,6 +19,7 @@ #include #include #include +#include #include "MessageDefinitions.hh" #include "WebsocketServer.hh" @@ -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 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 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"; diff --git a/plugins/websocket_server/WebsocketServer.hh b/plugins/websocket_server/WebsocketServer.hh index 484cdddb..cf81c9c4 100644 --- a/plugins/websocket_server/WebsocketServer.hh +++ b/plugins/websocket_server/WebsocketServer.hh @@ -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. ///