Expand description
§wabot-feature-socket-controller
Socket.IO controllers. Port of
wabot-ts/src/feature/socket-controller, built on
socketioxide.
#[injectable]
struct RoomController { rooms: Arc<Rooms> }
#[socket_controller("/rooms", handshake(ApiKeyHandshake))]
impl RoomController {
#[on_socket_event("connection")]
async fn on_connect(&self, socket: SocketRef) -> SocketResult<()> { … }
#[on_socket_event("join")]
async fn join(&self, req: JoinRoom, socket: SocketRef) -> SocketResult<Joined> { … }
}An event handler takes the validated payload and the socket, and whatever it returns is sent back through the client’s acknowledgement callback — so a Socket.IO event reads like a request/response, which is how clients actually use them.
§What a connection is
Each connection gets a child container, built once at handshake and reused for every event on that socket. That is the analogue of the per-request container in REST: a handshake middleware authenticates and registers what it learned, and every later event on that socket resolves it.
handshake → middlewares → child container (+ Auth, + whatever) → events§Refusing a connection
A HandshakeMiddleware that returns Err rejects the handshake:
the client gets a connect error and no events are ever wired.
Rejecting at the handshake rather than per event is the point —
otherwise every handler would have to re-check, and the one that
forgot would be the hole.
Re-exports§
pub use runtime::register_socket_namespace;pub use runtime::HandshakeEntry;pub use runtime::SocketEventEntry;pub use runtime::SocketEventFn;pub use server::run_socket_controllers;pub use server::socket_layer;pub use server::SocketServerConfig;pub use testing::EmittedEvent;pub use testing::SocketHarness;pub use socketioxide;
Modules§
- runtime
- Per-connection wiring — the part every
#[socket_controller]shares. Port ofrunSocketControllers.ts. - server
- Serving the socket namespaces.
- testing
- Drive socket events in a test, without a connection.
Structs§
- Socket
Controller Registration - Everything a
#[socket_controller]needs to attach itself.
Enums§
- AckSink
- Where a handler’s answer goes.
- Socket
Error
Traits§
- Handshake
Middleware - Runs at handshake, before any event is wired.
Functions§
- ack_
with - Send
valueback through the ack. - connection_
container - The connection’s container, from inside an event handler.