Skip to content

Commit

Permalink
radio: remove SongInfo.IsFallback
Browse files Browse the repository at this point in the history
To figure out if we are actively streaming or not we instead should
be using the value of the UserStream from the manager. This will be nil
if there is nobody streaming.
  • Loading branch information
Wessie committed May 13, 2024
1 parent 27d5789 commit 5ecb463
Show file tree
Hide file tree
Showing 8 changed files with 237 additions and 258 deletions.
2 changes: 1 addition & 1 deletion ircbot/commands_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func NowPlaying(e Event) error {

status := e.Bot.StatusValue.Latest()

if status.SongInfo.IsFallback {
if e.Bot.UserValue.Latest() == nil {
e.EchoPublic("Stream is currently down.")
return nil
}
Expand Down
2 changes: 2 additions & 0 deletions ircbot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func Execute(ctx context.Context, cfg config.Config) error {
}
})
b.ListenersValue = util.StreamValue(ctx, cfg.Manager.CurrentListeners)
b.UserValue = util.StreamValue(ctx, cfg.Manager.CurrentUser)

errCh := make(chan error, 2)
go func() {
Expand Down Expand Up @@ -134,6 +135,7 @@ type Bot struct {
// Values used by commands
StatusValue *util.Value[radio.Status]
ListenersValue *util.Value[radio.Listeners]
UserValue *util.Value[*radio.User]

c *girc.Client
}
Expand Down
12 changes: 3 additions & 9 deletions manager/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ func (m *Manager) UpdateUser(ctx context.Context, u *radio.User) error {

m.userStream.Send(u)

// only update status if we get a non-nil user, this leaves the status
// data with the last known DJ so that we can display something
if u != nil {
m.mu.Lock()
m.status.StreamerName = u.DJ.Name
Expand Down Expand Up @@ -84,15 +86,7 @@ func (m *Manager) UpdateSong(ctx context.Context, update *radio.SongUpdate) erro
// first we check if this is the same song as the previous one we received to
// avoid double announcement or drifting start/end timings
m.mu.Lock()
if m.status.Song.Metadata == new.Metadata && !info.IsFallback {
m.mu.Unlock()
return nil
}

// check if we're on a fallback stream
if info.IsFallback {
m.logger.Info().Str("fallback", new.Metadata).Msg("fallback engaged")
m.status.SongInfo.IsFallback = info.IsFallback
if m.status.Song.Metadata == new.Metadata {
m.mu.Unlock()
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions proxy/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ func (eh *EventHandler) eventLiveMetadataUpdate(ctx context.Context, mountName s
err := eh.cfg.Manager.UpdateSong(ctx, &radio.SongUpdate{
Song: radio.NewSong(metadata),
Info: radio.SongInfo{
Start: instant,
IsFallback: false,
Start: instant,
},
})
if err != nil {
Expand Down
3 changes: 0 additions & 3 deletions radio.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,6 @@ type SongInfo struct {
Start time.Time
// End is the expected time the current song stops playing
End time.Time
// IsFallback indicates if the song currently playing is one marked as a
// fallback song for when the icecast main stream is down
IsFallback bool
}

type SearchService interface {
Expand Down
10 changes: 4 additions & 6 deletions rpc/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,15 @@ func fromProtoSong(s *Song) radio.Song {

func toProtoSongInfo(i radio.SongInfo) *SongInfo {
return &SongInfo{
StartTime: tp(i.Start),
EndTime: tp(i.End),
IsFallback: i.IsFallback,
StartTime: tp(i.Start),
EndTime: tp(i.End),
}
}

func fromProtoSongInfo(i *SongInfo) radio.SongInfo {
return radio.SongInfo{
Start: t(i.StartTime),
End: t(i.EndTime),
IsFallback: i.IsFallback,
Start: t(i.StartTime),
End: t(i.EndTime),
}
}

Expand Down
459 changes: 224 additions & 235 deletions rpc/radio.pb.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions rpc/radio.proto
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ message SongInfo {
google.protobuf.Timestamp start_time = 3;
// the time this song will end playing
google.protobuf.Timestamp end_time = 4;
// indicates if the song is a fallback track
bool is_fallback = 5;
// old is_fallback field
reserved 5;
}

message StreamerConfig {
Expand Down

0 comments on commit 5ecb463

Please sign in to comment.