Skip to content

Commit

Permalink
revert timeout to 5ms, remove log in server.js
Browse files Browse the repository at this point in the history
  • Loading branch information
jerch committed Sep 29, 2022
1 parent 2236e23 commit 193d305
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
17 changes: 3 additions & 14 deletions demo/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ function startServer() {
var app = express();
expressWs(app);

var terminals = {},
logs = {};
var terminals = {};

app.use('/xterm.css', express.static(__dirname + '/../css/xterm.css'));
app.get('/logo.png', (req, res) => {
Expand Down Expand Up @@ -55,10 +54,6 @@ 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();
});
Expand All @@ -77,7 +72,6 @@ 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;
Expand Down Expand Up @@ -132,17 +126,13 @@ function startServer() {
}
};
}
const send = (USE_BINARY ? bufferUtf8 : buffer)(ws, 2, 262144);
const send = (USE_BINARY ? bufferUtf8 : buffer)(ws, 5, 262144);

// 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
// the problem and how to implement flow control at https://xtermjs.org/docs/guides/flowcontrol/
term.on('data', function(data) {
try {
send(data);
} catch (ex) {
// The WebSocket is not open, ignore
}
send(data);
});
ws.on('message', function(msg) {
term.write(msg);
Expand All @@ -153,7 +143,6 @@ function startServer() {
console.log('Closed terminal ' + term.pid);
// Clean things up
delete terminals[term.pid];
delete logs[term.pid];
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/common/input/WriteBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export class WriteBuffer {
this._bufferOffset = 0;

// If this is the first write call after the user has done some input,
// parse it immediately in an upcoming microtask to minimize reduce input,
// parse it immediately to minimize reduce input,
// otherwise schedule for the next event
if (this._didUserInput) {
this._didUserInput = false;
Expand Down

0 comments on commit 193d305

Please sign in to comment.