Skip to main content

Module push

Module push 

Source

Structs§

PushPlugin
The two routes @live(...)/[broadcast] need, bundled for larust_http::Router::plugin - sugar for the two .get calls this module’s own doc comment shows an app writing by hand today.

Functions§

broadcast
Pushes html to every browser tab currently subscribed to channel via an open @live(...) WebSocket - call this from wherever server state actually changes (an event listener, a controller action), not from inside the request that’s rendering the page itself. A no-op, not an error, when nobody’s listening (Sender::send returning Err only ever means “zero receivers exist right now”): ordinary fire-and-forget pub/sub semantics, since there’s no reason a broadcast should fail just because no browser tab happens to have this channel open at the moment.
runtime_js
GET /__larust_push/runtime.js - the vendored client runtime, same “served from the installed crate itself, not copied into public/js/” reasoning as crate::routes::runtime_js.
socket
GET /__larust_push/{channel} - upgrades to a WebSocket and streams every [broadcast] call’s HTML straight through, verbatim, for the lifetime of the connection. Pure server → client push in v1: no client → server message is ever acted on (an inbound message is only read at all to detect the browser tab closing the connection).
wrap
Wraps inner_html in the same data-live-channel-carrying <div> @live(...)’s own codegen produces for its initial render - the client’s DOM patcher matches an incoming broadcast against the existing root element by replacing it wholesale if position/tag don’t line up, so a broadcast payload needs this exact wrapper shape, not just the inner content, to patch cleanly in place instead of being discarded or mismatched.