Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- [core] Add `SpotifyUri` type to represent more types of URI than `SpotifyId` can
- [discovery] Add support for device aliases
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add that link to the API docs?


### Changed

Expand Down
11 changes: 11 additions & 0 deletions discovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ impl Builder {
is_group: false,
device_id: device_id.into(),
client_id: client_id.into(),
aliases: Vec::new(),
},
port: 0,
zeroconf_ip: vec![],
Expand All @@ -462,6 +463,16 @@ impl Builder {
self
}

/// Adds an alias for this device. Multiple aliases can be added by calling this method multiple times.
pub fn add_alias(mut self, alias: String, id: u32, is_group: bool) -> Self {
self.server_config.aliases.push(server::Alias {
name: alias,
id,
is_group,
});
self
}

/// Set the ip addresses on which it should listen to incoming connections. The default is all interfaces.
pub fn zeroconf_ip(mut self, zeroconf_ip: Vec<std::net::IpAddr>) -> Self {
self.zeroconf_ip = zeroconf_ip;
Expand Down
14 changes: 14 additions & 0 deletions discovery/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@ type Aes128Ctr = ctr::Ctr128BE<aes::Aes128>;

type Params<'a> = BTreeMap<Cow<'a, str>, Cow<'a, str>>;

pub struct Alias {
pub name: String,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also be a Cow<'static, str> like the primary name?

And then I see that the primary device_id is actually a String instead of u32 - don't know which it should be.

pub id: u32,
pub is_group: bool,
}

pub struct Config {
pub name: Cow<'static, str>,
pub device_type: DeviceType,
pub device_id: String,
pub is_group: bool,
pub client_id: String,
pub aliases: Vec<Alias>,
}

struct RequestHandler {
Expand Down Expand Up @@ -110,6 +117,13 @@ impl RequestHandler {
// undocumented but should still work
"accountReq": "PREMIUM",
"activeUser": active_user,
"aliases": self.config.aliases.iter().map(|alias| {
json!({
"name": alias.name,
"id": alias.id.to_string(),
"isGroup": alias.is_group.to_string(),
})
}).collect::<Vec<_>>(),
// others seen-in-the-wild:
// - "deviceAPI_isGroup": False
})
Expand Down
Loading