From f71f18393ef3d061a98ac8f6aa6cfe05193849ac Mon Sep 17 00:00:00 2001 From: nguyentrungthat <80239428+nguentrungthat@users.noreply.github.com> Date: Thu, 4 Dec 2025 10:23:54 +0700 Subject: [PATCH] =?UTF-8?q?Update=20b=E1=BA=A5t=20=C4=91=E1=BB=93ng=20b?= =?UTF-8?q?=E1=BB=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BACKEND/providers/socket_io_provider.ts | 62 +++++++++++------------ FRONTEND/src/components/TerminalXTerm.tsx | 4 +- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/BACKEND/providers/socket_io_provider.ts b/BACKEND/providers/socket_io_provider.ts index 5f36df3..57a98f0 100644 --- a/BACKEND/providers/socket_io_provider.ts +++ b/BACKEND/providers/socket_io_provider.ts @@ -665,7 +665,7 @@ export class WebSocketIo { action: LineAction, options: HandleOptions = {} ): Promise { - for (const lineId of lineIds) { + lineIds.forEach(async (lineId) => { try { const line = this.lineMap.get(lineId) // console.log(line?.config) @@ -675,45 +675,45 @@ export class WebSocketIo { // await sleep(500) await action(line, options) } else { - if (this.lineConnecting.includes(lineId)) continue - - const linesData = await Line.findBy('id', lineId) - const stationData = await Station.findBy('id', stationId) - io.emit('line_connecting', { - stationId, - lineId, - }) - if (linesData && stationData) { - this.lineConnecting.push(lineId) - await this.connectLine( - io, - [linesData], - stationData, - line?.config?.output || '', - line?.config?.inventory || '' - ) - this.lineConnecting = this.lineConnecting.filter((el) => el !== lineId) - - const lineReconnect = this.lineMap.get(lineId) - if (lineReconnect) { - this.setTimeoutConnect(lineId, lineReconnect) - await sleep(100) - await action(lineReconnect, options) - } - } else { - io.emit('line_disconnected', { + if (!this.lineConnecting.includes(lineId)) { + const linesData = await Line.findBy('id', lineId) + const stationData = await Station.findBy('id', stationId) + io.emit('line_connecting', { stationId, lineId, - status: 'disconnected', }) - io.emit('line_error', { lineId, error: 'Line not connected\r\n', stationId }) + if (linesData && stationData) { + this.lineConnecting.push(lineId) + await this.connectLine( + io, + [linesData], + stationData, + line?.config?.output || '', + line?.config?.inventory || '' + ) + this.lineConnecting = this.lineConnecting.filter((el) => el !== lineId) + + const lineReconnect = this.lineMap.get(lineId) + if (lineReconnect) { + this.setTimeoutConnect(lineId, lineReconnect) + await sleep(100) + await action(lineReconnect, options) + } + } else { + io.emit('line_disconnected', { + stationId, + lineId, + status: 'disconnected', + }) + io.emit('line_error', { lineId, error: 'Line not connected\r\n', stationId }) + } } } } catch (err: any) { this.lineConnecting = this.lineConnecting.filter((el) => el !== lineId) io.emit('line_error', { lineId, error: `\n[ERROR] ${err.message}\n`, stationId }) } - } + }) } private async connectApc(socket: any, apcName: string, station: Station) { diff --git a/FRONTEND/src/components/TerminalXTerm.tsx b/FRONTEND/src/components/TerminalXTerm.tsx index b86353c..233fe60 100644 --- a/FRONTEND/src/components/TerminalXTerm.tsx +++ b/FRONTEND/src/components/TerminalXTerm.tsx @@ -162,7 +162,9 @@ const TerminalCLI: React.FC = ({ terminal.current?.write(initContent); setIsInit(true); if (!miniSize && !isDisabled) terminal.current?.focus(); - terminal.current.scrollToBottom(); + setTimeout(() => { + if (terminal.current) terminal.current.scrollToBottom(); + }, 100); if (terminal.current.options.theme) { const textColor = localStorage.getItem("terminal-text-color") || "#41ee4a";