Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

Persist mDNS device ID for discovery

Generate and cache a 64-bit hex device ID in
~/.config/rockbox.org/device-id using dirs and rand. Reuse this ID when
registering mDNS service names. Add deps and update Cargo.lock.

+28 -2
+2
Cargo.lock
··· 9267 9267 version = "0.1.0" 9268 9268 dependencies = [ 9269 9269 "async-stream 0.3.6", 9270 + "dirs 6.0.0", 9270 9271 "futures-util", 9271 9272 "libmdns", 9272 9273 "mdns", 9273 9274 "mdns-sd", 9275 + "rand 0.8.5", 9274 9276 "tokio", 9275 9277 ] 9276 9278
+2
crates/discovery/Cargo.toml
··· 9 9 libmdns = "0.9.1" 10 10 mdns = "3.0.0" 11 11 mdns-sd = "0.5.9" 12 + dirs = "6.0.0" 13 + rand = { workspace = true } 12 14 tokio = {version = "1.36.0", features = ["full"]}
+24 -2
crates/discovery/src/lib.rs
··· 1 1 use async_stream::stream; 2 2 use futures_util::Stream; 3 3 use mdns_sd::{ServiceDaemon, ServiceEvent, ServiceInfo}; 4 - use std::{env, thread}; 4 + use rand::RngCore as _; 5 + use std::{env, fs, path::PathBuf, thread}; 5 6 6 7 pub const ROCKBOX_SERVICE_NAME: &'static str = "_rockbox._tcp.local."; 7 8 pub const MUSIC_PLAYER_SERVICE_NAME: &'static str = "_music-player._tcp.local."; ··· 35 36 } 36 37 } 37 38 39 + fn get_or_create_device_id() -> String { 40 + let path = dirs::home_dir() 41 + .unwrap_or_else(|| PathBuf::from(".")) 42 + .join(".config/rockbox.org/device-id"); 43 + 44 + if let Ok(id) = fs::read_to_string(&path) { 45 + let id = id.trim().to_string(); 46 + if !id.is_empty() { 47 + return id; 48 + } 49 + } 50 + 51 + let id = format!("{:016x}", rand::thread_rng().next_u64()); 52 + 53 + if let Some(parent) = path.parent() { 54 + let _ = fs::create_dir_all(parent); 55 + } 56 + let _ = fs::write(&path, &id); 57 + id 58 + } 59 + 38 60 pub fn register_services() { 39 - let device_id = "123"; 61 + let device_id = get_or_create_device_id(); 40 62 let http_service = format!("http-{}", device_id); 41 63 let graphql_service = format!("graphql-{}", device_id); 42 64 let grpc_service = format!("grpc-{}", device_id);