Commit 31dac225 authored by Hubert Denkmair's avatar Hubert Denkmair

stringify json message only once (and broadcast)

parent 239e1a59
......@@ -2,8 +2,7 @@
#include <iostream>
#include <string>
#include <TcpServer/EPoll.h>
#include <nlohmann/json.hpp>
using nlohmann::json;
#include "JsonProtocol.h"
RelayServer::RelayServer()
{
......@@ -38,18 +37,22 @@ int RelayServer::Run()
con->FrameComplete(frame_id, _tcpProtocol);
auto key = con->getViewerKey();
if (logMessages.find(key) == logMessages.end())
if (logMessages.find(key) != logMessages.end())
{
return;
}
for (auto& item: logMessages.at(key))
{
con->LogMessage(frame_id, item.message);
for (auto& item: logMessages.at(key))
{
con->LogMessage(frame_id, item.message);
}
}
}
);
_tcpProtocol.ClearLogItems();
for (auto& msg: _tcpProtocol.GetPendingMessages())
{
std::string s = json(*msg).dump();
h.getDefaultGroup<uWS::SERVER>().broadcast(s.data(), s.length(), uWS::OpCode::TEXT);
}
}
);
epoll.AddFileDescriptor(_clientSocket, EPOLLIN|EPOLLPRI|EPOLLERR);
......
......@@ -16,12 +16,6 @@ void WebsocketConnection::FrameComplete(uint64_t frame_id, const TcpProtocol &pr
sendInitialData(proto);
_firstFrameSent = true;
}
msgpack::sbuffer buf;
for (auto& msg: proto.GetPendingMessages())
{
sendString(json(*msg).dump());
}
}
void WebsocketConnection::LogMessage(uint64_t frame_id, const std::string &message)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment