stefanw / channels-yroom

Django Channels WebSocket consumer and worker for synchronizing Yjs clients
https://channels-yroom.readthedocs.io/en/latest/
MIT License
15 stars 5 forks source link

Is there any way to edit YDocs directly instead of using YRoomDocument? #12

Open linspw opened 1 year ago

linspw commented 1 year ago

Hello Stefan, how are you?

Is there any way to edit YDocs directly instead of using YRoomDocument export?

The purpose of this is to be able to handle YDocs directly the way they are on the server side.

stefanw commented 1 year ago

Hey, so this is where it's getting tricky. channels-yroom exists because ypy (the Python bindings to the Y eco system) do not support xml fragments and are currently not up to date with yrs APIs. I created my own higher-level API for syncing+awareness but exposing YDocs directly was not the goal of the project – that's more tricky and where ypy should come in.

I have a draft PR for ypy that upgrades it to a newer yrs version.

I see two ways forward:

  1. Get ypy upgraded and then use that API in the yroom worker. Definitely the long-term solution.
  2. Expose some limited API in channels-yroom. For that I would need a better description of your use case. E.g. something like:

room_manager.add_xml_node_to_room(room_name, document_name, xml_string)

But this is clearly more of an ad-hoc band-aid solution for limited use cases.

linspw commented 1 year ago

Your solution is amazing! When I tried to use YPY directly I saw that some functions were not integrated yet, now I understand.

I will choose to help unlock the update.

linspw commented 1 year ago

My use case:

There are two features I want to do.

First: Update from other languages (HTML, MD and Text) to Tiptap's XML format, for that I'm using internal implementations but I want to send these implementations to the library https://pypi.org/project/tiptapy/ But for that, I want to work on the server side in YDoc to implement this update, when YDoc is loaded.

Second: Take advantage of YDoc synchronization to put other fields in the document, for example: Updated At + Title, and I want to do this on the server side with YPY (updated at)

zswaff commented 11 months ago

@stefanw this is basically the other thing that we need to be able to do. I see that the PR against ypy is still open. What are your latest thoughts on this?

stefanw commented 11 months ago

I haven't looked into this for some months now as there's no comments or guidance from the maintainers. I'm still learning Rust, so my approach in this PR was more "make it compile" and not "make it elegant", so I'm relying on some pointers if this is going into the right direction.

zswaff commented 11 months ago

Cool, thanks. Let me see if I can poke the right people enough to get it moving haha.