Compare commits

..

2 commits

Author SHA1 Message Date
Nickiel12
1777b5e39f added support for running on non-webrtc OSs 2024-09-18 12:11:18 -07:00
Nickiel12
cf5e0f9386 version bumped deps 2024-09-18 12:10:49 -07:00
7 changed files with 140 additions and 70 deletions

83
Cargo.lock generated
View file

@ -198,17 +198,6 @@ dependencies = [
"pin-project-lite",
]
[[package]]
name = "async-recursion"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.77",
]
[[package]]
name = "async-stream"
version = "0.3.5"
@ -615,7 +604,7 @@ dependencies = [
"bitflags 1.3.2",
"block",
"cocoa-foundation",
"core-foundation",
"core-foundation 0.9.4",
"core-graphics",
"foreign-types",
"libc",
@ -630,7 +619,7 @@ checksum = "8c6234cbb2e4c785b456c0644748b1ac416dd045799740356f8363dfe00c93f7"
dependencies = [
"bitflags 1.3.2",
"block",
"core-foundation",
"core-foundation 0.9.4",
"core-graphics-types",
"libc",
"objc",
@ -770,6 +759,16 @@ dependencies = [
"libc",
]
[[package]]
name = "core-foundation"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b55271e5c8c478ad3f38ad24ef34923091e0548492a266d19b3c0b4d82574c63"
dependencies = [
"core-foundation-sys",
"libc",
]
[[package]]
name = "core-foundation-sys"
version = "0.8.7"
@ -783,7 +782,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb"
dependencies = [
"bitflags 1.3.2",
"core-foundation",
"core-foundation 0.9.4",
"core-graphics-types",
"foreign-types",
"libc",
@ -796,7 +795,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45390e6114f68f718cc7a830514a96f903cccd70d02a8f6d9f643ac4ba45afaf"
dependencies = [
"bitflags 1.3.2",
"core-foundation",
"core-foundation 0.9.4",
"libc",
]
@ -1611,9 +1610,9 @@ dependencies = [
[[package]]
name = "gilrs"
version = "0.10.10"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a556964c6d62458084356ce9770676f5104bd667e12e9a795691076e8a17c5cf"
checksum = "bbb2c998745a3c1ac90f64f4f7b3a54219fd3612d7705e7798212935641ed18f"
dependencies = [
"fnv",
"gilrs-core",
@ -1624,11 +1623,11 @@ dependencies = [
[[package]]
name = "gilrs-core"
version = "0.5.15"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "732dadc05170599ddec9a89653f10d7a2af54da9181b3fa6e2bd49907ec8f7e4"
checksum = "495af945e45efd6386227613cd9fb7bd7c43d3c095040e30c5304c489e6abed5"
dependencies = [
"core-foundation",
"core-foundation 0.10.0",
"inotify",
"io-kit-sys",
"js-sys",
@ -2138,11 +2137,11 @@ dependencies = [
[[package]]
name = "inotify"
version = "0.10.2"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fdd168d97690d0b8c412d6b6c10360277f4d7ee495c5d0d5d5fe0854923255cc"
checksum = "f37dccff2791ab604f9babef0ba14fbe0be30bd368dc541e2b08d07c8aa908f3"
dependencies = [
"bitflags 1.3.2",
"bitflags 2.6.0",
"inotify-sys",
"libc",
]
@ -4100,7 +4099,7 @@ dependencies = [
"cairo-rs",
"cc",
"cocoa",
"core-foundation",
"core-foundation 0.9.4",
"core-graphics",
"crossbeam-channel",
"dispatch",
@ -4518,18 +4517,6 @@ dependencies = [
"tokio",
]
[[package]]
name = "tokio-tungstenite"
version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c83b561d025642014097b66e6c1bb422783339e0909e4429cde4749d1990bc38"
dependencies = [
"futures-util",
"log",
"tokio",
"tungstenite 0.21.0",
]
[[package]]
name = "tokio-tungstenite"
version = "0.23.1"
@ -4542,6 +4529,18 @@ dependencies = [
"tungstenite 0.23.0",
]
[[package]]
name = "tokio-tungstenite"
version = "0.24.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "edc5f74e248dc973e0dbb7b74c7e0d6fcc301c694ff50049504004ef4d0cdcd9"
dependencies = [
"futures-util",
"log",
"tokio",
"tungstenite 0.24.0",
]
[[package]]
name = "tokio-util"
version = "0.7.12"
@ -4763,9 +4762,9 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
[[package]]
name = "tungstenite"
version = "0.21.0"
version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ef1a641ea34f399a848dea702823bbecfb4c486f911735368f1f137cb8257e1"
checksum = "6e2e2ce1e47ed2994fd43b04c8f618008d4cabdd5ee34027cf14f9d918edd9c8"
dependencies = [
"byteorder",
"bytes",
@ -4776,15 +4775,14 @@ dependencies = [
"rand 0.8.5",
"sha1",
"thiserror",
"url",
"utf-8",
]
[[package]]
name = "tungstenite"
version = "0.23.0"
version = "0.24.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e2e2ce1e47ed2994fd43b04c8f618008d4cabdd5ee34027cf14f9d918edd9c8"
checksum = "18e5b8366ee7a95b16d32197d0b2604b43a0be89dc5fac9f8e96ccafbaedda8a"
dependencies = [
"byteorder",
"bytes",
@ -4934,7 +4932,6 @@ name = "vcs-controller"
version = "2.0.0"
dependencies = [
"async-channel",
"async-recursion",
"bincode",
"config",
"console-subscriber",
@ -4950,7 +4947,7 @@ dependencies = [
"tauri",
"tauri-build",
"tokio",
"tokio-tungstenite 0.21.0",
"tokio-tungstenite 0.24.0",
"toml 0.8.19",
"tracing",
"tracing-appender",

View file

@ -17,28 +17,27 @@ tokio-logging = []
custom-protocol = [ "tauri/custom-protocol" ]
[dependencies]
async-channel = "2.2.0"
async-recursion = "1.1.1"
async-channel = "2.3.1"
bincode = "1.3.3"
config = "0.14.0"
futures = "0.3.30"
futures-core = "0.3.30"
futures-util = { version = "0.3.30" }
gilrs = "0.10.6"
log = "0.4.21"
serde = { version = "1.0.197", features = ["derive"] }
gilrs = "0.11.0"
log = "0.4.22"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1.37.0", features = ["rt-multi-thread", "time", "sync"] }
tokio-tungstenite = "0.21.0"
toml = "0.8.12"
tokio = { version = "1.40", features = ["rt-multi-thread", "time", "sync"] }
tokio-tungstenite = "0.24.0"
toml = "0.8.19"
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["tracing-log"] }
tracing-appender = "0.2.3"
snafu = "0.8.2"
snafu = "0.8.4"
console-subscriber = "0.3.0"
tauri = { version = "1.6.1", features = [] }
tauri = { version = "1.8", features = [] }
lazy_static = "1.5.0"
vcs-common = { git = "https://git.nickiel.net/VCC/vcs-common.git", branch = "main" }
bincode = "1.3.3"
futures = "0.3.30"

View file

@ -18,6 +18,7 @@ use joystick_source::joystick_loop;
use satellite_connection::SatelliteConnection;
pub enum ApplicationEvent {
SupportsWebRTC(bool),
WebRTCMessage((String, vcs_common::ApplicationMessage)),
JoystickMove(Point),
RetryDisconnectedSatellites,
@ -40,6 +41,7 @@ pub struct AppState {
to_mec: Sender<ApplicationEvent>,
mec: Receiver<ApplicationEvent>,
pub runtime: Handle,
pub has_webrtc_support: Option<bool>,
_config: Arc<tokio::sync::RwLock<AppConfig>>,
@ -70,6 +72,7 @@ impl AppState {
to_mec,
mec,
runtime: rt,
has_webrtc_support: None,
_config: config,
@ -119,14 +122,24 @@ pub async fn run_main_event_loop(
Err(TryRecvError::Closed) => break,
Ok(msg) => {
match msg {
ApplicationEvent::SupportsWebRTC(has_support) => {
state.has_webrtc_support = Some(has_support);
state
.camera_satellites
.iter_mut()
.filter(|x| x.is_connected())
.for_each(|x| {
x.send_blocking(
ApplicationMessage::ConnectionSupportsWebRTC(has_support),
state.runtime.clone(),
);
});
}
ApplicationEvent::Close => {
state.mec.close(); // cleanup is handled on reading from a closed mec
}
ApplicationEvent::RetryDisconnectedSatellites => {
state
.camera_satellites
.iter_mut()
.for_each(|x| {
state.camera_satellites.iter_mut().for_each(|x| {
info!("Resetting connections");
x.try_connecting = true;
x.retry_attempts = 0;
@ -202,14 +215,22 @@ pub async fn run_main_event_loop(
ApplicationMessage::ConnectionSupportsWebRTCRequest => {
let does_support_webrtc = true;
if let Err(e) = connection
.send(ApplicationMessage::ConnectionSupportsWebRTC(does_support_webrtc))
.send(ApplicationMessage::ConnectionSupportsWebRTC(
does_support_webrtc,
))
.await
{
info!("Was not able to send webrtc support status to remote: {:?}", e);
info!(
"Was not able to send webrtc support status to remote: {:?}",
e
);
}
}
ApplicationMessage::ConnectionSupportsWebRTC(does_support) => {
info!("Cool, the camera satellite supports webrtc: {}", does_support);
info!(
"Cool, the camera satellite supports webrtc: {}",
does_support
);
}
ApplicationMessage::WebRTCIceCandidateInit(pkt) => {
send_frontend_message(serde_json::to_string(&pkt).unwrap())

View file

@ -2,7 +2,7 @@ use std::sync::{atomic::AtomicBool, Arc};
use async_channel::TryRecvError;
use tokio::runtime::Handle;
use tracing::{error, instrument, warn, info};
use tracing::{error, info, instrument, warn};
use crate::config::ConnectionString;
@ -47,7 +47,13 @@ impl SatelliteConnection {
#[instrument(skip(self))]
pub async fn close(&mut self) {
if self.to_socket.is_some() {
if let Err(_) = self.to_socket.as_ref().unwrap().send(ApplicationMessage::CloseConnection).await {
if let Err(_) = self
.to_socket
.as_ref()
.unwrap()
.send(ApplicationMessage::CloseConnection)
.await
{
info!("Could not send close connection to active satellite");
}
}
@ -106,6 +112,20 @@ impl SatelliteConnection {
}
}
/// This is not the recommneded method, as it ignores error, but sometimes
/// you just really don't want to be async
#[instrument(skip(self))]
pub fn send_blocking(&mut self, msg: ApplicationMessage, rt: tokio::runtime::Handle) {
if self.to_socket.is_some() {
let sender = self.to_socket.as_ref().unwrap().clone();
rt.spawn(async move {
if let Err(e) = sender.send(msg).await {
error!("Unhandled send error while in send_blocking! {e}");
}
});
}
}
#[instrument(skip(self))]
pub async fn send(&mut self, msg: ApplicationMessage) -> Result<(), SatelliteConnectionError> {
if self.to_socket.is_some() {

View file

@ -74,7 +74,10 @@ fn main() {
to_mec: to_mec.clone(),
rt: handle2.clone(),
})
.invoke_handler(tauri::generate_handler![tauri_functions::connect_to_camera])
.invoke_handler(tauri::generate_handler![
tauri_functions::connect_to_camera,
tauri_functions::supports_webrtc
])
.setup(|app| {
*APP_HANDLE.lock().unwrap() = Some(app.handle());

View file

@ -17,3 +17,11 @@ pub fn connect_to_camera(state: State<'_, TauriState>) {
let _ = mec.send_blocking(ApplicationEvent::RetryDisconnectedSatellites);
});
}
#[tauri::command(rename_all="snake_case")]
pub fn supports_webrtc(has_support: bool, state: State<'_, TauriState>) {
let mec = state.to_mec.clone();
state.rt.spawn(async move {
let _ = mec.send_blocking(ApplicationEvent::SupportsWebRTC(has_support));
});
}

View file

@ -16,7 +16,29 @@ function call_camera_connect() {
async function init() {
console.log("Setting up");
document.getElementById("camera_connect_button").addEventListener("click", call_camera_connect);
let webrtc_support = supports_webrtc();
invoke("supports_webrtc", { has_support: webrtc_support });
if (webrtc_support) {
await rtc_init();
}
}
function supports_webrtc() {
var isWebRTCSupported = false;
['RTCPeerConnection', 'webkitRTCPeerConnection', 'mozRTCPeerConnection', 'RTCIceGatherer'].forEach(function(item) {
if (isWebRTCSupported) {
return;
}
if (item in window) {
isWebRTCSupported = true;
}
});
return isWebRTCSupported;
}
export { init };