Merge pull request #4194 from silamon/fixmissingline
Capture data between terminal creation and connected to terminal in demo
This commit is contained in:
+17
-3
@@ -16,7 +16,9 @@ function startServer() {
|
|||||||
var app = express();
|
var app = express();
|
||||||
expressWs(app);
|
expressWs(app);
|
||||||
|
|
||||||
var terminals = {};
|
var terminals = {},
|
||||||
|
unsentOutput = {},
|
||||||
|
temporaryDisposable = {};
|
||||||
|
|
||||||
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 +56,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;
|
||||||
|
unsentOutput[term.pid] = '';
|
||||||
|
temporaryDisposable[term.pid] = term.onData(function(data) {
|
||||||
|
unsentOutput[term.pid] += data;
|
||||||
|
});
|
||||||
res.send(term.pid.toString());
|
res.send(term.pid.toString());
|
||||||
res.end();
|
res.end();
|
||||||
});
|
});
|
||||||
@@ -72,6 +78,10 @@ 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);
|
||||||
|
temporaryDisposable[term.pid].dispose();
|
||||||
|
delete temporaryDisposable[term.pid];
|
||||||
|
ws.send(unsentOutput[term.pid]);
|
||||||
|
delete unsentOutput[term.pid];
|
||||||
|
|
||||||
// unbuffered delivery after user input
|
// unbuffered delivery after user input
|
||||||
let userInput = false;
|
let userInput = false;
|
||||||
@@ -131,8 +141,12 @@ function startServer() {
|
|||||||
// WARNING: This is a naive implementation that will not throttle the flow of data. This means
|
// WARNING: This is a naive implementation that will not throttle the flow of data. This means
|
||||||
// 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.onData(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);
|
||||||
|
|||||||
Reference in New Issue
Block a user