show connected clients count for websocket server interface

This commit is contained in:
liamcottle 2025-02-07 17:17:46 +13:00
commit 03d7b669ae

View file

@ -57,6 +57,10 @@ class WebsocketServerInterface(Interface):
thread.daemon = True
thread.start()
@property
def clients(self):
return len(self.spawned_interfaces)
# todo docs
def received_announce(self, from_spawned=False):
if from_spawned:
@ -124,6 +128,9 @@ class WebsocketServerInterface(Interface):
# run read loop
spawned_interface.read_loop()
# client must have disconnected as the read loop finished, so forget the spawned interface
self.spawned_interfaces.remove(spawned_interface)
# run websocket server
try:
with serve(on_websocket_client_connected, self.listen_ip, self.listen_port, compression=None) as server: