From 350b0e6b7d240686638094a7a6ec2b469d04a065 Mon Sep 17 00:00:00 2001 From: Indra Gunawan <1284811+coderbuzz@users.noreply.github.com> Date: Wed, 1 Jul 2026 17:44:41 +0700 Subject: [PATCH] perf: kirim keystrokes raw text, resize via binary frame, hapus OCRNL --- internal/http/console.go | 22 +++++++++++----------- internal/http/templates/layout.html | 5 +++-- internal/ssh/client.go | 1 - 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/internal/http/console.go b/internal/http/console.go index 9810c4e..e44dabb 100644 --- a/internal/http/console.go +++ b/internal/http/console.go @@ -94,24 +94,24 @@ func (h *ConsoleHandler) ServeWS(w http.ResponseWriter, r *http.Request) { // WebSocket → SSH stdin go func() { for { - _, msg, err := conn.ReadMessage() + messageType, msg, err := conn.ReadMessage() if err != nil { errCh <- err return } - var input ssh.Input - if json.Unmarshal(msg, &input) == nil { - if input.Resize != nil { - inCh <- input - continue - } - if len(input.Data) > 0 { + + switch messageType { + case websocket.TextMessage: + // Keystrokes — raw text, no JSON parsing + inCh <- ssh.Input{Data: string(msg)} + + case websocket.BinaryMessage: + // Resize events — JSON + var input ssh.Input + if json.Unmarshal(msg, &input) == nil && input.Resize != nil { inCh <- input - continue } } - - inCh <- ssh.Input{Data: string(msg)} } }() diff --git a/internal/http/templates/layout.html b/internal/http/templates/layout.html index d5cafbf..faee3e8 100644 --- a/internal/http/templates/layout.html +++ b/internal/http/templates/layout.html @@ -415,9 +415,10 @@ document.getElementById('console-status').textContent = 'Connected'; document.getElementById('console-status').className = 'badge badge-online'; term.focus(); + var enc = new TextEncoder(); var dims = fitAddon.proposeDimensions(); if (dims) { - ws.send(JSON.stringify({resize: {width: dims.cols, height: dims.rows}})); + ws.send(enc.encode(JSON.stringify({resize: {width: dims.cols, height: dims.rows}}))); } }; @@ -448,7 +449,7 @@ fitAddon.fit(); var dims = fitAddon.proposeDimensions(); if (dims) { - ws.send(JSON.stringify({resize: {width: dims.cols, height: dims.rows}})); + ws.send(enc.encode(JSON.stringify({resize: {width: dims.cols, height: dims.rows}}))); } }; window.addEventListener('resize', window._consoleResizeHandler); diff --git a/internal/ssh/client.go b/internal/ssh/client.go index 0bc399d..48cdf1e 100644 --- a/internal/ssh/client.go +++ b/internal/ssh/client.go @@ -95,7 +95,6 @@ func (c *Client) Shell(ctx context.Context, rows, cols int) (<-chan Output, chan if err := session.RequestPty("xterm-256color", rows, cols, gossh.TerminalModes{ gossh.ECHO: 1, - gossh.OCRNL: 1, gossh.TTY_OP_ISPEED: 14400, gossh.TTY_OP_OSPEED: 14400, }); err != nil {