Skip to content

Commit

Permalink
websocket buffer; requestAnimationFrame
Browse files Browse the repository at this point in the history
  • Loading branch information
jerch committed Jul 1, 2016
1 parent 39c4356 commit c1d8e4f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
27 changes: 23 additions & 4 deletions demo/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ var expressWs = require('express-ws')(app);
var os = require('os');
var pty = require('pty.js');

var sendHandler = null;
var buf = '';

app.use('/src', express.static(__dirname + '/../src'));
app.use('/addons', express.static(__dirname + '/../addons'));

Expand Down Expand Up @@ -31,10 +34,26 @@ app.ws('/bash', function(ws, req) {
env: process.env
});
term.on('data', function(data) {
try {
ws.send(data);
} catch (ex) {
// The WebSocket is not open, ignore
buf += data;
clearTimeout(sendHandler);
if (buf.length < 128000) {
//clearTimeout(sendHandler);
sendHandler = setTimeout(
function() {
try {
ws.send(buf);
buf = '';
} catch (ex) {
// The WebSocket is not open, ignore
}
}, 2);
} else {
try {
ws.send(buf);
buf = '';
} catch (ex) {
// The WebSocket is not open, ignore
}
}
});
ws.on('message', function(msg) {
Expand Down
5 changes: 3 additions & 2 deletions src/xterm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1218,8 +1218,9 @@
this._fullRefreshNext = true;
} else {
setTimeout(function () {
self.refresh(start, end, false);
}, 34)
requestAnimationFrame(function() {self.refresh(start, end, false);});
//self.refresh(start, end, false);
}, 10)
this._refreshIsQueued = true;
}
return;
Expand Down

0 comments on commit c1d8e4f

Please sign in to comment.