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

Method handleDesktopVNC

agent/x/agentdesktop/api.go:87–129  ·  view source on GitHub ↗
(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

85}
86
87func (a *API) handleDesktopVNC(rw http.ResponseWriter, r *http.Request) {
88 ctx := r.Context()
89 logger := a.logger.With(agentchat.Fields(ctx)...)
90
91 // Start the desktop session (idempotent).
92 _, err := a.desktop.Start(ctx)
93 if err != nil {
94 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
95 Message: "Failed to start desktop session.",
96 Detail: err.Error(),
97 })
98 return
99 }
100
101 // Get a VNC connection.
102 vncConn, err := a.desktop.VNCConn(ctx)
103 if err != nil {
104 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
105 Message: "Failed to connect to VNC server.",
106 Detail: err.Error(),
107 })
108 return
109 }
110 defer vncConn.Close()
111
112 // Accept WebSocket from coderd.
113 conn, err := websocket.Accept(rw, r, &websocket.AcceptOptions{
114 CompressionMode: websocket.CompressionDisabled,
115 })
116 if err != nil {
117 logger.Error(ctx, "failed to accept websocket", slog.Error(err))
118 return
119 }
120
121 // No read limit — RFB framebuffer updates can be large.
122 conn.SetReadLimit(-1)
123
124 wsCtx, wsNetConn := codersdk.WebsocketNetConn(ctx, conn, websocket.MessageBinary)
125 defer wsNetConn.Close()
126
127 // Bicopy raw bytes between WebSocket and VNC TCP.
128 agentssh.Bicopy(wsCtx, wsNetConn, vncConn)
129}
130
131func (a *API) handleAction(rw http.ResponseWriter, r *http.Request) {
132 ctx := r.Context()

Callers

nothing calls this directly

Calls 10

FieldsFunction · 0.92
WriteFunction · 0.92
WebsocketNetConnFunction · 0.92
BicopyFunction · 0.92
ContextMethod · 0.65
StartMethod · 0.65
VNCConnMethod · 0.65
CloseMethod · 0.65
ErrorMethod · 0.45
AcceptMethod · 0.45

Tested by

no test coverage detected