working on broadcast

This commit is contained in:
talksik
2024-01-27 12:49:49 -08:00
parent fa9d2a8478
commit 3a63dfbe7b
2 changed files with 52 additions and 44 deletions
+52 -44
View File
@@ -36,51 +36,59 @@ int main()
.cert_file_name = "misc/cert.pem", .cert_file_name = "misc/cert.pem",
.passphrase = "1234"}) .passphrase = "1234"})
.ws<PerSocketData>( .ws<PerSocketData>(
"/*", {/* Settings */ "/*",
.compression = uWS::CompressOptions(uWS::DEDICATED_COMPRESSOR_4KB | uWS::DEDICATED_DECOMPRESSOR), {/* Settings */
.maxPayloadLength = 100 * 1024 * 1024, .compression = uWS::CompressOptions(uWS::DEDICATED_COMPRESSOR_4KB | uWS::DEDICATED_DECOMPRESSOR),
.idleTimeout = 16, .maxPayloadLength = 100 * 1024 * 1024,
.maxBackpressure = 100 * 1024 * 1024, .idleTimeout = 16,
.closeOnBackpressureLimit = false, .maxBackpressure = 100 * 1024 * 1024,
.resetIdleTimeoutOnSend = false, .closeOnBackpressureLimit = false,
.sendPingsAutomatically = true, .resetIdleTimeoutOnSend = false,
/* Handlers */ .sendPingsAutomatically = true,
.upgrade = nullptr, /* Handlers */
.open = .upgrade = nullptr,
[](uWS::WebSocket<false, true, PerSocketData> *ws) { .open =
auto user_data = ws->getUserData(); [](uWS::WebSocket<false, true, PerSocketData> *ws) {
user_data->created_at = DateTime::now(); auto user_data = ws->getUserData();
user_data->created_at = DateTime::now();
DateTime::outputTime("Client connected at ", user_data->created_at); DateTime::outputTime("Client connected at ", user_data->created_at);
}, if (!ws->subscribe("*"))
.message = {
[](auto *ws, std::string_view message, uWS::OpCode opCode) { std::cout << "Failed to subscribe to * channel\n";
/* This is the opposite of what you probably want; compress if message is LARGER than 16 kb ws->close();
* 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; .message =
ws->send(message, opCode, message.length() < 16 * 1024); [](uWS::WebSocket<false, true, PerSocketData> *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
.dropped = * the reason we do the opposite here; compress if SMALLER than 16 kb is to allow for
[](auto * /*ws*/, std::string_view /*message*/, uWS::OpCode /*opCode*/) { * benchmarking of large message sending without compression */
/* A message was dropped due to set maxBackpressure and closeOnBackpressureLimit limit */ std::cout << "Message received: " << message << std::endl;
}, ws->send(message, opCode, false);
.drain = ws->publish("*", message, opCode, false);
[](auto * /*ws*/) { },
/* Check ws->getBufferedAmount() here */ .dropped =
}, [](auto * /*ws*/, std::string_view /*message*/, uWS::OpCode /*opCode*/) {
.ping = /* A message was dropped due to set maxBackpressure and closeOnBackpressureLimit limit */
[](auto * /*ws*/, std::string_view) { },
/* Not implemented yet */ .drain =
}, [](auto * /*ws*/) {
.pong = /* Check ws->getBufferedAmount() here */
[](auto * /*ws*/, std::string_view) { },
/* Not implemented yet */ .ping =
}, [](auto * /*ws*/, std::string_view) {
.close = /* Not implemented yet */
[](auto * /*ws*/, int /*code*/, std::string_view /*message*/) { },
/* You may access ws->getUserData() here */ .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, .listen(9001,
[](auto *listen_socket) { [](auto *listen_socket) {
if (listen_socket) if (listen_socket)