refactor(app): add StartDestinationFailedEvent
This commit is contained in:
parent
f4021a2886
commit
3019387f38
@ -181,7 +181,7 @@ func (a *App) Run(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if !a.handleCommand(cmd, state, repl, ui) {
|
if !a.handleCommand(cmd, state, repl) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
case <-uiUpdateT.C:
|
case <-uiUpdateT.C:
|
||||||
@ -209,7 +209,6 @@ func (a *App) handleCommand(
|
|||||||
cmd domain.Command,
|
cmd domain.Command,
|
||||||
state *domain.AppState,
|
state *domain.AppState,
|
||||||
repl *replicator.Actor,
|
repl *replicator.Actor,
|
||||||
ui *terminal.UI,
|
|
||||||
) bool {
|
) bool {
|
||||||
a.logger.Debug("Command received", "cmd", cmd.Name())
|
a.logger.Debug("Command received", "cmd", cmd.Name())
|
||||||
switch c := cmd.(type) {
|
switch c := cmd.(type) {
|
||||||
@ -243,7 +242,7 @@ func (a *App) handleCommand(
|
|||||||
a.eventBus.Send(event.DestinationRemovedEvent{URL: c.URL})
|
a.eventBus.Send(event.DestinationRemovedEvent{URL: c.URL})
|
||||||
case domain.CommandStartDestination:
|
case domain.CommandStartDestination:
|
||||||
if !state.Source.Live {
|
if !state.Source.Live {
|
||||||
ui.ShowSourceNotLiveModal()
|
a.eventBus.Send(event.StartDestinationFailedEvent{})
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ const (
|
|||||||
EventNameAppStateChanged Name = "app_state_changed"
|
EventNameAppStateChanged Name = "app_state_changed"
|
||||||
EventNameDestinationAdded Name = "destination_added"
|
EventNameDestinationAdded Name = "destination_added"
|
||||||
EventNameAddDestinationFailed Name = "add_destination_failed"
|
EventNameAddDestinationFailed Name = "add_destination_failed"
|
||||||
|
EventNameStartDestinationFailed Name = "start_destination_failed"
|
||||||
EventNameDestinationRemoved Name = "destination_removed"
|
EventNameDestinationRemoved Name = "destination_removed"
|
||||||
EventNameRemoveDestinationFailed Name = "remove_destination_failed"
|
EventNameRemoveDestinationFailed Name = "remove_destination_failed"
|
||||||
EventNameFatalErrorOccurred Name = "fatal_error_occurred"
|
EventNameFatalErrorOccurred Name = "fatal_error_occurred"
|
||||||
@ -46,6 +47,13 @@ func (e AddDestinationFailedEvent) name() Name {
|
|||||||
return EventNameAddDestinationFailed
|
return EventNameAddDestinationFailed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StartDestinationFailedEvent is emitted when a destination fails to start.
|
||||||
|
type StartDestinationFailedEvent struct{}
|
||||||
|
|
||||||
|
func (e StartDestinationFailedEvent) name() Name {
|
||||||
|
return EventNameStartDestinationFailed
|
||||||
|
}
|
||||||
|
|
||||||
// DestinationRemovedEvent is emitted when a destination is successfully
|
// DestinationRemovedEvent is emitted when a destination is successfully
|
||||||
// removed.
|
// removed.
|
||||||
type DestinationRemovedEvent struct {
|
type DestinationRemovedEvent struct {
|
||||||
|
@ -282,6 +282,7 @@ func (ui *UI) run(ctx context.Context) {
|
|||||||
appStateChangedC := ui.eventBus.Register(event.EventNameAppStateChanged)
|
appStateChangedC := ui.eventBus.Register(event.EventNameAppStateChanged)
|
||||||
destinationAddedC := ui.eventBus.Register(event.EventNameDestinationAdded)
|
destinationAddedC := ui.eventBus.Register(event.EventNameDestinationAdded)
|
||||||
addDestinationFailedC := ui.eventBus.Register(event.EventNameAddDestinationFailed)
|
addDestinationFailedC := ui.eventBus.Register(event.EventNameAddDestinationFailed)
|
||||||
|
startDestinationFailedC := ui.eventBus.Register(event.EventNameStartDestinationFailed)
|
||||||
destinationRemovedC := ui.eventBus.Register(event.EventNameDestinationRemoved)
|
destinationRemovedC := ui.eventBus.Register(event.EventNameDestinationRemoved)
|
||||||
removeDestinationFailedC := ui.eventBus.Register(event.EventNameRemoveDestinationFailed)
|
removeDestinationFailedC := ui.eventBus.Register(event.EventNameRemoveDestinationFailed)
|
||||||
mediaServerStartedC := ui.eventBus.Register(event.EventNameMediaServerStarted)
|
mediaServerStartedC := ui.eventBus.Register(event.EventNameMediaServerStarted)
|
||||||
@ -308,6 +309,10 @@ func (ui *UI) run(ctx context.Context) {
|
|||||||
ui.app.QueueUpdateDraw(func() {
|
ui.app.QueueUpdateDraw(func() {
|
||||||
ui.handleDestinationAdded(evt.(event.DestinationAddedEvent))
|
ui.handleDestinationAdded(evt.(event.DestinationAddedEvent))
|
||||||
})
|
})
|
||||||
|
case evt := <-startDestinationFailedC:
|
||||||
|
ui.app.QueueUpdateDraw(func() {
|
||||||
|
ui.handleStartDestinationFailed(evt.(event.StartDestinationFailedEvent))
|
||||||
|
})
|
||||||
case evt := <-addDestinationFailedC:
|
case evt := <-addDestinationFailedC:
|
||||||
ui.app.QueueUpdateDraw(func() {
|
ui.app.QueueUpdateDraw(func() {
|
||||||
ui.handleDestinationEventError(evt.(event.AddDestinationFailedEvent).Err)
|
ui.handleDestinationEventError(evt.(event.AddDestinationFailedEvent).Err)
|
||||||
@ -413,16 +418,14 @@ func (ui *UI) fkeyHandler(key tcell.Key) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *UI) ShowSourceNotLiveModal() {
|
func (ui *UI) handleStartDestinationFailed(event.StartDestinationFailedEvent) {
|
||||||
ui.app.QueueUpdateDraw(func() {
|
|
||||||
ui.showModal(
|
ui.showModal(
|
||||||
pageNameModalNotLive,
|
pageNameModalStartDestinationFailed,
|
||||||
"Waiting for stream.\n\nStart streaming to a source URL then try again.",
|
"Waiting for stream.\n\nStart streaming to a source URL then try again.",
|
||||||
[]string{"Ok"},
|
[]string{"Ok"},
|
||||||
false,
|
false,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ShowStartupCheckModal shows a modal dialog to the user, asking if they want
|
// ShowStartupCheckModal shows a modal dialog to the user, asking if they want
|
||||||
@ -605,8 +608,8 @@ const (
|
|||||||
pageNameModalQuit = "modal-quit"
|
pageNameModalQuit = "modal-quit"
|
||||||
pageNameModalRemoveDestination = "modal-remove-destination"
|
pageNameModalRemoveDestination = "modal-remove-destination"
|
||||||
pageNameModalSourceError = "modal-source-error"
|
pageNameModalSourceError = "modal-source-error"
|
||||||
|
pageNameModalStartDestinationFailed = "modal-start-destination-failed"
|
||||||
pageNameModalStartupCheck = "modal-startup-check"
|
pageNameModalStartupCheck = "modal-startup-check"
|
||||||
pageNameModalNotLive = "modal-not-live"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// modalVisible returns true if any modal, including the add destination form,
|
// modalVisible returns true if any modal, including the add destination form,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user