Keep SSH session alive.

This commit is contained in:
Karmaa
2025-03-21 00:50:26 -05:00
parent 8209fb5318
commit 4f384dd60b
2 changed files with 16 additions and 2 deletions

View File

@@ -178,7 +178,16 @@ export const NewTerminal = forwardRef(({ hostConfig, isVisible, setIsNoAuthHidde
}
});
const pingInterval = setInterval(() => {
socketRef.current.emit("ping");
}, 5000);
socketRef.current.on("pong", () => {
console.log("Received pong from server.");
});
return () => {
clearInterval(pingInterval);
if (terminalInstance.current) {
terminalInstance.current.dispose();
terminalInstance.current = null;

View File

@@ -53,7 +53,7 @@ io.on("connection", (socket) => {
.on("ready", function () {
logger.info("SSH connection established");
conn.shell({ term: "xterm-256color" }, function (err, newStream) {
conn.shell({ term: "xterm-256color", keepaliveInterval: 30000 }, function (err, newStream) {
if (err) {
logger.error("Shell error:", err.message);
socket.emit("error", err.message);
@@ -93,6 +93,9 @@ io.on("connection", (socket) => {
logger.error("Error:", err.message);
socket.emit("error", err.message);
})
.on("ping", function () {
socket.emit("ping");
})
.connect({
host: ip,
port: port,
@@ -102,7 +105,9 @@ io.on("connection", (socket) => {
algorithms: {
kex: ['curve25519-sha256', 'curve25519-sha256@libssh.org', 'ecdh-sha2-nistp256'],
serverHostKey: ['ssh-ed25519', 'ecdsa-sha2-nistp256']
}
},
keepaliveInterval: 30000,
keepaliveCountMax: 3,
});
});