From 98f485bac9465e57e5eeb3dbbd89c39160d2ee07 Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Fri, 5 Sep 2025 11:37:49 -0500 Subject: [PATCH] Fixed issue with recurring api calls. --- apps/proxy/ts_proxy/views.py | 13 +++++++++++++ frontend/src/api.js | 2 +- frontend/src/pages/Stats.jsx | 12 ++++++++++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/apps/proxy/ts_proxy/views.py b/apps/proxy/ts_proxy/views.py index ff815bdc..582bcc49 100644 --- a/apps/proxy/ts_proxy/views.py +++ b/apps/proxy/ts_proxy/views.py @@ -28,6 +28,7 @@ from apps.accounts.permissions import ( from .constants import ChannelState, EventType, StreamType, ChannelMetadataField from .config_helper import ConfigHelper from .services.channel_service import ChannelService +from core.utils import send_websocket_update from .url_utils import ( generate_stream_url, transform_url, @@ -633,6 +634,18 @@ def channel_status(request, channel_id=None): if cursor == 0: break + # Send WebSocket update with the stats + # Format it the same way the original Celery task did + send_websocket_update( + "updates", + "update", + { + "success": True, + "type": "channel_stats", + "stats": json.dumps({'channels': all_channels, 'count': len(all_channels)}) + } + ) + return JsonResponse({"channels": all_channels, "count": len(all_channels)}) except Exception as e: diff --git a/frontend/src/api.js b/frontend/src/api.js index f8e2e1ec..cb834bd5 100644 --- a/frontend/src/api.js +++ b/frontend/src/api.js @@ -1319,7 +1319,7 @@ export default class API { static async fetchActiveChannelStats() { try { - const response = await request(`${host}/proxy/ts/status/`); + const response = await request(`${host}/proxy/ts/status`); return response; } catch (e) { errorNotification('Failed to fetch active channel stats', e); diff --git a/frontend/src/pages/Stats.jsx b/frontend/src/pages/Stats.jsx index 1a27d163..de3fbe7f 100644 --- a/frontend/src/pages/Stats.jsx +++ b/frontend/src/pages/Stats.jsx @@ -831,9 +831,16 @@ const ChannelsPage = () => { const response = await API.fetchActiveChannelStats(); if (response) { setChannelStats(response); + } else { + console.log('API response was empty or null'); } } catch (error) { console.error('Error fetching channel stats:', error); + console.error('Error details:', { + message: error.message, + status: error.status, + body: error.body, + }); } }, [setChannelStats]); @@ -868,6 +875,7 @@ const ChannelsPage = () => { }, [fetchChannelStats]); useEffect(() => { + console.log('Processing channel stats:', channelStats); if ( !channelStats || !channelStats.channels || @@ -934,7 +942,7 @@ const ChannelsPage = () => { }); console.log('Processed active channels:', stats); - + // Update clients based on new stats const clientStats = Object.values(stats).reduce((acc, ch) => { if (ch.clients && Array.isArray(ch.clients)) { @@ -948,7 +956,7 @@ const ChannelsPage = () => { return acc; }, []); setClients(clientStats); - + return stats; }); }, [channelStats, channels, channelsByUUID, streamProfiles]);