Skip to content

Commit dbe3f2f

Browse files
committed
feat: Add aliases to discovery
1 parent 61f517b commit dbe3f2f

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- [core] Add `SpotifyUri` type to represent more types of URI than `SpotifyId` can
13+
- [discovery] Add support for [device aliases](https://developer.spotify.com/documentation/commercial-hardware/implementation/guides/zeroconf#device-aliases)
1314

1415
### Changed
1516

discovery/src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ impl Builder {
437437
is_group: false,
438438
device_id: device_id.into(),
439439
client_id: client_id.into(),
440+
aliases: Vec::new(),
440441
},
441442
port: 0,
442443
zeroconf_ip: vec![],
@@ -462,6 +463,21 @@ impl Builder {
462463
self
463464
}
464465

466+
/// Adds an alias for this device. Multiple aliases can be added by calling this method multiple times.
467+
pub fn add_alias(
468+
mut self,
469+
alias: impl Into<Cow<'static, str>>,
470+
id: u32,
471+
is_group: bool,
472+
) -> Self {
473+
self.server_config.aliases.push(server::Alias {
474+
name: alias.into(),
475+
id,
476+
is_group,
477+
});
478+
self
479+
}
480+
465481
/// Set the ip addresses on which it should listen to incoming connections. The default is all interfaces.
466482
pub fn zeroconf_ip(mut self, zeroconf_ip: Vec<std::net::IpAddr>) -> Self {
467483
self.zeroconf_ip = zeroconf_ip;

discovery/src/server.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,19 @@ type Aes128Ctr = ctr::Ctr128BE<aes::Aes128>;
3131

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

34+
pub struct Alias {
35+
pub name: Cow<'static, str>,
36+
pub id: u32,
37+
pub is_group: bool,
38+
}
39+
3440
pub struct Config {
3541
pub name: Cow<'static, str>,
3642
pub device_type: DeviceType,
3743
pub device_id: String,
3844
pub is_group: bool,
3945
pub client_id: String,
46+
pub aliases: Vec<Alias>,
4047
}
4148

4249
struct RequestHandler {
@@ -110,6 +117,13 @@ impl RequestHandler {
110117
// undocumented but should still work
111118
"accountReq": "PREMIUM",
112119
"activeUser": active_user,
120+
"aliases": self.config.aliases.iter().map(|alias| {
121+
json!({
122+
"name": alias.name,
123+
"id": alias.id.to_string(),
124+
"isGroup": alias.is_group.to_string(),
125+
})
126+
}).collect::<Vec<_>>(),
113127
// others seen-in-the-wild:
114128
// - "deviceAPI_isGroup": False
115129
})

0 commit comments

Comments
 (0)