diff --git a/includes/websocket.js b/includes/websocket.js index f32a5e7..ead7d56 100644 --- a/includes/websocket.js +++ b/includes/websocket.js @@ -14,35 +14,21 @@ function startDockerStatsInterval(ws, client, user, docker) { return null; } - (async () => { + // Send initial stats immediately + (async () => { try { const initialStats = await getContainerStats(docker, user); - // Get container info to retrieve IP address - const container = docker.getContainer(user); - const containerInfo = await container.inspect(); - const ipAddress = containerInfo.NetworkSettings.Networks?.minecraft_network?.IPAddress || 'N/A'; - if (ws.readyState === ws.OPEN) { - ws.send(JSON.stringify({ - type: 'docker', - data: { - ...initialStats, - user, - ipAddress - } - })); + ws.send(JSON.stringify({ type: 'docker', data: { ...initialStats, user } })); } } catch (error) { console.error(`Error sending initial docker stats for ${user}:`, error.message); if (ws.readyState === ws.OPEN) { - ws.send(JSON.stringify({ - type: 'docker', - error: `Failed to fetch initial stats: ${error.message}` - })); + ws.send(JSON.stringify({ type: 'docker', error: `Failed to fetch initial stats: ${error.message}` })); } } })(); - // Start interval for periodic stats + // Start interval for periodic stats const intervalId = setInterval(async () => { try { @@ -61,20 +47,11 @@ function startDockerStatsInterval(ws, client, user, docker) { } const stats = await getContainerStats(docker, user); - const ipAddress = inspect.NetworkSettings.Networks?.minecraft_network?.IPAddress || 'N/A'; - if (stats.error) { console.error(`Error fetching stats for ${user}: ${stats.error}`); ws.send(JSON.stringify({ type: 'docker', error: stats.error })); } else { - ws.send(JSON.stringify({ - type: 'docker', - data: { - ...stats, - user, - ipAddress - } - })); + ws.send(JSON.stringify({ type: 'docker', data: { ...stats, user } })); } } catch (error) { console.error(`Error in docker stats interval for ${user}:`, error.message);