This library is an extension over Yjs/Yrs Conflict-Free Replicated Data Types (CRDT) message exchange protocol. It provides an utilities connect with Yjs web socket provider using Rust tokio's warp web server.
A working demo can be seen under examples subfolder. It integrates this library API with Code Mirror 6, enhancing it with collaborative rich text document editing capabilities.
In order to gossip updates between different web socket connection from the clients collaborating over the same logical document, a broadcast group can be used:
```rust
async fn main() { let awareness = Arc::new(RwLock::new(Awareness::new(Doc::new()))); // open a broadcast group that listens to awareness and document updates // and has a pending message buffer of up to 32 updates let bcast = Arc::new(BroadcastGroup::open(awareness.clone(), 32).await);
// pass dependencies to awareness and broadcast group to every new created connection
let ws = warp::path("my-room")
.and(warp::ws())
.and(warp::any().map(move || awareness.clone()))
.and(warp::any().map(move || bcast.clone()))
.and_then(ws_handler);
warp::serve(ws).run(([0, 0, 0, 0], 8000)).await;
}
async fn wshandler(
ws: Ws,
awareness: AwarenessRef,
bcast: Arc
async fn peer(ws: WebSocket, awareness: AwarenessRef, bcast: Arc
y-sync protocol enables to extend it's own protocol, and yrs-warp supports this as well. This can be done by implementing your own protocol, eg.:
```rust use y_sync::sync::Protocol;
struct EchoProtocol;
impl Protocol for EchoProtocol {
fn missing_handle(
&self,
awareness: &mut Awareness,
tag: u8,
data: Vec
async fn peer(ws: WebSocket, awareness: AwarenessRef) { //.. later in code create a warp connection using new protocol let conn = WarpConn::with_protocol(awareness, ws, EchoProtocol); // .. rest of the code } ```