More infos in debug/admin mode in server
All checks were successful
Check / mypy (push) Successful in 1m6s
Check / ruff (push) Successful in 7s

This commit is contained in:
Christoph Stahl 2025-06-16 23:13:55 +02:00
parent 72c70c03ec
commit 81c6d2468c

View file

@ -263,7 +263,7 @@ class Server:
return web.FileResponse(os.path.join(self.app["root_folder"], "favicon.ico")) return web.FileResponse(os.path.join(self.app["root_folder"], "favicon.ico"))
return web.FileResponse(os.path.join(self.app["root_folder"], "index.html")) return web.FileResponse(os.path.join(self.app["root_folder"], "index.html"))
async def get_number_connections(self) -> int: def get_number_connections(self) -> int:
""" """
Get the number of connections to the server. Get the number of connections to the server.
@ -277,6 +277,22 @@ class Server:
num += 1 num += 1
return num return num
def get_connections(self) -> dict[str, dict[str, list[tuple[str, str]]]]:
"""
Get all connections to the server.
:return: A dictionary mapping namespaces to rooms and participants.
:rtype: dict[str, dict[str, list[tuple[str, str]]]]
"""
connections: dict[str, dict[str, list[tuple[str, str]]]] = {}
for namespace in self.sio.manager.get_namespaces():
connections[namespace] = {}
for room in self.sio.manager.rooms[namespace]:
connections[namespace][room] = []
for participant in self.sio.manager.get_participants(namespace, room):
connections[namespace][room].append(participant)
return connections
async def get_clients(self, room: str) -> list[dict[str, Any]]: async def get_clients(self, room: str) -> list[dict[str, Any]]:
""" """
Get the number of clients in a room. Get the number of clients in a room.
@ -294,10 +310,7 @@ class Server:
client["type"] = "playback" client["type"] = "playback"
else: else:
client["type"] = "web" client["type"] = "web"
client["admin"] = False client["admin"] = await self.is_admin(self.clients[room], sid)
async with self.sio.session(sid) as session:
if "admin" in session:
client["admin"] = session["admin"]
clients.append(client) clients.append(client)
return clients return clients
@ -320,7 +333,8 @@ class Server:
info_dict = { info_dict = {
"version": SYNG_VERSION, "version": SYNG_VERSION,
"protocol_version": SYNG_PROTOCOL_VERSION, "protocol_version": SYNG_PROTOCOL_VERSION,
"connections": await self.get_number_connections(), "num_connections": self.get_number_connections(),
"connections": self.get_connections(),
"rooms": rooms, "rooms": rooms,
} }
return web.json_response(info_dict, dumps=jsonencoder.dumps) return web.json_response(info_dict, dumps=jsonencoder.dumps)