mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
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:
parent
932c6fa25f
commit
0752b8d753
2 changed files with 6 additions and 10 deletions
|
@ -148,8 +148,6 @@ pub struct ContextResolver {
|
||||||
// time after which an unavailable context is retried
|
// time after which an unavailable context is retried
|
||||||
const RETRY_UNAVAILABLE: Duration = Duration::from_secs(3600);
|
const RETRY_UNAVAILABLE: Duration = Duration::from_secs(3600);
|
||||||
|
|
||||||
const CONCERNING_AMOUNT_OF_SKIPS: usize = 1_000;
|
|
||||||
|
|
||||||
impl ContextResolver {
|
impl ContextResolver {
|
||||||
pub fn new(session: Session) -> Self {
|
pub fn new(session: Session) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -211,14 +209,12 @@ impl ContextResolver {
|
||||||
loop {
|
loop {
|
||||||
let next = self.queue.front()?;
|
let next = self.queue.front()?;
|
||||||
match next.resolve_uri() {
|
match next.resolve_uri() {
|
||||||
// this is here to prevent an endless amount of skips
|
None if idx < self.queue.len() => {
|
||||||
None if idx > CONCERNING_AMOUNT_OF_SKIPS => unreachable!(),
|
|
||||||
None => {
|
|
||||||
warn!("skipped {idx} because of no valid resolve_uri: {next}");
|
warn!("skipped {idx} because of no valid resolve_uri: {next}");
|
||||||
idx += 1;
|
idx += 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Some(uri) => break Some((next, uri, idx)),
|
value => break value.map(|uri| (next, uri, idx)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -452,7 +452,7 @@ impl SpircTask {
|
||||||
self.connect_state.prev_autoplay_track_uris()
|
self.connect_state.prev_autoplay_track_uris()
|
||||||
}).await
|
}).await
|
||||||
}, if allow_context_resolving && self.context_resolver.has_next() => {
|
}, if allow_context_resolving && self.context_resolver.has_next() => {
|
||||||
self.handle_context(next_context)
|
self.handle_next_context(next_context)
|
||||||
},
|
},
|
||||||
else => break
|
else => break
|
||||||
}
|
}
|
||||||
|
@ -471,7 +471,7 @@ impl SpircTask {
|
||||||
self.session.dealer().close().await;
|
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 {
|
let next_context = match next_context {
|
||||||
Err(why) => {
|
Err(why) => {
|
||||||
self.context_resolver.mark_next_unavailable();
|
self.context_resolver.mark_next_unavailable();
|
||||||
|
@ -1026,7 +1026,7 @@ impl SpircTask {
|
||||||
|
|
||||||
async fn handle_disconnect(&mut self) -> Result<(), Error> {
|
async fn handle_disconnect(&mut self) -> Result<(), Error> {
|
||||||
self.context_resolver.clear();
|
self.context_resolver.clear();
|
||||||
self.handle_stop();
|
self.handle_pause();
|
||||||
|
|
||||||
self.play_status = SpircPlayStatus::Stopped {};
|
self.play_status = SpircPlayStatus::Stopped {};
|
||||||
self.connect_state
|
self.connect_state
|
||||||
|
@ -1115,7 +1115,7 @@ impl SpircTask {
|
||||||
ContextAction::Replace,
|
ContextAction::Replace,
|
||||||
));
|
));
|
||||||
let context = self.context_resolver.get_next_context(Vec::new).await;
|
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
|
// for play commands with skip by uid, the context of the command contains
|
||||||
|
|
Loading…
Reference in a new issue