got webrtc working with controller-side connection
This commit is contained in:
parent
c5880964e7
commit
c41b9eb69c
5 changed files with 45 additions and 13 deletions
|
@ -30,7 +30,7 @@ impl Default for AppConfig {
|
|||
fn default() -> Self {
|
||||
AppConfig {
|
||||
cameras: vec![ConnectionString {
|
||||
ip: "10.0.0.29".to_owned(),
|
||||
ip: "127.0.0.1".to_owned(),
|
||||
port: 8765,
|
||||
}],
|
||||
|
||||
|
|
|
@ -133,11 +133,29 @@ pub async fn run_main_event_loop(
|
|||
});
|
||||
}
|
||||
ApplicationEvent::WebRTCMessage((name, msg)) => {
|
||||
info!(
|
||||
"Valid camera names are: {:?}",
|
||||
state
|
||||
.camera_satellites
|
||||
.iter()
|
||||
.map(|x| x.name.clone())
|
||||
.collect::<Vec<String>>()
|
||||
);
|
||||
info!("Reqested name is: {}", name);
|
||||
info!(
|
||||
"Count of is_connected: {}",
|
||||
state
|
||||
.camera_satellites
|
||||
.iter()
|
||||
.filter(|x| x.is_connected())
|
||||
.count()
|
||||
);
|
||||
for conn in state
|
||||
.camera_satellites
|
||||
.iter_mut()
|
||||
.filter(|x| x.name == name && x.is_connected())
|
||||
{
|
||||
info!("Sending message");
|
||||
if let Err(_) = conn.send(msg.clone()).await {
|
||||
error!("The websocket gave an error when I tried to send a message! I hope your logging is good enough");
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::sync::{atomic::AtomicBool, Arc};
|
|||
|
||||
use async_channel::TryRecvError;
|
||||
use tokio::runtime::Handle;
|
||||
use tracing::{error, instrument, warn};
|
||||
use tracing::{error, instrument, warn, info};
|
||||
|
||||
use crate::config::ConnectionString;
|
||||
|
||||
|
@ -19,9 +19,11 @@ pub struct SatelliteConnection {
|
|||
pub try_connecting: bool,
|
||||
connection: ConnectionString,
|
||||
|
||||
currently_connecting: bool,
|
||||
|
||||
to_socket: Option<AppSender>,
|
||||
from_socket: Option<AppReceiver>,
|
||||
socket_is_alive: Arc<AtomicBool>,
|
||||
socket_is_dead: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
impl SatelliteConnection {
|
||||
|
@ -34,29 +36,39 @@ impl SatelliteConnection {
|
|||
retry_attempts: 0,
|
||||
try_connecting: true,
|
||||
|
||||
currently_connecting: false,
|
||||
|
||||
to_socket: None,
|
||||
from_socket: None,
|
||||
socket_is_alive: Arc::new(AtomicBool::new(false)),
|
||||
socket_is_dead: Arc::new(AtomicBool::new(true)),
|
||||
}
|
||||
}
|
||||
|
||||
#[instrument(skip(self))]
|
||||
pub async fn close(&mut self) {
|
||||
self.socket_is_alive
|
||||
.store(false, std::sync::atomic::Ordering::SeqCst);
|
||||
self.socket_is_dead
|
||||
.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||
self.to_socket.take(); // closing all senders will dispose of the
|
||||
self.from_socket.take(); // channel
|
||||
}
|
||||
|
||||
#[instrument(skip(self))]
|
||||
pub fn is_connected(&self) -> bool {
|
||||
return self
|
||||
.socket_is_alive
|
||||
return !self
|
||||
.socket_is_dead
|
||||
.load(std::sync::atomic::Ordering::SeqCst);
|
||||
}
|
||||
|
||||
#[instrument(skip(self, rt))]
|
||||
pub async fn connect(&mut self, rt: Handle) {
|
||||
if self.currently_connecting
|
||||
|| !self
|
||||
.socket_is_dead
|
||||
.load(std::sync::atomic::Ordering::SeqCst)
|
||||
{
|
||||
return;
|
||||
}
|
||||
self.currently_connecting = true;
|
||||
match vcs_common::connect_to_server(self.connection.build_conn_string(), rt).await {
|
||||
Ok((sender, recvr, is_alive)) => {
|
||||
if let Err(e) = sender.send(ApplicationMessage::NameRequest(None)).await {
|
||||
|
@ -68,7 +80,8 @@ impl SatelliteConnection {
|
|||
}
|
||||
self.to_socket = Some(sender);
|
||||
self.from_socket = Some(recvr);
|
||||
self.socket_is_alive = is_alive;
|
||||
self.socket_is_dead = is_alive;
|
||||
self.currently_connecting = false;
|
||||
}
|
||||
Err(e) => {
|
||||
self.retry_attempts += 1;
|
||||
|
|
|
@ -106,12 +106,14 @@ fn main() {
|
|||
if message.is_some() {
|
||||
if let Err(e) =
|
||||
to_mec.send_blocking(ApplicationEvent::WebRTCMessage((
|
||||
"first".to_owned(),
|
||||
"CameraSatellite_1".to_owned(),
|
||||
message.unwrap(),
|
||||
)))
|
||||
{
|
||||
error!("Could not send to mec! {e}");
|
||||
}
|
||||
} else {
|
||||
error!("Could not deserialize ui webrtc message");
|
||||
}
|
||||
}
|
||||
None => {
|
||||
|
|
|
@ -14,7 +14,6 @@ pub struct TauriState {
|
|||
pub fn connect_to_camera(state: State<'_, TauriState>) {
|
||||
let mec = state.to_mec.clone();
|
||||
state.rt.spawn(async move {
|
||||
let _ = mec
|
||||
.send_blocking(ApplicationEvent::RetryDisconnectedSatellites);
|
||||
let _ = mec.send_blocking(ApplicationEvent::RetryDisconnectedSatellites);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue