pub struct PresenceTracker {
local_user: UserId,
users: HashMap<UserId, UserPresence>,
stale_timeout: u64,
pending_delta: Option<PresenceDelta>,
}Expand description
Presence tracker for a collaborative session.
Tracks all users’ cursors, selections, and status.
Fields§
§local_user: UserIdThe local user’s ID.
users: HashMap<UserId, UserPresence>All user presence records.
stale_timeout: u64Timeout for stale presence (milliseconds).
pending_delta: Option<PresenceDelta>Pending delta for replication.
Implementations§
Source§impl PresenceTracker
impl PresenceTracker
Sourcepub fn local_user(&self) -> &UserId
pub fn local_user(&self) -> &UserId
Get the local user ID.
Sourcepub fn set_stale_timeout(&mut self, timeout_ms: u64)
pub fn set_stale_timeout(&mut self, timeout_ms: u64)
Set the stale timeout.
Sourcepub fn local_presence(&self) -> Option<&UserPresence>
pub fn local_presence(&self) -> Option<&UserPresence>
Get the local user’s presence.
Sourcepub fn set_cursor(&mut self, document_id: impl Into<String>, cursor: Cursor)
pub fn set_cursor(&mut self, document_id: impl Into<String>, cursor: Cursor)
Update the local user’s cursor.
Sourcepub fn remove_cursor(&mut self, document_id: &str)
pub fn remove_cursor(&mut self, document_id: &str)
Remove the local user’s cursor from a document.
Sourcepub fn set_status(&mut self, status: UserStatus)
pub fn set_status(&mut self, status: UserStatus)
Set the local user’s status.
Sourcepub fn set_state(&mut self, key: impl Into<String>, value: impl Into<String>)
pub fn set_state(&mut self, key: impl Into<String>, value: impl Into<String>)
Set local user’s custom state.
Sourcepub fn get_user(&self, user_id: &UserId) -> Option<&UserPresence>
pub fn get_user(&self, user_id: &UserId) -> Option<&UserPresence>
Get a user’s presence.
Sourcepub fn all_users(&self) -> impl Iterator<Item = &UserPresence> + '_
pub fn all_users(&self) -> impl Iterator<Item = &UserPresence> + '_
Get all users.
Sourcepub fn online_users(&self) -> impl Iterator<Item = &UserPresence> + '_
pub fn online_users(&self) -> impl Iterator<Item = &UserPresence> + '_
Get all online users.
Sourcepub fn users_in_document(&self, document_id: &str) -> Vec<&UserPresence>
pub fn users_in_document(&self, document_id: &str) -> Vec<&UserPresence>
Get users with cursors in a document.
Sourcepub fn cursors_in_document(
&self,
document_id: &str,
) -> Vec<(&UserPresence, &Cursor)>
pub fn cursors_in_document( &self, document_id: &str, ) -> Vec<(&UserPresence, &Cursor)>
Get all cursors in a document (excluding local user).
Sourcepub fn online_count(&self) -> usize
pub fn online_count(&self) -> usize
Count online users.
Sourcepub fn take_delta(&mut self) -> Option<PresenceDelta>
pub fn take_delta(&mut self) -> Option<PresenceDelta>
Take the pending delta.
Sourcepub fn apply_delta(&mut self, delta: &PresenceDelta)
pub fn apply_delta(&mut self, delta: &PresenceDelta)
Apply a delta from another replica.
Sourcepub fn cleanup_stale(&mut self) -> Vec<UserId>
pub fn cleanup_stale(&mut self) -> Vec<UserId>
Clean up stale presence records.
Trait Implementations§
Source§impl Clone for PresenceTracker
impl Clone for PresenceTracker
Source§fn clone(&self) -> PresenceTracker
fn clone(&self) -> PresenceTracker
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for PresenceTracker
impl Debug for PresenceTracker
Source§impl Lattice for PresenceTracker
impl Lattice for PresenceTracker
Source§fn join(&self, other: &Self) -> Self
fn join(&self, other: &Self) -> Self
Join operation (least upper bound)
Must be commutative, associative, and idempotent
Source§fn partial_cmp_lattice(&self, other: &Self) -> Option<Ordering>
fn partial_cmp_lattice(&self, other: &Self) -> Option<Ordering>
Partial order derived from join: a ≤ b iff a ⊔ b = b
Source§fn join_assign(&mut self, other: &Self)
fn join_assign(&mut self, other: &Self)
Join-assign: self = self ⊔ other
Source§impl PartialEq for PresenceTracker
impl PartialEq for PresenceTracker
impl StructuralPartialEq for PresenceTracker
Auto Trait Implementations§
impl Freeze for PresenceTracker
impl RefUnwindSafe for PresenceTracker
impl Send for PresenceTracker
impl Sync for PresenceTracker
impl Unpin for PresenceTracker
impl UnwindSafe for PresenceTracker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more