change demo to utf8 input

This commit is contained in:
Jörg Breitbart
2019-01-20 23:06:51 +01:00
parent 3a2076805c
commit e6e5ecc0f2
3 changed files with 13 additions and 6 deletions
+1
View File
@@ -134,6 +134,7 @@ function createTerminal(): void {
pid = processId;
socketURL += processId;
socket = new WebSocket(socketURL);
socket.binaryType = 'arraybuffer';
socket.onopen = runRealTerminal;
socket.onclose = runFakeTerminal;
socket.onerror = runFakeTerminal;
+7 -6
View File
@@ -32,7 +32,8 @@ function startServer() {
cols: cols || 80,
rows: rows || 24,
cwd: process.env.PWD,
env: process.env
env: process.env,
encoding: null
});
console.log('Created terminal with PID: ' + term.pid);
@@ -62,20 +63,20 @@ function startServer() {
ws.send(logs[term.pid]);
function buffer(socket, timeout) {
let s = '';
let buffer = [];
let sender = null;
return (data) => {
s += data;
buffer.push(data);
if (!sender) {
sender = setTimeout(() => {
socket.send(s);
s = '';
socket.send(Buffer.concat(buffer));
buffer = [];
sender = null;
}, timeout);
}
};
}
const send = buffer(ws, 5);
const send = buffer(ws, 5);
term.on('data', function(data) {
try {
+5
View File
@@ -42,6 +42,11 @@ export function attach(term: Terminal, socket: WebSocket, bidirectional: boolean
addonTerminal.__getMessage = function(ev: MessageEvent): void {
let str: string;
if (ev.data instanceof ArrayBuffer) {
addonTerminal.writeUtf8(new Uint8Array(ev.data));
return;
}
if (typeof ev.data === 'object') {
if (!myTextDecoder) {
myTextDecoder = new TextDecoder();