Expand description
Loro WebSocket Client
Two layers are exposed:
- Low-level
Clientto send/receive rawloro_protocol::ProtocolMessage. - High-level
LoroWebsocketClientthat joins rooms and applies incoming updates to a providedloro::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.
- Client
Config - Configuration knobs for the high-level client.
- Crdt
Adaptor Context - EloDoc
Adaptor - Experimental %ELO adaptor. Snapshot-only packaging is implemented today; delta packaging and API stability are WIP and may change.
- Loro
DocAdaptor - Loro
Websocket Client - A higher-level WebSocket client that manages rooms and applies updates to a LoroDoc.
- Loro
Websocket Client Room - Room handle providing helpers to send updates from a bound
LoroDoc.
Enums§
- Client
Error - Errors that may occur in the client.