mirror of
https://github.com/Dispatcharr/Dispatcharr.git
synced 2026-01-23 02:35:14 +00:00
Closes channel when no clients are connected.
This commit is contained in:
parent
3b3e5f7b52
commit
f976a045a9
1 changed files with 11 additions and 0 deletions
|
|
@ -74,9 +74,13 @@ class ClientManager:
|
|||
self.lock: threading.Lock = threading.Lock()
|
||||
self.last_client_time: float = time.time()
|
||||
self.cleanup_timer: Optional[threading.Timer] = None
|
||||
self._proxy_server = None
|
||||
self._channel_id = None
|
||||
|
||||
def start_cleanup_timer(self, proxy_server, channel_id):
|
||||
"""Start timer to cleanup idle channels"""
|
||||
self._proxy_server = proxy_server
|
||||
self._channel_id = channel_id
|
||||
if self.cleanup_timer:
|
||||
self.cleanup_timer.cancel()
|
||||
self.cleanup_timer = threading.Timer(
|
||||
|
|
@ -98,6 +102,10 @@ class ClientManager:
|
|||
"""Add new client connection"""
|
||||
with self.lock:
|
||||
self.active_clients.add(client_id)
|
||||
self.last_client_time = time.time() # Reset the timer
|
||||
if self.cleanup_timer:
|
||||
self.cleanup_timer.cancel() # Cancel existing timer
|
||||
self.start_cleanup_timer(self._proxy_server, self._channel_id) # Restart timer
|
||||
logging.info(f"New client connected: {client_id} (total: {len(self.active_clients)})")
|
||||
|
||||
def remove_client(self, client_id: int) -> int:
|
||||
|
|
@ -213,6 +221,9 @@ class ProxyServer:
|
|||
self.stream_buffers[channel_id] = StreamBuffer()
|
||||
self.client_managers[channel_id] = ClientManager()
|
||||
|
||||
# Start cleanup timer immediately after initialization
|
||||
self.client_managers[channel_id].start_cleanup_timer(self, channel_id)
|
||||
|
||||
fetcher = StreamFetcher(
|
||||
self.stream_managers[channel_id],
|
||||
self.stream_buffers[channel_id]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue