@@ -25,7 +25,7 @@ class YRoom:
2525 """
2626 The ID of the room. This is a composite ID following the format:
2727
28- room_id := "{file_type}:{file_format}
28+ room_id := "{file_type}:{file_format}:{file_id}"
2929 """
3030
3131 _jupyter_ydoc : YBaseDoc
@@ -95,6 +95,9 @@ def __init__(
9595 # messages in the message queue to the appropriate handler method.
9696 self ._message_queue = asyncio .Queue ()
9797 self ._loop .create_task (self ._on_new_message ())
98+
99+ # Log notification that room is ready
100+ self .log .info (f"Room '{ self .room_id } ' initialized." )
98101
99102
100103 @property
@@ -156,13 +159,15 @@ async def _on_new_message(self) -> None:
156159 while True :
157160 try :
158161 client_id , message = await self ._message_queue .get ()
162+ self .log .info (f"HANDLING NEW MESSAGE FROM '{ client_id } '" )
163+ self .log .info (f"Message: { message } " )
159164 except asyncio .QueueShutDown :
160165 break
161166
162167 # Handle Awareness messages
163168 message_type = message [0 ]
164169 if message_type == YMessageType .AWARENESS :
165- self .handle_awareness_update (client_id , message [ 1 :] )
170+ self .handle_awareness_update (client_id , message )
166171 continue
167172
168173 # Handle Sync messages
@@ -196,6 +201,8 @@ def handle_sync_step1(self, client_id: str, message: bytes) -> None:
196201 - Sending the reply to the client over WS, and
197202 - Sending a new SyncStep1 message immediately after.
198203 """
204+ self .log .info (f"Handling SS1 message from client '{ client_id } '." )
205+
199206 # Mark client as desynced
200207 new_client = self .clients .get (client_id )
201208 self .clients .mark_desynced (client_id )
@@ -218,7 +225,7 @@ def handle_sync_step1(self, client_id: str, message: bytes) -> None:
218225 try :
219226 # TODO: remove the assert once websocket is made required
220227 assert isinstance (new_client .websocket , WebSocketHandler )
221- new_client .websocket .write_message (sync_step2_message )
228+ new_client .websocket .write_message (sync_step2_message , binary = True )
222229 except Exception as e :
223230 self .log .error (
224231 "An exception occurred when writing the SyncStep2 reply "
@@ -228,18 +235,21 @@ def handle_sync_step1(self, client_id: str, message: bytes) -> None:
228235 return
229236
230237 self .clients .mark_synced (client_id )
238+ self .log .info (f"Sent SS2 reply to client '{ client_id } '." )
231239
232240 # Send SyncStep1 message
233241 try :
234242 assert isinstance (new_client .websocket , WebSocketHandler )
235243 sync_step1_message = pycrdt .create_sync_message (self ._ydoc )
236- new_client .websocket .write_message (sync_step1_message )
244+ new_client .websocket .write_message (sync_step1_message , binary = True )
237245 except Exception as e :
238246 self .log .error (
239247 "An exception occurred when writing a SyncStep1 message "
240248 f"to newly-synced client '{ new_client .id } ':"
241249 )
242250 self .log .exception (e )
251+ self .log .info (f"Sent SS1 message to client '{ client_id } '." )
252+ self .log .info (f"Message: { sync_step1_message } " )
243253
244254
245255 def handle_sync_step2 (self , client_id : str , message : bytes ) -> None :
@@ -251,6 +261,7 @@ def handle_sync_step2(self, client_id: str, message: bytes) -> None:
251261 clients after this method is called via the `self.write_sync_update()`
252262 observer.
253263 """
264+ self .log .info ("HANDLING SS2 MESSAGE" )
254265 try :
255266 message_payload = message [1 :]
256267 pycrdt .handle_sync_message (message_payload , self ._ydoc )
@@ -271,6 +282,7 @@ def handle_sync_update(self, client_id: str, message: bytes) -> None:
271282 clients after this method is called via the `self.write_sync_update()`
272283 observer.
273284 """
285+ self .log .info ("HANDLING SYNCUPDATE" )
274286 # Remove client and kill websocket if received SyncUpdate when client is desynced
275287 if self ._should_ignore_update (client_id , "SyncUpdate" ):
276288 self .log .error (f"Should not receive SyncUpdate message when double handshake is not completed for client '{ client_id } ' and room '{ self .room_id } '" )
@@ -310,6 +322,7 @@ def write_sync_update(self, message_payload: bytes, client_id: str | None = None
310322
311323
312324 def handle_awareness_update (self , client_id : str , message : bytes ) -> None :
325+ self .log .info ("HANDLING AWARENESS UPDATE" )
313326 # Apply the AwarenessUpdate message
314327 try :
315328 message_payload = pycrdt .read_message (message [1 :])
@@ -356,7 +369,7 @@ def _broadcast_message(self, message: bytes, message_type: Literal['AwarenessUpd
356369 try :
357370 # TODO: remove this assertion once websocket is made required
358371 assert isinstance (client .websocket , WebSocketHandler )
359- client .websocket .write_message (message )
372+ client .websocket .write_message (message , binary = True )
360373 except Exception as e :
361374 self .log .warning (
362375 f"An exception occurred when broadcasting a "
0 commit comments