Fix web-socket timeout.

This commit is contained in:
LukeGus
2024-12-10 21:28:39 -06:00
parent e1f9251186
commit 2061ac5e3b
3 changed files with 31 additions and 18 deletions

View File

@@ -43,6 +43,15 @@ wss.on('connection', (ws) => {
if (data?.host && data.port && data.username && data.password) {
conn.on('ready', () => {
console.log('SSH Connection established');
const interval = setInterval(() => {
if (ws.readyState === WebSocket.OPEN) {
ws.ping();
} else {
clearInterval(interval);
}
}, 15000);
conn.shell({ term: 'xterm', cols: currentCols, rows: currentRows }, (error, newStream) => {
if (error) {
console.error(`SSH Shell Error: ${error}`);
@@ -81,6 +90,7 @@ wss.on('connection', (ws) => {
ws.on('close', () => {
console.log('WebSocket closed');
clearInterval(interval);
if (conn) {
conn.end();
}