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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//! Server-Sent Events (SSE) support for acton-service.
//!
//! This module provides one-way server-to-client real-time communication.
//! SSE is simpler than WebSocket for cases where bidirectional communication
//! isn't needed.
//!
//! # Features
//!
//! - **One-way streaming**: Efficient server-to-client event delivery
//! - **Automatic reconnection**: Browser handles reconnects with Last-Event-ID
//! - **Keep-alive**: Configurable heartbeat to prevent connection timeouts
//! - **Named events**: Support for event types with `event:` field
//! - **HTMX integration**: First-class support for HTMX SSE extension
//! - **Broadcasting**: Efficient multi-connection event delivery
//!
//! # Quick Start
//!
//! ```rust,ignore
//! use acton_service::prelude::*;
//! use acton_service::sse::{Sse, Event, KeepAlive, SseEventExt};
//! use futures::stream::{self, Stream};
//! use std::convert::Infallible;
//! use std::time::Duration;
//!
//! async fn events_handler() -> Sse<impl Stream<Item = Result<Event, Infallible>>> {
//! let stream = stream::repeat_with(|| {
//! Event::default().data("heartbeat")
//! })
//! .map(Ok)
//! .throttle(Duration::from_secs(1));
//!
//! Sse::new(stream).keep_alive(KeepAlive::default())
//! }
//! ```
//!
//! # HTMX Integration
//!
//! ```rust,ignore
//! use acton_service::sse::htmx::htmx_event;
//!
//! // In your handler
//! let event = htmx_event("notifications", "<li>New message!</li>");
//! ```
//!
//! ```html
//! <!-- In your HTML -->
//! <ul hx-ext="sse" sse-connect="/notifications" sse-swap="notifications">
//! <!-- New items will be appended here -->
//! </ul>
//! ```
//!
//! # Broadcasting to Multiple Connections
//!
//! ```rust,ignore
//! use acton_service::sse::{SseBroadcaster, BroadcastMessage};
//! use std::sync::Arc;
//!
//! let broadcaster = Arc::new(SseBroadcaster::new());
//!
//! // In your SSE handler
//! let mut receiver = broadcaster.subscribe();
//!
//! // In your trigger endpoint
//! broadcaster.broadcast(BroadcastMessage::new("New data!"));
//! ```
// Re-exports
pub use ;
pub use SseConfig;
pub use ;
pub use ;
pub use ;
// Re-export axum SSE types for convenience
pub use ;