|
Orbit Framework 2.0.0
A high-performance asynchronous C++20 HTTP server framework.
|
A Socket.IO style event router for WebSockets with Room and Session support. More...
#include <EventRouter.hpp>
Classes | |
| struct | RoomBroadcaster |
Public Types | |
| using | SocketPtr = std::shared_ptr< EventSocket< SessionType > > |
Public Member Functions | |
| template<typename PayloadType > | |
| void | on (const std::string &event, std::function< void(EventSocket< SessionType > &, const PayloadType &)> handler) |
| void | on (const std::string &event, std::function< void(EventSocket< SessionType > &)> handler) |
| Registers an untyped event handler (no data expected). | |
| void | on_connect (std::function< void(EventSocket< SessionType > &)> handler) |
| Registers a connection handler. | |
| void | on_connect (std::function< void(EventSocket< SessionType > &, const http::HttpRequest &)> handler) |
Registers a connection handler that also sees the handshake request, to initialise the session from authenticated data (e.g. req.user set by jwt_auth() in attach()'s middleware) rather than from what the client sends later. The request is valid only during the call. | |
| void | on_disconnect (std::function< void(EventSocket< SessionType > &)> handler) |
| Registers a disconnection handler. | |
| void | attach (server::App &app, const std::string &path, std::vector< routing::Middleware > mws={}) |
| Attaches this EventRouter to the Orbit App at a specific path. | |
| RoomBroadcaster | to (const std::string &room) |
| void | join_room (const std::string &id, const std::string &room) |
| void | leave_room (const std::string &id, const std::string &room) |
| void | broadcast_to_room (const std::string &room, const std::string &msg) |
Private Member Functions | |
| SocketPtr | get_socket (const std::string &id) |
Private Attributes | |
| std::mutex | mutex_ |
| std::unordered_map< std::string, SocketPtr > | sockets_ |
| std::unordered_map< std::string, std::unordered_set< std::string > > | rooms_ |
| std::unordered_map< std::string, std::function< void(EventSocket< SessionType > &, const nlohmann::json &)> > | handlers_ |
| std::function< void(EventSocket< SessionType > &, const http::HttpRequest &)> | on_connect_ |
| std::function< void(EventSocket< SessionType > &)> | on_disconnect_ |
A Socket.IO style event router for WebSockets with Room and Session support.
| using orbit::websocket::EventRouter< SessionType >::SocketPtr = std::shared_ptr<EventSocket<SessionType> > |
|
inline |
Attaches this EventRouter to the Orbit App at a specific path.
| mws | Middleware run on the handshake before the upgrade, as for app.ws(): require_origin() (browsers do not apply CORS to WebSockets), jwt_auth(), rate limits. One that stops the request refuses the connection. |
|
inline |
|
inlineprivate |
|
inline |
|
inline |
|
inline |
Registers an untyped event handler (no data expected).
|
inline |
|
inline |
Registers a connection handler.
|
inline |
Registers a connection handler that also sees the handshake request, to initialise the session from authenticated data (e.g. req.user set by jwt_auth() in attach()'s middleware) rather than from what the client sends later. The request is valid only during the call.
|
inline |
Registers a disconnection handler.
|
inline |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |