Add pings to the camera while paused
This commit is contained in:
2 files changed
+41
-7
No files matched your search
@@ -7,8 +7,11 @@
|
||||
|
||||
use super::{camera::Camera, connected::Connected, streaming::Streaming};
|
||||
use anyhow::Result;
|
||||
use futures::stream::StreamExt;
|
||||
use log::*;
|
||||
use neolink_core::bc_protocol::BcCamera;
|
||||
use tokio::time::{interval, Duration};
|
||||
use tokio_stream::wrappers::IntervalStream;
|
||||
|
||||
pub(crate) struct LoggedIn {
|
||||
pub(crate) camera: BcCamera,
|
||||
@@ -98,12 +101,29 @@ impl Camera<LoggedIn> {
|
||||
&self.state.camera
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
#[allow(dead_code)]
|
||||
pub(crate) async fn join(&self) -> Result<()> {
|
||||
self.state
|
||||
.camera
|
||||
.join()
|
||||
.await
|
||||
.map_err(|e| anyhow::anyhow!("Camera join error: {:?}", e))
|
||||
tokio::select! {
|
||||
v = async {
|
||||
self.state
|
||||
.camera
|
||||
.join()
|
||||
.await
|
||||
.map_err(|e| anyhow::anyhow!("Camera join error: {:?}", e))
|
||||
} => v,
|
||||
v = self.keepalive() => {v}
|
||||
}
|
||||
}
|
||||
|
||||
async fn keepalive(&self) -> Result<()> {
|
||||
let mut interval = IntervalStream::new(interval(Duration::from_secs(5)));
|
||||
while let Some(_update) = interval.next().await {
|
||||
if self.state.camera.ping().await.is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
futures::pending!(); // Never actually finish, has to be aborted
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,8 @@ use log::*;
|
||||
use neolink_core::bcmedia::model::BcMedia;
|
||||
use tokio::sync::RwLock;
|
||||
use tokio::task::JoinHandle;
|
||||
use tokio::time::{timeout, Duration};
|
||||
use tokio::time::{interval, timeout, Duration};
|
||||
use tokio_stream::wrappers::IntervalStream;
|
||||
|
||||
use neolink_core::bc_protocol::{BcCamera, StreamKind as Stream};
|
||||
|
||||
@@ -157,10 +158,23 @@ impl Camera<Streaming> {
|
||||
Ok(())
|
||||
} => v,
|
||||
v = self.state.camera.join() => v.map_err(|e| anyhow!("Camera join error: {:?}", e)),
|
||||
v = self.keepalive() => {v},
|
||||
}?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn keepalive(&self) -> Result<()> {
|
||||
let mut interval = IntervalStream::new(interval(Duration::from_secs(5)));
|
||||
while let Some(_update) = interval.next().await {
|
||||
if self.state.camera.ping().await.is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
futures::pending!(); // Never actually finish, has to be aborted
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn get_camera(&self) -> &BcCamera {
|
||||
&self.state.camera
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user