-
Notifications
You must be signed in to change notification settings - Fork 748
Fix: Harden the transfer flow for unexpected data #1581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
photovoltex
wants to merge
4
commits into
librespot-org:dev
Choose a base branch
from
photovoltex:fix/harden-transfer-flow
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
24bc45e
fix: transfer data has an invalid uri and no tracks
photovoltex cb6a9dc
fix: play/pause button being disabled on transfer
photovoltex 51a9a21
Merge branch 'dev' into fix/harden-transfer-flow
photovoltex cb08c52
chore: update Changelog
photovoltex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1056,7 +1056,7 @@ impl SpircTask { | |
fn handle_transfer(&mut self, mut transfer: TransferState) -> Result<(), Error> { | ||
let mut ctx_uri = match transfer.current_session.context.uri { | ||
None => Err(SpircError::NoUri("transfer context"))?, | ||
// can apparently happen when a state is transferred stared with "uris" via the api | ||
// can apparently happen when a state is transferred and was started with "uris" via the api | ||
Some(ref uri) if uri == "-" => String::new(), | ||
Some(ref uri) => uri.clone(), | ||
}; | ||
|
@@ -1088,16 +1088,21 @@ impl SpircTask { | |
ContextAction::Replace, | ||
)); | ||
} else { | ||
self.load_context_from_tracks( | ||
transfer | ||
.current_session | ||
.context | ||
.pages | ||
.iter() | ||
.cloned() | ||
.flat_map(|p| p.tracks) | ||
.collect::<Vec<_>>(), | ||
)? | ||
let all_tracks = transfer | ||
.current_session | ||
.context | ||
.pages | ||
.iter() | ||
.cloned() | ||
.flat_map(|p| p.tracks) | ||
.collect::<Vec<_>>(); | ||
|
||
if !all_tracks.is_empty() { | ||
self.load_context_from_tracks(all_tracks)? | ||
} else { | ||
warn!("tried to transfer with an invalid state, using fallback ({fallback})"); | ||
ctx_uri = fallback.clone(); | ||
} | ||
} | ||
|
||
self.context_resolver.add(ResolveContext::from_uri( | ||
|
@@ -1111,7 +1116,7 @@ impl SpircTask { | |
|
||
let timestamp = self.now_ms(); | ||
let state = &mut self.connect_state; | ||
state.handle_initial_transfer(&mut transfer); | ||
state.handle_initial_transfer(&mut transfer, ctx_uri.clone()); | ||
|
||
// adjust active context, so resolve knows for which context it should set up the state | ||
state.active_context = if autoplay { | ||
|
@@ -1148,11 +1153,18 @@ impl SpircTask { | |
if load_from_context_uri { | ||
self.transfer_state = Some(transfer); | ||
} else { | ||
let ctx = self.connect_state.get_context(ContextType::Default)?; | ||
let idx = ConnectState::find_index_in_context(ctx, |pt| { | ||
self.connect_state.current_track(|t| pt.uri == t.uri) | ||
})?; | ||
self.connect_state.reset_playback_to_position(Some(idx))?; | ||
match self.connect_state.get_context(ContextType::Default) { | ||
Err(_) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be helpful to capture the error? Err(e) => {
warn!("no context to reset with: {e}, continuing transfer after context resolved"),
// ..
} |
||
self.transfer_state = Some(transfer); | ||
warn!("no context to reset with, continuing transfer after context resolved"); | ||
} | ||
Ok(ctx) => { | ||
let idx = ConnectState::find_index_in_context(ctx, |pt| { | ||
self.connect_state.current_track(|t| pt.uri == t.uri) | ||
})?; | ||
self.connect_state.reset_playback_to_position(Some(idx))?; | ||
} | ||
} | ||
} | ||
|
||
self.load_track(is_playing, position.try_into()?) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,10 @@ impl ConnectState { | |
transfer: &TransferState, | ||
) -> Result<ProvidedTrack, Error> { | ||
let track = if transfer.queue.is_playing_queue.unwrap_or_default() { | ||
debug!("transfer track was used from the queue"); | ||
transfer.queue.tracks.first() | ||
} else { | ||
debug!("transfer track was the current track"); | ||
transfer.playback.current_track.as_ref() | ||
} | ||
.ok_or(StateError::CouldNotResolveTrackFromTransfer)?; | ||
|
@@ -37,7 +39,7 @@ impl ConnectState { | |
} | ||
|
||
/// handles the initially transferable data | ||
pub fn handle_initial_transfer(&mut self, transfer: &mut TransferState) { | ||
pub fn handle_initial_transfer(&mut self, transfer: &mut TransferState, ctx_uri: String) { | ||
let current_context_metadata = self.context.as_ref().map(|c| c.metadata.clone()); | ||
let player = self.player_mut(); | ||
|
||
|
@@ -84,8 +86,8 @@ impl ConnectState { | |
} | ||
} | ||
|
||
player.context_url.clear(); | ||
player.context_uri.clear(); | ||
player.context_url = format!("context://{ctx_uri}"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to check for an empty or otherwise malformed |
||
player.context_uri = ctx_uri; | ||
|
||
if let Some(metadata) = current_context_metadata { | ||
for (key, value) in metadata { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.