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

stringify json message only once (and broadcast)

parent 239e1a59
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
@@ -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);
						}
					}
				}
			);
			_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);
+0 −6
Original line number Diff line number Diff line
@@ -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)