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
//! Send your application's events to the browser over WebSockets, so a page updates when an order
//! ships or a teammate joins a room.
//!
//! An event with `#[event(broadcast(..))]` publishes its `pub` fields to the channels it names,
//! through a [Reverb](https://reverb.laravel.com) server, each time you dispatch it. Use
//! `#[event(broadcast)]` and implement [`Broadcast`] when the channels or the payload need code.
//! [`event`] dispatches with options such as [`to_others`](PendingBroadcast::to_others).
//! [`public`], [`private`], and [`presence`] publish a message that isn't an event. [`Channels`]
//! authorizes subscriptions to private and presence channels, and [`fake`](fake()) records
//! broadcasts in tests.
//!
//! ```no_run
//! use laravel::event::Event;
//!
//! #[derive(Event)]
//! #[event(broadcast(private = "orders.{order_id}"))]
//! pub struct OrderShipped {
//! pub order_id: i64,
//! pub tracking_number: String,
//! }
//!
//! # async fn example() -> laravel::Result<()> {
//! OrderShipped { order_id: 42, tracking_number: "TRACK-123".into() }.dispatch().await?;
//! # Ok(()) }
//! ```
//!
//! To learn how to configure broadcasting, authorize channels, and receive broadcasts with Echo,
//! check out the [broadcasting guide](https://github.com/laravel/rust-framework/blob/0.x/docs/broadcasting.md).
//!
//! # Delivery
//!
//! A dispatch publishes through a queued delivery job, unless the attribute says `immediately`.
//! Laravel prepares and queues the broadcast before the event's listeners run, and an error in
//! either step stops the dispatch. Inside a database transaction, they wait for the commit, after the
//! event's `at_dispatch` listeners. A later listener failure doesn't undo a delivery job the
//! queue already accepted. The dispatcher evaluates the event's condition, channels, name, and
//! payload once, and stores them in the delivery job, so every attempt publishes the same values.
//! Credentials come from the worker's configuration. Delivery jobs allow three attempts, with
//! one-second and five-second backoffs, and store the payload in queue storage. If Reverb refuses
//! a broadcast with a `4xx` status other than `408`, `409`, or `429`, such as a `401` for a wrong
//! secret, the job fails without another attempt. The `sync` queue connection publishes in the
//! dispatching process. The `log` and `discard` connections follow the same queue and transaction
//! rules, and issue no subscription grants.
//!
//! With `dispatch_background`, Laravel reports broadcast errors rather than returning them,
//! and a background event isn't durable until its delivery job reaches the queue. A process
//! failure between a database commit and queue submission can lose a broadcast. If a request
//! times out after Reverb accepts it, a retry can deliver the event twice. Publishing to more than
//! 100 channels uses several requests, so a failed later request leaves earlier channels
//! delivered. Concurrent workers can deliver events out of order, so include a revision in the
//! payload when subscribers need to reject stale updates.
//!
//! Channel names allow ASCII letters, digits, and `_ - = @ , . ;`, and the full name, prefix
//! included, may be up to 200 bytes. Event names may be up to 200 bytes and can't start with the
//! reserved `pusher:` prefix. A placeholder in `#[event(broadcast(..))]` names a field, formats it
//! with `Display`, and may name a private field. Broadcast events are structs with named fields,
//! or unit structs, without generic parameters.
pub use *;
pub use ;
pub use ;