pub struct Awareness {
local_user_id: String,
local_user_name: String,
local_color: String,
tracker: Arc<RwLock<PresenceTracker>>,
event_tx: Sender<AwarenessEvent>,
}Expand description
Awareness manager for a document or session.
Fields§
§local_user_id: String§local_user_name: String§local_color: String§tracker: Arc<RwLock<PresenceTracker>>§event_tx: Sender<AwarenessEvent>Implementations§
Source§impl Awareness
impl Awareness
Sourcepub fn new(
local_user_id: impl Into<String>,
local_user_name: impl Into<String>,
) -> Self
pub fn new( local_user_id: impl Into<String>, local_user_name: impl Into<String>, ) -> Self
Create a new awareness manager for a local user.
The local user is initialized with a default color and an online presence record in the underlying tracker.
Sourcepub fn local_user_id(&self) -> &str
pub fn local_user_id(&self) -> &str
Return the local user identifier.
Sourcepub fn local_user_name(&self) -> &str
pub fn local_user_name(&self) -> &str
Return the local user display name.
Sourcepub fn set_cursor(&self, document_id: &str, position: usize)
pub fn set_cursor(&self, document_id: &str, position: usize)
Set the local user’s cursor position for a document.
Emits AwarenessEvent::CursorMoved.
Sourcepub fn set_selection(&self, document_id: &str, start: usize, end: usize)
pub fn set_selection(&self, document_id: &str, start: usize, end: usize)
Set the local user’s selection range for a document.
Emits AwarenessEvent::CursorMoved.
Sourcepub fn set_status(&self, status: UserStatus)
pub fn set_status(&self, status: UserStatus)
Update the local user’s presence status.
Sourcepub fn get_users(&self) -> Vec<UserPresenceInfo>
pub fn get_users(&self) -> Vec<UserPresenceInfo>
Return a snapshot of all known users and cursor states.
Sourcepub fn get_cursors(&self, document_id: &str) -> Vec<CursorInfo>
pub fn get_cursors(&self, document_id: &str) -> Vec<CursorInfo>
Return cursor information for users active in a specific document.
Sourcepub fn get_local_color(&self) -> &str
pub fn get_local_color(&self) -> &str
Return the local user’s assigned color string.
Sourcepub fn subscribe(&self) -> Receiver<AwarenessEvent>
pub fn subscribe(&self) -> Receiver<AwarenessEvent>
Subscribe to awareness updates.
This uses a broadcast channel; late subscribers receive only future events.
Sourcepub fn cleanup_stale(&self)
pub fn cleanup_stale(&self)
Remove stale user entries that have not been active recently.