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

Support document fork #18

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pycrdt_websocket/yroom.py
Original file line number Diff line number Diff line change
@@ -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: