Crate loro_websocket_client

Crate loro_websocket_client 

Source
Expand description

Loro WebSocket Client

Two layers are exposed:

  • Low-level Client to send/receive raw loro_protocol::ProtocolMessage.
  • High-level LoroWebsocketClient that joins rooms and applies incoming updates to a provided loro::LoroDoc. This mirrors the JS client’s responsibilities.

Low-level example (not run here):

use loro_websocket_client::Client;
use loro_protocol::{ProtocolMessage, CrdtType};
let mut client = Client::connect("ws://127.0.0.1:9000").await?;
client.send(&ProtocolMessage::Leave { crdt: CrdtType::Loro, room_id: "room1".to_string() }).await?;
if let Some(msg) = client.next().await? {
    println!("got: {:?}", msg);
}

High-level example (not run here):

use std::sync::Arc;
use loro::{LoroDoc};
use loro_websocket_client::LoroWebsocketClient;
let client = LoroWebsocketClient::connect("ws://127.0.0.1:9000").await?;
let doc = Arc::new(tokio::sync::Mutex::new(LoroDoc::new()));
let _room = client.join_loro("room1", doc.clone()).await?;
// mutate doc then commit; client auto-sends local updates to the room
{ let mut d = doc.lock().await; d.get_text("text").insert(0, "hello").unwrap(); d.commit(); }

Re-exports§

pub use CrdtDocAdaptor as DocAdaptor;
pub use EloDocAdaptor as EloAdaptor;
pub use LoroDocAdaptor as LoroAdaptor;
pub use loro_protocol as protocol;

Structs§

Client
A minimal client wrapping a WebSocket stream.
ClientConfig
Configuration knobs for the high-level client.
CrdtAdaptorContext
EloDocAdaptor
Experimental %ELO adaptor. Snapshot-only packaging is implemented today; delta packaging and API stability are WIP and may change.
LoroDocAdaptor
LoroWebsocketClient
A higher-level WebSocket client that manages rooms and applies updates to a LoroDoc.
LoroWebsocketClientRoom
Room handle providing helpers to send updates from a bound LoroDoc.

Enums§

ClientError
Errors that may occur in the client.

Traits§

CrdtDocAdaptor