From 9201695dac941765f5bad01a41d63105a0205a6a Mon Sep 17 00:00:00 2001 From: Nate Koenig Date: Mon, 12 Apr 2021 08:48:15 -0700 Subject: [PATCH 1/3] Support particle_emitters in the websocket server (#104) * Support particle_emitters in the websocket server Signed-off-by: Nate Koenig * update documentation Signed-off-by: Nate Koenig * Spelling Signed-off-by: Nate Koenig Co-authored-by: Nate Koenig --- plugins/websocket_server/WebsocketServer.cc | 31 +++++++++++++++++++++ plugins/websocket_server/WebsocketServer.hh | 9 +++--- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/plugins/websocket_server/WebsocketServer.cc b/plugins/websocket_server/WebsocketServer.cc index 265421cb..2bdf8c51 100644 --- a/plugins/websocket_server/WebsocketServer.cc +++ b/plugins/websocket_server/WebsocketServer.cc @@ -779,6 +779,37 @@ void WebsocketServer::OnMessage(int _socketId, const std::string &_msg) this->QueueMessage(this->connections[_socketId].get(), data.c_str(), data.length()); } + /// \todo(nkoeng) Deprecate this in Ignition Fortress, and instruct users + /// to rely on the "scene" message. + else if (frameParts[0] == "particle_emitters") + { + igndbg << "Particle emitter request received for world[" + << frameParts[1] << "]\n"; + ignition::msgs::Empty req; + req.set_unused(true); + + ignition::msgs::ParticleEmitter_V rep; + bool result; + unsigned int timeout = 2000; + + std::string serviceName = std::string("/world/") + frameParts[1] + + "/particle_emitters"; + + bool executed = this->node.Request(serviceName, req, timeout, rep, result); + if (!executed || !result) + { + ignerr << "Failed to get the particle emitter information for " + << frameParts[1] << " world.\n"; + } + + std::string data = BUILD_MSG(this->operations[PUBLISH], frameParts[0], + std::string("ignition.msgs.ParticleEmitter_V"), + rep.SerializeAsString()); + + // Queue the message for delivery. + this->QueueMessage(this->connections[_socketId].get(), + data.c_str(), data.length()); + } else if (frameParts[0] == "sub") { // Store the relation of socketId to subscribed topic. diff --git a/plugins/websocket_server/WebsocketServer.hh b/plugins/websocket_server/WebsocketServer.hh index 85c3bb13..853dcdfa 100644 --- a/plugins/websocket_server/WebsocketServer.hh +++ b/plugins/websocket_server/WebsocketServer.hh @@ -86,10 +86,11 @@ namespace ignition /// 2. "pub": Publish a message from the Ignition Transport topic in /// the `topic_name` component, /// 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. + /// 4. "topics-types": Get the list of available topics and their + /// message types, + /// 5. "protos": Get a string containing all the protobuf + /// definitions, and + /// 6. "particle_emitters": Get the list of particle emitters. /// /// The `topic_name` component is mandatory for the "sub" and "pub" /// operations. If present, it must be the name of an Ignition Transport From 0d8b9a3c24d98ec75bf0c6fbd36655564845d196 Mon Sep 17 00:00:00 2001 From: Nate Koenig Date: Mon, 12 Apr 2021 11:47:28 -0700 Subject: [PATCH 2/3] Support unsubscribing from a topic (#107) * Support unsubscribing from a topic Signed-off-by: Nate Koenig * extract to erase Signed-off-by: Nate Koenig Co-authored-by: Nate Koenig --- plugins/websocket_server/WebsocketServer.cc | 26 +++++++++++++++++++++ plugins/websocket_server/WebsocketServer.hh | 8 ++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/plugins/websocket_server/WebsocketServer.cc b/plugins/websocket_server/WebsocketServer.cc index 2bdf8c51..144d0221 100644 --- a/plugins/websocket_server/WebsocketServer.cc +++ b/plugins/websocket_server/WebsocketServer.cc @@ -262,6 +262,7 @@ int rootCallback(struct lws *_wsi, igndbg << "LWS_CALLBACK_HTTP\n"; return httpCallback(_wsi, _reason, _user, _in, _len); break; + // Publish outboud messages case LWS_CALLBACK_SERVER_WRITEABLE: { @@ -858,7 +859,32 @@ void WebsocketServer::OnMessage(int _socketId, const std::string &_msg) this->node.Subscribe(frameParts[1], &WebsocketServer::OnWebsocketSubscribedImageMessage, this); } + else if (frameParts[0] == "unsub") + { + igndbg << "Unsubscribe request for topic[" << frameParts[1] << "]\n"; + std::map>::iterator topicConnectionIter = + this->topicConnections.find(frameParts[1]); + if (topicConnectionIter != this->topicConnections.end()) + { + // Remove from the topic connections map + topicConnectionIter->second.erase(_socketId); + + // Only unsubscribe from the Ignition Transport topic if there are no + // more websocket connections. + if (topicConnectionIter->second.empty()) + { + igndbg << "Unsubscribing from Ignition Transport Topic[" + << frameParts[1] << "]\n"; + this->node.Unsubscribe(frameParts[1]); + } + } + else + { + ignwarn << "The websocket server is not subscribed to topic[" + << frameParts[1] << "]. Unable to unsubscribe from the topic\n"; + } + } } ////////////////////////////////////////////////// diff --git a/plugins/websocket_server/WebsocketServer.hh b/plugins/websocket_server/WebsocketServer.hh index 853dcdfa..b1cb0f19 100644 --- a/plugins/websocket_server/WebsocketServer.hh +++ b/plugins/websocket_server/WebsocketServer.hh @@ -91,10 +91,12 @@ namespace ignition /// 5. "protos": Get a string containing all the protobuf /// definitions, and /// 6. "particle_emitters": Get the list of particle emitters. + /// definitions. + /// 7. "unsub": Unsubscribe from the topic in the `topic_name` component /// - /// The `topic_name` component is mandatory for the "sub" and "pub" - /// operations. If present, it must be the name of an Ignition Transport - /// topic. + /// The `topic_name` component is mandatory for the "sub", "pub", and + /// "unsub" operations. If present, it must be the name of an Ignition + /// Transport topic. /// /// The `message_type` component is mandatory for the "pub" operation. If /// present it names the Ignition Message type, such as From 460cfa89b23579643b602498142db1316932a7e2 Mon Sep 17 00:00:00 2001 From: Nate Koenig Date: Mon, 12 Apr 2021 13:36:48 -0700 Subject: [PATCH 3/3] prepare for 3.2.0 (#108) Signed-off-by: Nate Koenig Co-authored-by: Nate Koenig --- CMakeLists.txt | 2 +- Changelog.md | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 254083f9..47e07295 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.5.1 FATAL_ERROR) #============================================================================ # Initialize the project #============================================================================ -project(ignition-launch3 VERSION 3.1.1) +project(ignition-launch3 VERSION 3.2.0) #============================================================================ # Find ignition-cmake diff --git a/Changelog.md b/Changelog.md index 766c3d8a..bd563d37 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,23 @@ ## Ignition Launch 3.x +### Ignition Launch 3.2.0 (2021-04-12) + +1. Support unsubscribing from a topic in the websocket server. + * [Pull request 107](https://github.com/ignitionrobotics/ign-launch/pull/107) + +1. Support particle_emitters in the websocket server. + * [Pull request 104](https://github.com/ignitionrobotics/ign-launch/pull/104) + +1. Support getting topic names and message types in the websocket server. + * [Pull request 102](https://github.com/ignitionrobotics/ign-launch/pull/102) + +1. Image streaming over websocket. + * [Pull request 97](https://github.com/ignitionrobotics/ign-launch/pull/97) + +1. Treat IGN_LAUNCH_CONFIG_PATH as a path list. + * [Pull request 93](https://github.com/ignitionrobotics/ign-launch/pull/93) + + ### Ignition Launch 3.1.1 (2021-01-08) 1. All changes up to and including those in version 2.2.1.