2929
3030
3131class YRoom :
32- remote_clients : set
33- local_clients : set [YRoom ]
32+ clients : set [ Websocket ]
33+ fork_ydocs : set [Doc ]
3434 ydoc : Doc
3535 ystore : BaseYStore | None
3636 _on_message : Callable [[bytes ], Awaitable [bool ] | bool ] | None
@@ -43,10 +43,10 @@ class YRoom:
4343
4444 def __init__ (
4545 self ,
46- ydoc : Doc | None = None ,
4746 ready : bool = True ,
4847 ystore : BaseYStore | None = None ,
4948 log : Logger | None = None ,
49+ ydoc : Doc | None = None ,
5050 ):
5151 """Initialize the object.
5252
@@ -77,8 +77,8 @@ def __init__(
7777 self .ready = ready
7878 self .ystore = ystore
7979 self .log = log or getLogger (__name__ )
80- self .remote_clients = set ()
81- self .local_clients = set ()
80+ self .clients = set ()
81+ self .fork_ydocs = set ()
8282 self ._on_message = None
8383 self ._started = None
8484 self ._starting = False
@@ -135,11 +135,11 @@ async def _broadcast_updates(self):
135135 return
136136 # broadcast internal ydoc's update to all clients, that includes changes from the
137137 # clients and changes from the backend (out-of-band changes)
138- for client in self .local_clients :
139- client . ydoc .apply_update (update )
140- if self .remote_clients :
138+ for ydoc in self .fork_ydocs :
139+ ydoc .apply_update (update )
140+ if self .clients :
141141 message = create_update_message (update )
142- for client in self .remote_clients :
142+ for client in self .clients :
143143 self .log .debug (
144144 "Sending Y update to remote client with endpoint: %s" , client .path
145145 )
@@ -204,7 +204,7 @@ async def serve(self, websocket: Websocket):
204204 websocket: The WebSocket through which to serve the client.
205205 """
206206 async with create_task_group () as tg :
207- self .remote_clients .add (websocket )
207+ self .clients .add (websocket )
208208 await sync (self .ydoc , websocket , self .log )
209209 try :
210210 async for message in websocket :
@@ -231,7 +231,7 @@ async def serve(self, websocket: Websocket):
231231 YMessageType .AWARENESS .name ,
232232 websocket .path ,
233233 )
234- for client in self .remote_clients :
234+ for client in self .clients :
235235 self .log .debug (
236236 "Sending Y awareness from client with endpoint "
237237 "%s to client with endpoint: %s" ,
@@ -243,4 +243,4 @@ async def serve(self, websocket: Websocket):
243243 self .log .debug ("Error serving endpoint: %s" , websocket .path , exc_info = e )
244244
245245 # remove this client
246- self .remote_clients .remove (websocket )
246+ self .clients .remove (websocket )
0 commit comments