Fix timeout on close.

This commit is contained in:
LukeGus
2024-12-10 21:32:58 -06:00
parent 2061ac5e3b
commit 4d8263a788
2 changed files with 18 additions and 11 deletions

View File

@@ -16,6 +16,7 @@ wss.on('connection', (ws) => {
let stream = null;
let currentCols = 80;
let currentRows = 24;
let interval = null;
const resizeTerminal = (cols, rows) => {
if (stream && stream.setWindow) {
@@ -44,7 +45,7 @@ wss.on('connection', (ws) => {
conn.on('ready', () => {
console.log('SSH Connection established');
const interval = setInterval(() => {
interval = setInterval(() => {
if (ws.readyState === WebSocket.OPEN) {
ws.ping();
} else {
@@ -90,7 +91,9 @@ wss.on('connection', (ws) => {
ws.on('close', () => {
console.log('WebSocket closed');
clearInterval(interval);
if (interval) {
clearInterval(interval);
}
if (conn) {
conn.end();
}