Skip to content

Commit

Permalink
Merge 73e8943 into 9201695
Browse files Browse the repository at this point in the history
  • Loading branch information
nkoenig authored Apr 12, 2021
2 parents 9201695 + 73e8943 commit 5a4209d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
26 changes: 26 additions & 0 deletions plugins/websocket_server/WebsocketServer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
{
Expand Down Expand Up @@ -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<std::string, std::set<int>>::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";
}
}
}

//////////////////////////////////////////////////
Expand Down
8 changes: 5 additions & 3 deletions plugins/websocket_server/WebsocketServer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5a4209d

Please sign in to comment.