il faut réparer la detection des devices
This commit is contained in:
@@ -26,7 +26,7 @@
|
|||||||
use crate::content_handler::ContentHandler;
|
use crate::content_handler::ContentHandler;
|
||||||
use pmoupnp::actions::{ActionError, ActionHandler};
|
use pmoupnp::actions::{ActionError, ActionHandler};
|
||||||
use pmoupnp::{action_handler, get, set};
|
use pmoupnp::{action_handler, get, set};
|
||||||
use tracing::{debug, error};
|
use tracing::{debug, error, info};
|
||||||
|
|
||||||
/// Handler pour l'action Browse.
|
/// Handler pour l'action Browse.
|
||||||
///
|
///
|
||||||
@@ -61,6 +61,11 @@ pub fn browse_handler() -> ActionHandler {
|
|||||||
let _filter: String = get!(&data, "Filter", String);
|
let _filter: String = get!(&data, "Filter", String);
|
||||||
let _sort_criteria: String = get!(&data, "SortCriteria", String);
|
let _sort_criteria: String = get!(&data, "SortCriteria", String);
|
||||||
|
|
||||||
|
info!(
|
||||||
|
"📂 Browse requested: object_id={} flag={} start={} count={}",
|
||||||
|
object_id, browse_flag, starting_index, requested_count
|
||||||
|
);
|
||||||
|
|
||||||
// Appeler la logique métier
|
// Appeler la logique métier
|
||||||
let (didl, returned, total, update_id) = handler
|
let (didl, returned, total, update_id) = handler
|
||||||
.browse(&object_id, &browse_flag, starting_index, requested_count)
|
.browse(&object_id, &browse_flag, starting_index, requested_count)
|
||||||
@@ -80,6 +85,10 @@ pub fn browse_handler() -> ActionHandler {
|
|||||||
"✅ Browse completed: returned={}, total={}",
|
"✅ Browse completed: returned={}, total={}",
|
||||||
returned, total
|
returned, total
|
||||||
);
|
);
|
||||||
|
info!(
|
||||||
|
"📂 Browse completed: object_id={} returned={} total={}",
|
||||||
|
object_id, returned, total
|
||||||
|
);
|
||||||
Ok(data)
|
Ok(data)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use std::collections::HashMap;
|
|||||||
use std::net::{SocketAddr, UdpSocket};
|
use std::net::{SocketAddr, UdpSocket};
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tracing::{info, warn};
|
use tracing::{debug, info, warn};
|
||||||
|
|
||||||
/// Serveur SSDP gérant les annonces et découvertes
|
/// Serveur SSDP gérant les annonces et découvertes
|
||||||
pub struct SsdpServer {
|
pub struct SsdpServer {
|
||||||
@@ -62,6 +62,17 @@ impl SsdpServer {
|
|||||||
devices.insert(uuid.clone(), device.clone());
|
devices.insert(uuid.clone(), device.clone());
|
||||||
drop(devices);
|
drop(devices);
|
||||||
|
|
||||||
|
info!(
|
||||||
|
"🆕 SSDP device registered: {} ({} NTs)",
|
||||||
|
uuid,
|
||||||
|
device.get_notification_types().len()
|
||||||
|
);
|
||||||
|
debug!(
|
||||||
|
"🆕 SSDP device notification types for {}: {:?}",
|
||||||
|
uuid,
|
||||||
|
device.get_notification_types()
|
||||||
|
);
|
||||||
|
|
||||||
// Envoyer alive pour tous les NTs
|
// Envoyer alive pour tous les NTs
|
||||||
if let Some(ref socket) = self.socket {
|
if let Some(ref socket) = self.socket {
|
||||||
for nt in device.get_notification_types() {
|
for nt in device.get_notification_types() {
|
||||||
@@ -76,6 +87,12 @@ impl SsdpServer {
|
|||||||
if let Some(device) = devices.remove(uuid) {
|
if let Some(device) = devices.remove(uuid) {
|
||||||
drop(devices);
|
drop(devices);
|
||||||
|
|
||||||
|
info!(
|
||||||
|
"🗑️ SSDP device removed: {} ({} NTs)",
|
||||||
|
uuid,
|
||||||
|
device.get_notification_types().len()
|
||||||
|
);
|
||||||
|
|
||||||
// Envoyer byebye pour tous les NTs
|
// Envoyer byebye pour tous les NTs
|
||||||
if let Some(ref socket) = self.socket {
|
if let Some(ref socket) = self.socket {
|
||||||
for nt in device.get_notification_types() {
|
for nt in device.get_notification_types() {
|
||||||
@@ -111,7 +128,13 @@ impl SsdpServer {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
match socket.send_to(msg.as_bytes(), addr) {
|
match socket.send_to(msg.as_bytes(), addr) {
|
||||||
Ok(_) => info!("✅ NOTIFY alive: {} (NT={})", usn, nt),
|
Ok(_) => {
|
||||||
|
info!("✅ NOTIFY alive: {} (NT={})", usn, nt);
|
||||||
|
debug!(
|
||||||
|
"📣 NOTIFY alive payload\n<details>\n\n```\n{}\n```\n</details>\n",
|
||||||
|
msg
|
||||||
|
);
|
||||||
|
}
|
||||||
Err(e) => warn!("❌ Failed to send NOTIFY alive for {}: {}", usn, e),
|
Err(e) => warn!("❌ Failed to send NOTIFY alive for {}: {}", usn, e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -139,7 +162,13 @@ impl SsdpServer {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
match socket.send_to(msg.as_bytes(), addr) {
|
match socket.send_to(msg.as_bytes(), addr) {
|
||||||
Ok(_) => info!("👋 NOTIFY byebye: {} (NT={})", usn, nt),
|
Ok(_) => {
|
||||||
|
info!("👋 NOTIFY byebye: {} (NT={})", usn, nt);
|
||||||
|
debug!(
|
||||||
|
"📣 NOTIFY byebye payload\n<details>\n\n```\n{}\n```\n</details>\n",
|
||||||
|
msg
|
||||||
|
);
|
||||||
|
}
|
||||||
Err(e) => warn!("❌ Failed to send NOTIFY byebye for {}: {}", usn, e),
|
Err(e) => warn!("❌ Failed to send NOTIFY byebye for {}: {}", usn, e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -151,6 +180,7 @@ impl SsdpServer {
|
|||||||
|
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
loop {
|
loop {
|
||||||
|
debug!("⏰ SSDP periodic announcement tick");
|
||||||
std::thread::sleep(period);
|
std::thread::sleep(period);
|
||||||
|
|
||||||
let devices = devices.read().unwrap();
|
let devices = devices.read().unwrap();
|
||||||
@@ -189,7 +219,13 @@ impl SsdpServer {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
match socket.send_to(msg.as_bytes(), addr) {
|
match socket.send_to(msg.as_bytes(), addr) {
|
||||||
Ok(_) => info!("✅ NOTIFY alive (periodic): {} (NT={})", usn, nt),
|
Ok(_) => {
|
||||||
|
info!("✅ NOTIFY alive (periodic): {} (NT={})", usn, nt);
|
||||||
|
debug!(
|
||||||
|
"📣 NOTIFY alive (periodic) payload\n<details>\n\n```\n{}\n```\n</details>\n",
|
||||||
|
msg
|
||||||
|
);
|
||||||
|
}
|
||||||
Err(e) => warn!("❌ Failed to send periodic NOTIFY alive for {}: {}", usn, e),
|
Err(e) => warn!("❌ Failed to send periodic NOTIFY alive for {}: {}", usn, e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -205,6 +241,10 @@ impl SsdpServer {
|
|||||||
Ok((n, src)) => {
|
Ok((n, src)) => {
|
||||||
let data = String::from_utf8_lossy(&buf[..n]);
|
let data = String::from_utf8_lossy(&buf[..n]);
|
||||||
if data.starts_with("M-SEARCH") {
|
if data.starts_with("M-SEARCH") {
|
||||||
|
debug!(
|
||||||
|
"🔍 M-SEARCH received from {}\n<details>\n\n```\n{}\n```\n</details>\n",
|
||||||
|
src, data
|
||||||
|
);
|
||||||
if let Some(st) = Self::parse_st(&data) {
|
if let Some(st) = Self::parse_st(&data) {
|
||||||
let devices = devices.read().unwrap();
|
let devices = devices.read().unwrap();
|
||||||
for device in devices.values() {
|
for device in devices.values() {
|
||||||
@@ -270,12 +310,14 @@ impl SsdpServer {
|
|||||||
\r\n",
|
\r\n",
|
||||||
MAX_AGE, date, device.location, device.server, nt, usn
|
MAX_AGE, date, device.location, device.server, nt, usn
|
||||||
);
|
);
|
||||||
|
|
||||||
match socket.send_to(resp.as_bytes(), src) {
|
match socket.send_to(resp.as_bytes(), src) {
|
||||||
Ok(_) => info!(
|
Ok(_) => {
|
||||||
"📡 M-SEARCH response sent to {} with ST={}\n<details>\n\n```\n{}\n```\n</details>\n",
|
info!("📡 M-SEARCH response sent to {} with ST={}", src, nt);
|
||||||
src, nt, resp
|
debug!(
|
||||||
),
|
"📡 M-SEARCH response payload\n<details>\n\n```\n{}\n```\n</details>\n",
|
||||||
|
resp
|
||||||
|
);
|
||||||
|
}
|
||||||
Err(e) => warn!("❌ Failed to send M-SEARCH response to {}: {}", src, e),
|
Err(e) => warn!("❌ Failed to send M-SEARCH response to {}: {}", src, e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user