From d68eca64c8cdc3c1017a6680548b8efd84db2e50 Mon Sep 17 00:00:00 2001 From: nguyentrungthat <80239428+nguentrungthat@users.noreply.github.com> Date: Thu, 26 Feb 2026 09:47:48 +0700 Subject: [PATCH] Emit update_status_ready and filter ready lines Emit a dedicated 'update_status_ready' event when a LineConnection becomes ready, and stop sending isReady in the 'line_output' payload. On the server side, normalize incoming run_all_dpelp data and filter lineIds to only include lines that are already ready; also bail out early if no eligible lines or station isn't configured to send wiki. On the frontend, initialize line state with isReady, stop deriving readiness from line_output, and listen for the new 'update_status_ready' event to update line readiness in the UI. --- BACKEND/app/services/line_connection.ts | 6 +++++- BACKEND/providers/socket_io_provider.ts | 12 ++++++++++-- FRONTEND/src/App.tsx | 20 +++++++++++++++----- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/BACKEND/app/services/line_connection.ts b/BACKEND/app/services/line_connection.ts index 2a5b353..d9b95af 100644 --- a/BACKEND/app/services/line_connection.ts +++ b/BACKEND/app/services/line_connection.ts @@ -253,13 +253,17 @@ export default class LineConnection { this.config.output = this.config.output.slice(-15000) if (!this.isReady && canInputCommand(message)) { this.isReady = true + this.socketIO.emit('update_status_ready', { + stationId, + lineId: id, + isReady: true, + }) } this.socketIO.emit('line_output', { stationId, lineId: id, data: message, ports: this.config.ports, - isReady: this.isReady ? true : canInputCommand(message), }) setTimeout(() => { if (!this.config.inventory) { diff --git a/BACKEND/providers/socket_io_provider.ts b/BACKEND/providers/socket_io_provider.ts index 08decde..d2ff63a 100644 --- a/BACKEND/providers/socket_io_provider.ts +++ b/BACKEND/providers/socket_io_provider.ts @@ -605,7 +605,7 @@ export class WebSocketIo { socket.on('run_all_dpelp', async (data) => { try { - const lineIds = data.lineIds + const dataLines = data.lineIds || [] const stationName = data.stationName || '' const stationId = data.stationId || '' const scenarioName = data.scenarioName || '' @@ -613,9 +613,17 @@ export class WebSocketIo { // Check station is active const activeStation = await checkStationActive(stationId) if (!activeStation) return + // Filter line is not ready + let lineIds: number[] = [] + for (const lineId of dataLines) { + const line = this.lineMap.get(lineId) + if (line && line.isReady) { + lineIds.push(lineId) + } + } // Check station sendWiki flag console.log('[DPELP] Received run all dpelp', lineIds) - if (!station || !station?.send_wiki) return + if (!station || !station?.send_wiki || lineIds?.length < 1) return const results = await this.waitUntilAllReady(lineIds) const tableHTML = this.generateTable(results) diff --git a/FRONTEND/src/App.tsx b/FRONTEND/src/App.tsx index 6848cde..57ce4f3 100644 --- a/FRONTEND/src/App.tsx +++ b/FRONTEND/src/App.tsx @@ -257,6 +257,7 @@ function App() { output: "[CLEAR_TERMINAL_SCROLL_BACK]", listFeatureTested: [], latestScenario: undefined, + isReady: false, }, data?.stationId ) @@ -264,11 +265,11 @@ function App() { socket?.on("line_output", (data) => { const { lineId, data: text } = data; - updateValueLineStation( - data?.lineId, - { isReady: data.isReady }, - data?.stationId - ); + // updateValueLineStation( + // data?.lineId, + // { isReady: data.isReady }, + // data?.stationId + // ); const buf = lineBuffersRef.current.get(lineId) || ""; lineBuffersRef.current.set(lineId, buf + text); @@ -279,6 +280,15 @@ function App() { } }); + socket?.on("update_status_ready", (data) => { + const { isReady } = data; + updateValueLineStation( + data?.lineId, + { isReady: isReady }, + data?.stationId + ); + }); + socket?.on("line_error", (data) => { updateValueLineStation( data?.lineId,