WebSocketServer: Make QObject again

This commit is contained in:
tt2468 2021-04-28 22:13:02 -07:00
parent 0370b5882d
commit b43fc4fec6
2 changed files with 5 additions and 7 deletions

View File

@ -13,6 +13,7 @@
#include "plugin-macros.generated.h" #include "plugin-macros.generated.h"
WebSocketServer::WebSocketServer() : WebSocketServer::WebSocketServer() :
QObject(nullptr),
_sessions() _sessions()
{ {
// Randomize the random number generator // Randomize the random number generator
@ -196,11 +197,6 @@ void WebSocketServer::BroadcastEvent(uint64_t requiredIntent, std::string eventT
; ;
} }
WebSocketSession *WebSocketServer::GetWebSocketSession(websocketpp::connection_hdl hdl)
{
return new WebSocketSession();
}
void WebSocketServer::onOpen(websocketpp::connection_hdl hdl) void WebSocketServer::onOpen(websocketpp::connection_hdl hdl)
{ {
auto conn = _server.get_con_from_hdl(hdl); auto conn = _server.get_con_from_hdl(hdl);

View File

@ -12,8 +12,10 @@
using json = nlohmann::json; using json = nlohmann::json;
class WebSocketServer class WebSocketServer : QObject
{ {
Q_OBJECT
public: public:
enum WebSocketCloseCode: uint16_t { enum WebSocketCloseCode: uint16_t {
UnknownReason = 4000, UnknownReason = 4000,
@ -71,11 +73,11 @@ class WebSocketServer
std::string GetConnectUrl(); std::string GetConnectUrl();
public Q_SLOTS:
void BroadcastEvent(uint64_t requiredIntent, std::string eventType, json eventData = nullptr); void BroadcastEvent(uint64_t requiredIntent, std::string eventType, json eventData = nullptr);
private: private:
void ServerRunner(); void ServerRunner();
WebSocketSession *GetWebSocketSession(websocketpp::connection_hdl hdl);
void onOpen(websocketpp::connection_hdl hdl); void onOpen(websocketpp::connection_hdl hdl);
void onClose(websocketpp::connection_hdl hdl); void onClose(websocketpp::connection_hdl hdl);