diff --git a/plugins/yjs/fps_yjs/routes.py b/plugins/yjs/fps_yjs/routes.py index 12110ba0..73216488 100644 --- a/plugins/yjs/fps_yjs/routes.py +++ b/plugins/yjs/fps_yjs/routes.py @@ -106,8 +106,8 @@ async def fork_room( update = root_room.ydoc.get_update() fork_ydoc = Doc() fork_ydoc.apply_update(update) - fork_room = await self.room_manager.websocket_server.get_room(idx, fork_ydoc) - root_room.local_clients.add(fork_room) + await self.room_manager.websocket_server.get_room(idx, ydoc=fork_ydoc) + root_room.fork_ydocs.add(fork_ydoc) res = { "sessionId": SERVER_SESSION, @@ -256,7 +256,7 @@ async def serve(self, websocket: YWebsocket, permissions) -> None: await self.websocket_server.started.wait() await self.websocket_server.serve(websocket) - if is_stored_document and not room.remote_clients: + if is_stored_document and not room.clients: # no client in this room after we disconnect self.cleaners[room] = asyncio.create_task(self.maybe_clean_room(room, websocket.path)) diff --git a/plugins/yjs/fps_yjs/ywebsocket/websocket_server.py b/plugins/yjs/fps_yjs/ywebsocket/websocket_server.py index d78fff8d..40100211 100644 --- a/plugins/yjs/fps_yjs/ywebsocket/websocket_server.py +++ b/plugins/yjs/fps_yjs/ywebsocket/websocket_server.py @@ -151,7 +151,7 @@ async def _serve(self, websocket: Websocket, tg: TaskGroup): await self.start_room(room) await room.serve(websocket) - if self.auto_clean_rooms and not room.remote_clients: + if self.auto_clean_rooms and not room.clients: self.delete_room(room=room) tg.cancel_scope.cancel() diff --git a/plugins/yjs/fps_yjs/ywebsocket/yroom.py b/plugins/yjs/fps_yjs/ywebsocket/yroom.py index a4dd68a9..d4905ae9 100644 --- a/plugins/yjs/fps_yjs/ywebsocket/yroom.py +++ b/plugins/yjs/fps_yjs/ywebsocket/yroom.py @@ -29,8 +29,8 @@ class YRoom: - remote_clients: set - local_clients: set[YRoom] + clients: set[Websocket] + fork_ydocs: set[Doc] ydoc: Doc ystore: BaseYStore | None _on_message: Callable[[bytes], Awaitable[bool] | bool] | None @@ -43,10 +43,10 @@ class YRoom: def __init__( self, - ydoc: Doc | None = None, ready: bool = True, ystore: BaseYStore | None = None, log: Logger | None = None, + ydoc: Doc | None = None, ): """Initialize the object. @@ -77,8 +77,8 @@ def __init__( self.ready = ready self.ystore = ystore self.log = log or getLogger(__name__) - self.remote_clients = set() - self.local_clients = set() + self.clients = set() + self.fork_ydocs = set() self._on_message = None self._started = None self._starting = False @@ -135,11 +135,11 @@ 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 client in self.local_clients: - client.ydoc.apply_update(update) - if self.remote_clients: + for ydoc in self.fork_ydocs: + ydoc.apply_update(update) + if self.clients: message = create_update_message(update) - for client in self.remote_clients: + for client in self.clients: self.log.debug( "Sending Y update to remote client with endpoint: %s", client.path ) @@ -204,7 +204,7 @@ async def serve(self, websocket: Websocket): websocket: The WebSocket through which to serve the client. """ async with create_task_group() as tg: - self.remote_clients.add(websocket) + self.clients.add(websocket) await sync(self.ydoc, websocket, self.log) try: async for message in websocket: @@ -231,7 +231,7 @@ async def serve(self, websocket: Websocket): YMessageType.AWARENESS.name, websocket.path, ) - for client in self.remote_clients: + for client in self.clients: self.log.debug( "Sending Y awareness from client with endpoint " "%s to client with endpoint: %s", @@ -243,4 +243,4 @@ async def serve(self, websocket: Websocket): self.log.debug("Error serving endpoint: %s", websocket.path, exc_info=e) # remove this client - self.remote_clients.remove(websocket) + self.clients.remove(websocket)