Skip to content
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

Spirc: Replace Mecury with Dealer #1356

Merged
merged 140 commits into from
Dec 10, 2024
Merged
Changes from 1 commit
Commits
Show all changes
140 commits
Select commit Hold shift + click to select a range
736faaf
dealer wrapper for eas of use
photovoltex Sep 14, 2024
1073081
improve sending protobuf requests
photovoltex Sep 14, 2024
dfdfbd5
replace connect config with connect_state config
photovoltex Sep 14, 2024
2ecb8f0
start integrating dealer into spirc
photovoltex Sep 14, 2024
c066c29
payload handling, gzip support
photovoltex Sep 15, 2024
f8f350c
put connect state consistent
photovoltex Sep 15, 2024
23107e7
formatting
photovoltex Sep 15, 2024
68728fe
request payload handling, gzip support
photovoltex Sep 20, 2024
e450428
expose dealer::protocol, move request in own file
photovoltex Sep 20, 2024
618473b
integrate handle of connect-state commands
photovoltex Sep 20, 2024
db8f6ee
spirc: remove ident field
photovoltex Sep 22, 2024
c74606d
transfer playing state better
photovoltex Sep 24, 2024
f51d2f9
spirc: remove remote_update stream
photovoltex Sep 25, 2024
b0f8fc4
spirc: replace command sender with connect state update
photovoltex Sep 25, 2024
2b879f2
spirc: remove device state and remaining unused methods
photovoltex Sep 25, 2024
d487a1e
spirc: remove mercury sender
photovoltex Sep 25, 2024
4ca0e0c
add repeat track state
photovoltex Sep 29, 2024
5959fb8
ConnectState: add methods to replace state in spirc
photovoltex Sep 29, 2024
ae738dd
spirc: move context into connect_state, update load and next
photovoltex Sep 29, 2024
a038e91
spirc: remove state, adjust remaining methods
photovoltex Sep 29, 2024
9684cfa
spirc: handle more dealer request commands
photovoltex Sep 29, 2024
959993a
revert rustfmt.toml
photovoltex Sep 29, 2024
7d7843f
spirc: impl shuffle
photovoltex Oct 5, 2024
4cdd30e
spirc: handle device became inactive
photovoltex Oct 5, 2024
a51c83f
dealer: adjust payload handling
photovoltex Oct 5, 2024
9b80245
spirc: better set volume handling
photovoltex Oct 5, 2024
7dd5159
dealer: box PlayCommand (clippy warning)
photovoltex Oct 5, 2024
9b70d4c
dealer: always respect queued tracks
photovoltex Oct 5, 2024
cadb79d
spirc: update duration of track
photovoltex Oct 5, 2024
81babd7
ConnectState: update more restrictions
photovoltex Oct 5, 2024
4b135a0
cleanup
photovoltex Oct 5, 2024
274fe97
spirc: handle queue requests
photovoltex Oct 6, 2024
dd26b5c
spirc: skip next with track
photovoltex Oct 6, 2024
dff943a
proto: exclude spirc.proto
photovoltex Oct 13, 2024
0785aae
spirc: stabilize transfer/context handling
photovoltex Oct 13, 2024
0294194
core: cleanup some remains
photovoltex Oct 13, 2024
1f14f66
connect: improvements to code structure and performance
photovoltex Oct 18, 2024
8dd2a61
connect: delayed volume update
photovoltex Oct 20, 2024
7d4dfdc
connect: move context resolve into own function
photovoltex Oct 20, 2024
6048a35
connect: load context asynchronous
photovoltex Oct 20, 2024
f68ce40
connect: handle reconnect
photovoltex Oct 20, 2024
f550845
connect: some fixes and adjustments
photovoltex Oct 21, 2024
1a07ff5
connect: replace error case with option
photovoltex Oct 21, 2024
6c99a38
connect: use own context state
photovoltex Oct 26, 2024
9856aeb
connect: more stabilising
photovoltex Oct 26, 2024
fdac4b2
connect: working autoplay
photovoltex Oct 26, 2024
606dc7f
connect: handle repeat context/track
photovoltex Oct 27, 2024
2816959
connect: some quick fixes
photovoltex Oct 27, 2024
dde7102
connect: handle add_to_queue via set_queue
photovoltex Oct 28, 2024
dc831d0
Merge remote-tracking branch 'fork/dev' into integrate-dealer
photovoltex Oct 28, 2024
c7d95a8
fix clippy warnings
photovoltex Oct 28, 2024
f1c9cf6
fix check errors, fix/update example
photovoltex Oct 28, 2024
f5290a3
fix 1.75 specific error
photovoltex Oct 28, 2024
eebc8f2
connect: position update improvements
photovoltex Oct 29, 2024
8c31fd0
connect: handle unavailable
photovoltex Oct 29, 2024
8a3e725
connect: fix incorrect status handling for desktop and mobile
photovoltex Oct 30, 2024
fddc22c
core: fix dealer reconnect
photovoltex Oct 31, 2024
f803822
connect: split state into multiple files
photovoltex Oct 31, 2024
13e692b
connect: encapsulate provider logic
photovoltex Oct 31, 2024
2e93607
connect: remove public access to next and prev tracks
photovoltex Oct 31, 2024
d5b8a61
connect: remove public access to player
photovoltex Oct 31, 2024
ace9ca9
connect: move state only commands into own file
photovoltex Oct 31, 2024
37d2539
connect: improve logging
photovoltex Oct 31, 2024
d5e487b
connect: handle transferred queue again
photovoltex Oct 31, 2024
8468717
connect: fix all-features specific error
photovoltex Oct 31, 2024
2b5f2a3
connect: extract transfer handling into own file
photovoltex Nov 6, 2024
168743d
connect: remove old context model
photovoltex Nov 6, 2024
229aeb2
connect: handle more transfer cases correctly
photovoltex Nov 6, 2024
7d51ed9
connect: do auth_token pre-acquiring earlier
photovoltex Nov 6, 2024
8a21a44
connect: handle play with skip_to by uid
photovoltex Nov 6, 2024
78494c5
connect: simplified cluster update log
photovoltex Nov 6, 2024
2f10b4e
core/connect: add remaining set value commands
photovoltex Nov 10, 2024
adfa444
connect: position update workaround/fix
photovoltex Nov 10, 2024
cbbe72e
connect: some queue cleanups
photovoltex Nov 10, 2024
f2406d2
connect: add uid to queue
photovoltex Nov 10, 2024
6b397d8
connect: duration as volume delay const
photovoltex Nov 10, 2024
a83329c
connect: some adjustments and todo cleanups
photovoltex Nov 16, 2024
bf43f2d
connect: handle shuffle from set_options
photovoltex Nov 16, 2024
1e7624f
connect: handle context update
photovoltex Nov 16, 2024
e7a1f50
connect: move other structs into model.rs
photovoltex Nov 16, 2024
c725ebb
connect: reduce SpircCommand visibility
photovoltex Nov 16, 2024
93c5655
connect: fix visibility of model
photovoltex Nov 16, 2024
b52a176
connect: fix: shuffle on startup isn't applied
photovoltex Nov 16, 2024
658dfb0
connect: prevent loading a context with no tracks
photovoltex Nov 17, 2024
1b9192b
connect: use the first page of a context
photovoltex Nov 17, 2024
ac10e63
connect: improve context resolving
photovoltex Nov 19, 2024
98e55f5
connect: prevent integer underflow
photovoltex Nov 19, 2024
73257ab
connect: rename method for better clarity
photovoltex Nov 19, 2024
6bd09ff
connect: handle mutate and update messages
photovoltex Nov 19, 2024
7be55c9
connect: fix 1.75 problems
photovoltex Nov 19, 2024
abad156
connect: fill, instead of replace next page
photovoltex Nov 24, 2024
29954f8
connect: reduce context update to single method
photovoltex Nov 24, 2024
7d36dd4
connect: remove unused SpircError, handle local files
photovoltex Nov 24, 2024
d86f219
connect: reduce nesting, adjust initial transfer handling
photovoltex Nov 24, 2024
209146a
connect: don't update volume initially
photovoltex Nov 24, 2024
b5530bb
core: disable trace logging of handled mercury responses
photovoltex Nov 24, 2024
27c0ab6
core/connect: prevent takeover from other clients, handle session-update
photovoltex Nov 24, 2024
232fb60
connect: add queue-uid for set_queue command
photovoltex Nov 24, 2024
dab0948
connect: adjust fields for PlayCommand
photovoltex Nov 24, 2024
45f2a42
connect: preserve context position after update_context
photovoltex Nov 24, 2024
f3ed11c
connect: unify metadata modification
photovoltex Nov 24, 2024
dee269a
connect: polish request command handling
photovoltex Nov 26, 2024
875aea8
Merge remote-tracking branch 'refs/remotes/fork/dev' into integrate-d…
photovoltex Nov 26, 2024
bca6b70
connect: add uid to tracks without
photovoltex Nov 26, 2024
ffc31bb
connect: simpler update of current index
photovoltex Nov 26, 2024
85a68c8
core/connect: update log msg, fix wrong behavior
photovoltex Nov 26, 2024
2a8d6e1
core: add option to request without metrics and salt
photovoltex Nov 26, 2024
81020fa
core/context: adjust context requests and update
photovoltex Nov 26, 2024
7ebacc7
connect: handle possible search context uri
photovoltex Nov 27, 2024
749622a
connect: remove logout support
photovoltex Nov 27, 2024
049b7ee
connect: adjust detailed tracks/context handling
photovoltex Nov 29, 2024
3d77f5d
connect: adjust context resolve handling, again
photovoltex Nov 29, 2024
58a9690
connect: add autoplay metadata to tracks
photovoltex Nov 29, 2024
e46ab03
core/connect: cleanup session after spirc stops
photovoltex Nov 29, 2024
2957546
update CHANGELOG.md
photovoltex Nov 29, 2024
a252a59
playback: fix clippy warnings
photovoltex Nov 29, 2024
6cd4492
connect: adjust metadata
photovoltex Nov 30, 2024
7c394e7
connect: add delimiter between context and autoplay playback
photovoltex Nov 30, 2024
37444bc
connect: stop and resume correctly
photovoltex Nov 30, 2024
b8d3e9d
connect: adjust context resolving
photovoltex Nov 30, 2024
f35e4cd
connect: ignore failure during stop
photovoltex Nov 30, 2024
7362c83
connect: revert resolve_uri changes
photovoltex Nov 30, 2024
421d9f5
connect: correct context reset
photovoltex Nov 30, 2024
68be3d1
connect: reduce boiler code
photovoltex Nov 30, 2024
afbbcf0
connect: fix some incorrect states
photovoltex Dec 1, 2024
87a5569
core: adjust incorrect separator
photovoltex Dec 3, 2024
239e61d
connect: move `add_to_queue` and `mark_unavailable` into tracks.rs
photovoltex Dec 3, 2024
3f38945
connect: refactor - directly modify PutStateRequest
photovoltex Dec 3, 2024
18af5d2
connect: adjust handling of context metadata/restrictions
photovoltex Dec 3, 2024
4f534d1
connect: fix incorrect context states
photovoltex Dec 3, 2024
2aa616f
connect: become inactive when no cluster is reported
photovoltex Dec 3, 2024
f9f7fc9
update CHANGELOG.md
photovoltex Dec 6, 2024
be81f2a
core/playback: preemptively fix clippy warnings
photovoltex Dec 6, 2024
a0c416f
connect: minor adjustment to session changed
photovoltex Dec 7, 2024
f258f75
connect: change return type changing active context
photovoltex Dec 7, 2024
1760f16
connect: handle unavailable contexts
photovoltex Dec 7, 2024
e4528d8
connect: fix previous restrictions blocking load with shuffle
photovoltex Dec 8, 2024
cdbbfe0
connect: update comments and logging
photovoltex Dec 8, 2024
54a5cd2
core/connect: reduce some more duplicate code
photovoltex Dec 8, 2024
521ea74
more docs around the dealer
photovoltex Dec 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
spirc: remove remote_update stream
photovoltex committed Sep 28, 2024

Verified

This commit was signed with the committer’s verified signature.
arvindh123 Arvindh
commit f51d2f9d238fa890fffee9e1b553ea0a572658e7
198 changes: 0 additions & 198 deletions connect/src/spirc.rs
Original file line number Diff line number Diff line change
@@ -91,7 +91,6 @@ struct SpircTask {
play_request_id: Option<u64>,
play_status: SpircPlayStatus,

remote_update: BoxedStream<Result<(String, Frame), Error>>,
connection_id_update: BoxedStream<Result<String, Error>>,
connect_state_update: BoxedStream<Result<ClusterUpdate, Error>>,
connect_state_command: BoxedStream<RequestReply>,
@@ -280,24 +279,6 @@ impl Spirc {

let connect_state = ConnectState::new(config, &session);

let remote_update = Box::pin(
session
.mercury()
.listen_for("hm://remote/user/")
.map(UnboundedReceiverStream::new)
.flatten_stream()
.map(|response| -> Result<(String, Frame), Error> {
let uri_split: Vec<&str> = response.uri.split('/').collect();
let username = match uri_split.get(4) {
Some(s) => s.to_string(),
None => String::new(),
};

let data = response.payload.first().ok_or(SpircError::NoData)?;
Ok((username, Frame::parse_from_bytes(data)?))
}),
);

let connection_id_update = Box::pin(
session
.dealer()
@@ -482,22 +463,6 @@ impl SpircTask {
break;
}
},
remote_update = self.remote_update.next() => match remote_update {
Some(result) => match result {
Ok((username, frame)) => {
if username != self.session.username() {
warn!("could not dispatch remote update: frame was intended for {}", username);
} else if let Err(e) = self.handle_remote_update(frame) {
error!("could not dispatch remote update: {}", e);
}
},
Err(e) => error!("could not parse remote update: {}", e),
}
None => {
error!("remote update selected, but none received");
break;
}
},
user_attributes_update = self.user_attributes_update.next() => match user_attributes_update {
Some(result) => match result {
Ok(attributes) => self.handle_user_attributes_update(attributes),
@@ -900,169 +865,6 @@ impl SpircTask {
}
}

fn handle_remote_update(&mut self, update: Frame) -> Result<(), Error> {
trace!("Received update frame: {:#?}", update);

// First see if this update was intended for us.
let device_id = &self.connect_state.device.device_id;
let ident = update.ident();
if ident == device_id
|| (!update.recipient.is_empty() && !update.recipient.contains(device_id))
{
return Err(SpircError::Ident(ident.to_string()).into());
}

let old_client_id = self.session.client_id();

for entry in update.device_state.metadata.iter() {
match entry.type_() {
"client_id" => self.session.set_client_id(entry.metadata()),
"brand_display_name" => self.session.set_client_brand_name(entry.metadata()),
"model_display_name" => self.session.set_client_model_name(entry.metadata()),
_ => (),
}
}

self.session.set_client_name(update.device_state.name());

let new_client_id = self.session.client_id();

if self.device.is_active() && new_client_id != old_client_id {
self.player.emit_session_client_changed_event(
new_client_id,
self.session.client_name(),
self.session.client_brand_name(),
self.session.client_model_name(),
);
}

match update.typ() {
MessageType::kMessageTypeHello => self.notify(Some(ident)),

MessageType::kMessageTypeLoad => {
self.handle_load(update.state.get_or_default())?;
self.notify(None)
}

MessageType::kMessageTypePlay => {
self.handle_play();
self.notify(None)
}

MessageType::kMessageTypePlayPause => {
self.handle_play_pause();
self.notify(None)
}

MessageType::kMessageTypePause => {
self.handle_pause();
self.notify(None)
}

MessageType::kMessageTypeNext => {
self.handle_next()?;
self.notify(None)
}

MessageType::kMessageTypePrev => {
self.handle_prev()?;
self.notify(None)
}

MessageType::kMessageTypeVolumeUp => {
self.handle_volume_up();
self.notify(None)
}

MessageType::kMessageTypeVolumeDown => {
self.handle_volume_down();
self.notify(None)
}

MessageType::kMessageTypeRepeat => {
let repeat = update.state.repeat();
self.state.set_repeat(repeat);

self.player.emit_repeat_changed_event(repeat);

self.notify(None)
}

MessageType::kMessageTypeShuffle => {
let shuffle = update.state.shuffle();
self.state.set_shuffle(shuffle);
if shuffle {
let current_index = self.state.playing_track_index();
let tracks = &mut self.state.track;
if !tracks.is_empty() {
tracks.swap(0, current_index as usize);
if let Some((_, rest)) = tracks.split_first_mut() {
let mut rng = rand::thread_rng();
rest.shuffle(&mut rng);
}
self.state.set_playing_track_index(0);
}
}
self.player.emit_shuffle_changed_event(shuffle);

self.notify(None)
}

MessageType::kMessageTypeSeek => {
self.handle_seek(update.position());
self.notify(None)
}

MessageType::kMessageTypeReplace => {
let context_uri = update.state.context_uri().to_owned();

// completely ignore local playback.
if context_uri.starts_with("spotify:local-files") {
self.notify(None)?;
return Err(SpircError::UnsupportedLocalPlayBack.into());
}

self.update_tracks(update.state.get_or_default());

if let SpircPlayStatus::Playing {
preloading_of_next_track_triggered,
..
}
| SpircPlayStatus::Paused {
preloading_of_next_track_triggered,
..
} = self.play_status
{
if preloading_of_next_track_triggered {
// Get the next track_id in the playlist
if let Some(track_id) = self.preview_next_track() {
self.player.preload(track_id);
}
}
}

self.notify(None)
}

MessageType::kMessageTypeVolume => {
self.set_volume(update.volume() as u16);
self.notify(None)
}

MessageType::kMessageTypeNotify => {
if self.device.is_active()
&& update.device_state.is_active()
&& self.device.became_active_at() <= update.device_state.became_active_at()
{
self.handle_disconnect();
}
self.notify(None)
}

_ => Ok(()),
}
}

fn handle_cluster_update(&mut self, mut cluster_update: ClusterUpdate) -> Result<(), Error> {
let reason = cluster_update.update_reason.enum_value_or_default();