Ajout de la notification UPnP GENA pour les mises à jour des sources RadioFrance

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
This commit is contained in:
2026-01-23 20:28:15 +01:00
parent df8b062af6
commit 5cee6539c6
2 changed files with 37 additions and 0 deletions

View File

@@ -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;

View File

@@ -53,6 +53,9 @@ pub struct RadioFranceSource {
/// Last change timestamp
last_change: Arc<RwLock<Option<SystemTime>>>,
/// Callback for notifying container updates (UPnP GENA)
container_notifier: Option<Arc<dyn Fn(&[String]) + Send + Sync + 'static>>,
}
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<dyn Fn(&[String]) + Send + Sync + 'static>,
) -> Self {
self.container_notifier = Some(notifier);
self
}
/// Set the cover cache
#[cfg(feature = "cache")]
pub fn with_cover_cache(mut self, cache: Arc<CoverCache>) -> 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]);
}
}
}