Adds logs again in server.js

This commit is contained in:
Simon Lamon
2022-10-09 12:16:26 +00:00
parent 0ba12301a6
commit fb91b01217
+13 -2
View File
@@ -16,7 +16,8 @@ function startServer() {
var app = express();
expressWs(app);
var terminals = {};
var terminals = {},
logs = {};
app.use('/xterm.css', express.static(__dirname + '/../css/xterm.css'));
app.get('/logo.png', (req, res) => {
@@ -54,6 +55,10 @@ function startServer() {
console.log('Created terminal with PID: ' + term.pid);
terminals[term.pid] = term;
logs[term.pid] = '';
term.on('data', function(data) {
logs[term.pid] += data;
});
res.send(term.pid.toString());
res.end();
});
@@ -72,6 +77,7 @@ function startServer() {
app.ws('/terminals/:pid', function (ws, req) {
var term = terminals[parseInt(req.params.pid)];
console.log('Connected to terminal ' + term.pid);
ws.send(logs[term.pid]);
// unbuffered delivery after user input
let userInput = false;
@@ -132,7 +138,11 @@ function startServer() {
// it could flood the communication channel and make the terminal unresponsive. Learn more about
// the problem and how to implement flow control at https://xtermjs.org/docs/guides/flowcontrol/
term.on('data', function(data) {
send(data);
try {
send(data);
} catch (ex) {
// The WebSocket is not open, ignore
}
});
ws.on('message', function(msg) {
term.write(msg);
@@ -143,6 +153,7 @@ function startServer() {
console.log('Closed terminal ' + term.pid);
// Clean things up
delete terminals[term.pid];
delete logs[term.pid];
});
});