Documentation
¶
Overview ¶
Package server provides the WebSocket server for CapyDeploy Agent.
Index ¶
- type AgentConfigResponse
- type ChunkUploadResponse
- type CompleteUploadRequest
- type CompleteUploadResponse
- type Config
- type HubConnection
- type InitUploadRequest
- type InitUploadResponse
- type OperationEvent
- type Server
- func (s *Server) CreateUpload(config protocol.UploadConfig, totalBytes int64, files []transfer.FileEntry) *transfer.UploadSession
- func (s *Server) DeleteUpload(id string)
- func (s *Server) DisableConnections()
- func (s *Server) DisconnectHub()
- func (s *Server) EnableConnections()
- func (s *Server) GetConnectedHub() string
- func (s *Server) GetInfo() protocol.AgentInfo
- func (s *Server) GetInstallPath() string
- func (s *Server) GetPort() int
- func (s *Server) GetUpload(id string) (*transfer.UploadSession, bool)
- func (s *Server) GetUploadPath(gameName, installPath string) string
- func (s *Server) IsHubConnected() bool
- func (s *Server) NotifyConsoleLogStatus()
- func (s *Server) NotifyOperation(opType, status, gameName string, progress float64, message string)
- func (s *Server) NotifyShortcutChange()
- func (s *Server) NotifyTelemetryStatus()
- func (s *Server) Run(ctx context.Context) error
- func (s *Server) SendEvent(msgType protocol.MessageType, payload any)
- func (s *Server) SetConsoleLogEnabled(enabled bool) error
- func (s *Server) StartConsoleLog()
- func (s *Server) StartTelemetry()
- func (s *Server) StopConsoleLog()
- func (s *Server) StopTelemetry()
- type ShortcutsResponse
- type SteamUsersResponse
- type UploadStatusResponse
- type WSServer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AgentConfigResponse ¶
type AgentConfigResponse struct {
InstallPath string `json:"installPath"`
}
AgentConfigResponse is the response for GET /config.
type ChunkUploadResponse ¶
type ChunkUploadResponse struct {
BytesWritten int `json:"bytesWritten"`
TotalReceived int64 `json:"totalReceived"`
Error string `json:"error,omitempty"`
}
ChunkUploadResponse is the response for POST /uploads/{id}/chunks.
type CompleteUploadRequest ¶
type CompleteUploadRequest struct {
CreateShortcut bool `json:"createShortcut"`
Shortcut *protocol.ShortcutConfig `json:"shortcut,omitempty"`
}
CompleteUploadRequest is the request body for POST /uploads/{id}/complete.
type CompleteUploadResponse ¶
type CompleteUploadResponse struct {
Success bool `json:"success"`
Path string `json:"path,omitempty"`
AppID uint32 `json:"appId,omitempty"`
Error string `json:"error,omitempty"`
}
CompleteUploadResponse is the response for POST /uploads/{id}/complete.
type Config ¶
type Config struct {
Port int // Port to listen on (0 = dynamic, OS assigns)
Name string
Version string
Platform string
Verbose bool
UploadPath string // Base path for uploaded files (deprecated, use GetInstallPath)
AcceptConnections func() bool // Callback to check if connections are accepted
GetInstallPath func() string // Callback to get the install path from config
OnShortcutChange func() // Callback when shortcuts are created/deleted
OnOperation func(event OperationEvent) // Callback for operation progress
OnHubConnect func(hubID, hubName, hubIP string) // Callback when a Hub connects
OnHubDisconnect func() // Callback when the Hub disconnects
AuthManager *auth.Manager // Authentication manager for pairing
OnPairingCode func(code string, expiresIn time.Duration) // Callback when pairing code is generated
OnPairingSuccess func() // Callback when pairing is successful
OnPortAssigned func(port int) // Callback when port is assigned (useful for dynamic ports)
GetTelemetryEnabled func() bool // Callback to check if telemetry is enabled
GetTelemetryInterval func() int // Callback to get telemetry interval in seconds
GetSteamStatus func() (running bool, gamingMode bool) // Callback to get Steam process status
GetConsoleLogEnabled func() bool // Callback to check if console log is enabled
SetConsoleLogEnabled func(enabled bool) error // Callback to enable/disable console log
}
Config holds the agent server configuration.
type HubConnection ¶
type HubConnection struct {
// contains filtered or unexported fields
}
HubConnection represents an active connection from a Hub.
type InitUploadRequest ¶
type InitUploadRequest struct {
Config protocol.UploadConfig `json:"config"`
TotalSize int64 `json:"totalSize"`
Files []transfer.FileEntry `json:"files"`
}
InitUploadRequest is the request body for POST /uploads.
type InitUploadResponse ¶
type InitUploadResponse struct {
UploadID string `json:"uploadId"`
ChunkSize int `json:"chunkSize"`
ResumeFrom map[string]int64 `json:"resumeFrom,omitempty"`
Error string `json:"error,omitempty"`
}
InitUploadResponse is the response for POST /uploads.
type OperationEvent ¶
type OperationEvent struct {
Type string `json:"type"` // "install", "delete"
Status string `json:"status"` // "start", "progress", "complete", "error"
GameName string `json:"gameName"`
Progress float64 `json:"progress"` // 0-100
Message string `json:"message,omitempty"`
}
OperationEvent represents an operation notification for the UI.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the main agent server that handles WebSocket connections and mDNS discovery.
func (*Server) CreateUpload ¶
func (s *Server) CreateUpload(config protocol.UploadConfig, totalBytes int64, files []transfer.FileEntry) *transfer.UploadSession
CreateUpload creates a new upload session.
func (*Server) DeleteUpload ¶
DeleteUpload removes an upload session.
func (*Server) DisableConnections ¶ added in v0.6.0
func (s *Server) DisableConnections()
DisableConnections disconnects the current Hub and stops mDNS advertising.
func (*Server) DisconnectHub ¶
func (s *Server) DisconnectHub()
DisconnectHub disconnects the currently connected Hub.
func (*Server) EnableConnections ¶ added in v0.6.0
func (s *Server) EnableConnections()
EnableConnections restarts mDNS advertising.
func (*Server) GetConnectedHub ¶
GetConnectedHub returns the name of the connected Hub, or empty string if none.
func (*Server) GetInstallPath ¶
GetInstallPath returns the current install path (expanded).
func (*Server) GetPort ¶
GetPort returns the actual port the server is listening on. This may differ from the configured port if 0 was specified (dynamic port).
func (*Server) GetUpload ¶
func (s *Server) GetUpload(id string) (*transfer.UploadSession, bool)
GetUpload returns an upload session by ID.
func (*Server) GetUploadPath ¶
GetUploadPath returns the full path for an upload. Uses the install path from config callback, or falls back to UploadPath.
func (*Server) IsHubConnected ¶
IsHubConnected returns true if a Hub is currently connected via WebSocket.
func (*Server) NotifyConsoleLogStatus ¶ added in v0.6.0
func (s *Server) NotifyConsoleLogStatus()
NotifyConsoleLogStatus sends the current console log status to the Hub.
func (*Server) NotifyOperation ¶
NotifyOperation emits an operation event to the UI.
func (*Server) NotifyShortcutChange ¶
func (s *Server) NotifyShortcutChange()
NotifyShortcutChange calls the OnShortcutChange callback if set.
func (*Server) NotifyTelemetryStatus ¶ added in v0.6.0
func (s *Server) NotifyTelemetryStatus()
NotifyTelemetryStatus sends the current telemetry status to the Hub.
func (*Server) Run ¶
Run starts the WebSocket server and mDNS discovery. If cfg.Port is 0, the OS will assign an available port dynamically.
func (*Server) SendEvent ¶
func (s *Server) SendEvent(msgType protocol.MessageType, payload any)
SendEvent sends a push event to the connected Hub via WebSocket.
func (*Server) SetConsoleLogEnabled ¶ added in v0.6.0
SetConsoleLogEnabled enables or disables console log via the config callback, then starts/stops the collector.
func (*Server) StartConsoleLog ¶ added in v0.6.0
func (s *Server) StartConsoleLog()
StartConsoleLog starts the console log collector if enabled and a Hub is connected.
func (*Server) StartTelemetry ¶ added in v0.6.0
func (s *Server) StartTelemetry()
StartTelemetry starts the telemetry collector if enabled and a Hub is connected.
func (*Server) StopConsoleLog ¶ added in v0.6.0
func (s *Server) StopConsoleLog()
StopConsoleLog stops the console log collector.
func (*Server) StopTelemetry ¶ added in v0.6.0
func (s *Server) StopTelemetry()
StopTelemetry stops the telemetry collector.
type ShortcutsResponse ¶
type ShortcutsResponse struct {
Shortcuts []protocol.ShortcutInfo `json:"shortcuts,omitempty"`
AppID uint32 `json:"appId,omitempty"`
Error string `json:"error,omitempty"`
}
ShortcutsResponse is the response for shortcut operations.
type SteamUsersResponse ¶
type SteamUsersResponse struct {
Users []steam.User `json:"users"`
Error string `json:"error,omitempty"`
}
SteamUsersResponse is the response for GET /steam/users.
type UploadStatusResponse ¶
type UploadStatusResponse struct {
Progress *protocol.UploadProgress `json:"progress,omitempty"`
Error string `json:"error,omitempty"`
}
UploadStatusResponse is the response for GET /uploads/{id}.
type WSServer ¶
type WSServer struct {
// contains filtered or unexported fields
}
WSServer handles WebSocket connections from the Hub.
func NewWSServer ¶
func NewWSServer(s *Server, authMgr *auth.Manager, onConnect func(string, string, string), onDisconnect func()) *WSServer
NewWSServer creates a new WebSocket server.
func (*WSServer) DisconnectHub ¶
func (ws *WSServer) DisconnectHub()
DisconnectHub closes the current Hub connection if any. Sends a WebSocket close frame so the Hub detects disconnection immediately.
func (*WSServer) GetConnectedHub ¶
GetConnectedHub returns the name of the connected hub, or empty if none.
func (*WSServer) HandleWS ¶
func (ws *WSServer) HandleWS(w http.ResponseWriter, r *http.Request)
HandleWS handles the WebSocket upgrade and connection.
func (*WSServer) IsConnected ¶
IsConnected returns true if a hub is connected.