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

Function ReadLoop

pkg/web/ws.go:130–165  ·  view source on GitHub ↗
(conn *websocket.Conn, outputCh chan any, closeCh chan any, rpcInputCh chan baseds.RpcInputChType, routeId string)

Source from the content-addressed store, hash-verified

128}
129
130func ReadLoop(conn *websocket.Conn, outputCh chan any, closeCh chan any, rpcInputCh chan baseds.RpcInputChType, routeId string) {
131 readWait := wsReadWaitTimeout
132 conn.SetReadLimit(wsMaxMessageSize)
133 conn.SetReadDeadline(time.Now().Add(readWait))
134 defer close(closeCh)
135 for {
136 _, message, err := conn.ReadMessage()
137 if err != nil {
138 log.Printf("[websocket] ReadPump error (%s): %v\n", routeId, err)
139 break
140 }
141 jmsg := map[string]any{}
142 err = json.Unmarshal(message, &jmsg)
143 if err != nil {
144 log.Printf("[websocket] error unmarshalling json: %v\n", err)
145 break
146 }
147 conn.SetReadDeadline(time.Now().Add(readWait))
148 msgType := getMessageType(jmsg)
149 if msgType == "pong" {
150 // nothing
151 continue
152 }
153 if msgType == "ping" {
154 now := time.Now()
155 pongMessage := map[string]interface{}{"type": "pong", "stime": now.UnixMilli()}
156 outputCh <- pongMessage
157 continue
158 }
159 wsCommand := getStringFromMap(jmsg, "wscommand")
160 if wsCommand == "" {
161 continue
162 }
163 processWSCommand(jmsg, outputCh, rpcInputCh)
164 }
165}
166
167func WritePing(conn *websocket.Conn) error {
168 now := time.Now()

Callers 1

HandleWsInternalFunction · 0.85

Calls 4

getMessageTypeFunction · 0.85
getStringFromMapFunction · 0.85
processWSCommandFunction · 0.85
SetReadDeadlineMethod · 0.80

Tested by

no test coverage detected