Fully interactive terminal!
This commit is contained in:
parent
7df0eea51d
commit
250509ffe1
|
@ -16,9 +16,10 @@ export class Session {
|
||||||
this.run();
|
this.run();
|
||||||
ws.on("message", this.handleClientMessage);
|
ws.on("message", this.handleClientMessage);
|
||||||
}
|
}
|
||||||
handleClientMessage(msg) {
|
handleClientMessage = (event: string) => {
|
||||||
|
let msg: any;
|
||||||
try {
|
try {
|
||||||
msg = JSON.parse(msg);
|
msg = JSON.parse(event);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`failed to parse client message: ${msg}`);
|
console.error(`failed to parse client message: ${msg}`);
|
||||||
return;
|
return;
|
||||||
|
@ -37,8 +38,8 @@ export class Session {
|
||||||
console.error(`unknown client message type: ${msg.event}`);
|
console.error(`unknown client message type: ${msg.event}`);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
run() {
|
run = () => {
|
||||||
const cmdline = this.config.cmdline;
|
const cmdline = this.config.cmdline;
|
||||||
if (this.term) {
|
if (this.term) {
|
||||||
this.term.kill();
|
this.term.kill();
|
||||||
|
@ -51,5 +52,5 @@ export class Session {
|
||||||
this.term.on("data", (data) =>
|
this.term.on("data", (data) =>
|
||||||
this.ws.send(JSON.stringify({ event: "terminalOutput", output: data }))
|
this.ws.send(JSON.stringify({ event: "terminalOutput", output: data }))
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,3 +53,7 @@ socket.addEventListener("close", (event) => {
|
||||||
socket.addEventListener("onerror", (event) =>
|
socket.addEventListener("onerror", (event) =>
|
||||||
console.error("Connection error:", event)
|
console.error("Connection error:", event)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
term.onData((data) =>
|
||||||
|
socket.send(JSON.stringify({ event: "terminalInput", input: data }))
|
||||||
|
);
|
||||||
|
|
Loading…
Reference in New Issue