#Using xterm.js with Go backend

12 messages · Page 1 of 1 (latest)

gilded rover
#

Has anybody already implemented this? I'm getting stuck right now and would really appreciate if somebody can give me some help.
Basically I want to stream a bash shell inside a Docker container to the browser via websockets.

In short I have a handler that listens for a websocket connection and it then starts two goroutines that are copying data sent from the browser and to the stdin of a exec.Command("docker", "exec", "-i", "id", "/bin/sh" and in reverse (from stdout to the websocket). If I test in the browser console it works. I can send a command likews.send("ls") and it returns successfully. When connecting that same endpoint to xterm.js nothing works as expected. There might be a problem with my xterm.js setup so don't bother with that. I will spend some more time on that. I just want to make sure on how would you go about doing that.

I realize this is a broad question, but if anyone has any suggestions on how to approach this, I’d really appreciate it.

Below is the main code (in case somebody will skim through it):

pseudo birch
#

I have done this, hold on

#

I never got that far with it, but there's a session broker, xterm.js on the front end, web sockets, and a pseudo tty

#

The code probably isn't great, but you might be able to use it for some inspiration

gilded rover
#

insane man. Thanks will check it out

pseudo birch
#

Let me know if there's any questions and I'll struggle to remember wtf I was doing when I wrote it

gilded rover
#

i sure will

winter frigate
#

ah I wanted to do that too for grol! nice

#

(and run it locally not remotely, I have a non shell wasm/js like on grol.io but I'd like to get the interactive version instead with colors etc)

pseudo birch
#

It was a really neat little proof of concept, I've been meaning to do more with it when I have the time

#

One caveat, this is a 3 year old version of xterm. You'll wanna use a newer version, and they may have changed the API