I’ve been playing with the demo server code (https://github.com/lxc/lxd-demo-server) as a way to give clients access to a terminal via web socket (I’m writing an iOS native terminal front-end to view this). While that effort appears to be working, I’m hitting a wall trying to send a resize console command over the control web socket. My Go-fu is weak (er, non-existent might be better said), so it’s not entirely clear how I might tackle sending a command correctly.
If you don’t mind looking at the whole method, here’s what I’ve written to make this attempt:
func restConsoleResizeHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
http.Error(w, "Not implemented", 501)
return
}
name := r.FormValue("id")
width := r.FormValue("width")
height := r.FormValue("height")
widthInt, err := strconv.Atoi(width)
heightInt, err := strconv.Atoi(height)
w.Header().Set("Access-Control-Allow-Origin", "*")
req := api.ContainerConsolePost{
Width: widthInt,
Height: heightInt,
}
// control socket handler
control := func(conn *websocket.Conn) {
for {
_, _, err = conn.ReadMessage()
if err != nil {
break
}
}
}
consoleDisconnect := make(chan bool)
sendDisconnect := make(chan bool)
defer close(sendDisconnect)
consoleArgs := lxd.ContainerConsoleArgs{
Terminal: &ReadWriteCloser{inRead, outWrite},
Control: control,
ConsoleDisconnect: consoleDisconnect,
}
go func() {
<-sendDisconnect
close(consoleDisconnect)
}()
// Run the command in the container
op, err := lxdDaemon.ConsoleContainer(name, req, &consoleArgs)
fmt.Fprintln(os.Stdout, "Resize op:", op)
fmt.Fprintln(os.Stdout, "Resize err:", err)
return
}
I believe the problem is the Terminal argument in ContainerConsoleArgs; ultimately it’s not going to the same terminal instance as the one created in the console handler. But a definitive dearth of documentation around these methods is stopping me.
Any suggestions for how to proceed from here would be most welcome!