ConnectDesktopVNC opens a WebSocket to the agent's desktop endpoint and returns a net.Conn carrying raw RFB (VNC) binary data.
(ctx context.Context)
| 597 | // ConnectDesktopVNC opens a WebSocket to the agent's desktop endpoint and |
| 598 | // returns a net.Conn carrying raw RFB (VNC) binary data. |
| 599 | func (c *agentConn) ConnectDesktopVNC(ctx context.Context) (net.Conn, error) { |
| 600 | ctx, span := tracing.StartSpan(ctx) |
| 601 | defer span.End() |
| 602 | |
| 603 | host := net.JoinHostPort(c.agentAddress().String(), strconv.Itoa(AgentHTTPAPIServerPort)) |
| 604 | |
| 605 | dialOpts := &websocket.DialOptions{ |
| 606 | HTTPClient: c.apiClient(), |
| 607 | CompressionMode: websocket.CompressionDisabled, |
| 608 | } |
| 609 | c.headersMu.RLock() |
| 610 | if len(c.extraHeaders) > 0 { |
| 611 | dialOpts.HTTPHeader = c.extraHeaders.Clone() |
| 612 | } |
| 613 | c.headersMu.RUnlock() |
| 614 | |
| 615 | url := fmt.Sprintf("http://%s/api/v0/desktop/vnc", host) |
| 616 | conn, res, err := websocket.Dial(ctx, url, dialOpts) |
| 617 | if err != nil { |
| 618 | if res == nil { |
| 619 | return nil, err |
| 620 | } |
| 621 | return nil, codersdk.ReadBodyAsError(res) |
| 622 | } |
| 623 | if res != nil && res.Body != nil { |
| 624 | defer res.Body.Close() |
| 625 | } |
| 626 | |
| 627 | // No read limit — RFB framebuffer updates can be large. |
| 628 | conn.SetReadLimit(-1) |
| 629 | |
| 630 | return websocket.NetConn(ctx, conn, websocket.MessageBinary), nil |
| 631 | } |
| 632 | |
| 633 | // DesktopAction is the request body for the desktop action |
| 634 | // endpoint. |
nothing calls this directly
no test coverage detected