streamer movement

This commit is contained in:
legop3
2026-11-16 22:59:38 -05:00
parent b0de727d3e
commit 91c9194856
52 changed files with 909 additions and 2518 deletions
+39 -6
View File
@@ -15,6 +15,7 @@ import (
type ManagementClient struct {
cfg *Config
repo string
configPath string
events chan RoverEvent
log *log.Logger
@@ -26,11 +27,13 @@ type ManagementClient struct {
}
type managementCommand struct {
Type string `json:"type"`
ID string `json:"id"`
Config json.RawMessage `json:"config"`
Reboot *rebootPayload `json:"reboot"`
Media *mediaCommand `json:"media"`
Type string `json:"type"`
ID string `json:"id"`
Config json.RawMessage `json:"config"`
Reboot *rebootPayload `json:"reboot"`
Category string `json:"category"`
Profile *MediaProfile `json:"profile"`
Media *mediaCommand `json:"media"`
}
func NewManagementClient(cfg *Config, path string, events chan RoverEvent, logger *log.Logger, restart func()) *ManagementClient {
@@ -78,7 +81,7 @@ func (m *ManagementClient) connect(parent context.Context) error {
conn.SetReadLimit(1024 * 1024)
if err := writeJSON(ctx, conn, map[string]any{
"type": "hello", "name": m.cfg.Name, "config": m.cfg,
"schema": ConfigurationSchema(), "profiles": map[string]any{"video": []any{}, "audioCapture": []any{}, "audioPlayback": []any{}},
"schema": ConfigurationSchema(), "profiles": m.profileCatalog(), "mediaStatus": m.mediaStatus(),
}); err != nil {
return err
}
@@ -144,6 +147,19 @@ func (m *ManagementClient) execute(ctx context.Context, command managementComman
if m.stopping {
return nil, fmt.Errorf("management action already pending")
}
if command.Type == "profile.set" {
if command.Profile == nil {
return nil, fmt.Errorf("profile required")
}
if err := SaveCustomProfile(command.Category, *command.Profile); err != nil {
return nil, err
}
m.stopping = true
if m.runtime != nil {
_ = m.runtime.PrepareShutdown()
}
return m.restart, nil
}
if command.Type == "media" {
if m.media == nil || command.Media == nil {
return nil, fmt.Errorf("media supervisor unavailable")
@@ -271,3 +287,20 @@ func (m *ManagementClient) emit(event string, data map[string]any) {
default:
}
}
func (m *ManagementClient) SetRepository(repo string) { m.repo = repo }
func (m *ManagementClient) profileCatalog() map[string][]MediaProfile {
profiles, err := LoadMediaProfiles(m.repo)
if err != nil {
m.log.Printf("profile catalog: %v", err)
return map[string][]MediaProfile{}
}
return profiles
}
func (m *ManagementClient) mediaStatus() map[string]string {
if m.media == nil {
return nil
}
return m.media.Status()
}