diff --git a/BACKEND/app/services/line_connection.ts b/BACKEND/app/services/line_connection.ts index c3d26c9..a67a649 100644 --- a/BACKEND/app/services/line_connection.ts +++ b/BACKEND/app/services/line_connection.ts @@ -130,6 +130,7 @@ export default class LineConnection { private outputPhysicalTest: string private outputLoadIosLicense: string | boolean private listDeviceIos: string[] + private debounceTimer: NodeJS.Timeout | null = null constructor(config: LineConfig, socketIO: any, handleClearLine: () => void) { this.config = config @@ -159,6 +160,7 @@ export default class LineConnection { this.outputPhysicalTest = '' this.outputLoadIosLicense = '' this.listDeviceIos = [] + this.debounceTimer = null } /** * Connect to line with socket @@ -209,13 +211,18 @@ export default class LineConnection { } if (this.config.runningPhysical) { this.outputPhysicalTest += message - const ports = this.physicalTest.handleLog(message) - if (ports?.length) - this.socketIO.emit('test_port_physical', { - stationId, - lineId: id, - data: ports, - }) + if (this.debounceTimer) clearTimeout(this.debounceTimer) + + this.debounceTimer = setTimeout(() => { + this.flushLogBuffer() + }, 1000) // 1s debounce + // const ports = this.physicalTest.handleLog(message) + // if (ports?.length) + // this.socketIO.emit('test_port_physical', { + // stationId, + // lineId: id, + // data: ports, + // }) } if (data.toString().includes('More') || data.toString().includes('MORE')) this.writeCommand(' ') @@ -1076,6 +1083,25 @@ export default class LineConnection { // }, 10000) } + flushLogBuffer() { + const lines = this.outputPhysicalTest.split(/\r?\n/) + + // giữ lại dòng cuối nếu chưa kết thúc hoàn chỉnh + this.outputPhysicalTest = lines.pop() || '' + + const completeLines = lines.join('\n') + + if (completeLines.trim()) { + const ports = this.physicalTest.handleLog(completeLines) + if (ports?.length) + this.socketIO.emit('test_port_physical', { + stationId: this.config.stationId, + lineId: this.config.id, + data: ports, + }) + } + } + /** * End all testing */ diff --git a/BACKEND/app/services/physical_test_service.ts b/BACKEND/app/services/physical_test_service.ts index d3c6546..4b66b83 100644 --- a/BACKEND/app/services/physical_test_service.ts +++ b/BACKEND/app/services/physical_test_service.ts @@ -74,14 +74,14 @@ export class PhysicalPortTest { markTested = true } - if (!iface) return + if (!iface) continue const port = this.ports.get(iface) - if (!port) return + if (!port) continue port.lastSeen = new Date() - if (state && port.lastState === state) return + if (state && port.lastState === state) continue if (state) port.lastState = state // ⭐ PASS nếu có ít nhất 1 event hợp lệ diff --git a/FRONTEND/src/components/Modal/ModalTerminal.tsx b/FRONTEND/src/components/Modal/ModalTerminal.tsx index b96de78..ddf7206 100644 --- a/FRONTEND/src/components/Modal/ModalTerminal.tsx +++ b/FRONTEND/src/components/Modal/ModalTerminal.tsx @@ -9,6 +9,7 @@ import { Menu, Modal, ScrollArea, + SimpleGrid, Tabs, Text, Textarea, @@ -983,9 +984,9 @@ const ModalTerminal = ({ - + {line?.runningPhysical && line?.ports - ? line?.ports?.map((port, i) => ( + ? line.ports.map((port, i) => ( )) - : ""} - + : null} +