MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / processWSCommand

Function processWSCommand

pkg/web/ws.go:88–128  ·  view source on GitHub ↗
(jmsg map[string]any, outputCh chan any, rpcInputCh chan baseds.RpcInputChType)

Source from the content-addressed store, hash-verified

86}
87
88func processWSCommand(jmsg map[string]any, outputCh chan any, rpcInputCh chan baseds.RpcInputChType) {
89 var rtnErr error
90 var cmdType string
91 defer func() {
92 panicCtx := "processWSCommand"
93 if cmdType != "" {
94 panicCtx = fmt.Sprintf("processWSCommand:%s", cmdType)
95 }
96 panicErr := panichandler.PanicHandler(panicCtx, recover())
97 if panicErr != nil {
98 rtnErr = panicErr
99 }
100 if rtnErr == nil {
101 return
102 }
103 rtn := map[string]any{"type": "error", "error": rtnErr.Error()}
104 outputCh <- rtn
105 }()
106 wsCommand, err := webcmd.ParseWSCommandMap(jmsg)
107 if err != nil {
108 rtnErr = fmt.Errorf("cannot parse wscommand: %v", err)
109 return
110 }
111 cmdType = wsCommand.GetWSCommand()
112 switch cmd := wsCommand.(type) {
113 case *webcmd.WSRpcCommand:
114 rpcMsg := cmd.Message
115 if rpcMsg == nil {
116 return
117 }
118 if rpcMsg.Command != "" {
119 cmdType = fmt.Sprintf("%s:%s", cmdType, rpcMsg.Command)
120 }
121 msgBytes, err := json.Marshal(rpcMsg)
122 if err != nil {
123 // this really should never fail since we just unmarshalled this value
124 return
125 }
126 rpcInputCh <- baseds.RpcInputChType{MsgBytes: msgBytes}
127 }
128}
129
130func ReadLoop(conn *websocket.Conn, outputCh chan any, closeCh chan any, rpcInputCh chan baseds.RpcInputChType, routeId string) {
131 readWait := wsReadWaitTimeout

Callers 1

ReadLoopFunction · 0.85

Calls 4

PanicHandlerFunction · 0.92
ParseWSCommandMapFunction · 0.92
GetWSCommandMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected