change demo to utf8 input
This commit is contained in:
@@ -134,6 +134,7 @@ function createTerminal(): void {
|
|||||||
pid = processId;
|
pid = processId;
|
||||||
socketURL += processId;
|
socketURL += processId;
|
||||||
socket = new WebSocket(socketURL);
|
socket = new WebSocket(socketURL);
|
||||||
|
socket.binaryType = 'arraybuffer';
|
||||||
socket.onopen = runRealTerminal;
|
socket.onopen = runRealTerminal;
|
||||||
socket.onclose = runFakeTerminal;
|
socket.onclose = runFakeTerminal;
|
||||||
socket.onerror = runFakeTerminal;
|
socket.onerror = runFakeTerminal;
|
||||||
|
|||||||
+7
-6
@@ -32,7 +32,8 @@ function startServer() {
|
|||||||
cols: cols || 80,
|
cols: cols || 80,
|
||||||
rows: rows || 24,
|
rows: rows || 24,
|
||||||
cwd: process.env.PWD,
|
cwd: process.env.PWD,
|
||||||
env: process.env
|
env: process.env,
|
||||||
|
encoding: null
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('Created terminal with PID: ' + term.pid);
|
console.log('Created terminal with PID: ' + term.pid);
|
||||||
@@ -62,20 +63,20 @@ function startServer() {
|
|||||||
ws.send(logs[term.pid]);
|
ws.send(logs[term.pid]);
|
||||||
|
|
||||||
function buffer(socket, timeout) {
|
function buffer(socket, timeout) {
|
||||||
let s = '';
|
let buffer = [];
|
||||||
let sender = null;
|
let sender = null;
|
||||||
return (data) => {
|
return (data) => {
|
||||||
s += data;
|
buffer.push(data);
|
||||||
if (!sender) {
|
if (!sender) {
|
||||||
sender = setTimeout(() => {
|
sender = setTimeout(() => {
|
||||||
socket.send(s);
|
socket.send(Buffer.concat(buffer));
|
||||||
s = '';
|
buffer = [];
|
||||||
sender = null;
|
sender = null;
|
||||||
}, timeout);
|
}, timeout);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const send = buffer(ws, 5);
|
const send = buffer(ws, 5);
|
||||||
|
|
||||||
term.on('data', function(data) {
|
term.on('data', function(data) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -42,6 +42,11 @@ export function attach(term: Terminal, socket: WebSocket, bidirectional: boolean
|
|||||||
addonTerminal.__getMessage = function(ev: MessageEvent): void {
|
addonTerminal.__getMessage = function(ev: MessageEvent): void {
|
||||||
let str: string;
|
let str: string;
|
||||||
|
|
||||||
|
if (ev.data instanceof ArrayBuffer) {
|
||||||
|
addonTerminal.writeUtf8(new Uint8Array(ev.data));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof ev.data === 'object') {
|
if (typeof ev.data === 'object') {
|
||||||
if (!myTextDecoder) {
|
if (!myTextDecoder) {
|
||||||
myTextDecoder = new TextDecoder();
|
myTextDecoder = new TextDecoder();
|
||||||
|
|||||||
Reference in New Issue
Block a user