From 5cee6539c6d9373eac347a05b9fedb9be1345e24 Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Fri, 23 Jan 2026 20:28:15 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20de=20la=20notification=20UPnP=20GENA=20?= =?UTF-8?q?pour=20les=20mises=20=C3=A0=20jour=20des=20sources=20RadioFranc?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cette modification ajoute la capacité de notifier les événements UPnP GENA lors des mises à jour des sources RadioFrance. Cela permet de mettre à jour correctement le ContentDirectory UPnP lorsque les flux radio sont modifiés. - Ajout d'un notifier pour les conteneurs UPnP dans le module sources - Ajout d'un champ container_notifier dans RadioFranceSource - Implémentation de la méthode with_container_notifier - Ajout de la notification dans les deux méthodes de mise à jour (stream et playlist) - Utilisation de l'API state::notify_containers_updated pour envoyer les notifications --- pmomediaserver/src/sources.rs | 8 ++++++++ pmoradiofrance/src/source.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/pmomediaserver/src/sources.rs b/pmomediaserver/src/sources.rs index 07c66e14..30ef3f13 100644 --- a/pmomediaserver/src/sources.rs +++ b/pmomediaserver/src/sources.rs @@ -3,6 +3,7 @@ //! Ce module fournit des helpers pour créer et enregistrer facilement des sources //! musicales préconfigurées à partir de la configuration système. +use crate::contentdirectory::state; use pmoserver::Server; use pmosource::MusicSourceExt; use std::sync::Arc; @@ -262,6 +263,13 @@ impl SourcesExt for Server { SourceInitError::RadioFranceError(format!("Failed to create source: {}", e)) })?; + // Configurer le notifier pour les événements UPnP GENA + let notifier = Arc::new(|containers: &[String]| { + let refs: Vec<&str> = containers.iter().map(|s| s.as_str()).collect(); + state::notify_containers_updated(&refs); + }); + let source = source.with_container_notifier(notifier); + // Enregistrer la source self.register_music_source(Arc::new(source)).await; diff --git a/pmoradiofrance/src/source.rs b/pmoradiofrance/src/source.rs index e0a09eb0..b8426f7e 100644 --- a/pmoradiofrance/src/source.rs +++ b/pmoradiofrance/src/source.rs @@ -53,6 +53,9 @@ pub struct RadioFranceSource { /// Last change timestamp last_change: Arc>>, + + /// Callback for notifying container updates (UPnP GENA) + container_notifier: Option>, } impl RadioFranceSource { @@ -87,9 +90,19 @@ impl RadioFranceSource { server_base_url: None, update_id: Arc::new(RwLock::new(0)), last_change: Arc::new(RwLock::new(None)), + container_notifier: None, }) } + /// Set the container notifier for UPnP GENA events + pub fn with_container_notifier( + mut self, + notifier: Arc, + ) -> Self { + self.container_notifier = Some(notifier); + self + } + /// Set the cover cache #[cfg(feature = "cache")] pub fn with_cover_cache(mut self, cache: Arc) -> Self { @@ -133,6 +146,7 @@ impl RadioFranceSource { server_base_url: Some(base_url.into()), update_id: Arc::new(RwLock::new(0)), last_change: Arc::new(RwLock::new(None)), + container_notifier: None, }) } @@ -150,6 +164,7 @@ impl RadioFranceSource { let slug = station_slug.to_string(); let update_id = self.update_id.clone(); let last_change = self.last_change.clone(); + let container_notifier = self.container_notifier.clone(); #[cfg(feature = "cache")] let cover_cache = self.cover_cache.clone(); @@ -178,6 +193,13 @@ impl RadioFranceSource { // Update change tracking *update_id.write().await = update_id.read().await.wrapping_add(1); *last_change.write().await = Some(SystemTime::now()); + + // Notify UPnP ContentDirectory of the change + if let Some(ref notifier) = container_notifier { + // Notify the station's stream item container + let container_id = format!("radiofrance:{}", slug); + notifier(&[container_id]); + } } } @@ -193,6 +215,13 @@ impl RadioFranceSource { // Update change tracking *update_id.write().await = update_id.read().await.wrapping_add(1); *last_change.write().await = Some(SystemTime::now()); + + // Notify UPnP ContentDirectory of the change + if let Some(ref notifier) = container_notifier { + // Notify the station's stream item container + let container_id = format!("radiofrance:{}", slug); + notifier(&[container_id]); + } } }