Skip to content

Commit

Permalink
simple refactor of shell's ping/pong (#3146)
Browse files Browse the repository at this point in the history
  • Loading branch information
johrstrom authored Nov 6, 2023
1 parent 2fa2f65 commit 5dc68ba
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions apps/shell/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,6 @@ function detect_auth_error(requestToken, client_origin, server_origin, host) {
}
}

function noop() {}

function heartbeat() {
this.isAlive = true;
}

wss.on('connection', function connection (ws, req) {
var dir,
term,
Expand All @@ -152,7 +146,6 @@ wss.on('connection', function connection (ws, req) {
cmd = process.env.OOD_SSH_WRAPPER || 'ssh';

ws.isAlive = true;
ws.on('pong', heartbeat);

console.log('Connection established');

Expand Down Expand Up @@ -198,6 +191,10 @@ wss.on('connection', function connection (ws, req) {
term.end();
console.log('Closed terminal: ' + term.pid);
});

ws.on('pong', function () {
this.isAlive = true;
});
}
});

Expand All @@ -206,10 +203,14 @@ const interval = setInterval(function ping() {
if (ws.isAlive === false) return ws.terminate();

ws.isAlive = false;
ws.ping(noop);
ws.ping();
});
}, 30000);

wss.on('close', function close() {
clearInterval(interval);
});

server.on('upgrade', function upgrade(request, socket, head) {
wss.handleUpgrade(request, socket, head, function done(ws) {
wss.emit('connection', ws, request);
Expand Down

0 comments on commit 5dc68ba

Please sign in to comment.