hocuspocus-rs
A Rust implementation of the Hocuspocus protocol (Yjs over WebSockets).
This crate provides a thread-safe handler for Yjs documents that follows the Hocuspocus V2 protocol, allowing Rust-based servers to synchronize with Hocuspocus and y-websocket clients.
Features
- Hocuspocus V2 Protocol: Full support for document-name prefixed messages.
- Yjs Sync: Seamless synchronization using the
yrslibrary. - Optional Persistence: Built-in SQLite persistence with debounced saving (via
sqlitefeature). - Awareness: Forwarding of awareness/presence messages.
- Axum Integration: Built-in WebSocket handlers for the Axum web framework (via
serverfeature).
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Feature Flags
server: Enablesaxumintegration and built-in WebSocket handlers.sqlite: Enablesrusqlitepersistence layer.
Client Compatibility
This server implementation is designed to connect with the Hocuspocus JavaScript client.
In your frontend project, you can use the @hocuspocus/provider to connect:
import from '@hocuspocus/provider'
import * as Y from 'yjs'
const ydoc =
const provider =
Usage
Using with Axum (and SQLite)
Enable the server and sqlite features in your Cargo.toml.
use ;
use Arc;
async
Using with Axum (In-Memory / No SQLite)
Enable only the server feature.
use ;
use Arc;
async
Manual Integration
You can also use the DocHandler directly if you're using a different web framework:
use DocHandler;
async
Protocol Details
Hocuspocus V2 protocol prefixes every message with the document name as a VarString. This implementation handles that automatically, allowing multiple documents to be multiplexed over the same connection if needed.
License
BSD-3-Clause - Copyright (c) 2026, Jagtesh Chadha.