refactor(app): add destination error events
This commit is contained in:
parent
b8550f050b
commit
f4021a2886
@ -220,8 +220,8 @@ func (a *App) handleCommand(
|
||||
URL: c.URL,
|
||||
})
|
||||
if err := a.configService.SetConfig(newCfg); err != nil {
|
||||
a.logger.Error("Config update failed", "err", err)
|
||||
ui.ConfigUpdateFailed(err)
|
||||
a.logger.Error("Add destination failed", "err", err)
|
||||
a.eventBus.Send(event.AddDestinationFailedEvent{Err: err})
|
||||
break
|
||||
}
|
||||
a.cfg = newCfg
|
||||
@ -234,8 +234,8 @@ func (a *App) handleCommand(
|
||||
return dest.URL == c.URL
|
||||
})
|
||||
if err := a.configService.SetConfig(newCfg); err != nil {
|
||||
a.logger.Error("Config update failed", "err", err)
|
||||
ui.ConfigUpdateFailed(err)
|
||||
a.logger.Error("Remove destination failed", "err", err)
|
||||
a.eventBus.Send(event.RemoveDestinationFailedEvent{Err: err})
|
||||
break
|
||||
}
|
||||
a.cfg = newCfg
|
||||
|
@ -7,9 +7,11 @@ type Name string
|
||||
const (
|
||||
EventNameAppStateChanged Name = "app_state_changed"
|
||||
EventNameDestinationAdded Name = "destination_added"
|
||||
EventNameAddDestinationFailed Name = "add_destination_failed"
|
||||
EventNameDestinationRemoved Name = "destination_removed"
|
||||
EventNameMediaServerStarted Name = "media_server_started"
|
||||
EventNameRemoveDestinationFailed Name = "remove_destination_failed"
|
||||
EventNameFatalErrorOccurred Name = "fatal_error_occurred"
|
||||
EventNameMediaServerStarted Name = "media_server_started"
|
||||
)
|
||||
|
||||
// Event represents something which happened in the appllication.
|
||||
@ -35,6 +37,15 @@ func (e DestinationAddedEvent) name() Name {
|
||||
return EventNameDestinationAdded
|
||||
}
|
||||
|
||||
// AddDestinationFailedEvent is emitted when a destination fails to be added.
|
||||
type AddDestinationFailedEvent struct {
|
||||
Err error
|
||||
}
|
||||
|
||||
func (e AddDestinationFailedEvent) name() Name {
|
||||
return EventNameAddDestinationFailed
|
||||
}
|
||||
|
||||
// DestinationRemovedEvent is emitted when a destination is successfully
|
||||
// removed.
|
||||
type DestinationRemovedEvent struct {
|
||||
@ -45,14 +56,14 @@ func (e DestinationRemovedEvent) name() Name {
|
||||
return EventNameDestinationRemoved
|
||||
}
|
||||
|
||||
// MediaServerStartedEvent is emitted when the mediaserver component starts successfully.
|
||||
type MediaServerStartedEvent struct {
|
||||
RTMPURL string
|
||||
RTMPSURL string
|
||||
// RemoveDestinationFailedEvent is emitted when a destination fails to be
|
||||
// removed.
|
||||
type RemoveDestinationFailedEvent struct {
|
||||
Err error
|
||||
}
|
||||
|
||||
func (e MediaServerStartedEvent) name() Name {
|
||||
return "media_server_started"
|
||||
func (e RemoveDestinationFailedEvent) name() Name {
|
||||
return EventNameRemoveDestinationFailed
|
||||
}
|
||||
|
||||
// FatalErrorOccurredEvent is emitted when a fatal application
|
||||
@ -64,3 +75,13 @@ type FatalErrorOccurredEvent struct {
|
||||
func (e FatalErrorOccurredEvent) name() Name {
|
||||
return "fatal_error_occurred"
|
||||
}
|
||||
|
||||
// MediaServerStartedEvent is emitted when the mediaserver component starts successfully.
|
||||
type MediaServerStartedEvent struct {
|
||||
RTMPURL string
|
||||
RTMPSURL string
|
||||
}
|
||||
|
||||
func (e MediaServerStartedEvent) name() Name {
|
||||
return "media_server_started"
|
||||
}
|
||||
|
@ -281,7 +281,9 @@ func (ui *UI) run(ctx context.Context) {
|
||||
|
||||
appStateChangedC := ui.eventBus.Register(event.EventNameAppStateChanged)
|
||||
destinationAddedC := ui.eventBus.Register(event.EventNameDestinationAdded)
|
||||
addDestinationFailedC := ui.eventBus.Register(event.EventNameAddDestinationFailed)
|
||||
destinationRemovedC := ui.eventBus.Register(event.EventNameDestinationRemoved)
|
||||
removeDestinationFailedC := ui.eventBus.Register(event.EventNameRemoveDestinationFailed)
|
||||
mediaServerStartedC := ui.eventBus.Register(event.EventNameMediaServerStarted)
|
||||
fatalErrorOccurredC := ui.eventBus.Register(event.EventNameFatalErrorOccurred)
|
||||
|
||||
@ -306,10 +308,18 @@ func (ui *UI) run(ctx context.Context) {
|
||||
ui.app.QueueUpdateDraw(func() {
|
||||
ui.handleDestinationAdded(evt.(event.DestinationAddedEvent))
|
||||
})
|
||||
case evt := <-addDestinationFailedC:
|
||||
ui.app.QueueUpdateDraw(func() {
|
||||
ui.handleDestinationEventError(evt.(event.AddDestinationFailedEvent).Err)
|
||||
})
|
||||
case evt := <-destinationRemovedC:
|
||||
ui.app.QueueUpdateDraw(func() {
|
||||
ui.handleDestinationRemoved(evt.(event.DestinationRemovedEvent))
|
||||
})
|
||||
case evt := <-removeDestinationFailedC:
|
||||
ui.app.QueueUpdateDraw(func() {
|
||||
ui.handleDestinationEventError(evt.(event.RemoveDestinationFailedEvent).Err)
|
||||
})
|
||||
case evt := <-mediaServerStartedC:
|
||||
ui.app.QueueUpdateDraw(func() {
|
||||
ui.handleMediaServerStarted(evt.(event.MediaServerStartedEvent))
|
||||
@ -866,24 +876,6 @@ func (ui *UI) Close() {
|
||||
ui.app.Stop()
|
||||
}
|
||||
|
||||
func (ui *UI) ConfigUpdateFailed(err error) {
|
||||
ui.app.QueueUpdateDraw(func() {
|
||||
ui.showModal(
|
||||
pageNameConfigUpdateFailed,
|
||||
"Configuration update failed:\n\n"+err.Error(),
|
||||
[]string{"Ok"},
|
||||
false,
|
||||
func(int, string) {
|
||||
pageName, frontPage := ui.pages.GetFrontPage()
|
||||
if pageName != pageNameAddDestination {
|
||||
ui.logger.Warn("Unexpected page when configuration form closed", "page", pageName)
|
||||
}
|
||||
ui.app.SetFocus(frontPage)
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
func (ui *UI) addDestination() {
|
||||
const (
|
||||
inputLen = 60
|
||||
@ -981,6 +973,22 @@ func (ui *UI) handleDestinationRemoved(event.DestinationRemovedEvent) {
|
||||
ui.selectPreviousDestination()
|
||||
}
|
||||
|
||||
func (ui *UI) handleDestinationEventError(err error) {
|
||||
ui.showModal(
|
||||
pageNameConfigUpdateFailed,
|
||||
"Configuration update failed:\n\n"+err.Error(),
|
||||
[]string{"Ok"},
|
||||
false,
|
||||
func(int, string) {
|
||||
pageName, frontPage := ui.pages.GetFrontPage()
|
||||
if pageName != pageNameAddDestination {
|
||||
ui.logger.Warn("Unexpected page when configuration form closed", "page", pageName)
|
||||
}
|
||||
ui.app.SetFocus(frontPage)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func (ui *UI) closeAddDestinationForm() {
|
||||
var hasDestinations bool
|
||||
ui.mu.Lock()
|
||||
|
Loading…
x
Reference in New Issue
Block a user