Add pings to the camera while paused

This commit is contained in:
QuantumEntangledAndy committed 2023-08-21 11:00:45 +07:00
1 parent cc275ed02e
commit 48892344b8
2 files changed
+41 -7

No files matched your search

+26 -6
View File
@@ -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(())
}
}
+15 -1
View File
@@ -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
}