Skip to content

Commit

Permalink
add image msg header
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Chen <[email protected]>
  • Loading branch information
iche033 committed Apr 10, 2021
1 parent 88c2355 commit e759e22
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion plugins/websocket_server/WebsocketServer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,15 @@ void WebsocketServer::OnWebsocketSubscribedImageMessage(

if (timeDelta > this->publishPeriod)
{
// Get the header, or build a new header if it doesn't exist.
auto header = this->publishHeaders.find(_info.Topic());
if (header == this->publishHeaders.end())
{
this->publishHeaders[_info.Topic()] = BUILD_HEADER(
this->operations[PUBLISH], _info.Topic(), _info.Type());
header = this->publishHeaders.find(_info.Topic());
}

// Store the last time this topic was published.
this->topicTimestamps[_info.Topic()] = systemTime;

Expand All @@ -908,13 +917,16 @@ void WebsocketServer::OnWebsocketSubscribedImageMessage(
image.SavePNGToBuffer(buffer);
std::string img(reinterpret_cast<char *>(buffer.data()), buffer.size());

// Construct the final message.
std::string msg = header->second + img;

// Send the message
for (const int &socketId : iter->second)
{
if (this->connections.find(socketId) != this->connections.end())
{
this->QueueMessage(this->connections[socketId].get(),
img.c_str(), img.length());
msg.c_str(), msg.length());
}
}
}
Expand Down

0 comments on commit e759e22

Please sign in to comment.