node.jswebsocketsshdssh2-exec

xterm.js + ws + ssh2 not transmitting terminal resize signals (SIGWINCH) to ssh server


Rephrasing my issue here.

I have a web-app using 'xterm.js', 'ws', and 'ssh2' node modules. Everything works great. Except one thing:

SIGWINCH window resize signal won't make it to the sshd server, or the ssh2 stream. Other sigs, esc, ansi work fine. Esc[8 just disappears.

In a real xterm, echo -e "\e[8;30;120t" resizes the terminal on both ends. Not here. sock.send("\u001b[8;30;120t") won't do anything either.

Console.log on the my node app server shows Escape[8 (or \e, \u001b, or \x1b) doesn't make it. Other escape codes work-- arrows, mouse-clicks etc.

I can do term.resize(x,y) on the client, but currently have to use stty on the server. Ssh2's pty sets them at login only. How do I propagate SIGWINCH? Where is it being trapped?


Solution

  • Ok. So my own answer to this question: In the browser, use term.resize(cols,rows) to resize the local terminal. Transmit the cols and rows via the ansi escape sequence over websocket. Then, on the node server app, in the ssh2 client, use Regexp to match resize escape sequence and extract the second and third numbers, which are the number of cols and rows (the '8' is the code for resize). Use the ssh2 client resize function with extracted cols and rows (tells the ssh2 psuedoterminal to send sigwinch and cols/rows to the ssh server). Not ideal, I know there is a better way if I could find it, but it works beautifully if you make a function in the browser for it and add it to an event listener for window resize. Now my terminal session will resize appropriately on both the client and server ends when I resize the browser window, or when the soft keyboard pops up or hides on mobile.