connect: adjust behavior

- rename `handle_context` to `handle_next_context`
- disconnect should only pause the playback
- find_next should not exceed queue length
This commit is contained in:
Felix Prillwitz 2024-12-14 16:13:09 +01:00
parent 932c6fa25f
commit 0752b8d753
No known key found for this signature in database
GPG key ID: DE334B43606D1455
2 changed files with 6 additions and 10 deletions

View file

@ -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 {
@ -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)),
}
}
}

View file

@ -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
}
@ -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();
@ -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
@ -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