modules

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2026 License: AGPL-3.0, AGPL-3.0-or-later Imports: 9 Imported by: 0

Documentation

Overview

Package modules provides platform-specific modules for Hub-Agent communication.

The module system allows the Hub to communicate with Agents running on different platforms (Linux, Windows) using a unified interface. WebSocket clients implement the same set of interfaces, enabling platform-agnostic code.

Architecture

The module system consists of:

  • PlatformModule: Interface for platform-specific metadata (image formats)
  • PlatformClient: Base interface for all Agent clients (health, info, config)
  • Capability interfaces: ShortcutManager, ArtworkManager, SteamController, FileUploader
  • Registry: Manages modules and provides platform metadata lookup
  • WSClient: WebSocket-based client implementing all interfaces

Usage

Basic usage with discovered agents:

agents, _ := discoveryClient.Discover(ctx, 3*time.Second)
for _, agent := range agents {
    wsClient, err := modules.WSClientFromAgent(agent, hubName, version)
    if err != nil {
        continue
    }
    if err := wsClient.Connect(ctx); err != nil {
        continue
    }

    // Check capabilities using type assertions
    if sm, ok := modules.AsShortcutManager(wsClient); ok {
        shortcuts, _ := sm.ListShortcuts(ctx, userID)
    }
}

Capability Checking

Use the As* functions to check for specific capabilities:

caps := modules.GetCapabilities(client)
if caps.Shortcuts {
    // Client supports shortcut operations
}
if caps.Upload {
    // Client supports file uploads
}

Package modules provides platform-specific module interfaces for Hub-Agent communication.

Index

Constants

View Source
const (
	// PlatformLinux is the identifier for Linux-based systems (SteamOS, Bazzite, etc.).
	PlatformLinux = "linux"
)
View Source
const (
	// PlatformWindows is the identifier for Windows-based systems.
	PlatformWindows = "windows"
)

Variables

View Source
var DefaultRegistry = NewRegistry()

DefaultRegistry is the global default registry with standard modules.

Functions

func GetSupportedImageFormats

func GetSupportedImageFormats(platform string) []string

GetSupportedImageFormats returns the supported image formats for a platform. Uses normalized platform to handle aliases like "steamdeck" -> "linux".

func IsPairingRequired

func IsPairingRequired(err error) bool

IsPairingRequired checks if the error indicates pairing is required.

func IsPlatformSupported

func IsPlatformSupported(platform string) bool

IsPlatformSupported checks if a platform is supported in the default registry.

Types

type ArtworkManager

type ArtworkManager interface {
	// ApplyArtwork applies artwork to a shortcut.
	ApplyArtwork(ctx context.Context, userID string, appID uint32, cfg *protocol.ArtworkConfig) (*protocol.ArtworkResponse, error)
}

ArtworkManager handles Steam artwork operations.

func AsArtworkManager

func AsArtworkManager(client PlatformClient) (ArtworkManager, bool)

AsArtworkManager checks if the client supports artwork operations. Returns the ArtworkManager interface and true if supported.

type ClientCapabilities

type ClientCapabilities struct {
	Shortcuts  bool
	Artwork    bool
	Steam      bool
	Upload     bool
	SteamUsers bool
}

ClientCapabilities represents the capabilities of a platform client.

func GetCapabilities

func GetCapabilities(client PlatformClient) ClientCapabilities

GetCapabilities returns a summary of what operations a client supports.

type FileUploader

type FileUploader interface {
	// InitUpload initializes a new upload session.
	InitUpload(ctx context.Context, config protocol.UploadConfig, totalSize int64, files []transfer.FileEntry) (*protocol.InitUploadResponseFull, error)

	// UploadChunk sends a single chunk to the agent.
	UploadChunk(ctx context.Context, uploadID string, chunk *transfer.Chunk) error

	// CompleteUpload finalizes an upload session.
	CompleteUpload(ctx context.Context, uploadID string, createShortcut bool, shortcut *protocol.ShortcutConfig) (*protocol.CompleteUploadResponseFull, error)

	// CancelUpload cancels an upload session.
	CancelUpload(ctx context.Context, uploadID string) error

	// GetUploadStatus returns the status of an upload session.
	GetUploadStatus(ctx context.Context, uploadID string) (*protocol.UploadProgress, error)
}

FileUploader handles file upload operations.

func AsFileUploader

func AsFileUploader(client PlatformClient) (FileUploader, bool)

AsFileUploader checks if the client supports file upload operations. Returns the FileUploader interface and true if supported.

type FullPlatformClient

FullPlatformClient combines all client capabilities. This is useful for type checking if a client supports all features.

func AsFullClient

func AsFullClient(client PlatformClient) (FullPlatformClient, bool)

AsFullClient checks if the client supports all capabilities. Returns the FullPlatformClient interface and true if supported.

type GameManager

type GameManager interface {
	// DeleteGame removes a game completely (shortcut, files, artwork) and restarts Steam.
	DeleteGame(ctx context.Context, appID uint32) (*protocol.DeleteGameResponse, error)
}

GameManager handles high-level game operations. The Agent handles everything internally (user detection, Steam restart, etc.)

func AsGameManager

func AsGameManager(client PlatformClient) (GameManager, bool)

AsGameManager checks if the client supports high-level game operations. Returns the GameManager interface and true if supported.

type LinuxModule

type LinuxModule struct{}

LinuxModule handles communication with Linux-based Agents. This includes SteamOS, Bazzite, and other Linux distributions.

func NewLinuxModule

func NewLinuxModule() *LinuxModule

NewLinuxModule creates a new Linux platform module.

func (*LinuxModule) Platform

func (m *LinuxModule) Platform() string

Platform returns the platform identifier.

func (*LinuxModule) SupportedImageFormats

func (m *LinuxModule) SupportedImageFormats() []string

SupportedImageFormats returns the image formats supported by Linux Steam. Linux Steam supports PNG, JPEG, WebP, and animated GIF.

type PlatformClient

type PlatformClient interface {
	// Health checks if the agent is responsive.
	Health(ctx context.Context) error

	// GetInfo returns information about the agent.
	GetInfo(ctx context.Context) (*protocol.AgentInfo, error)

	// GetConfig returns the agent configuration.
	GetConfig(ctx context.Context) (*protocol.ConfigResponse, error)
}

PlatformClient is the base interface for all Agent clients. Use type assertions to check for additional capabilities.

type PlatformModule

type PlatformModule interface {
	// Platform returns the platform identifier (e.g., "linux", "windows").
	Platform() string

	// SupportedImageFormats returns the MIME types supported for Steam artwork.
	SupportedImageFormats() []string
}

PlatformModule defines the interface for platform-specific configuration. Each platform (Linux, Windows) implements this interface to provide platform-specific metadata like supported image formats.

func GetModule

func GetModule(platform string) PlatformModule

GetModule returns a module from the default registry.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry manages platform modules and provides platform-specific metadata.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new module registry with default modules registered.

func (*Registry) Get

func (r *Registry) Get(platform string) PlatformModule

Get returns the module for a specific platform. Returns nil if the platform is not registered.

func (*Registry) IsSupported

func (r *Registry) IsSupported(platform string) bool

IsSupported checks if a platform is supported.

func (*Registry) Platforms

func (r *Registry) Platforms() []string

Platforms returns a list of all registered platform names.

func (*Registry) Register

func (r *Registry) Register(module PlatformModule)

Register adds a platform module to the registry.

type ShortcutManager

type ShortcutManager interface {
	// ListShortcuts returns all shortcuts for a user.
	ListShortcuts(ctx context.Context, userID string) ([]protocol.ShortcutInfo, error)

	// CreateShortcut creates a new Steam shortcut.
	CreateShortcut(ctx context.Context, userID string, config protocol.ShortcutConfig) (uint32, error)

	// DeleteShortcut removes a Steam shortcut by app ID.
	DeleteShortcut(ctx context.Context, userID string, appID uint32) error
}

ShortcutManager handles Steam shortcut operations.

func AsShortcutManager

func AsShortcutManager(client PlatformClient) (ShortcutManager, bool)

AsShortcutManager checks if the client supports shortcut operations. Returns the ShortcutManager interface and true if supported.

type SteamController

type SteamController interface {
	// RestartSteam restarts the Steam client.
	RestartSteam(ctx context.Context) (*protocol.RestartSteamResponse, error)
}

SteamController manages Steam process operations.

func AsSteamController

func AsSteamController(client PlatformClient) (SteamController, bool)

AsSteamController checks if the client supports Steam control operations. Returns the SteamController interface and true if supported.

type SteamUserProvider

type SteamUserProvider interface {
	// GetSteamUsers returns the list of Steam users on the agent.
	GetSteamUsers(ctx context.Context) ([]steam.User, error)
}

SteamUserProvider provides Steam user information.

func AsSteamUserProvider

func AsSteamUserProvider(client PlatformClient) (SteamUserProvider, bool)

AsSteamUserProvider checks if the client can provide Steam user information. Returns the SteamUserProvider interface and true if supported.

type WSClient

type WSClient struct {
	// contains filtered or unexported fields
}

WSClient wraps wsclient.Client and implements all module interfaces.

func NewWSClient

func NewWSClient(host string, port int, platform, hubName, hubVersion string) *WSClient

NewWSClient creates a new WebSocket-based client.

func NewWSClientWithAuth

func NewWSClientWithAuth(host string, port int, platform, hubName, hubVersion, hubID, agentID string,
	getToken func(string) string, saveToken func(string, string) error) *WSClient

NewWSClientWithAuth creates a new WebSocket-based client with authentication.

func WSClientFromAgent

func WSClientFromAgent(agent *discovery.DiscoveredAgent, hubName, hubVersion string) (*WSClient, error)

WSClientFromAgent creates a WebSocket client for a discovered agent. The returned client must be connected using Connect() before use.

func WSClientFromAgentWithAuth

func WSClientFromAgentWithAuth(agent *discovery.DiscoveredAgent, hubName, hubVersion, hubID string,
	getToken func(string) string, saveToken func(string, string) error) (*WSClient, error)

WSClientFromAgentWithAuth creates a WebSocket client with authentication. The returned client must be connected using Connect() before use.

func (*WSClient) ApplyArtwork

func (c *WSClient) ApplyArtwork(ctx context.Context, userID string, appID uint32, cfg *protocol.ArtworkConfig) (*protocol.ArtworkResponse, error)

func (*WSClient) CancelUpload

func (c *WSClient) CancelUpload(ctx context.Context, uploadID string) error

func (*WSClient) Close

func (c *WSClient) Close() error

Close closes the WebSocket connection.

func (*WSClient) CompleteUpload

func (c *WSClient) CompleteUpload(ctx context.Context, uploadID string, createShortcut bool, shortcut *protocol.ShortcutConfig) (*protocol.CompleteUploadResponseFull, error)

func (*WSClient) ConfirmPairing

func (c *WSClient) ConfirmPairing(ctx context.Context, code string) error

ConfirmPairing sends the pairing code to confirm authentication.

func (*WSClient) Connect

func (c *WSClient) Connect(ctx context.Context) error

Connect establishes the WebSocket connection.

func (*WSClient) CreateShortcut

func (c *WSClient) CreateShortcut(ctx context.Context, userID string, config protocol.ShortcutConfig) (uint32, error)

func (*WSClient) DeleteGame

func (c *WSClient) DeleteGame(ctx context.Context, appID uint32) (*protocol.DeleteGameResponse, error)

func (*WSClient) DeleteShortcut

func (c *WSClient) DeleteShortcut(ctx context.Context, userID string, appID uint32) error

func (*WSClient) GetAgentID

func (c *WSClient) GetAgentID() string

GetAgentID returns the agent ID for this client.

func (*WSClient) GetConfig

func (c *WSClient) GetConfig(ctx context.Context) (*protocol.ConfigResponse, error)

func (*WSClient) GetInfo

func (c *WSClient) GetInfo(ctx context.Context) (*protocol.AgentInfo, error)

func (*WSClient) GetSteamUsers

func (c *WSClient) GetSteamUsers(ctx context.Context) ([]steam.User, error)

func (*WSClient) GetUploadStatus

func (c *WSClient) GetUploadStatus(ctx context.Context, uploadID string) (*protocol.UploadProgress, error)

func (*WSClient) Health

func (c *WSClient) Health(ctx context.Context) error

func (*WSClient) InitUpload

func (c *WSClient) InitUpload(ctx context.Context, config protocol.UploadConfig, totalSize int64, files []transfer.FileEntry) (*protocol.InitUploadResponseFull, error)

func (*WSClient) IsConnected

func (c *WSClient) IsConnected() bool

IsConnected returns true if the client is connected.

func (*WSClient) ListShortcuts

func (c *WSClient) ListShortcuts(ctx context.Context, userID string) ([]protocol.ShortcutInfo, error)

func (*WSClient) RestartSteam

func (c *WSClient) RestartSteam(ctx context.Context) (*protocol.RestartSteamResponse, error)

func (*WSClient) SendArtworkImage added in v0.3.0

func (c *WSClient) SendArtworkImage(ctx context.Context, appID uint32, artworkType, contentType string, data []byte) error

SendArtworkImage sends a binary artwork image to the agent.

func (*WSClient) SetCallbacks

func (c *WSClient) SetCallbacks(
	onDisconnect func(),
	onUploadProgress func(protocol.UploadProgressEvent),
	onOperationEvent func(protocol.OperationEvent),
	onTelemetryStatus func(protocol.TelemetryStatusEvent),
	onTelemetryData func(protocol.TelemetryData),
	onConsoleLogStatus func(protocol.ConsoleLogStatusEvent),
	onConsoleLogData func(protocol.ConsoleLogBatch),
	onGameLogWrapperStatus func(protocol.GameLogWrapperStatusEvent),
)

SetCallbacks sets the event callbacks.

func (*WSClient) SetConsoleLogEnabled added in v0.6.0

func (c *WSClient) SetConsoleLogEnabled(ctx context.Context, enabled bool) (bool, error)

SetConsoleLogEnabled enables or disables console log streaming on the agent.

func (*WSClient) SetConsoleLogFilter added in v0.6.0

func (c *WSClient) SetConsoleLogFilter(ctx context.Context, mask uint32) (uint32, error)

SetConsoleLogFilter sets the log level bitmask on the agent.

func (*WSClient) SetGameLogWrapper added in v0.6.0

func (c *WSClient) SetGameLogWrapper(ctx context.Context, appID uint32, enabled bool) (bool, error)

SetGameLogWrapper enables or disables the game log wrapper for a specific game.

func (*WSClient) SetPairingCallback

func (c *WSClient) SetPairingCallback(cb func(agentID string))

SetPairingCallback sets the callback for when pairing is required.

func (*WSClient) SetPlatform

func (c *WSClient) SetPlatform(platform string)

SetPlatform sets the hub platform to be sent during connection.

func (*WSClient) UploadChunk

func (c *WSClient) UploadChunk(ctx context.Context, uploadID string, chunk *transfer.Chunk) error

type WindowsModule

type WindowsModule struct{}

WindowsModule handles communication with Windows-based Agents.

func NewWindowsModule

func NewWindowsModule() *WindowsModule

NewWindowsModule creates a new Windows platform module.

func (*WindowsModule) Platform

func (m *WindowsModule) Platform() string

Platform returns the platform identifier.

func (*WindowsModule) SupportedImageFormats

func (m *WindowsModule) SupportedImageFormats() []string

SupportedImageFormats returns the image formats supported by Windows Steam.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL