Added enable config option
This commit is contained in:
6 files changed
+103
-58
No files matched your search
@@ -213,13 +213,19 @@ impl BcCamera {
|
||||
//
|
||||
// We loop infinitly and allow the caller to timeout at the
|
||||
// interval they desire
|
||||
let mut retry = 0;
|
||||
const MAX_RETRY: usize = 10;
|
||||
loop {
|
||||
tokio::task::yield_now().await;
|
||||
if let Ok(result) = discovery.get_registration(uid).await {
|
||||
reg_result = result;
|
||||
break;
|
||||
}
|
||||
log::debug!("Registration failed. Retrying");
|
||||
if retry >= MAX_RETRY {
|
||||
return Err(Error::DiscoveryTimeout);
|
||||
}
|
||||
log::info!("{}: Registration with reolink servers failed. Retrying: {}/{}", options.name, retry + 1, MAX_RETRY);
|
||||
retry += 1;
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
|
||||
// New discovery to get new client IDs
|
||||
discovery = Discovery::new().await?;
|
||||
|
||||
@@ -442,69 +442,103 @@ impl Discoverer {
|
||||
|
||||
// Send and await acceptance
|
||||
let (sid, dev, dmap, relay) = self
|
||||
.retry_send(msg, lookup.reg, |bc, _| match bc {
|
||||
UdpDiscovery {
|
||||
tid: _,
|
||||
payload:
|
||||
UdpXml {
|
||||
r2c_c_r:
|
||||
Some(R2cCr {
|
||||
dmap,
|
||||
dev,
|
||||
relay,
|
||||
sid,
|
||||
rsp,
|
||||
..
|
||||
}),
|
||||
..
|
||||
},
|
||||
} if (dev
|
||||
.as_ref()
|
||||
.map(|d| !d.ip.is_empty() && d.port > 0)
|
||||
.unwrap_or(false)
|
||||
|| dmap
|
||||
.retry_send(msg, lookup.reg, |bc, socket| {
|
||||
trace!("{}", socket.ip());
|
||||
match bc {
|
||||
UdpDiscovery {
|
||||
tid: _,
|
||||
payload:
|
||||
UdpXml {
|
||||
r2c_c_r:
|
||||
Some(R2cCr {
|
||||
dmap,
|
||||
dev,
|
||||
relay,
|
||||
sid,
|
||||
rsp,
|
||||
..
|
||||
}),
|
||||
..
|
||||
},
|
||||
} if (dev
|
||||
.as_ref()
|
||||
.map(|d| !d.ip.is_empty() && d.port > 0)
|
||||
.unwrap_or(false)
|
||||
|| relay
|
||||
.as_ref()
|
||||
.map(|d| !d.ip.is_empty() && d.port > 0)
|
||||
.unwrap_or(false))
|
||||
&& rsp != -1 =>
|
||||
{
|
||||
Some(Ok((sid, dev, dmap, relay)))
|
||||
}
|
||||
UdpDiscovery {
|
||||
tid: _,
|
||||
payload:
|
||||
UdpXml {
|
||||
r2c_c_r:
|
||||
Some(R2cCr {
|
||||
dev,
|
||||
dmap,
|
||||
relay,
|
||||
rsp,
|
||||
..
|
||||
}),
|
||||
..
|
||||
},
|
||||
} if (dev
|
||||
.as_ref()
|
||||
.map(|d| !d.ip.is_empty() && d.port > 0)
|
||||
.unwrap_or(false)
|
||||
|| dmap
|
||||
|| dmap
|
||||
.as_ref()
|
||||
.map(|d| !d.ip.is_empty() && d.port > 0)
|
||||
.unwrap_or(false)
|
||||
|| relay
|
||||
.as_ref()
|
||||
.map(|d| !d.ip.is_empty() && d.port > 0)
|
||||
.unwrap_or(false))
|
||||
&& rsp != -1 =>
|
||||
{
|
||||
Some(Ok((sid, dev, dmap, relay)))
|
||||
}
|
||||
// UdpDiscovery {
|
||||
// tid: _,
|
||||
// payload:
|
||||
// UdpXml {
|
||||
// r2c_c_r:
|
||||
// Some(R2cCr {
|
||||
// dmap,
|
||||
// dev,
|
||||
// relay: Some(mut relay),
|
||||
// sid,
|
||||
// rsp,
|
||||
// ..
|
||||
// }),
|
||||
// ..
|
||||
// },
|
||||
// } if (dev
|
||||
// .as_ref()
|
||||
// .map(|d| !d.ip.is_empty() && d.port > 0)
|
||||
// .unwrap_or(false)
|
||||
// || dmap
|
||||
// .as_ref()
|
||||
// .map(|d| !d.ip.is_empty() && d.port > 0)
|
||||
// .unwrap_or(false)
|
||||
// || (relay.ip == format!("{}", socket.ip()) && relay.port == 0))
|
||||
// && rsp != -1 =>
|
||||
// {
|
||||
// // For a relay connection if port is 0 and the ip is the current socker addr
|
||||
// // we use the current port
|
||||
// relay.port = socket.port();
|
||||
// Some(Ok((sid, dev, dmap, Some(relay))))
|
||||
// }
|
||||
UdpDiscovery {
|
||||
tid: _,
|
||||
payload:
|
||||
UdpXml {
|
||||
r2c_c_r:
|
||||
Some(R2cCr {
|
||||
dev,
|
||||
dmap,
|
||||
relay,
|
||||
rsp,
|
||||
..
|
||||
}),
|
||||
..
|
||||
},
|
||||
} if (dev
|
||||
.as_ref()
|
||||
.map(|d| !d.ip.is_empty() && d.port > 0)
|
||||
.unwrap_or(false)
|
||||
|| relay
|
||||
.as_ref()
|
||||
.map(|d| !d.ip.is_empty() && d.port > 0)
|
||||
.unwrap_or(false))
|
||||
&& rsp == -1 =>
|
||||
{
|
||||
Some(Err(Error::RegisterError))
|
||||
|| dmap
|
||||
.as_ref()
|
||||
.map(|d| !d.ip.is_empty() && d.port > 0)
|
||||
.unwrap_or(false)
|
||||
|| relay
|
||||
.as_ref()
|
||||
.map(|d| !d.ip.is_empty() && d.port > 0)
|
||||
.unwrap_or(false))
|
||||
&& rsp == -1 =>
|
||||
{
|
||||
Some(Err(Error::RegisterError))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.await??;
|
||||
|
||||
|
||||
@@ -123,6 +123,9 @@ pub(crate) struct CameraConfig {
|
||||
|
||||
#[serde(default = "default_true", alias = "splash")]
|
||||
pub(crate) use_splash: bool,
|
||||
|
||||
#[serde(default = "default_true", alias = "enable")]
|
||||
pub(crate) enabled: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Validate, Clone)]
|
||||
|
||||
@@ -95,6 +95,7 @@ pub(crate) async fn main(_: Opt, config: Config) -> Result<()> {
|
||||
for camera_config in config
|
||||
.cameras
|
||||
.iter()
|
||||
.filter(|c| c.enabled)
|
||||
.map(|a| Arc::new(a.clone()))
|
||||
.collect::<Vec<_>>()
|
||||
{
|
||||
|
||||
+1
-1
@@ -88,7 +88,7 @@ pub(crate) async fn main(_opt: Opt, mut config: Config) -> Result<()> {
|
||||
)
|
||||
}
|
||||
let mut cameras = vec![];
|
||||
for camera_config in config.cameras.drain(..) {
|
||||
for camera_config in config.cameras.drain(..).filter(|c| c.enabled) {
|
||||
cameras
|
||||
.push(Camera::<Disconnected>::new(camera_config, &config.users, rtsp.clone()).await?);
|
||||
}
|
||||
|
||||
@@ -153,6 +153,7 @@ pub(crate) fn find_camera_by_name<'a>(config: &'a Config, name: &str) -> Result<
|
||||
config
|
||||
.cameras
|
||||
.iter()
|
||||
.filter(|c| c.enabled)
|
||||
.find(|c| c.name == name)
|
||||
.ok_or_else(|| anyhow!("Camera {} not found in the config file", name))
|
||||
}
|
||||
Reference in new issue
Block a user