Skip to main content

Session

Struct Session 

Source
pub struct Session<T: NetworkTransport> { /* private fields */ }
Expand description

A collaborative session that manages documents and peers.

Implementations§

Source§

impl<T: NetworkTransport> Session<T>

Source

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.

Source

pub fn session_id(&self) -> &str

Return the stable session identifier.

Source

pub fn local_peer_id(&self) -> &PeerId

Return the local peer identifier for this session.

Source

pub fn user_name(&self) -> &str

Return the local user name for this session.

Source

pub fn awareness(&self) -> &Arc<Awareness>

Return the presence/awareness manager.

Use this to set cursor position, selections, and status.

Source

pub fn subscribe(&self) -> Receiver<SessionEvent>

Subscribe to session lifecycle events.

This uses a broadcast channel; late subscribers only receive future events.

Source

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.

Source

pub async fn disconnect(&self) -> Result<(), SdkError>

Disconnect from the session locally.

This emits SessionEvent::Disconnected for local listeners.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn open_documents(&self) -> Vec<String>

Return all currently opened document IDs across document types.

Source

pub async fn peers(&self) -> Vec<Peer>

Return peers currently connected through the underlying transport.

Auto Trait Implementations§

§

impl<T> Freeze for Session<T>

§

impl<T> !RefUnwindSafe for Session<T>

§

impl<T> Send for Session<T>

§

impl<T> Sync for Session<T>

§

impl<T> Unpin for Session<T>

§

impl<T> UnsafeUnpin for Session<T>

§

impl<T> !UnwindSafe for Session<T>

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> 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, 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.
Source§

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

Source§

fn vzip(self) -> V