Keep SSH session alive.
This commit is contained in:
@@ -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 () => {
|
return () => {
|
||||||
|
clearInterval(pingInterval);
|
||||||
if (terminalInstance.current) {
|
if (terminalInstance.current) {
|
||||||
terminalInstance.current.dispose();
|
terminalInstance.current.dispose();
|
||||||
terminalInstance.current = null;
|
terminalInstance.current = null;
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ io.on("connection", (socket) => {
|
|||||||
.on("ready", function () {
|
.on("ready", function () {
|
||||||
logger.info("SSH connection established");
|
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) {
|
if (err) {
|
||||||
logger.error("Shell error:", err.message);
|
logger.error("Shell error:", err.message);
|
||||||
socket.emit("error", err.message);
|
socket.emit("error", err.message);
|
||||||
@@ -93,6 +93,9 @@ io.on("connection", (socket) => {
|
|||||||
logger.error("Error:", err.message);
|
logger.error("Error:", err.message);
|
||||||
socket.emit("error", err.message);
|
socket.emit("error", err.message);
|
||||||
})
|
})
|
||||||
|
.on("ping", function () {
|
||||||
|
socket.emit("ping");
|
||||||
|
})
|
||||||
.connect({
|
.connect({
|
||||||
host: ip,
|
host: ip,
|
||||||
port: port,
|
port: port,
|
||||||
@@ -102,7 +105,9 @@ io.on("connection", (socket) => {
|
|||||||
algorithms: {
|
algorithms: {
|
||||||
kex: ['curve25519-sha256', 'curve25519-sha256@libssh.org', 'ecdh-sha2-nistp256'],
|
kex: ['curve25519-sha256', 'curve25519-sha256@libssh.org', 'ecdh-sha2-nistp256'],
|
||||||
serverHostKey: ['ssh-ed25519', 'ecdsa-sha2-nistp256']
|
serverHostKey: ['ssh-ed25519', 'ecdsa-sha2-nistp256']
|
||||||
}
|
},
|
||||||
|
keepaliveInterval: 30000,
|
||||||
|
keepaliveCountMax: 3,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user