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