@@ -265,7 +265,8 @@ bool WebVideoServer::handle_list_streams(
265265 async_web_server_cpp::HttpConnectionPtr connection, const char * /* begin */ ,
266266 const char * /* end */ )
267267{
268- std::map<std::string, std::vector<std::string>> topics_by_type;
268+ std::map<std::string, std::vector<std::string>> topics_by_streamer_type;
269+ std::map<std::string, std::vector<std::string>> topics_by_snapshot_type;
269270 std::set<std::string> all_topics;
270271
271272 for (const auto & factory_pair : image_streamer_factories_) {
@@ -276,7 +277,20 @@ bool WebVideoServer::handle_list_streams(
276277 factory_pair.first .c_str (), factory_topics.size ());
277278 for (const auto & topic : factory_topics) {
278279 RCLCPP_DEBUG (get_logger (), " Topic: %s" , topic.c_str ());
279- topics_by_type[factory_pair.first ].push_back (topic);
280+ topics_by_streamer_type[factory_pair.first ].push_back (topic);
281+ all_topics.insert (topic);
282+ }
283+ }
284+
285+ for (const auto & factory_pair : snapshot_streamer_factories_) {
286+ RCLCPP_DEBUG (get_logger (), " Getting topics from factory: %s" , factory_pair.first .c_str ());
287+ std::vector<std::string> factory_topics =
288+ factory_pair.second ->get_available_topics (shared_from_this ());
289+ RCLCPP_DEBUG (get_logger (), " Factory %s returned %zu topics" ,
290+ factory_pair.first .c_str (), factory_topics.size ());
291+ for (const auto & topic : factory_topics) {
292+ RCLCPP_DEBUG (get_logger (), " Topic: %s" , topic.c_str ());
293+ topics_by_snapshot_type[factory_pair.first ].push_back (topic);
280294 all_topics.insert (topic);
281295 }
282296 }
@@ -297,8 +311,9 @@ bool WebVideoServer::handle_list_streams(
297311 for (const std::string & topic : all_topics) {
298312 std::vector<std::string> available_stream_viewers;
299313 std::vector<std::string> available_streams;
314+ std::vector<std::string> available_snapshots;
300315
301- for (const auto & factory_pair : topics_by_type ) {
316+ for (const auto & factory_pair : topics_by_streamer_type ) {
302317 const auto & type = factory_pair.first ;
303318 const auto & topics = factory_pair.second ;
304319 if (std::find (topics.begin (), topics.end (), topic) != topics.end ()) {
@@ -311,21 +326,41 @@ bool WebVideoServer::handle_list_streams(
311326 }
312327 }
313328
329+ for (const auto & factory_pair : topics_by_snapshot_type) {
330+ const auto & type = factory_pair.first ;
331+ const auto & topics = factory_pair.second ;
332+ if (std::find (topics.begin (), topics.end (), topic) != topics.end ()) {
333+ available_snapshots.push_back (
334+ " <a href=\" /snapshot?topic=" + topic +
335+ " &type=" + type + " \" >" + type + " </a>" );
336+ }
337+ }
338+
314339 connection->write (" <li>" );
315340 connection->write (topic);
316341 connection->write (" <ul>" );
317- connection->write (" <li>" );
318- connection->write (" <a href=\" /stream_viewer?topic=" + topic + " \" >" );
319- connection->write (" Stream Viewer</a> (" );
320- connection->write (boost::algorithm::join (available_stream_viewers, " , " ));
321- connection->write (" )" );
322- connection->write (" </li>" );
323- connection->write (" <li>" );
324- connection->write (" <a href=\" /stream?topic=" + topic + " \" >" );
325- connection->write (" Stream</a> (" );
326- connection->write (boost::algorithm::join (available_streams, " , " ));
327- connection->write (" )" );
328- connection->write (" </li>" );
342+ if (!available_streams.empty ()) {
343+ connection->write (" <li>" );
344+ connection->write (" <a href=\" /stream_viewer?topic=" + topic + " \" >" );
345+ connection->write (" Stream Viewer</a> (" );
346+ connection->write (boost::algorithm::join (available_stream_viewers, " , " ));
347+ connection->write (" )" );
348+ connection->write (" </li>" );
349+ connection->write (" <li>" );
350+ connection->write (" <a href=\" /stream?topic=" + topic + " \" >" );
351+ connection->write (" Stream</a> (" );
352+ connection->write (boost::algorithm::join (available_streams, " , " ));
353+ connection->write (" )" );
354+ connection->write (" </li>" );
355+ }
356+ if (!available_snapshots.empty ()) {
357+ connection->write (" <li>" );
358+ connection->write (" <a href=\" /snapshot?topic=" + topic + " \" >" );
359+ connection->write (" Snapshot</a> (" );
360+ connection->write (boost::algorithm::join (available_snapshots, " , " ));
361+ connection->write (" )" );
362+ connection->write (" </li>" );
363+ }
329364 connection->write (" </ul>" );
330365 connection->write (" </li>" );
331366
0 commit comments