| 428 | } |
| 429 | |
| 430 | func (f *CopilotWebSocketForwarder) receiveLoop(ctx context.Context) { |
| 431 | defer close(f.done) |
| 432 | for { |
| 433 | typ, data, err := f.conn.Read(ctx) |
| 434 | if err != nil { |
| 435 | if websocket.CloseStatus(err) == websocket.StatusNormalClosure || websocket.CloseStatus(err) == websocket.StatusGoingAway { |
| 436 | f.err = nil |
| 437 | } else if ctx.Err() != nil { |
| 438 | f.err = nil |
| 439 | } else { |
| 440 | f.err = err |
| 441 | } |
| 442 | return |
| 443 | } |
| 444 | out := CopilotWebSocketMessage{Data: data, Binary: typ == websocket.MessageBinary} |
| 445 | if f.OnSendResponseMessage != nil { |
| 446 | transformed := f.OnSendResponseMessage(out) |
| 447 | if transformed == nil { |
| 448 | continue |
| 449 | } |
| 450 | out = *transformed |
| 451 | } |
| 452 | if out.Binary { |
| 453 | _ = f.resp.SendBinary(out.Data) |
| 454 | } else { |
| 455 | _ = f.resp.SendText(out.Data) |
| 456 | } |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | func (f *CopilotWebSocketForwarder) SendRequestMessage(ctx context.Context, msg CopilotWebSocketMessage) error { |
| 461 | out := msg |