Skip to content
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
Expand Up @@ -33,6 +33,7 @@

class YRoom:
clients: set[Websocket]
fork_ydocs: set[Doc]
ydoc: Doc
ystore: BaseYStore | None
ready_event: Event
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down
Loading