Modifying Yjs document data with the REST API
Liveblocks allows you to update your Yjs document data, or yDoc
, from the REST
API, helpful for sending updates from the server. This is made possible through
Liveblocks.sendYjsBinaryUpdate
in @liveblocks/node
.
Updating a Yjs document
Updating a Yjs document requires you to create a
binary update, before sending it to
Liveblocks using
Liveblocks.sendYjsBinaryUpdate
.
Here’s an example in a serverless endpoint.
Note that if you’re using a text editor, each one works differently, so you’ll most likely need to modify these two lines to use a format your editor defines.
Initializing a Yjs document
It’s also possible to create a new room with an initial Yjs document. To do
this, call
Liveblocks.createRoom
, then
send the update as before.
Each editor works differently
Note that each text and code editor may work differently, and may include
specific functions for creating binary updates, or use different shared types.
Slate and Tiptap use
Y.XmlFragment
instead
of Y.Text
.
Slate
This is how to initialize a Slate document.
Tiptap
This is how to initialize a Tiptap document.