29
29
30
30
31
31
class YRoom :
32
- remote_clients : set
33
- local_clients : set [YRoom ]
32
+ clients : set [ Websocket ]
33
+ fork_ydocs : set [Doc ]
34
34
ydoc : Doc
35
35
ystore : BaseYStore | None
36
36
_on_message : Callable [[bytes ], Awaitable [bool ] | bool ] | None
@@ -43,10 +43,10 @@ class YRoom:
43
43
44
44
def __init__ (
45
45
self ,
46
- ydoc : Doc | None = None ,
47
46
ready : bool = True ,
48
47
ystore : BaseYStore | None = None ,
49
48
log : Logger | None = None ,
49
+ ydoc : Doc | None = None ,
50
50
):
51
51
"""Initialize the object.
52
52
@@ -77,8 +77,8 @@ def __init__(
77
77
self .ready = ready
78
78
self .ystore = ystore
79
79
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 ()
82
82
self ._on_message = None
83
83
self ._started = None
84
84
self ._starting = False
@@ -135,11 +135,11 @@ async def _broadcast_updates(self):
135
135
return
136
136
# broadcast internal ydoc's update to all clients, that includes changes from the
137
137
# 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 :
141
141
message = create_update_message (update )
142
- for client in self .remote_clients :
142
+ for client in self .clients :
143
143
self .log .debug (
144
144
"Sending Y update to remote client with endpoint: %s" , client .path
145
145
)
@@ -204,7 +204,7 @@ async def serve(self, websocket: Websocket):
204
204
websocket: The WebSocket through which to serve the client.
205
205
"""
206
206
async with create_task_group () as tg :
207
- self .remote_clients .add (websocket )
207
+ self .clients .add (websocket )
208
208
await sync (self .ydoc , websocket , self .log )
209
209
try :
210
210
async for message in websocket :
@@ -231,7 +231,7 @@ async def serve(self, websocket: Websocket):
231
231
YMessageType .AWARENESS .name ,
232
232
websocket .path ,
233
233
)
234
- for client in self .remote_clients :
234
+ for client in self .clients :
235
235
self .log .debug (
236
236
"Sending Y awareness from client with endpoint "
237
237
"%s to client with endpoint: %s" ,
@@ -243,4 +243,4 @@ async def serve(self, websocket: Websocket):
243
243
self .log .debug ("Error serving endpoint: %s" , websocket .path , exc_info = e )
244
244
245
245
# remove this client
246
- self .remote_clients .remove (websocket )
246
+ self .clients .remove (websocket )
0 commit comments