PresenceTracker

Struct PresenceTracker 

Source
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: UserId

The local user’s ID.

§users: HashMap<UserId, UserPresence>

All user presence records.

§stale_timeout: u64

Timeout for stale presence (milliseconds).

§pending_delta: Option<PresenceDelta>

Pending delta for replication.

Implementations§

Source§

impl PresenceTracker

Source

pub fn new(local_user: UserId, info: UserInfo) -> Self

Create a new presence tracker.

Source

pub fn local_user(&self) -> &UserId

Get the local user ID.

Source

pub fn set_stale_timeout(&mut self, timeout_ms: u64)

Set the stale timeout.

Source

pub fn local_presence(&self) -> Option<&UserPresence>

Get the local user’s presence.

Source

pub fn set_cursor(&mut self, document_id: impl Into<String>, cursor: Cursor)

Update the local user’s cursor.

Source

pub fn remove_cursor(&mut self, document_id: &str)

Remove the local user’s cursor from a document.

Source

pub fn set_status(&mut self, status: UserStatus)

Set the local user’s status.

Source

pub fn set_state(&mut self, key: impl Into<String>, value: impl Into<String>)

Set local user’s custom state.

Source

pub fn heartbeat(&mut self)

Send a heartbeat to keep presence alive.

Source

pub fn get_user(&self, user_id: &UserId) -> Option<&UserPresence>

Get a user’s presence.

Source

pub fn all_users(&self) -> impl Iterator<Item = &UserPresence> + '_

Get all users.

Source

pub fn online_users(&self) -> impl Iterator<Item = &UserPresence> + '_

Get all online users.

Source

pub fn users_in_document(&self, document_id: &str) -> Vec<&UserPresence>

Get users with cursors in a document.

Source

pub fn cursors_in_document( &self, document_id: &str, ) -> Vec<(&UserPresence, &Cursor)>

Get all cursors in a document (excluding local user).

Source

pub fn online_count(&self) -> usize

Count online users.

Source

pub fn take_delta(&mut self) -> Option<PresenceDelta>

Take the pending delta.

Source

pub fn apply_delta(&mut self, delta: &PresenceDelta)

Apply a delta from another replica.

Source

pub fn cleanup_stale(&mut self) -> Vec<UserId>

Clean up stale presence records.

Source

pub fn leave(&mut self)

Leave (remove local user).

Trait Implementations§

Source§

impl Clone for PresenceTracker

Source§

fn clone(&self) -> PresenceTracker

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PresenceTracker

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Lattice for PresenceTracker

Source§

fn bottom() -> Self

The bottom element (identity for join)
Source§

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>

Partial order derived from join: a ≤ b iff a ⊔ b = b
Source§

fn leq(&self, other: &Self) -> bool

Check if self ≤ other in the lattice order
Source§

fn join_assign(&mut self, other: &Self)

Join-assign: self = self ⊔ other
Source§

impl PartialEq for PresenceTracker

Source§

fn eq(&self, other: &PresenceTracker) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for PresenceTracker

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V