pub struct LiveReload { /* private fields */ }Expand description
SSE live-reload broadcaster. Cheap to clone; share across handlers.
Implementations§
Source§impl LiveReload
impl LiveReload
Sourcepub fn new(endpoint: impl Into<String>) -> Self
pub fn new(endpoint: impl Into<String>) -> Self
Create a new broadcaster.
endpoint should be a root-relative URL path (e.g.
"/__webui/livereload"). Use a root-relative path so the script
works when the served pages set <base href> for sub-path
deployments.
Sourcepub fn client_script(&self) -> &str
pub fn client_script(&self) -> &str
The inline <script>...</script> that subscribes to this endpoint.
Inject this into served HTML.
Sourcepub fn inject(&self, html: &str) -> String
pub fn inject(&self, html: &str) -> String
Inject Self::client_script immediately before </body> in
html. Appends to the end if no closing tag is found.
Sourcepub fn broadcast_reload(&self)
pub fn broadcast_reload(&self)
Broadcast a Reload event to all connected clients. A failed send
(no subscribers) is ignored — that’s a normal state when no browser
is currently connected.
Sourcepub fn broadcast_error(&self, msg: impl Into<String>)
pub fn broadcast_error(&self, msg: impl Into<String>)
Broadcast a reload-error event. Newlines in the message are
replaced with spaces to keep the SSE frame on one line.
Sourcepub fn sender(&self) -> &Sender<ReloadEvent>
pub fn sender(&self) -> &Sender<ReloadEvent>
Direct access to the underlying broadcaster, e.g. to count
subscribers (sender().receiver_count()).
Trait Implementations§
Source§impl Clone for LiveReload
impl Clone for LiveReload
Source§fn clone(&self) -> LiveReload
fn clone(&self) -> LiveReload
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more