moved ui handling to coordinator

This commit is contained in:
Nickiel12 2024-09-10 01:34:44 +00:00
parent 27ce4bceed
commit 66aa62de98
8 changed files with 193 additions and 188 deletions

102
Cargo.lock generated
View file

@ -4,9 +4,9 @@ version = 3
[[package]]
name = "addr2line"
version = "0.22.0"
version = "0.24.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678"
checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375"
dependencies = [
"gimli",
]
@ -99,9 +99,9 @@ dependencies = [
[[package]]
name = "anyhow"
version = "1.0.86"
version = "1.0.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
checksum = "10f00e1f6e58a40e807377c75c6a7f97bf9044fab57816f2414e6f5f4499d7b8"
[[package]]
name = "arc-swap"
@ -233,9 +233,9 @@ dependencies = [
[[package]]
name = "async-trait"
version = "0.1.81"
version = "0.1.82"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107"
checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1"
dependencies = [
"proc-macro2",
"quote",
@ -325,17 +325,17 @@ dependencies = [
[[package]]
name = "backtrace"
version = "0.3.73"
version = "0.3.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a"
checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a"
dependencies = [
"addr2line",
"cc",
"cfg-if",
"libc",
"miniz_oxide 0.7.4",
"miniz_oxide 0.8.0",
"object",
"rustc-demangle",
"windows-targets 0.52.6",
]
[[package]]
@ -455,9 +455,9 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
[[package]]
name = "bytemuck"
version = "1.17.1"
version = "1.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773d90827bc3feecfb67fab12e24de0749aad83c74b9504ecde46237b5cd24e2"
checksum = "94bbb0ad554ad961ddc5da507a12a29b14e4ae5bda06b19f575a3e6079d2e2ae"
[[package]]
name = "byteorder"
@ -516,9 +516,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.1.15"
version = "1.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57b6a275aa2903740dc87da01c62040406b8812552e97129a63ea8850a17c6e6"
checksum = "b62ac837cdb5cb22e10a256099b4fc502b1dfe560cb282963a974d7abd80e476"
dependencies = [
"shlex",
]
@ -802,9 +802,9 @@ dependencies = [
[[package]]
name = "cpufeatures"
version = "0.2.13"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51e852e6dc9a5bed1fae92dd2375037bf2b768725bf3be87811edee3249d09ad"
checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0"
dependencies = [
"libc",
]
@ -1645,9 +1645,9 @@ dependencies = [
[[package]]
name = "gimli"
version = "0.29.0"
version = "0.31.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd"
checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64"
[[package]]
name = "gio"
@ -1732,9 +1732,9 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]]
name = "globset"
version = "0.4.14"
version = "0.4.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57da3b9b5b85bd66f31093f8c408b90a74431672542466497dcbdfdc02034be1"
checksum = "15f1ce686646e7f1e19bf7d5533fe443a45dbfb990e00629110797578b42fb19"
dependencies = [
"aho-corasick",
"bstr",
@ -2079,9 +2079,9 @@ dependencies = [
[[package]]
name = "ignore"
version = "0.4.22"
version = "0.4.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b46810df39e66e925525d6e38ce1e7f6e1d208f72dc39757880fcb66e2c58af1"
checksum = "6d89fd380afde86567dfba715db065673989d6253f42b88179abd3eae47bda4b"
dependencies = [
"crossbeam-deque",
"globset",
@ -2207,9 +2207,9 @@ dependencies = [
[[package]]
name = "ipnet"
version = "2.9.0"
version = "2.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3"
checksum = "187674a687eed5fe42285b40c6291f9a01517d415fad1c3cbc6a9f778af7fcd4"
[[package]]
name = "itertools"
@ -2808,9 +2808,9 @@ dependencies = [
[[package]]
name = "parking"
version = "2.2.0"
version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae"
checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba"
[[package]]
name = "parking_lot"
@ -2868,9 +2868,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
[[package]]
name = "pest"
version = "2.7.11"
version = "2.7.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd53dff83f26735fdc1ca837098ccf133605d794cdae66acfc2bfac3ec809d95"
checksum = "9c73c26c01b8c87956cea613c907c9d6ecffd8d18a2a5908e5de0adfaa185cea"
dependencies = [
"memchr",
"thiserror",
@ -2879,9 +2879,9 @@ dependencies = [
[[package]]
name = "pest_derive"
version = "2.7.11"
version = "2.7.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a548d2beca6773b1c244554d36fcf8548a8a58e74156968211567250e48e49a"
checksum = "664d22978e2815783adbdd2c588b455b1bd625299ce36b2a99881ac9627e6d8d"
dependencies = [
"pest",
"pest_generator",
@ -2889,9 +2889,9 @@ dependencies = [
[[package]]
name = "pest_generator"
version = "2.7.11"
version = "2.7.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c93a82e8d145725dcbaf44e5ea887c8a869efdcc28706df2d08c69e17077183"
checksum = "a2d5487022d5d33f4c30d91c22afa240ce2a644e87fe08caad974d4eab6badbe"
dependencies = [
"pest",
"pest_meta",
@ -2902,9 +2902,9 @@ dependencies = [
[[package]]
name = "pest_meta"
version = "2.7.11"
version = "2.7.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a941429fea7e08bedec25e4f6785b6ffaacc6b755da98df5ef3e7dcf4a124c4f"
checksum = "0091754bbd0ea592c4deb3a122ce8ecbb0753b738aa82bc055fcc2eccc8d8174"
dependencies = [
"once_cell",
"pest",
@ -3529,9 +3529,9 @@ dependencies = [
[[package]]
name = "rustix"
version = "0.38.35"
version = "0.38.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a85d50532239da68e9addb745ba38ff4612a242c1c7ceea689c4bc7c2f43c36f"
checksum = "3f55e80d50763938498dd5ebb18647174e0c76dc38c5505294bb224624f30f36"
dependencies = [
"bitflags 2.6.0",
"errno",
@ -3562,9 +3562,9 @@ checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0"
[[package]]
name = "rustls-webpki"
version = "0.102.7"
version = "0.102.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84678086bd54edf2b415183ed7a94d0efb049f1b646a33e22a36f3794be6ae56"
checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9"
dependencies = [
"ring",
"rustls-pki-types",
@ -3661,18 +3661,18 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.209"
version = "1.0.210"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09"
checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.209"
version = "1.0.210"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170"
checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f"
dependencies = [
"proc-macro2",
"quote",
@ -3681,9 +3681,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.127"
version = "1.0.128"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8043c06d9f82bd7271361ed64f415fe5e12a77fdb52e573e7f06a516dea329ad"
checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8"
dependencies = [
"indexmap 2.5.0",
"itoa 1.0.11",
@ -4092,9 +4092,9 @@ dependencies = [
[[package]]
name = "tao"
version = "0.16.9"
version = "0.16.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "575c856fc21e551074869dcfaad8f706412bd5b803dfa0fbf6881c4ff4bfafab"
checksum = "48d298c441a1da46e28e8ad8ec205aab7fd8cd71b9d10e05454224eef422e1ae"
dependencies = [
"bitflags 1.3.2",
"cairo-rs",
@ -4507,9 +4507,9 @@ dependencies = [
[[package]]
name = "tokio-stream"
version = "0.1.15"
version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "267ac89e0bec6e691e5813911606935d77c476ff49024f98abcea3e7b15e37af"
checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1"
dependencies = [
"futures-core",
"pin-project-lite",
@ -4542,9 +4542,9 @@ dependencies = [
[[package]]
name = "tokio-util"
version = "0.7.11"
version = "0.7.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1"
checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a"
dependencies = [
"bytes",
"futures-core",
@ -4914,7 +4914,7 @@ checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
name = "vcs-common"
version = "0.1.0"
source = "git+https://git.nickiel.net/VCC/vcs-common.git?branch=main#a70172133856dc5e776bcfc0ab16405e534e198a"
source = "git+https://git.nickiel.net/VCC/vcs-common.git?branch=main#01495ff1d8d105de485f0c746251cd471176d1cc"
dependencies = [
"async-channel",
"bincode",

View file

@ -9,7 +9,7 @@ tauri-build = { version = "1.5.1", features = [] }
[features]
tracker-state-debug = []
tokio-debug = []
tokio-logging = []
# this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled.
# If you use cargo directly instead of tauri's cli you can use this feature flag to switch between tauri's `dev` and `build` modes.

View file

@ -86,7 +86,7 @@ pub async fn joystick_loop(tx: Sender<ApplicationEvent>, is_alive: Arc<AtomicBoo
count_zeros = 0;
}
match tx.try_send(ApplicationEvent::Move(Point {
match tx.try_send(ApplicationEvent::JoystickMove(Point {
x: curr_x,
y: curr_y,
})) {

View file

@ -1,38 +1,52 @@
use std::fmt::Display;
use std::sync::{atomic::AtomicBool, Arc};
use std::time::Duration;
use async_channel::{Receiver, Sender, TryRecvError};
use tauri::Manager;
use tokio::runtime::Handle;
use tracing::info;
use tracing::{error, info};
use vcs_common::ApplicationMessage;
use crate::config::AppConfig;
use crate::sources::joystick_source::joystick_loop;
use crate::APP_HANDLE;
mod satellite_connection;
mod joystick_source;
use joystick_source::joystick_loop;
use satellite_connection::SatelliteConnection;
pub enum ApplicationEvent {
WebRTCMessage,
Move(Point),
WebRTCMessage((String, vcs_common::ApplicationMessage)),
JoystickMove(Point),
Close,
}
#[derive(Debug)]
pub struct Point {
pub x: i32,
pub y: i32,
}
impl Display for Point {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "({}, {})", self.x, self.y)
}
}
pub struct AppState {
to_mec: Sender<ApplicationEvent>,
mec: Receiver<ApplicationEvent>,
pub runtime: Handle,
config: Arc<tokio::sync::RwLock<AppConfig>>,
_config: Arc<tokio::sync::RwLock<AppConfig>>,
pub target_satellite: Option<usize>,
pub camera_satellites: Vec<SatelliteConnection>,
pub endpoint_satellites: Vec<SatelliteConnection>,
pub _endpoint_satellites: Vec<SatelliteConnection>,
pub joystick_task_is_alive: Arc<AtomicBool>,
}
@ -57,10 +71,12 @@ impl AppState {
mec,
runtime: rt,
config,
_config: config,
target_satellite: None,
camera_satellites,
endpoint_satellites: vec![],
_endpoint_satellites: vec![],
joystick_task_is_alive: Arc::new(AtomicBool::new(false)),
}
@ -76,13 +92,13 @@ impl AppState {
Arc::clone(&self.joystick_task_is_alive),
));
}
}
}
pub async fn run_main_event_loop(
mec: Receiver<ApplicationEvent>,
to_mec: Sender<ApplicationEvent>,
to_ui: Sender<ApplicationEvent>,
config: Arc<tokio::sync::RwLock<AppConfig>>,
rt: Handle,
) {
@ -92,42 +108,92 @@ pub async fn run_main_event_loop(
match state.mec.try_recv() {
Err(TryRecvError::Empty) => tokio::time::sleep(Duration::from_millis(50)).await,
Err(TryRecvError::Closed) => {
state.joystick_task_is_alive.store(false, std::sync::atomic::Ordering::SeqCst);
let close_handles: Vec<_> = state
.camera_satellites
.iter_mut()
.filter(|x| x.is_connected())
.map(|x| {
x.close()
})
.collect();
futures::future::join_all(close_handles).await;
break;
}
Err(TryRecvError::Closed) => break,
Ok(msg) => match msg {
ApplicationEvent::Close => {
state.mec.close(); // cleanup is handled on reading from a closed mec
}
ApplicationEvent::WebRTCMessage => {
ApplicationEvent::WebRTCMessage((name, msg)) => {
for conn in state
.camera_satellites
.iter_mut()
.filter(|x| x.name == name && x.is_connected())
{
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");
}
}
}
ApplicationEvent::Move(_coord) => {
ApplicationEvent::JoystickMove(coord) => {
if let Some(target) = state.target_satellite {
if state.camera_satellites.len() < target {
if let Err(e) = state.camera_satellites[target]
.send(ApplicationMessage::ManualMovementOverride((
coord.x, coord.y,
)))
.await
{
error!("There was an error sending the joystick movement message to the target! {:?}", e);
}
} else {
error!("That was not a valid target! Need to notifiy the UI about this");
}
}
}
}
}
for connection in state.camera_satellites.iter_mut() {
match connection.try_next().await {
Some(_msg) => {
info!("You have Mail!");
Some(msg) => match msg {
ApplicationMessage::NameRequest(None) => {
if let Err(e) = connection.send(ApplicationMessage::NameRequest(Some("Controller".to_owned()))).await {
info!("Was not able to send name to remote? {:?}", e);
}
}
ApplicationMessage::NameRequest(Some(name)) => connection.name = name,
ApplicationMessage::ChangeTrackingID(_) => {}
ApplicationMessage::ManualMovementOverride(_) => {}
ApplicationMessage::TrackingBoxes(_update) => {
}
ApplicationMessage::WebRTCIceCandidateInit(pkt) => {
send_frontend_message(serde_json::to_string(&pkt).unwrap())
}
ApplicationMessage::WebRTCIceCandidate(pkt) => {
send_frontend_message(serde_json::to_string(&pkt).unwrap())
}
ApplicationMessage::WebRTCPacket(pkt) => {
send_frontend_message(serde_json::to_string(&pkt).unwrap())
}
}
None => {}
}
}
}
state
.joystick_task_is_alive
.store(false, std::sync::atomic::Ordering::SeqCst);
let close_handles: Vec<_> = state
.camera_satellites
.iter_mut()
.filter(|x| x.is_connected())
.map(|x| x.close())
.collect();
futures::future::join_all(close_handles).await;
}
pub fn send_frontend_message(message: String) {
if let Ok(mut e) = APP_HANDLE.lock() {
if e.is_none() {
return;
} else {
let handle = e.take().unwrap();
handle.emit_all("frontend_message", message)
.expect("Could not send message to the tauri frontend!");
}
}
}

View file

@ -8,12 +8,13 @@ use crate::config::ConnectionString;
use vcs_common::{AppReceiver, AppSender, ApplicationMessage};
enum SatelliteConnectionError {
#[derive(Debug)]
pub enum SatelliteConnectionError {
SocketIsClosed,
}
pub struct SatelliteConnection {
name: String,
pub name: String,
connection: ConnectionString,
to_socket: Option<AppSender>,
@ -31,20 +32,22 @@ impl SatelliteConnection {
to_socket: None,
from_socket: None,
socket_is_alive: Arc::new(AtomicBool::new(false)),
}
}
#[instrument(skip(self))]
pub async fn close(&mut self) {
self.socket_is_alive.store(false, std::sync::atomic::Ordering::SeqCst);
self.to_socket.take(); // closing all senders will dispose of the
self.socket_is_alive
.store(false, 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.load(std::sync::atomic::Ordering::SeqCst);
return self
.socket_is_alive
.load(std::sync::atomic::Ordering::SeqCst);
}
#[instrument(skip(self, rt))]
@ -52,21 +55,28 @@ impl SatelliteConnection {
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 {
error!("Couldn't send message to fresh socket sender! '{}' \n {}", self.connection.build_conn_string(), e);
error!(
"Couldn't send message to fresh socket sender! '{}' \n {}",
self.connection.build_conn_string(),
e
);
}
self.to_socket = Some(sender);
self.from_socket = Some(recvr);
self.socket_is_alive = is_alive;
}
Err(e) => {
error!("Could not connect to socket remote: '{}' \n {}", self.connection.build_conn_string(), e);
error!(
"Could not connect to socket remote: '{}' \n {}",
self.connection.build_conn_string(),
e
);
}
}
}
#[instrument(skip(self))]
pub async fn send(&mut self, msg: ApplicationMessage) -> Result<(), SatelliteConnectionError> {
if self.to_socket.is_some() {
if let Err(_) = self.to_socket.as_ref().unwrap().send(msg).await {
self.close().await;
@ -81,18 +91,16 @@ impl SatelliteConnection {
pub async fn try_next(&mut self) -> Option<ApplicationMessage> {
if self.from_socket.is_some() {
match self.from_socket.as_ref().unwrap().try_recv() {
Ok(msg) => {
match msg {
ApplicationMessage::NameRequest(Some(name)) => {
self.name = name;
None
}
ApplicationMessage::NameRequest(None) => {
warn!("Got a request for a name, ignoring");
None
},
_ => Some(msg)
Ok(msg) => match msg {
ApplicationMessage::NameRequest(Some(name)) => {
self.name = name;
None
}
ApplicationMessage::NameRequest(None) => {
warn!("Got a request for a name, ignoring");
None
}
_ => Some(msg),
},
Err(TryRecvError::Empty) => None,
Err(TryRecvError::Closed) => {

View file

@ -3,10 +3,7 @@
use async_channel::Sender;
use lazy_static::lazy_static;
use std::{
sync::{Arc, Mutex},
time::Duration,
};
use std::sync::{Arc, Mutex};
use tauri::{AppHandle, Manager};
use tokio::{runtime, sync::RwLock};
use tracing::{self, debug, error, info};
@ -14,13 +11,11 @@ use tracing::{self, debug, error, info};
#[cfg(not(debug_assertions))]
use tracing_subscriber;
use vcs_common::ApplicationMessage;
use webrtc_remote::start_listener;
use crate::config::{load_config, AppConfig};
mod config;
mod coordinator;
mod sources;
mod tauri_functions;
mod webrtc_remote;
@ -28,7 +23,6 @@ use coordinator::{run_main_event_loop, ApplicationEvent};
lazy_static! {
static ref TO_MEC_REF: Mutex<Option<Sender<ApplicationEvent>>> = Mutex::new(None);
static ref TO_WEBRTC: Mutex<Option<Sender<ApplicationMessage>>> = Mutex::new(None);
static ref APP_HANDLE: Mutex<Option<AppHandle>> = Mutex::new(None);
}
@ -55,6 +49,7 @@ fn main() {
}
let (to_mec, mec) = async_channel::bounded::<ApplicationEvent>(10);
let (to_ui, ui_ec) = async_channel::bounded::<ApplicationEvent>(10);
info!("Logging intialized");
@ -63,78 +58,16 @@ fn main() {
let rt = runtime::Runtime::new().expect("Could not start tokio runtime");
let handle = rt.handle().clone();
let _coordinator = rt
.handle()
.spawn(run_main_event_loop(mec, to_mec.clone(), config, handle));
let _coordinator = rt.handle().spawn(run_main_event_loop(
mec,
to_mec.clone(),
to_ui,
config,
handle,
));
*TO_MEC_REF.lock().unwrap() = Some(to_mec.clone());
let (to_webrtc_send, to_webrtc_recv) =
async_channel::bounded::<vcs_common::ApplicationMessage>(10);
let (from_webrtc_send, from_webrtc_recv) =
async_channel::bounded::<vcs_common::ApplicationMessage>(10);
rt.handle()
.spawn(start_listener(to_webrtc_recv, from_webrtc_send));
*TO_WEBRTC.lock().unwrap() = Some(to_webrtc_send.clone());
rt.handle().spawn(async move {
while let Ok(msg) = from_webrtc_recv.recv().await {
let mut do_sleep = false;
{
if let Ok(mut e) = APP_HANDLE.lock() {
if e.is_none() {
do_sleep = true;
} else {
let handle = e.take().unwrap();
match msg {
vcs_common::ApplicationMessage::WebRTCPacket(msg) => {
debug!("Got a message from the webrtc connection! {:?}", msg);
handle
.emit_all(
"frontend_message",
serde_json::to_string(&msg).unwrap(),
)
.unwrap();
}
vcs_common::ApplicationMessage::WebRTCIceCandidateInit(msg) => {
debug!(
"Got an ICE init candidate from the webrtc connection! {:?}",
msg
);
handle
.emit_all(
"frontend_message",
serde_json::to_string(&msg).unwrap(),
)
.unwrap();
}
vcs_common::ApplicationMessage::WebRTCIceCandidate(msg) => {
debug!(
"Got an ICE candidate from the webrtc connection! {:?}",
msg
);
handle
.emit_all(
"frontend_message",
serde_json::to_string(&msg).unwrap(),
)
.unwrap();
}
}
*e = Some(handle);
}
}
}
if do_sleep {
tokio::time::sleep(Duration::from_millis(500)).await;
}
}
});
tauri::Builder::default()
.manage(tauri_functions::TauriState {
to_mec: to_mec.clone(),
@ -147,9 +80,9 @@ fn main() {
debug!("Got webrtc-message event from Tauri client! {:#?}", event);
match event.payload() {
Some(payload) => {
if let Ok(e) = TO_WEBRTC.lock() {
if let Ok(e) = TO_MEC_REF.lock() {
match e.as_ref() {
Some(to_webrtc) => {
Some(to_mec) => {
debug!("Sending message to the webrtc connection");
let message: Option<ApplicationMessage> = match payload {
s if s.starts_with("{\"type") => {
@ -169,7 +102,7 @@ fn main() {
};
if message.is_some() {
if let Err(e) = to_webrtc.send_blocking(message.unwrap()) {
if let Err(e) = to_mec.send_blocking(ApplicationEvent::WebRTCMessage(("first".to_owned(), message.unwrap()))) {
error!("Could not send to mec! {e}");
}
}

View file

@ -1 +0,0 @@
pub mod joystick_source;

View file

@ -10,8 +10,7 @@ pub struct TauriState {
#[tauri::command]
pub fn connect_to_camera(state: State<'_, TauriState>) {
// let _ = state
// .to_mec
// .send_blocking(ApplicationEvent::CameraConnectionPress);
info!("Connect to Camera button press event");
let _ = state
.to_mec
.send_blocking(ApplicationEvent::CameraConnectionPress);
}