Skip to content

Commit

Permalink
Merge pull request #2080 from jerch/demo_update
Browse files Browse the repository at this point in the history
apply attach changes to demo
  • Loading branch information
Tyriar committed May 14, 2019
2 parents eef8556 + b9cfbbe commit 9cb6706
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
12 changes: 8 additions & 4 deletions demo/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ declare let window: IWindowWithTerminal;
Terminal.applyAddon(fit);

let term;
let attachAddon: AttachAddon;
let searchAddon: SearchAddon;
let protocol;
let socketURL;
Expand Down Expand Up @@ -90,8 +89,6 @@ function createTerminal(): void {
// Load addons
const typedTerm = term as TerminalType;
typedTerm.loadAddon(new WebLinksAddon());
attachAddon = new AttachAddon();
typedTerm.loadAddon(attachAddon);
searchAddon = new SearchAddon();
typedTerm.loadAddon(searchAddon);

Expand Down Expand Up @@ -152,7 +149,14 @@ function createTerminal(): void {
}

function runRealTerminal(): void {
attachAddon.attach(socket);
/**
* The demo defaults to string transport by default.
* To run it with UTF8 binary transport, swap comment on
* the lines below. (Must also be switched in server.js)
*/
term.loadAddon(new AttachAddon(socket));
// term.loadAddon(new AttachAddon(socket, {inputUtf8: true}));

term._initialized = true;
}

Expand Down
31 changes: 29 additions & 2 deletions demo/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ var expressWs = require('express-ws');
var os = require('os');
var pty = require('node-pty');

/**
* Whether to use UTF8 binary transport.
* (Must also be switched in client.ts)
*/
const USE_BINARY_UTF8 = false;


function startServer() {
var app = express();
expressWs(app);
Expand Down Expand Up @@ -36,7 +43,8 @@ function startServer() {
cols: cols || 80,
rows: rows || 24,
cwd: process.env.PWD,
env: process.env
env: process.env,
encoding: USE_BINARY_UTF8 ? null : 'utf8'
});

console.log('Created terminal with PID: ' + term.pid);
Expand Down Expand Up @@ -65,6 +73,7 @@ function startServer() {
console.log('Connected to terminal ' + term.pid);
ws.send(logs[term.pid]);

// string message buffering
function buffer(socket, timeout) {
let s = '';
let sender = null;
Expand All @@ -79,7 +88,25 @@ function startServer() {
}
};
}
const send = buffer(ws, 5);
// binary message buffering
function bufferUtf8(socket, timeout) {
let buffer = [];
let sender = null;
let length = 0;
return (data) => {
buffer.push(data);
length += data.length;
if (!sender) {
sender = setTimeout(() => {
socket.send(Buffer.concat(buffer, length));
buffer = [];
sender = null;
length = 0;
}, timeout);
}
};
}
const send = USE_BINARY_UTF8 ? bufferUtf8(ws, 5) : buffer(ws, 5);

term.on('data', function(data) {
try {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@
"ts-loader": "^4.5.0",
"tslint": "^5.9.1",
"tslint-consistent-codestyle": "^1.13.0",
"utf8": "^3.0.0",
"typescript": "3.4",
"utf8": "^3.0.0",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0",
"webpack": "^4.17.1",
"webpack-cli": "^3.1.0",
"xterm-addon-attach": "0.1.0-beta7",
"xterm-addon-attach": "0.1.0-beta8",
"xterm-addon-search": "0.1.0-beta4",
"xterm-addon-web-links": "0.1.0-beta6",
"zmodem.js": "^0.1.5"
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7236,10 +7236,10 @@ xregexp@4.0.0:
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af"
integrity sha1-pcbVMr5lbiPbgg77lDofBJmNY68=

xterm-addon-attach@0.1.0-beta7:
version "0.1.0-beta7"
resolved "https://registry.yarnpkg.com/xterm-addon-attach/-/xterm-addon-attach-0.1.0-beta7.tgz#787f6cce709611ee08ab731b95a62fa1c0bce6a9"
integrity sha512-nQr6LcYtpZcyDoHyL/BDIPJcTgL7qlHR/rvm8lSizQysGVT0pSzr5M7SjY3kQHw33U3hTer3c6oZzwjfj4ohOw==
xterm-addon-attach@0.1.0-beta8:
version "0.1.0-beta8"
resolved "https://registry.yarnpkg.com/xterm-addon-attach/-/xterm-addon-attach-0.1.0-beta8.tgz#e469ed9d6ab7e535d0a9ffae23ef4f2efe58163b"
integrity sha512-HtQuwqnvcR+SwI9/JbBMd//Il+oEeo3rWrIucLLKHT8sB+OAOkdhmo5KIM/hhnovjI040WJ+tTHkDgPFwIJtmw==

xterm-addon-search@0.1.0-beta4:
version "0.1.0-beta4"
Expand Down

0 comments on commit 9cb6706

Please sign in to comment.