Custom backend
Collaboration & historyCustom collaboration backend
Bring your own realtime server.
Wire the WebSocket collaboration adapter to a small relay on your own server, so documents sync through infrastructure you control. See collaboration.
What your server has to do
createYjsWebSocketCollaborationAdapter({ url, protocols }) opens one WebSocket per editor and sends JSON text messages. It does not speak the y-websocket protocol. Your server only has to pass every message it receives to the other sockets in the same session; the editors merge the Yjs updates themselves. A message that comes back to its sender is ignored, so broadcasting to everyone in the room is fine.
url can be a function of the session id, which gives each design its own room:
ts
const adapter = createYjsWebSocketCollaborationAdapter({
url: (sessionId) => `wss://collab.example.com/rooms/${encodeURIComponent(sessionId)}`
});Messages
sync-requestis sent when a socket opens. Any peer answers withsync-state.sync-stateanddoc-updatecarry a Yjs update as an array of numbers inupdate.presenceandpresence-leavecarry who is here and what they selected.- Every message has a
fromfield with the sender's peer id.
Limits
- The adapter does not reconnect. When the socket closes, the status becomes
disconnected. - A relay stores nothing. Each editor seeds the shared document from the design it was loaded with, so load the same saved design in every editor and keep saving through your own save flow.