(conn *websocket.Conn, outputCh chan any, closeCh chan any, rpcInputCh chan baseds.RpcInputChType, routeId string)
| 128 | } |
| 129 | |
| 130 | func 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 | |
| 167 | func WritePing(conn *websocket.Conn) error { |
| 168 | now := time.Now() |
no test coverage detected