refactor(core,gui): make all needed changes to send and receive files on linux and android

This commit is contained in:
Patryk Hegenberg 2024-05-27 21:09:24 +02:00
parent 351b7b9323
commit 0416ab6dab
12 changed files with 108 additions and 193 deletions

View file

@ -10,7 +10,7 @@ use tokio_tungstenite::{
};
use tracing::{debug, error};
pub async fn start_receiver(relay: &str, name: &str) -> Result<()> {
pub async fn start_receiver(filepath: String, relay: &str, name: &str) -> Result<()> {
let http_url = replace_protocol(relay);
let res = http_client::download_info(http_url.as_str(), name)
.await
@ -18,12 +18,24 @@ pub async fn start_receiver(relay: &str, name: &str) -> Result<()> {
debug!("Got room_id from Server: {:?}", res);
let res_ip = String::from("ws://") + res.ip.as_str() + ":9000";
if let Err(local_err) = start_ws_com(res_ip.as_str(), res.local_room_id.as_str()).await {
#[cfg(not(target_os = "android"))]
if let Err(local_err) = start_ws_com(
filepath.clone(),
res_ip.as_str(),
res.local_room_id.as_str(),
)
.await
{
debug!("Failed to connect local: {local_err}");
if let Err(relay_err) = start_ws_com(relay, res.relay_room_id.as_str()).await {
if let Err(relay_err) = start_ws_com(filepath, relay, res.relay_room_id.as_str()).await {
debug!("Failed to connect remote: {relay_err}");
}
}
#[cfg(target_os = "android")]
if let Err(relay_err) = start_ws_com(filepath, relay, res.relay_room_id.as_str()).await {
debug!("Failed to connect remote: {relay_err}");
}
let _success = http_client::download_success(http_url.as_str(), name)
.await
.map_err(|e| anyhow!("Failed to download success: {}", e))?;
@ -32,7 +44,7 @@ pub async fn start_receiver(relay: &str, name: &str) -> Result<()> {
Ok(())
}
pub async fn start_ws_com(relay: &str, name: &str) -> Result<()> {
pub async fn start_ws_com(filepath: String, relay: &str, name: &str) -> Result<()> {
let url = String::from(relay) + "/ws";
let mut request = url
.into_client_request()
@ -48,7 +60,7 @@ pub async fn start_ws_com(relay: &str, name: &str) -> Result<()> {
.await
{
Ok(Ok((socket, _))) => {
receiver::start(socket, name).await;
receiver::start(filepath, socket, name).await;
Ok(())
}
Ok(Err(e)) => {