diff --git a/backend/src/api.ts b/backend/src/api.ts index 4aca096..e521b6d 100644 --- a/backend/src/api.ts +++ b/backend/src/api.ts @@ -16,9 +16,10 @@ export class Session { this.run(); ws.on("message", this.handleClientMessage); } - handleClientMessage(msg) { + handleClientMessage = (event: string) => { + let msg: any; try { - msg = JSON.parse(msg); + msg = JSON.parse(event); } catch (err) { console.error(`failed to parse client message: ${msg}`); return; @@ -37,8 +38,8 @@ export class Session { console.error(`unknown client message type: ${msg.event}`); break; } - } - run() { + }; + run = () => { const cmdline = this.config.cmdline; if (this.term) { this.term.kill(); @@ -51,5 +52,5 @@ export class Session { this.term.on("data", (data) => this.ws.send(JSON.stringify({ event: "terminalOutput", output: data })) ); - } + }; } diff --git a/frontend/src/app.ts b/frontend/src/app.ts index 33898ef..f95f6db 100644 --- a/frontend/src/app.ts +++ b/frontend/src/app.ts @@ -53,3 +53,7 @@ socket.addEventListener("close", (event) => { socket.addEventListener("onerror", (event) => console.error("Connection error:", event) ); + +term.onData((data) => + socket.send(JSON.stringify({ event: "terminalInput", input: data })) +);