diff --git a/server/.cache/clangd/index/Main.cpp.3A7DAD75EE1835F0.idx b/server/.cache/clangd/index/Main.cpp.3A7DAD75EE1835F0.idx index d0f1da0..7b3db11 100644 Binary files a/server/.cache/clangd/index/Main.cpp.3A7DAD75EE1835F0.idx and b/server/.cache/clangd/index/Main.cpp.3A7DAD75EE1835F0.idx differ diff --git a/server/src/Main.cpp b/server/src/Main.cpp index bc527a1..4d8da15 100644 --- a/server/src/Main.cpp +++ b/server/src/Main.cpp @@ -36,51 +36,59 @@ int main() .cert_file_name = "misc/cert.pem", .passphrase = "1234"}) .ws( - "/*", {/* Settings */ - .compression = uWS::CompressOptions(uWS::DEDICATED_COMPRESSOR_4KB | uWS::DEDICATED_DECOMPRESSOR), - .maxPayloadLength = 100 * 1024 * 1024, - .idleTimeout = 16, - .maxBackpressure = 100 * 1024 * 1024, - .closeOnBackpressureLimit = false, - .resetIdleTimeoutOnSend = false, - .sendPingsAutomatically = true, - /* Handlers */ - .upgrade = nullptr, - .open = - [](uWS::WebSocket *ws) { - auto user_data = ws->getUserData(); - user_data->created_at = DateTime::now(); + "/*", + {/* Settings */ + .compression = uWS::CompressOptions(uWS::DEDICATED_COMPRESSOR_4KB | uWS::DEDICATED_DECOMPRESSOR), + .maxPayloadLength = 100 * 1024 * 1024, + .idleTimeout = 16, + .maxBackpressure = 100 * 1024 * 1024, + .closeOnBackpressureLimit = false, + .resetIdleTimeoutOnSend = false, + .sendPingsAutomatically = true, + /* Handlers */ + .upgrade = nullptr, + .open = + [](uWS::WebSocket *ws) { + auto user_data = ws->getUserData(); + user_data->created_at = DateTime::now(); - DateTime::outputTime("Client connected at ", user_data->created_at); - }, - .message = - [](auto *ws, std::string_view message, uWS::OpCode opCode) { - /* This is the opposite of what you probably want; compress if message is LARGER than 16 kb - * the reason we do the opposite here; compress if SMALLER than 16 kb is to allow for - * benchmarking of large message sending without compression */ - std::cout << "Message received: " << message << std::endl; - ws->send(message, opCode, message.length() < 16 * 1024); - }, - .dropped = - [](auto * /*ws*/, std::string_view /*message*/, uWS::OpCode /*opCode*/) { - /* A message was dropped due to set maxBackpressure and closeOnBackpressureLimit limit */ - }, - .drain = - [](auto * /*ws*/) { - /* Check ws->getBufferedAmount() here */ - }, - .ping = - [](auto * /*ws*/, std::string_view) { - /* Not implemented yet */ - }, - .pong = - [](auto * /*ws*/, std::string_view) { - /* Not implemented yet */ - }, - .close = - [](auto * /*ws*/, int /*code*/, std::string_view /*message*/) { - /* You may access ws->getUserData() here */ - }}) + DateTime::outputTime("Client connected at ", user_data->created_at); + if (!ws->subscribe("*")) + { + std::cout << "Failed to subscribe to * channel\n"; + ws->close(); + } + }, + .message = + [](uWS::WebSocket *ws, std::string_view message, uWS::OpCode opCode) { + /* This is the opposite of what you probably want; compress if message is LARGER than 16 kb + * the reason we do the opposite here; compress if SMALLER than 16 kb is to allow for + * benchmarking of large message sending without compression */ + std::cout << "Message received: " << message << std::endl; + ws->send(message, opCode, false); + ws->publish("*", message, opCode, false); + }, + .dropped = + [](auto * /*ws*/, std::string_view /*message*/, uWS::OpCode /*opCode*/) { + /* A message was dropped due to set maxBackpressure and closeOnBackpressureLimit limit */ + }, + .drain = + [](auto * /*ws*/) { + /* Check ws->getBufferedAmount() here */ + }, + .ping = + [](auto * /*ws*/, std::string_view) { + /* Not implemented yet */ + }, + .pong = + [](auto * /*ws*/, std::string_view) { + /* Not implemented yet */ + }, + .close = + [](auto * /*ws*/, int /*code*/, std::string_view /*message*/) { + /* You may access ws->getUserData() here */ + std::cout << "Client disconnected\n"; + }}) .listen(9001, [](auto *listen_socket) { if (listen_socket)