refactor(app): add DestinationWentOffAirEvent
This commit is contained in:
parent
1f4a931903
commit
2f1cadcf40
@ -197,7 +197,8 @@ func (a *App) Run(ctx context.Context) error {
|
||||
destErrors := applyReplicatorState(replState, state)
|
||||
|
||||
for _, destError := range destErrors {
|
||||
handleDestError(destError, repl, ui)
|
||||
a.eventBus.Send(event.DestinationStreamExitedEvent{Name: destError.name, Err: destError.err})
|
||||
repl.StopDestination(destError.url)
|
||||
}
|
||||
|
||||
updateUI()
|
||||
@ -316,13 +317,6 @@ func applyReplicatorState(replState replicator.State, appState *domain.AppState)
|
||||
return errorsToDisplay
|
||||
}
|
||||
|
||||
// handleDestError displays a modal to the user, and stops the destination.
|
||||
func handleDestError(destError destinationError, repl *replicator.Actor, ui *terminal.UI) {
|
||||
ui.ShowDestinationErrorModal(destError.name, destError.err)
|
||||
|
||||
repl.StopDestination(destError.url)
|
||||
}
|
||||
|
||||
// applyConfig applies the config to the app state. For now we only set the
|
||||
// destinations.
|
||||
func applyConfig(cfg config.Config, appState *domain.AppState) {
|
||||
|
@ -8,6 +8,7 @@ const (
|
||||
EventNameAppStateChanged Name = "app_state_changed"
|
||||
EventNameDestinationAdded Name = "destination_added"
|
||||
EventNameAddDestinationFailed Name = "add_destination_failed"
|
||||
EventNameDestinationStreamExited Name = "destination_stream_exited"
|
||||
EventNameStartDestinationFailed Name = "start_destination_failed"
|
||||
EventNameDestinationRemoved Name = "destination_removed"
|
||||
EventNameRemoveDestinationFailed Name = "remove_destination_failed"
|
||||
@ -48,6 +49,16 @@ func (e AddDestinationFailedEvent) name() Name {
|
||||
return EventNameAddDestinationFailed
|
||||
}
|
||||
|
||||
// DestinationStreamExitedEvent is emitted when a destination goes off-air unexpectedly.
|
||||
type DestinationStreamExitedEvent struct {
|
||||
Name string
|
||||
Err error
|
||||
}
|
||||
|
||||
func (e DestinationStreamExitedEvent) name() Name {
|
||||
return EventNameDestinationStreamExited
|
||||
}
|
||||
|
||||
// StartDestinationFailedEvent is emitted when a destination fails to start.
|
||||
type StartDestinationFailedEvent struct{}
|
||||
|
||||
|
@ -305,6 +305,8 @@ func (ui *UI) run(ctx context.Context) {
|
||||
ui.handleStartDestinationFailed(evt)
|
||||
case event.AddDestinationFailedEvent:
|
||||
ui.handleDestinationEventError(evt.Err)
|
||||
case event.DestinationStreamExitedEvent:
|
||||
ui.handleDestinationStreamExited(evt)
|
||||
case event.DestinationRemovedEvent:
|
||||
ui.handleDestinationRemoved(evt)
|
||||
case event.RemoveDestinationFailedEvent:
|
||||
@ -431,20 +433,18 @@ func (ui *UI) handleOtherInstanceDetected(event.OtherInstanceDetectedEvent) {
|
||||
)
|
||||
}
|
||||
|
||||
func (ui *UI) ShowDestinationErrorModal(name string, err error) {
|
||||
ui.app.QueueUpdateDraw(func() {
|
||||
func (ui *UI) handleDestinationStreamExited(evt event.DestinationStreamExitedEvent) {
|
||||
ui.showModal(
|
||||
pageNameModalDestinationError,
|
||||
fmt.Sprintf(
|
||||
"Streaming to %s failed:\n\n%s",
|
||||
cmp.Or(name, "this destination"),
|
||||
err,
|
||||
cmp.Or(evt.Name, "this destination"),
|
||||
evt.Err,
|
||||
),
|
||||
[]string{"Ok"},
|
||||
true,
|
||||
nil,
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
func (ui *UI) handleFatalErrorOccurred(evt event.FatalErrorOccurredEvent) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user