From f743f8fa9c7e400b143003b5ec6fa83e668ff646 Mon Sep 17 00:00:00 2001 From: Karmaa Date: Fri, 21 Mar 2025 15:38:12 -0500 Subject: [PATCH] Optimize ssh connection (faster). Renamed all versions to reflect that this project is still under development (expect bugs). --- src/apps/ssh/Terminal.jsx | 12 +++++++++++- src/backend/ssh.cjs | 10 +++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/apps/ssh/Terminal.jsx b/src/apps/ssh/Terminal.jsx index db9e78ca..4fbf0600 100644 --- a/src/apps/ssh/Terminal.jsx +++ b/src/apps/ssh/Terminal.jsx @@ -117,8 +117,18 @@ export const NewTerminal = forwardRef(({ hostConfig, isVisible, setIsNoAuthHidde let isPasting = false; + let buffer = ""; + let bufferTimeout = null; + terminalInstance.current.onData((data) => { - socketRef.current.emit("data", data); + buffer += data; + if (!bufferTimeout) { + bufferTimeout = setTimeout(() => { + socketRef.current.emit("data", buffer); + buffer = ""; + bufferTimeout = null; + }, 20); + } }); terminalInstance.current.attachCustomKeyEventHandler((event) => { diff --git a/src/backend/ssh.cjs b/src/backend/ssh.cjs index b4281c3e..775a6149 100644 --- a/src/backend/ssh.cjs +++ b/src/backend/ssh.cjs @@ -10,7 +10,10 @@ const io = socketIo(server, { methods: ["GET", "POST"], credentials: true }, - allowEIO3: true + allowEIO3: true, + pingInterval: 2500, + pingTimeout: 5000, + maxHttpBufferSize: 1e7, }); const logger = { @@ -106,8 +109,9 @@ io.on("connection", (socket) => { kex: ['curve25519-sha256', 'curve25519-sha256@libssh.org', 'ecdh-sha2-nistp256'], serverHostKey: ['ssh-ed25519', 'ecdsa-sha2-nistp256'] }, - keepaliveInterval: 30000, - keepaliveCountMax: 3, + keepaliveInterval: 10000, + keepaliveCountMax: 5, + readyTimeout: 5000, }); });