StartNodeVNCServerWithSession starts the embedded server for a node VNC shell connection with session notifications.
(client *api.Client, nodeName string, session SessionNotifier)
| 105 | |
| 106 | // StartNodeVNCServerWithSession starts the embedded server for a node VNC shell connection with session notifications. |
| 107 | func (s *Server) StartNodeVNCServerWithSession(client *api.Client, nodeName string, session SessionNotifier) (string, error) { |
| 108 | s.logger.Info("Starting node VNC server for: %s", nodeName) |
| 109 | |
| 110 | // Create proxy configuration |
| 111 | s.logger.Debug("Creating VNC proxy configuration for node %s", nodeName) |
| 112 | |
| 113 | config, err := CreateNodeProxyConfigWithLogger(client, nodeName, s.logger) |
| 114 | if err != nil { |
| 115 | s.logger.Error("Failed to create node proxy config for %s: %v", nodeName, err) |
| 116 | |
| 117 | return "", fmt.Errorf("failed to create node proxy config: %w", err) |
| 118 | } |
| 119 | |
| 120 | s.logger.Debug("Node proxy config created - Port: %s", config.Port) |
| 121 | |
| 122 | // Create WebSocket proxy with session notifications |
| 123 | s.logger.Debug("Creating WebSocket proxy for node %s", nodeName) |
| 124 | s.proxy = NewWebSocketProxyWithSessionAndLogger(config, session, s.logger) |
| 125 | |
| 126 | // Start HTTP server |
| 127 | s.logger.Debug("Starting HTTP server for node %s", nodeName) |
| 128 | |
| 129 | if err := s.startHTTPServer(); err != nil { |
| 130 | s.logger.Error("Failed to start HTTP server for node %s: %v", nodeName, err) |
| 131 | |
| 132 | return "", fmt.Errorf("failed to start HTTP server: %w", err) |
| 133 | } |
| 134 | |
| 135 | // Generate noVNC URL with relative WebSocket connection for VS Code port forwarding compatibility |
| 136 | // By not specifying host and port, noVNC will use the current page's host and port (which includes VS Code forwarding) |
| 137 | vncURL := fmt.Sprintf("http://localhost:%d/vnc.html?autoconnect=true&reconnect=true&password=%s&path=vnc-proxy&resize=scale", |
| 138 | s.port, url.QueryEscape(config.Password)) |
| 139 | |
| 140 | s.logger.Info("Node VNC server started successfully for %s on port %d", nodeName, s.port) |
| 141 | s.logger.Debug("Node VNC URL generated: %s", vncURL) |
| 142 | |
| 143 | return vncURL, nil |
| 144 | } |
| 145 | |
| 146 | // startHTTPServer starts the embedded HTTP server on an available port. |
| 147 | func (s *Server) startHTTPServer() error { |
no test coverage detected