pub struct Session<T: NetworkTransport> { /* private fields */ }Expand description
A collaborative session that manages documents and peers.
Implementations§
Source§impl<T: NetworkTransport> Session<T>
impl<T: NetworkTransport> Session<T>
Sourcepub fn new(
session_id: impl Into<String>,
local_peer_id: PeerId,
user_name: impl Into<String>,
transport: Arc<T>,
) -> Self
pub fn new( session_id: impl Into<String>, local_peer_id: PeerId, user_name: impl Into<String>, transport: Arc<T>, ) -> Self
Create a new collaborative session bound to a local peer.
Most applications should use crate::client::Client::create_session
instead of calling this directly.
Sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
Return the stable session identifier.
Sourcepub fn local_peer_id(&self) -> &PeerId
pub fn local_peer_id(&self) -> &PeerId
Return the local peer identifier for this session.
Sourcepub fn awareness(&self) -> &Arc<Awareness>
pub fn awareness(&self) -> &Arc<Awareness>
Return the presence/awareness manager.
Use this to set cursor position, selections, and status.
Sourcepub fn subscribe(&self) -> Receiver<SessionEvent>
pub fn subscribe(&self) -> Receiver<SessionEvent>
Subscribe to session lifecycle events.
This uses a broadcast channel; late subscribers only receive future events.
Sourcepub async fn connect(&self) -> Result<(), SdkError>
pub async fn connect(&self) -> Result<(), SdkError>
Connect to the session and broadcast a handshake to peers.
§Errors
Returns SdkError::NetworkError if the transport broadcast fails.
Sourcepub async fn disconnect(&self) -> Result<(), SdkError>
pub async fn disconnect(&self) -> Result<(), SdkError>
Disconnect from the session locally.
This emits SessionEvent::Disconnected for local listeners.
Sourcepub fn open_text_doc(
&self,
document_id: impl Into<String>,
) -> Arc<RwLock<TextDoc>> ⓘ
pub fn open_text_doc( &self, document_id: impl Into<String>, ) -> Arc<RwLock<TextDoc>> ⓘ
Create or open a plain-text document by ID.
Returns a shared, lock-protected document handle.
Sourcepub fn open_rich_text_doc(
&self,
document_id: impl Into<String>,
) -> Arc<RwLock<RichTextDoc>> ⓘ
pub fn open_rich_text_doc( &self, document_id: impl Into<String>, ) -> Arc<RwLock<RichTextDoc>> ⓘ
Create or open a rich-text document by ID.
Returns a shared, lock-protected document handle.
Sourcepub fn open_json_doc(
&self,
document_id: impl Into<String>,
) -> Arc<RwLock<JsonDoc>> ⓘ
pub fn open_json_doc( &self, document_id: impl Into<String>, ) -> Arc<RwLock<JsonDoc>> ⓘ
Create or open a JSON document by ID.
Returns a shared, lock-protected document handle.
Sourcepub fn close_doc(&self, document_id: &str)
pub fn close_doc(&self, document_id: &str)
Close a locally opened document handle by ID.
If a document exists in multiple local maps, all matches are removed.
Sourcepub fn open_documents(&self) -> Vec<String>
pub fn open_documents(&self) -> Vec<String>
Return all currently opened document IDs across document types.