From 73da762853dd1f88c7ab03a08c2aba75ed486768 Mon Sep 17 00:00:00 2001 From: David Brochart Date: Mon, 11 Mar 2024 11:27:43 +0100 Subject: [PATCH] Support document fork --- pycrdt_websocket/yroom.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pycrdt_websocket/yroom.py b/pycrdt_websocket/yroom.py index 646642a..e8b9751 100644 --- a/pycrdt_websocket/yroom.py +++ b/pycrdt_websocket/yroom.py @@ -33,6 +33,7 @@ class YRoom: clients: set[Websocket] + fork_ydocs: set[Doc] ydoc: Doc ystore: BaseYStore | None ready_event: Event @@ -83,6 +84,7 @@ def __init__( self.ystore = ystore self.log = log or getLogger(__name__) self.clients = set() + self.fork_ydocs = set() self._on_message = None self.exception_handler = exception_handler self._stopped = Event() @@ -149,12 +151,15 @@ async def _broadcast_updates(self): return # broadcast internal ydoc's update to all clients, that includes changes from the # clients and changes from the backend (out-of-band changes) + for ydoc in self.fork_ydocs: + ydoc.apply_update(update) + if self.clients: message = create_update_message(update) for client in self.clients: try: self.log.debug( - "Sending Y update to client with endpoint: %s", client.path + "Sending Y update to remote client with endpoint: %s", client.path ) self._task_group.start_soon(client.send, message) except Exception as exception: