Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating the YDoc within a room server side #91

Open
weaversam8 opened this issue Jan 7, 2024 · 3 comments
Open

Updating the YDoc within a room server side #91

weaversam8 opened this issue Jan 7, 2024 · 3 comments

Comments

@weaversam8
Copy link

Is it possible to update the YDoc on the server and broadcast changes to clients? The only way I can see to do this right now would be to connect from the server to itself over Websocket, which feels like a layer of indirection.

I've been able to do something like this, but once I update the YDoc within the room, I'm not sure how to broadcast changes out to the clients. This existing code does not appear to broadcast anything to the clients, even when Y.apply_update is called.

doc = Y.YDoc() # server side doc with changes
room = await websocket_server.get_room("my-roomname")
remote_doc = room.ydoc
state_vector = Y.encode_state_vector(remote_doc)
diff = Y.encode_state_as_update(doc, state_vector)
Y.apply_update(remote_doc, diff)
@davidbrochart
Copy link
Collaborator

It is possible, we do it in Jupyter by watching the file system and e.g. updating a notebook shared model if a file has out-of-band changes. This is modifying the YDoc internally, but connecting to the server through WebSocket like any other peer works too. You should use a WebsocketProvider for that.
BTW, I don't plan to maintain this project (ypy-websocket) anymore, as I've switched from ypy to pycrdt. The equivalent project is pycrdt-websocket.

@weaversam8
Copy link
Author

Thanks for the tip. Can you link to where this is accomplished within Jupyter? I'm trying to modify the YDoc, as in the example above, but I can't seem to get the changes to propagate to the clients.

@davidbrochart
Copy link
Collaborator

For instance, here. This is a direct YDoc change. As I said, if you want to change a YDoc through a WebSocket, you should use the WebsocketProvider.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants