diff --git a/README.md b/README.md index 2bb63eb..9527804 100644 --- a/README.md +++ b/README.md @@ -199,7 +199,7 @@ Neolink will publish these messages: Messages that are prefixed with `neolink/` -- `/status` Tracks the connection of neolink, `online` for ready `offline` +- `/status` Tracks the connection of neolink, `connected` for ready `offline` for not ready this is a LastWill message - `/config` The configuration file used to start neolink, you can publish to this to **temporarily** alter the live configuration @@ -396,7 +396,7 @@ username = "admin" password = "password" uid = "ABCDEF0123456789" idle_disconnect = true - [cameras.pause] +[cameras.pause] on_client = true # Should pause when no rtsp client timeout = 2.1 # How long to wait after motion stops before pausing ``` diff --git a/crates/core/src/bc_protocol/connection/discovery.rs b/crates/core/src/bc_protocol/connection/discovery.rs index 6fe8499..0b91b0f 100644 --- a/crates/core/src/bc_protocol/connection/discovery.rs +++ b/crates/core/src/bc_protocol/connection/discovery.rs @@ -460,7 +460,9 @@ impl Discoverer { lookup: &UidLookupResults, ) -> Result { let tid = generate_tid(); - let local_addr = SocketAddr::new(get_local_ip()?, self.local_addr().port()); + let local_ip = get_local_ip()?; + let local_addr = SocketAddr::new(local_ip, self.local_addr().port()); + log::debug!("Registering {:?} to reolink", local_addr); let local_ip = local_addr.ip(); let local_port = local_addr.port(); let local_family = if local_addr.ip().is_ipv4() { 4 } else { 6 }; diff --git a/src/common/instance.rs b/src/common/instance.rs index ca4ea46..eeac953 100644 --- a/src/common/instance.rs +++ b/src/common/instance.rs @@ -5,7 +5,8 @@ //! The camera watch is used as an event to be triggered //! whenever the camera is lost/updated use anyhow::anyhow; -use std::sync::Weak; +use futures::TryFutureExt; +use std::sync::{Arc, Weak}; use tokio::sync::{ mpsc::Sender as MpscSender, oneshot::channel as oneshot, watch::Receiver as WatchReceiver, }; @@ -98,11 +99,11 @@ impl NeoInstance { _ = self.cancel.cancelled() => { Some(Err(anyhow!("Camera is disconnecting"))) } - v = camera_watch.changed() => { + v = camera_watch.wait_for(|new_cam| !Weak::ptr_eq(new_cam, &camera.as_ref().map(Arc::downgrade).unwrap_or_else(Weak::new))).map_ok(|new_cam| new_cam.upgrade()) => { // Camera value has changed! // update and try again - if v.is_ok() { - camera = camera_watch.borrow_and_update().upgrade(); + if let Ok(new_cam) = v { + camera = new_cam; None } else { Some(Err(anyhow!("Camera is disconnecting"))) @@ -128,7 +129,27 @@ impl NeoInstance { None }, Ok(e) => Some(Err(e.into())), - Err(e) => Some(Err(e)), + Err(e) => { + // Check if it is an io error + match e.downcast::() { + Ok(e) => { + // Check if the inner error is the Other type and then the discomnect + let is_dropped = e.get_ref().is_some_and(|e| + matches!(e.downcast_ref::(), + Some(neolink_core::Error::DroppedConnection) | Some(neolink_core::Error::TimeoutDisconnected) + ) + ); + if is_dropped { + // Retry is a None + camera = None; + None + } else { + Some(Err(e.into())) + } + }, + Err(e) =>Some(Err(e)) + } + }, } } } diff --git a/src/mqtt/discovery.rs b/src/mqtt/discovery.rs index 171e095..9bedcc2 100644 --- a/src/mqtt/discovery.rs +++ b/src/mqtt/discovery.rs @@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize, Serializer}; pub(crate) enum Discoveries { #[serde(alias = "floodlight", alias = "light")] Floodlight, - #[serde(alias = "camera")] + #[serde(alias = "camera", alias = "preview", alias = "Preview")] Camera, #[serde(alias = "motion", alias = "md", alias = "pir")] Motion,