feat(agent): displaycontroller in app.go verdrahtet
This commit is contained in:
parent
a3255a0ced
commit
c91e49dc57
2 changed files with 36 additions and 1 deletions
|
|
@ -13,6 +13,7 @@ import (
|
|||
"time"
|
||||
|
||||
"git.az-it.net/az/morz-infoboard/player/agent/internal/config"
|
||||
"git.az-it.net/az/morz-infoboard/player/agent/internal/displaycontroller"
|
||||
"git.az-it.net/az/morz-infoboard/player/agent/internal/mqttheartbeat"
|
||||
"git.az-it.net/az/morz-infoboard/player/agent/internal/mqttsubscriber"
|
||||
"git.az-it.net/az/morz-infoboard/player/agent/internal/playerserver"
|
||||
|
|
@ -78,6 +79,8 @@ type App struct {
|
|||
|
||||
// screenshotFn is kept so that applyMQTTConfig can pass it to the new subscriber.
|
||||
screenshotFn func()
|
||||
|
||||
displayCtrl *displaycontroller.Controller
|
||||
}
|
||||
|
||||
// mqttCloser is implemented by mqttsubscriber.Subscriber.
|
||||
|
|
@ -222,6 +225,21 @@ func (a *App) Run(ctx context.Context) error {
|
|||
go ss.TakeAndSendOnce(ctx)
|
||||
}
|
||||
|
||||
xDisplay := os.Getenv("DISPLAY")
|
||||
if xDisplay == "" {
|
||||
xDisplay = ":0"
|
||||
}
|
||||
a.displayCtrl = displaycontroller.New(xDisplay, a.Config.ScreenID, func(slug, state string) {
|
||||
a.mqttMu.Lock()
|
||||
pub := a.mqttPub
|
||||
a.mqttMu.Unlock()
|
||||
if pub != nil {
|
||||
if err := pub.SendDisplayState(slug, state); err != nil {
|
||||
a.logger.Printf("event=display_state_publish_error err=%v", err)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// Subscribe to playlist-changed and screenshot-request MQTT notifications (optional; fallback = polling).
|
||||
sub := mqttsubscriber.New(
|
||||
a.Config.MQTTBroker,
|
||||
|
|
@ -237,6 +255,10 @@ func (a *App) Run(ctx context.Context) error {
|
|||
a.logger.Printf("event=mqtt_playlist_notification screen_id=%s", a.Config.ScreenID)
|
||||
},
|
||||
a.screenshotFn,
|
||||
func(action string) {
|
||||
a.logger.Printf("event=display_command_received action=%s screen_id=%s", action, a.Config.ScreenID)
|
||||
a.displayCtrl.Execute(action)
|
||||
},
|
||||
)
|
||||
a.mqttMu.Lock()
|
||||
a.mqttSub = sub
|
||||
|
|
@ -435,6 +457,11 @@ func (a *App) reportStatus(ctx context.Context) {
|
|||
payloadConnectivity = ConnectivityOnline
|
||||
}
|
||||
|
||||
var displayState string
|
||||
if a.displayCtrl != nil {
|
||||
displayState = a.displayCtrl.State()
|
||||
}
|
||||
|
||||
mqttCfg, err := a.reporter.Send(ctx, statusreporter.Snapshot{
|
||||
Status: string(snapshot.Status),
|
||||
ServerConnectivity: string(payloadConnectivity),
|
||||
|
|
@ -444,6 +471,7 @@ func (a *App) reportStatus(ctx context.Context) {
|
|||
HeartbeatEverySeconds: snapshot.HeartbeatEvery,
|
||||
StartedAt: snapshot.StartedAt,
|
||||
LastHeartbeatAt: snapshot.LastHeartbeatAt,
|
||||
DisplayState: displayState,
|
||||
})
|
||||
if err != nil {
|
||||
a.mu.Lock()
|
||||
|
|
@ -511,7 +539,12 @@ func (a *App) applyMQTTConfig(broker, username, password string) {
|
|||
}
|
||||
a.logger.Printf("event=mqtt_playlist_notification screen_id=%s", a.Config.ScreenID)
|
||||
}
|
||||
sub := mqttsubscriber.New(broker, a.Config.ScreenID, username, password, playlistChangedFn, a.screenshotFn)
|
||||
sub := mqttsubscriber.New(broker, a.Config.ScreenID, username, password, playlistChangedFn, a.screenshotFn,
|
||||
func(action string) {
|
||||
a.logger.Printf("event=display_command_received action=%s screen_id=%s", action, a.Config.ScreenID)
|
||||
a.displayCtrl.Execute(action)
|
||||
},
|
||||
)
|
||||
a.mqttSub = sub
|
||||
if sub != nil {
|
||||
a.logger.Printf("event=mqtt_subscriber_restarted screen_id=%s broker=%s", a.Config.ScreenID, broker)
|
||||
|
|
|
|||
|
|
@ -320,6 +320,8 @@ func (r *recordingMQTTSender) SendHeartbeat(status, connectivity string, _ time.
|
|||
return r.err
|
||||
}
|
||||
|
||||
func (r *recordingMQTTSender) SendDisplayState(_, _ string) error { return nil }
|
||||
|
||||
func (r *recordingMQTTSender) Close() {}
|
||||
|
||||
func TestEmitHeartbeatCallsMQTTPublisher(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue