Skip to content

Commit

Permalink
Replace remote_clients with clients, local_clients with fork_ydocs
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Mar 12, 2024
1 parent 03b0801 commit bb8753d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions plugins/yjs/fps_yjs/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion plugins/yjs/fps_yjs/ywebsocket/websocket_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
24 changes: 12 additions & 12 deletions plugins/yjs/fps_yjs/ywebsocket/yroom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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:
Expand All @@ -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",
Expand All @@ -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)

0 comments on commit bb8753d

Please sign in to comment.