Skip to content

Commit

Permalink
connect: adjust behavior
Browse files Browse the repository at this point in the history
- rename `handle_context` to `handle_next_context`
- disconnect should only pause the playback
- find_next should not exceed queue length
  • Loading branch information
photovoltex committed Dec 14, 2024
1 parent 932c6fa commit 0752b8d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
8 changes: 2 additions & 6 deletions connect/src/context_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ pub struct ContextResolver {
// time after which an unavailable context is retried
const RETRY_UNAVAILABLE: Duration = Duration::from_secs(3600);

const CONCERNING_AMOUNT_OF_SKIPS: usize = 1_000;

impl ContextResolver {
pub fn new(session: Session) -> Self {
Self {
Expand Down Expand Up @@ -211,14 +209,12 @@ impl ContextResolver {
loop {
let next = self.queue.front()?;
match next.resolve_uri() {
// this is here to prevent an endless amount of skips
None if idx > CONCERNING_AMOUNT_OF_SKIPS => unreachable!(),
None => {
None if idx < self.queue.len() => {
warn!("skipped {idx} because of no valid resolve_uri: {next}");
idx += 1;
continue;
}
Some(uri) => break Some((next, uri, idx)),
value => break value.map(|uri| (next, uri, idx)),
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions connect/src/spirc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ impl SpircTask {
self.connect_state.prev_autoplay_track_uris()
}).await
}, if allow_context_resolving && self.context_resolver.has_next() => {
self.handle_context(next_context)
self.handle_next_context(next_context)
},
else => break
}
Expand All @@ -471,7 +471,7 @@ impl SpircTask {
self.session.dealer().close().await;
}

fn handle_context(&mut self, next_context: Result<Context, Error>) {
fn handle_next_context(&mut self, next_context: Result<Context, Error>) {
let next_context = match next_context {
Err(why) => {
self.context_resolver.mark_next_unavailable();
Expand Down Expand Up @@ -1026,7 +1026,7 @@ impl SpircTask {

async fn handle_disconnect(&mut self) -> Result<(), Error> {
self.context_resolver.clear();
self.handle_stop();
self.handle_pause();

self.play_status = SpircPlayStatus::Stopped {};
self.connect_state
Expand Down Expand Up @@ -1115,7 +1115,7 @@ impl SpircTask {
ContextAction::Replace,
));
let context = self.context_resolver.get_next_context(Vec::new).await;
self.handle_context(context);
self.handle_next_context(context);
}

// for play commands with skip by uid, the context of the command contains
Expand Down

0 comments on commit 0752b8d

Please sign in to comment.