pub struct Peer<S> {
pub id: PeerId,
pub state: S,
pub last_seen: Instant,
/* private fields */
}Expand description
One connected peer inside a Room: outbound channel, liveness,
and app-defined per-peer state S (position, name, flags, …).
Resuma does not interpret S — it is stored and handed back so apps can build
roster/snapshot messages without maintaining a second peer map of their own.
Fields§
§id: PeerId§state: S§last_seen: InstantImplementations§
Source§impl<S> Peer<S>
impl<S> Peer<S>
Sourcepub fn send(&self, msg: impl Into<String>)
pub fn send(&self, msg: impl Into<String>)
Send a pre-serialized text message to this peer only. Silently drops if the peer’s writer task already exited (client disconnected mid-send) — callers should not treat this as fatal, the read loop will observe the close soon.
Sourcepub fn touch(&mut self)
pub fn touch(&mut self)
Refresh liveness. Call on every inbound message, not just heartbeats, so a
chatty-but-silent-on-ping client is not swept as stale.
Sourcepub fn allow_rate(&mut self, kind: &'static str, min_interval: Duration) -> bool
pub fn allow_rate(&mut self, kind: &'static str, min_interval: Duration) -> bool
Throttle a noisy message kind (e.g. "pose", "place", "remove") to at
most once per min_interval. Returns true the first time and again after
each interval elapses, false otherwise.
Generalizes the last_pose / last_place / last_remove / last_sync
fields a hand-rolled multiplayer relay needs one-per-message-type — here it
is a single map keyed by a &'static str tag apps choose per call site.