MCPcopy Index your code
hub / github.com/coder/coder / ConnectDesktopVNC

Method ConnectDesktopVNC

codersdk/workspacesdk/agentconn.go:599–631  ·  view source on GitHub ↗

ConnectDesktopVNC opens a WebSocket to the agent's desktop endpoint and returns a net.Conn carrying raw RFB (VNC) binary data.

(ctx context.Context)

Source from the content-addressed store, hash-verified

597// ConnectDesktopVNC opens a WebSocket to the agent's desktop endpoint and
598// returns a net.Conn carrying raw RFB (VNC) binary data.
599func (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.

Callers

nothing calls this directly

Calls 8

agentAddressMethod · 0.95
apiClientMethod · 0.95
StartSpanFunction · 0.92
ReadBodyAsErrorFunction · 0.92
DialMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.45
CloneMethod · 0.45

Tested by

no test coverage detected