1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! rustlavel-ws: WebSockets and broadcasting, written from scratch on Tokio.
//!
//! Laravel answers real-time with Echo on the client and Reverb on the server.
//! This is both halves in one crate: an RFC 6455 implementation — handshake,
//! framing, control frames, close handshake — and a [`Broadcaster`] with
//! public, private and presence channels on top of it.
//!
//! # An echo server
//!
//! ```ignore
//! use rustlavel_ws::{websocket, WebSocket};
//!
//! r.get("/ws", websocket(|mut socket, _request| async move {
//! while let Some(message) = socket.recv().await {
//! let _ = socket.send(message).await;
//! }
//! }));
//! ```
//!
//! `recv` yields whole [`Message`]s. Fragments are reassembled, pings are
//! answered, text is checked for UTF-8, and a close is replied to with a close —
//! none of which an application should have to remember.
//!
//! # Broadcasting
//!
//! ```ignore
//! use rustlavel_ws::Broadcaster;
//!
//! let broadcaster = Broadcaster::new()
//! .authorize(|request: &Request, channel: &str| {
//! request.extension::<User>().is_some_and(|user| user.may_watch(channel))
//! });
//!
//! r.get("/broadcasting", broadcaster.route());
//!
//! // From anywhere: a controller, a queued job, a background task.
//! broadcaster.broadcast("orders", "order.created", Json::object([("id", 7.into())]));
//! ```
//!
//! The wire protocol clients speak is documented on [`broadcast`].
//!
//! # What is reported
//!
//! `ws.connected`, `ws.message`, `ws.disconnected` and `broadcast.sent` go to
//! `rustlavel_core::events`, carrying the channel, counts and durations — and
//! never a payload. A socket's contents are the application's business.
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use Message;
pub use ;