minor changes to ws

This commit is contained in:
sawka 2022-06-16 01:09:56 -07:00
parent 6f7a883cfd
commit a5fedb3668

View File

@ -15,6 +15,7 @@ import (
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/scripthaus-dev/sh2-runner/pkg/base" "github.com/scripthaus-dev/sh2-runner/pkg/base"
"github.com/scripthaus-dev/sh2-runner/pkg/cmdtail"
"github.com/scripthaus-dev/sh2-runner/pkg/packet" "github.com/scripthaus-dev/sh2-runner/pkg/packet"
"github.com/scripthaus-dev/sh2-runner/pkg/shexec" "github.com/scripthaus-dev/sh2-runner/pkg/shexec"
"github.com/scripthaus-dev/sh2-server/pkg/sstore" "github.com/scripthaus-dev/sh2-server/pkg/sstore"
@ -32,8 +33,9 @@ const MainServerAddr = "localhost:8080"
var GlobalRunnerProc *RunnerProc var GlobalRunnerProc *RunnerProc
type WsConnType struct { type WsConnType struct {
Id string Id string
Shell *wsshell.WSShell Shell *wsshell.WSShell
Tailer *cmdtail.Tailer
} }
type RunnerProc struct { type RunnerProc struct {
@ -71,14 +73,13 @@ func HandleWs(w http.ResponseWriter, r *http.Request) {
wsConn.Shell.Conn.Close() wsConn.Shell.Conn.Close()
}() }()
fmt.Printf("WebSocket opened %s\n", shell.RemoteAddr) fmt.Printf("WebSocket opened %s\n", shell.RemoteAddr)
for msg := range shell.ReadChan { for msgBytes := range shell.ReadChan {
jmsg := map[string]interface{}{} pk, err := packet.ParseJsonPacket(msgBytes)
err = json.Unmarshal(msg, &jmsg)
if err != nil { if err != nil {
fmt.Printf("error unmarshalling ws message: %v\n", err) fmt.Printf("error unmarshalling ws message: %v\n", err)
break continue
} }
fmt.Printf("got ws message: %v\n", jmsg) fmt.Printf("got ws message: %v\n", pk)
} }
} }