pub struct Client<T: NetworkTransport> { /* private fields */ }Expand description
The main MDCS client for collaborative editing.
The client manages sessions, documents, and network connections.
§Example
use mdcs_sdk::{Client, ClientConfig};
// Create a client
let config = ClientConfig {
user_name: "Alice".to_string(),
..Default::default()
};
let client = Client::new_with_memory_transport(config);
// Create a session
let session = client.create_session("my-session");
// Open a document
let doc = session.open_text_doc("shared-doc");
doc.write().insert(0, "Hello, world!");Implementations§
Source§impl Client<MemoryTransport>
impl Client<MemoryTransport>
Sourcepub fn new_with_memory_transport(config: ClientConfig) -> Self
pub fn new_with_memory_transport(config: ClientConfig) -> Self
Create a new client backed by MemoryTransport.
This constructor is ideal for tests, local demos, and examples where all peers run in the same process.
Source§impl<T: NetworkTransport> Client<T>
impl<T: NetworkTransport> Client<T>
Sourcepub fn new(peer_id: PeerId, transport: Arc<T>, config: ClientConfig) -> Self
pub fn new(peer_id: PeerId, transport: Arc<T>, config: ClientConfig) -> Self
Create a new client with a custom transport implementation.
Use this constructor when integrating with a real networking backend (WebSocket, QUIC, custom RPC, etc.).
Sourcepub fn create_session(&self, session_id: impl Into<String>) -> Arc<Session<T>>
pub fn create_session(&self, session_id: impl Into<String>) -> Arc<Session<T>>
Create or fetch a collaborative session by ID.
If the session already exists, this returns the same shared instance.
Sourcepub fn get_session(&self, session_id: &str) -> Option<Arc<Session<T>>>
pub fn get_session(&self, session_id: &str) -> Option<Arc<Session<T>>>
Get an existing session if it has already been created on this client.
Sourcepub fn close_session(&self, session_id: &str)
pub fn close_session(&self, session_id: &str)
Close a local session handle and remove it from the client cache.
This does not notify remote peers directly; use higher-level app signaling if your protocol requires explicit leave semantics.
Sourcepub fn session_ids(&self) -> Vec<String>
pub fn session_ids(&self) -> Vec<String>
List all currently active local session IDs.
Sourcepub async fn connect_peer(&self, peer_id: &PeerId) -> Result<(), SdkError>
pub async fn connect_peer(&self, peer_id: &PeerId) -> Result<(), SdkError>
Establish a transport-level connection to a peer.
§Errors
Returns SdkError::ConnectionFailed if the underlying transport
cannot connect to the target peer.
Sourcepub async fn disconnect_peer(&self, peer_id: &PeerId) -> Result<(), SdkError>
pub async fn disconnect_peer(&self, peer_id: &PeerId) -> Result<(), SdkError>
Disconnect from a peer.
§Errors
Returns SdkError::NetworkError if the transport reports a failure
while disconnecting.
Sourcepub async fn connected_peers(&self) -> Vec<Peer>
pub async fn connected_peers(&self) -> Vec<Peer>
Return the current list of connected peers reported by the transport.