From aec10bc26e9b8d75f451568ed7fb925f156b1209 Mon Sep 17 00:00:00 2001 From: Lucas Drufva Date: Thu, 25 Sep 2025 13:42:05 +0200 Subject: [PATCH] feat: Add aliases to discovery --- CHANGELOG.md | 1 + discovery/src/lib.rs | 11 +++++++++++ discovery/src/server.rs | 14 ++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a11d932e4..a2d0a6bde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 ### Changed diff --git a/discovery/src/lib.rs b/discovery/src/lib.rs index e440c67f5..672507ec1 100644 --- a/discovery/src/lib.rs +++ b/discovery/src/lib.rs @@ -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![], @@ -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) -> Self { self.zeroconf_ip = zeroconf_ip; diff --git a/discovery/src/server.rs b/discovery/src/server.rs index a328d9d82..f35c66fff 100644 --- a/discovery/src/server.rs +++ b/discovery/src/server.rs @@ -31,12 +31,19 @@ type Aes128Ctr = ctr::Ctr128BE; type Params<'a> = BTreeMap, Cow<'a, str>>; +pub struct Alias { + pub name: String, + 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, } struct RequestHandler { @@ -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::>(), // others seen-in-the-wild: // - "deviceAPI_isGroup": False })