Less verbosity

This commit is contained in:
BarsTiger
2023-07-27 18:55:42 +03:00
parent 3be0f6409d
commit 75b72db3b8
2 changed files with 10 additions and 10 deletions

View File

@@ -19,6 +19,8 @@ from dragonion_core.proto.web.webmessage import (
WebConnectionResultMessage WebConnectionResultMessage
) )
from datetime import datetime
@define @define
class Room(object): class Room(object):
@@ -74,7 +76,7 @@ class Room(object):
)) ))
await self.broadcast_webmessage(connection_message) await self.broadcast_webmessage(connection_message)
print(f'Accepted {connection_message.username}') print(f'[{datetime.now().time()}] Accepted {connection_message.username}')
return connection return connection
async def broadcast_webmessage(self, obj: webmessages_union): async def broadcast_webmessage(self, obj: webmessages_union):
@@ -84,7 +86,6 @@ class Room(object):
:return: :return:
""" """
for connection in self.connections.values(): for connection in self.connections.values():
print(f'Sending to {connection.username}: {obj}')
await connection.send_webmessage(obj) await connection.send_webmessage(obj)
async def broadcast_message(self, broadcastable: WebBroadcastableMessage): async def broadcast_message(self, broadcastable: WebBroadcastableMessage):
@@ -173,7 +174,6 @@ class Room(object):
reason=close_reason reason=close_reason
) )
except Exception as e: except Exception as e:
print(f'Cannot close {connection.username} ws, ' assert e
f'maybe it\'s already closed: {e}')
return connection.username return connection.username

View File

@@ -6,6 +6,7 @@ from dragonion_core.proto.web.webmessage import (
) )
from .managers.exceptions import GotInvalidWebmessage from .managers.exceptions import GotInvalidWebmessage
from datetime import datetime
service = Service() service = Service()
@@ -17,7 +18,7 @@ async def serve_websocket(websocket: WebSocket, room_name: str):
:param room_name: Room name to connect ws to :param room_name: Room name to connect ws to
:return: :return:
""" """
print(f'Connection opened room {room_name}') print(f'[{datetime.now().time()}] Connection opened room {room_name}')
room = await service.get_room(room_name) room = await service.get_room(room_name)
connection = await room.accept_connection(websocket) connection = await room.accept_connection(websocket)
@@ -28,7 +29,6 @@ async def serve_websocket(websocket: WebSocket, room_name: str):
try: try:
webmessage: webmessages_union = WebMessage.from_json(data) webmessage: webmessages_union = WebMessage.from_json(data)
except Exception as e: except Exception as e:
print(f"Cannot decode message, {e}")
await connection.send_error("invalid_webmessage") await connection.send_error("invalid_webmessage")
continue continue
@@ -40,21 +40,21 @@ async def serve_websocket(websocket: WebSocket, room_name: str):
await room.broadcast_message(webmessage) await room.broadcast_message(webmessage)
except GotInvalidWebmessage: except GotInvalidWebmessage:
print('Invalid webmsg')
await connection.send_error("invalid_webmessage") await connection.send_error("invalid_webmessage")
except RuntimeError: except RuntimeError:
username = await room.disconnect(connection) username = await room.disconnect(connection)
if username is not None: if username is not None:
await room.broadcast_user_disconnected(username) await room.broadcast_user_disconnected(username)
print(f'Closed {username}') print(f'[{datetime.now().time()}] Closed {username}')
break break
except WebSocketDisconnect: except WebSocketDisconnect:
username = await room.disconnect(connection) username = await room.disconnect(connection)
if username is not None: if username is not None:
await room.broadcast_user_disconnected(username) await room.broadcast_user_disconnected(username)
print(f'Closed {username}') print(f'[{datetime.now().time()}] Closed {username}')
break break
except Exception as e: except Exception as e:
print(f'Exception in {connection.username}: {e.__class__}: {e}') print(f'[{datetime.now().time()}] Exception in '
f'{connection.username}: {e.__class__}: {e}')
continue continue