Skip to content

Commit 341395f

Browse files
authored
Merge pull request #12 from coderbuzz/fix/protocol-optimize
perf: kirim keystrokes raw text, resize via binary frame, hapus OCRNL
2 parents e2f05ff + 350b0e6 commit 341395f

3 files changed

Lines changed: 14 additions & 14 deletions

File tree

‎internal/http/console.go‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,24 +94,24 @@ func (h *ConsoleHandler) ServeWS(w http.ResponseWriter, r *http.Request) {
9494
// WebSocket → SSH stdin
9595
go func() {
9696
for {
97-
_, msg, err := conn.ReadMessage()
97+
messageType, msg, err := conn.ReadMessage()
9898
if err != nil {
9999
errCh <- err
100100
return
101101
}
102-
var input ssh.Input
103-
if json.Unmarshal(msg, &input) == nil {
104-
if input.Resize != nil {
105-
inCh <- input
106-
continue
107-
}
108-
if len(input.Data) > 0 {
102+
103+
switch messageType {
104+
case websocket.TextMessage:
105+
// Keystrokes — raw text, no JSON parsing
106+
inCh <- ssh.Input{Data: string(msg)}
107+
108+
case websocket.BinaryMessage:
109+
// Resize events — JSON
110+
var input ssh.Input
111+
if json.Unmarshal(msg, &input) == nil && input.Resize != nil {
109112
inCh <- input
110-
continue
111113
}
112114
}
113-
114-
inCh <- ssh.Input{Data: string(msg)}
115115
}
116116
}()
117117

‎internal/http/templates/layout.html‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,10 @@
415415
document.getElementById('console-status').textContent = 'Connected';
416416
document.getElementById('console-status').className = 'badge badge-online';
417417
term.focus();
418+
var enc = new TextEncoder();
418419
var dims = fitAddon.proposeDimensions();
419420
if (dims) {
420-
ws.send(JSON.stringify({resize: {width: dims.cols, height: dims.rows}}));
421+
ws.send(enc.encode(JSON.stringify({resize: {width: dims.cols, height: dims.rows}})));
421422
}
422423
};
423424

@@ -448,7 +449,7 @@
448449
fitAddon.fit();
449450
var dims = fitAddon.proposeDimensions();
450451
if (dims) {
451-
ws.send(JSON.stringify({resize: {width: dims.cols, height: dims.rows}}));
452+
ws.send(enc.encode(JSON.stringify({resize: {width: dims.cols, height: dims.rows}})));
452453
}
453454
};
454455
window.addEventListener('resize', window._consoleResizeHandler);

‎internal/ssh/client.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ func (c *Client) Shell(ctx context.Context, rows, cols int) (<-chan Output, chan
9595

9696
if err := session.RequestPty("xterm-256color", rows, cols, gossh.TerminalModes{
9797
gossh.ECHO: 1,
98-
gossh.OCRNL: 1,
9998
gossh.TTY_OP_ISPEED: 14400,
10099
gossh.TTY_OP_OSPEED: 14400,
101100
}); err != nil {

0 commit comments

Comments
 (0)