From d4004f812f66e8a608a44a314e219db78bd3763d Mon Sep 17 00:00:00 2001 From: Sulaiman AlRomaih Date: Sun, 8 Sep 2024 22:50:08 +0300 Subject: [PATCH 01/12] Remove file file reassembler, Add test dependencies. --- Cargo.lock | 105 +++++++++++++++++++++++++++++++++++++-- client/angular.json | 4 +- server/Cargo.toml | 6 ++- server/src/attachment.rs | 39 +-------------- server/src/lib.rs | 4 +- server/src/server.rs | 3 +- server/src/session.rs | 3 -- 7 files changed, 113 insertions(+), 51 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 59a83cc..2c72ba0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -77,7 +77,7 @@ dependencies = [ "flate2", "futures-core", "h2", - "http", + "http 0.2.12", "httparse", "httpdate", "itoa", @@ -95,6 +95,31 @@ dependencies = [ "zstd", ] +[[package]] +name = "actix-http-test" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "061d27c2a6fea968fdaca0961ff429d23a4ec878c4f68f5d08626663ade69c80" +dependencies = [ + "actix-codec", + "actix-rt", + "actix-server", + "actix-service", + "actix-tls", + "actix-utils", + "awc", + "bytes", + "futures-core", + "http 0.2.12", + "log", + "serde", + "serde_json", + "serde_urlencoded", + "slab", + "socket2", + "tokio", +] + [[package]] name = "actix-macros" version = "0.2.4" @@ -113,7 +138,7 @@ checksum = "13d324164c51f63867b57e73ba5936ea151b8a41a1d23d1031eeb9f70d0236f8" dependencies = [ "bytestring", "cfg-if", - "http", + "http 0.2.12", "regex", "regex-lite", "serde", @@ -159,6 +184,29 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "actix-test" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439022b5a7b5dac10798465029a9566e8e0cca7a6014541ed277b695691fac5f" +dependencies = [ + "actix-codec", + "actix-http", + "actix-http-test", + "actix-rt", + "actix-service", + "actix-utils", + "actix-web", + "awc", + "futures-core", + "futures-util", + "log", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", +] + [[package]] name = "actix-tls" version = "3.4.0" @@ -169,6 +217,8 @@ dependencies = [ "actix-service", "actix-utils", "futures-core", + "http 0.2.12", + "http 1.1.0", "impl-more", "openssl", "pin-project-lite", @@ -390,6 +440,39 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +[[package]] +name = "awc" +version = "3.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79049b2461279b886e46f1107efc347ebecc7b88d74d023dda010551a124967b" +dependencies = [ + "actix-codec", + "actix-http", + "actix-rt", + "actix-service", + "actix-tls", + "actix-utils", + "base64", + "bytes", + "cfg-if", + "cookie", + "derive_more 0.99.18", + "futures-core", + "futures-util", + "h2", + "http 0.2.12", + "itoa", + "log", + "mime", + "percent-encoding", + "pin-project-lite", + "rand", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", +] + [[package]] name = "backtrace" version = "0.3.73" @@ -716,9 +799,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ "futures-core", + "futures-sink", "futures-task", "pin-project-lite", "pin-utils", + "slab", ] [[package]] @@ -759,7 +844,7 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http", + "http 0.2.12", "indexmap", "slab", "tokio", @@ -790,6 +875,17 @@ dependencies = [ "itoa", ] +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + [[package]] name = "httparse" version = "1.9.4" @@ -1247,11 +1343,14 @@ dependencies = [ "actix-broker", "actix-http", "actix-rt", + "actix-test", "actix-web", "actix-web-actors", "base64", + "bytes", "derive_more 1.0.0", "env_logger", + "futures-util", "log", "names", "openssl", diff --git a/client/angular.json b/client/angular.json index de96bfc..f8a8f8a 100644 --- a/client/angular.json +++ b/client/angular.json @@ -95,8 +95,8 @@ "development": { "buildTarget": "client:build:development", "ssl": true, - "sslKey": "../../../../../certs/key.pem", - "sslCert": "../../../../../certs/cert.pem", + "sslKey": "../certs/key.pem", + "sslCert": "../certs/cert.pem", "port": 443 }, "docker": { diff --git a/server/Cargo.toml b/server/Cargo.toml index c5f050d..4419900 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -12,7 +12,6 @@ actix = "0.13" actix-broker = "0.4" actix-web = { version = "4.7", features = ["openssl"] } actix-web-actors = "4.1" -actix-rt = "2.5" actix-http = "3.9.0" uuid = { version = "1.10", features = ["v4"] } @@ -25,6 +24,9 @@ base64 = "0.22.1" env_logger = "0.11" log = "0.4" rand = "0.8" +bytes = "1" [dev-dependencies] -actix-rt = "2.5" \ No newline at end of file +actix-rt = "2.2" +actix-test = "0.1" +futures-util = { version = "0.3.17", default-features = false, features = ["std"] } \ No newline at end of file diff --git a/server/src/attachment.rs b/server/src/attachment.rs index 9e6d166..76e37da 100644 --- a/server/src/attachment.rs +++ b/server/src/attachment.rs @@ -1,46 +1,11 @@ -use std::collections::HashMap; - use actix_web_actors::ws; use base64::{engine::general_purpose, Engine as _}; use crate::{ - message::FileChunkMetadata, ChatMessage, FileReassembler, ServerError, WsChatServer, - WsChatSession, MAX_FRAME_SIZE, + message::FileChunkMetadata, ChatMessage, ServerError, WsChatServer, WsChatSession, + MAX_FRAME_SIZE, }; -impl FileReassembler { - pub fn new(total_chunks: usize) -> Self { - FileReassembler { - chunks: HashMap::new(), - total_chunks, - } - } - - pub fn add_chunk(&mut self, index: usize, data: Vec) -> Result<(), ServerError> { - if index >= self.total_chunks { - return Err(ServerError::IndexOutOfBounds); - } - self.chunks.insert(index, data); - Ok(()) - } - - pub fn is_complete(&self) -> bool { - self.chunks.len() == self.total_chunks - } - - pub fn reassemble(&self) -> Result, ServerError> { - let mut file_data = Vec::new(); - for i in 0..self.total_chunks { - if let Some(chunk) = self.chunks.get(&i) { - file_data.extend(chunk); - } else { - return Err(ServerError::ChunkMissing); - } - } - Ok(file_data) - } -} - impl WsChatServer { #[allow(dead_code)] pub fn send_chat_attachment( diff --git a/server/src/lib.rs b/server/src/lib.rs index d84778d..ff45b74 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -10,8 +10,8 @@ mod session_manager; pub use error::ServerError; pub use message::{ - ChatMessage, ClientMetadata, FileReassembler, JoinRoom, LeaveRoom, ListRooms, SendFile, - SendMessage, WsChatServer, WsChatSession, + ChatMessage, ClientMetadata, JoinRoom, LeaveRoom, ListRooms, SendFile, SendMessage, + WsChatServer, WsChatSession, }; pub use session_manager::SessionManager; diff --git a/server/src/server.rs b/server/src/server.rs index dde02d1..637fb8f 100644 --- a/server/src/server.rs +++ b/server/src/server.rs @@ -1,6 +1,5 @@ -use std::collections::HashMap; -use std::collections::hash_map::Entry::Vacant; use actix::prelude::*; +use std::collections::{hash_map::Entry::Vacant, HashMap}; use crate::message::{ChatMessage, Client, ClientMetadata, Room, WsChatServer}; diff --git a/server/src/session.rs b/server/src/session.rs index 0adc3bb..1e829b5 100644 --- a/server/src/session.rs +++ b/server/src/session.rs @@ -1,5 +1,3 @@ -use std::collections::HashMap; - use actix::prelude::*; use actix_broker::BrokerIssue; use actix_web_actors::ws; @@ -19,7 +17,6 @@ impl WsChatSession { id: 0, room: "main".to_owned(), name, - file_reassemblers: HashMap::new(), } } From 27a89ffd317439030cb6ccddab31d0cafa96cccf Mon Sep 17 00:00:00 2001 From: Sulaiman AlRomaih Date: Sun, 20 Oct 2024 14:58:59 +0300 Subject: [PATCH 02/12] Modify the chat component. - Split every service to be alone. - update the send file transfer and send message to be through webrtc. --- .../src/app/features/chat/chat.component.html | 19 +- .../src/app/features/chat/chat.component.ts | 245 +++++++++++------- 2 files changed, 162 insertions(+), 102 deletions(-) diff --git a/client/src/app/features/chat/chat.component.html b/client/src/app/features/chat/chat.component.html index a90ea47..6729d82 100644 --- a/client/src/app/features/chat/chat.component.html +++ b/client/src/app/features/chat/chat.component.html @@ -47,6 +47,17 @@

{{ msg }}

+ + +
+

+ You have an incoming file: + {{ incomingFile.fileName }} + ({{ incomingFile.fileSize | number }} bytes) +

+ + +
@@ -63,13 +74,13 @@ required /> - + - +